lib/vagrant-vcenter/action/suspend.rb in vagrant-vcenter-0.3.2 vs lib/vagrant-vcenter/action/suspend.rb in vagrant-vcenter-0.3.3
- old
+ new
@@ -1,7 +1,5 @@
-require 'i18n'
-
module VagrantPlugins
module VCenter
module Action
# This class suspends the VM when it's powered on.
class Suspend
@@ -9,15 +7,14 @@
@app = app
@logger = Log4r::Logger.new('vagrant_vcenter::action::suspend')
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('Suspending VM...')
vm.SuspendVM_Task.wait_for_completion