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
|
# File 'lib/vagrant-vcloud/action/read_state.rb', line 16
def read_state(env)
begin
cfg = env[:machine].provider_config
cnx = cfg.vcloud_cnx.driver
vapp_id = env[:machine].get_vapp_id
vm_name = cfg.name ? cfg.name.to_sym : env[:machine].name
if env[:machine].id.nil?
@logger.info("VM [#{vm_name}] is not created yet")
return :not_created
end
vapp = cnx.get_vapp(vapp_id)
vm_status = vapp[:vms_hash][vm_name][:status]
if vm_status == 'stopped'
@logger.info("VM [#{vm_name}] is stopped")
return :stopped
elsif vm_status == 'running'
@logger.info("VM [#{vm_name}] is running")
return :running
elsif vm_status == 'paused'
@logger.info("VM [#{vm_name}] is suspended")
return :suspended
end
rescue Exception => e
@logger.debug("Couldn't Read VM State: #{e.message}")
raise VagrantPlugins::VCloud::Errors::VCloudError,
:message => e.message
end
end
|