diff --git a/Gemfile.lock b/Gemfile.lock index 80e99067..2f301c3a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,7 @@ GEM erubis (2.7.0) excon (0.62.0) ffi (1.9.23) + ffi (1.9.23-x64-mingw32) fission (0.5.0) CFPropertyList (~> 2.2) fog (2.0.0) @@ -230,6 +231,8 @@ GEM net-ssh (4.2.0) nokogiri (1.8.2) mini_portile2 (~> 2.3.0) + nokogiri (1.8.2-x64-mingw32) + mini_portile2 (~> 2.3.0) nori (2.6.0) rake (10.5.0) rb-fsevent (0.10.3) @@ -291,6 +294,7 @@ GEM PLATFORMS ruby + x64-mingw32 DEPENDENCIES coveralls diff --git a/lib/vagrant-cloudstack/action/read_winrm_info.rb b/lib/vagrant-cloudstack/action/read_winrm_info.rb index a643c09d..993238c1 100644 --- a/lib/vagrant-cloudstack/action/read_winrm_info.rb +++ b/lib/vagrant-cloudstack/action/read_winrm_info.rb @@ -43,15 +43,13 @@ def read_winrm_info(cloudstack, machine) # the username via winrm_info ... yet ;-) # Read password from file into domain_config - if domain_config.vm_password.nil? - vmcredentials_file = machine.data_dir.join("vmcredentials") - if vmcredentials_file.file? - vmcredentials_password = nil - File.read(vmcredentials_file).each_line do |line| - vmcredentials_password = line.strip - end - domain_config.vm_password = vmcredentials_password + vmcredentials_file = machine.data_dir.join("vmcredentials") + if vmcredentials_file.file? + vmcredentials_password = nil + File.read(vmcredentials_file).each_line do |line| + vmcredentials_password = line.strip end + domain_config.vm_password = vmcredentials_password end transport_info = transport_info.merge({ diff --git a/lib/vagrant-cloudstack/action/run_instance.rb b/lib/vagrant-cloudstack/action/run_instance.rb index 12917d52..fb83d498 100644 --- a/lib/vagrant-cloudstack/action/run_instance.rb +++ b/lib/vagrant-cloudstack/action/run_instance.rb @@ -37,7 +37,9 @@ def call(env) store_volumes - store_password + password = wait_for_password + + store_password(password) configure_networking @@ -381,6 +383,14 @@ def get_communicator_short_name(communicator) communicator_short_names[communicator.class.name] end + def get_communicator_connect_attempts(communicator) + communicator_connect_attempts = { + 'VagrantPlugins::CommunicatorSSH::Communicator' => 40, + 'VagrantPlugins::CommunicatorWinRM::Communicator' => 1 + } + return communicator_connect_attempts[communicator.class.name].nil? ? 1 : communicator_connect_attempts[communicator.class.name] + end + def evaluate_pf_private_port return unless @domain_config.pf_private_port.nil? @@ -488,9 +498,8 @@ def apply_port_forwarding_rule(rule) if response['queryasyncjobresultresponse']['jobstatus'] != 0 port_forwarding_rule = response['queryasyncjobresultresponse']['jobresult']['portforwardingrule'] break - else - sleep 2 end + sleep 2 end rescue Fog::Compute::Cloudstack::Error => e raise Errors::FogError, :message => e.message @@ -717,9 +726,8 @@ def apply_firewall_rule(acl_name, options, response_string, type_string) if response['queryasyncjobresultresponse']['jobstatus'] != 0 firewall_rule = response['queryasyncjobresultresponse']['jobresult'][type_string] break - else - sleep 2 end + sleep 2 end rescue Fog::Compute::Cloudstack::Error => e if e.message =~ /The range specified,.*conflicts with rule/ @@ -756,13 +764,13 @@ def generate_ssh_keypair(keyname, account = nil, domainid = nil, projectid = nil @domain_config.keypair = sshkeypair['name'] end - def store_password + def wait_for_password password = nil - if @server.password_enabled and @server.respond_to?('job_id') + + if @server.respond_to?('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 + raise 'ERROR -- Failed to retrieve job_result' end while true @@ -770,21 +778,33 @@ def store_password if server_job_result['queryasyncjobresultresponse']['jobstatus'] != 0 password = server_job_result['queryasyncjobresultresponse']['jobresult']['virtualmachine']['password'] break - else - sleep 2 end + sleep 2 end @env[:ui].info("Password of virtualmachine: #{password}") - # Set the password on the current communicator - @domain_config.vm_password = password + end - # Save password to file - vmcredentials_file = @env[:machine].data_dir.join('vmcredentials') - vmcredentials_file.open('w') do |f| - f.write("#{password}") - end + password + end + + def store_password(password) + unless @server.password_enabled + @env[:ui].info("VM is not password-enabled. Using virtualmachine password from config") + if @domain_config.vm_password.nil? + fail "No vm_password configured but VM is not password enabled either!" + end + password = @domain_config.vm_password + end + + # Save password to file + vmcredentials_file = @env[:machine].data_dir.join('vmcredentials') + vmcredentials_file.open('w') do |f| + f.write("#{password}") end + + # Set the password on the current communicator + @domain_config.vm_password = password end def store_volumes @@ -829,15 +849,18 @@ def wait_for_communicator_ready @env[:metrics]['instance_ssh_time'] = Util::Timer.time do # Wait for communicator to be ready. communicator_short_name = get_communicator_short_name(@env[:machine].communicate) + communicator_connect_attempts = get_communicator_connect_attempts(@env[:machine].communicate) @env[:ui].info( I18n.t('vagrant_cloudstack.waiting_for_communicator', communicator: communicator_short_name.to_s.upcase) ) - while true + connection_attempt = 0 + while connection_attempt