Class: VagrantPlugins::VCloud::Action::PowerOffVApp

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vcloud/action/power_off_vapp.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PowerOffVApp

Returns a new instance of PowerOffVApp.



5
6
7
8
# File 'lib/vagrant-vcloud/action/power_off_vapp.rb', line 5

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

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vagrant-vcloud/action/power_off_vapp.rb', line 10

def call(env)
  cfg = env[:machine].provider_config
  cnx = cfg.vcloud_cnx.driver

  vapp_id = env[:machine].get_vapp_id

  test_vapp = cnx.get_vapp(vapp_id)

  @logger.debug(
    "Number of VMs in the vApp: #{test_vapp[:vms_hash].count}"
  )

  # this is a helper to get vapp_edge_ip into cache for later destroy
  # of edge gateway rules
  vapp_edge_ip = cnx.get_vapp_edge_public_ip(vapp_id) if cfg.network_bridge.nil?

  # Poweroff vApp
  env[:ui].info('Single VM left in the vApp, Powering off vApp...')
  vapp_stop_task = cnx.poweroff_vapp(vapp_id)
  vapp_stop_wait = cnx.wait_task_completion(vapp_stop_task)

  unless vapp_stop_wait[:errormsg].nil?
    fail Errors::StopVAppError, :message => vapp_stop_wait[:errormsg]
  end

  @app.call env
end