lib/vagrant-vcenter/action/power_off.rb in vagrant-vcenter-0.3.2 vs lib/vagrant-vcenter/action/power_off.rb in vagrant-vcenter-0.3.3

- old
+ new

@@ -1,7 +1,5 @@ -require 'i18n' - module VagrantPlugins module VCenter module Action # This class powers off the VM that the Vagrant provider is managing. class PowerOff @@ -9,15 +7,14 @@ @app = app @logger = Log4r::Logger.new('vagrant_vcenter::action::poweroff') end def call(env) - config = env[:machine].provider_config - # FIXME: Raise a correct exception - dc = config.vcenter_cnx.serviceInstance.find_datacenter( - config.datacenter_name) or abort 'datacenter not found' - root_vm_folder = dc.vmFolder - vm = root_vm_folder.findByUuid(env[:machine].id) + cfg = env[:machine].provider_config + + vm = cfg.vmfolder.findByUuid(env[:machine].id) or + fail Errors::VMNotFound, + :vm_name => env[:machine].name # Poweroff VM env[:ui].info('Powering off VM...') vm.PowerOffVM_Task.wait_for_completion