Class: VagrantPlugins::VCenter::Action::PowerOff

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vcenter/action/power_off.rb

Overview

This class powers off the VM that the Vagrant provider is managing.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PowerOff

Returns a new instance of PowerOff.



8
9
10
11
# File 'lib/vagrant-vcenter/action/power_off.rb', line 8

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_vcenter::action::poweroff')
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-vcenter/action/power_off.rb', line 13

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)

  # Poweroff VM
  env[:ui].info('Powering off VM...')
  vm.PowerOffVM_Task.wait_for_completion

  @app.call env
end