Class: VagrantPlugins::VCloud::Action::PowerOn

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PowerOn

Returns a new instance of PowerOn.



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

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_vcloud::action::power_on')
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vagrant-vcloud/action/power_on.rb', line 10

def call(env)
  @env = env

  cfg = env[:machine].provider_config
  cnx = cfg.vcloud_cnx.driver

  # add vm metadata
  if !cfg..nil?
    env[:ui].info('Setting VM metadata...')
     = cnx. env[:machine].id, cfg.
    cnx.wait_task_completion()
  end

  # add/update hardware
  env[:ui].info('Setting VM hardware...')
  set_vm_hardware = cnx.set_vm_hardware(env[:machine].id, cfg)
  if set_vm_hardware
    wait = cnx.wait_task_completion(set_vm_hardware)
    unless wait[:errormsg].nil?
      fail Errors::ModifyVAppError, :message => wait[:errormsg]
    end
  end
  set_vm_network_connected = cnx.set_vm_network_connected(env[:machine].id)
  if set_vm_network_connected
    env[:ui].info('Connecting all NICs...')
    wait = cnx.wait_task_completion(set_vm_network_connected)
    unless wait[:errormsg].nil?
      fail Errors::ModifyVAppError, :message => wait[:errormsg]
    end
  end

  # enable nested hypervisor
  if !cfg.nested_hypervisor.nil? && cfg.nested_hypervisor == true
    env[:ui].info('Enabling nested hypervisor...')
    set_vm_nested_hypervisor = cnx.set_vm_nested_hypervisor(env[:machine].id, true)
    if set_vm_nested_hypervisor
      wait = cnx.wait_task_completion(set_vm_nested_hypervisor)
      unless wait[:errormsg].nil?
        fail Errors::ModifyVAppError, :message => wait[:errormsg]
      end
    end
  end

  # set ovf properties
  if !cfg.ovf_properties.nil?
    env[:ui].info('Setting VM OVF Properties...')
    set_ovf_properties = cnx.set_ovf_properties(env[:machine].id, cfg.ovf_properties)
    if set_ovf_properties
      wait = cnx.wait_task_completion(set_ovf_properties)
      unless wait[:errormsg].nil?
        fail Errors::SetOvfPropertyError, :message => wait[:errormsg]
      end
    end
  end

  if cfg.power_on.nil? || cfg.power_on == true
    env[:ui].info('Powering on VM...')
    poweron_vm = cnx.poweron_vm(env[:machine].id)
    wait = cnx.wait_task_completion(poweron_vm)
    unless wait[:errormsg].nil?
      fail Errors::PoweronVAppError, :message => wait[:errormsg]
    end
  end

  @app.call(env)
end