lib/vagrant-vcloud/action/power_on.rb in vagrant-vcloud-0.4.4 vs lib/vagrant-vcloud/action/power_on.rb in vagrant-vcloud-0.4.6
- old
+ new
@@ -11,27 +11,54 @@
@env = env
cfg = env[:machine].provider_config
cnx = cfg.vcloud_cnx.driver
- env[:ui].info('Setting VM hardware...')
+ # add vm metadata
+ if !cfg.metadata_vm.nil?
+ env[:ui].info('Setting VM metadata...')
+ set_metadata_vm = cnx.set_vm_metadata env[:machine].id, cfg.metadata_vm
+ cnx.wait_task_completion(set_metadata_vm)
+ end
+ # add/update hardware
+ env[:ui].info('Setting VM hardware...')
set_vm_hardware = cnx.set_vm_hardware(env[:machine].id, cfg)
if set_vm_hardware
- cnx.wait_task_completion(set_vm_hardware)
+ wait = cnx.wait_task_completion(set_vm_hardware)
+ unless wait[:errormsg].nil?
+ fail Errors::ModifyVAppError, :message => wait[:errormsg]
+ end
end
+ set_vm_network_connected = cnx.set_vm_network_connected(env[:machine].id)
+ if set_vm_network_connected
+ env[:ui].info('Connecting all NICs...')
+ wait = cnx.wait_task_completion(set_vm_network_connected)
+ unless wait[:errormsg].nil?
+ fail Errors::ModifyVAppError, :message => wait[:errormsg]
+ end
+ end
- env[:ui].info('Powering on VM...')
-
- if ! cfg.nested_hypervisor.nil?
- set_vm_nested_hypervisor = cnx.set_vm_nested_hypervisor(env[:machine].id, cfg.nested_hypervisor)
+ # enable nested hypervisor
+ if !cfg.nested_hypervisor.nil? && cfg.nested_hypervisor == true
+ env[:ui].info('Enabling nested hypervisor...')
+ set_vm_nested_hypervisor = cnx.set_vm_nested_hypervisor(env[:machine].id, true)
if set_vm_nested_hypervisor
- cnx.wait_task_completion(set_vm_nested_hypervisor)
+ wait = cnx.wait_task_completion(set_vm_nested_hypervisor)
+ unless wait[:errormsg].nil?
+ fail Errors::ModifyVAppError, :message => wait[:errormsg]
+ end
end
end
- poweron_vm = cnx.poweron_vm(env[:machine].id)
- cnx.wait_task_completion(poweron_vm)
+ if cfg.power_on.nil? || cfg.power_on == true
+ env[:ui].info('Powering on VM...')
+ poweron_vm = cnx.poweron_vm(env[:machine].id)
+ wait = cnx.wait_task_completion(poweron_vm)
+ unless wait[:errormsg].nil?
+ fail Errors::PoweronVAppError, :message => wait[:errormsg]
+ end
+ end
@app.call(env)
end
end
end