Class: VagrantPlugins::VCloud::Action::DestroyVApp

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ DestroyVApp

Returns a new instance of DestroyVApp.



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

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_vcloud::action::destroy_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vagrant-vcloud/action/destroy_vapp.rb', line 10

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

  cfg.org = cnx.get_organization_by_name(cfg.org_name)
  cfg.vdc_id = cnx.get_vdc_id_by_name(cfg.org, cfg.vdc_name)

  test_vapp = cnx.get_vapp(vapp_id)

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

  if cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway
    env[:ui].info(
      "Removing NAT rules on [#{cfg.vdc_edge_gateway}] " +
      "for IP [#{cfg.vdc_edge_gateway_ip}]."
    )
    @logger.debug(
      "Deleting Edge Gateway rules - vdc id: #{cfg.vdc_id}"
    )
    edge_remove = cnx.remove_edge_gateway_rules(
      cfg.vdc_edge_gateway,
      cfg.vdc_id,
      cfg.vdc_edge_gateway_ip,
      vapp_id
    )
    cnx.wait_task_completion(edge_remove)
  end

  env[:ui].info('Destroying vApp...')
  vapp_delete_task = cnx.delete_vapp(vapp_id)
  @logger.debug("vApp Delete task id #{vapp_delete_task}")
  cnx.wait_task_completion(vapp_delete_task)

  env[:machine].id = nil
  env[:machine].vappid = nil

  @app.call env
end