Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new VM password lookup #187

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Unreleased

Fixed bugs:

- `store_passwd` would sometimes try to lookup an async job status without including the job id causing an exception being raised

# 1.5.1 (18 Apr 2019)

**Implemented enhancements:**
Expand Down
5 changes: 3 additions & 2 deletions lib/vagrant-cloudstack/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def create_vm
options = compose_server_creation_options

@server = @env[:cloudstack_compute].servers.create(options)
@server_job_id = @server.job_id
rescue Fog::Compute::Cloudstack::NotFound => e
# Invalid subnet doesn't have its own error so we catch and
# check the error message here.
Expand Down Expand Up @@ -759,14 +760,14 @@ def generate_ssh_keypair(keyname, account = nil, domainid = nil, projectid = nil
def store_password
password = nil
if @server.password_enabled and @server.respond_to?('job_id')
server_job_result = @env[:cloudstack_compute].query_async_job_result({:jobid => @server.job_id})
server_job_result = @env[:cloudstack_compute].query_async_job_result({:jobid => @server_job_id})
if server_job_result.nil?
@env[:ui].warn(' -- Failed to retrieve job_result for retrieving the password')
return
end

while true
server_job_result = @env[:cloudstack_compute].query_async_job_result({:jobid => @server.job_id})
server_job_result = @env[:cloudstack_compute].query_async_job_result({:jobid => @server_job_id})
if server_job_result['queryasyncjobresultresponse']['jobstatus'] != 0
password = server_job_result['queryasyncjobresultresponse']['jobresult']['virtualmachine']['password']
break
Expand Down
1 change: 1 addition & 0 deletions spec/vagrant-cloudstack/action/run_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@

allow(machine).to receive(:provider_config).and_return(provider_config)
expect(server).to receive(:wait_for).and_return(ready = true)
allow(server).to receive(:job_id).and_return(JOB_ID)
allow(server).to receive(:password_enabled).and_return(false)
expect(cloudstack_compute).to receive(:servers).and_return(servers)
allow(cloudstack_compute).to receive(:send).with(:list_zones, available: true, name: ZONE_NAME).and_return(list_zones_response)
Expand Down