Class: Fog::Compute::VcloudDirector::Vm

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/vcloud_director/models/compute/vm.rb

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #lazy_load_attrs, #make_attr_loaded_method, #make_lazy_load_method

Constructor Details

This class inherits a constructor from Fog::Compute::VcloudDirector::Model

Instance Method Details

#cpu=(new_cpu) ⇒ Object



148
149
150
151
152
153
154
155
156
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 148

def cpu=(new_cpu)
  has_changed = ( cpu != new_cpu.to_i )
  not_first_set = !cpu.nil?
  attributes[:cpu] = new_cpu.to_i
  if not_first_set && has_changed
    response = service.put_cpu(id, cpu)
    service.process_task(response.body)
  end
end

#customizationObject



121
122
123
124
125
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 121

def customization
  requires :id
  data = service.get_vm_customization(id).body
  service.vm_customizations.new(data)
end

#disksObject



133
134
135
136
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 133

def disks
  requires :id
  service.disks(:vm => self)
end

#memory=(new_memory) ⇒ Object



138
139
140
141
142
143
144
145
146
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 138

def memory=(new_memory)
  has_changed = ( memory != new_memory.to_i )
  not_first_set = !memory.nil?
  attributes[:memory] = new_memory.to_i
  if not_first_set && has_changed
    response = service.put_memory(id, memory)
    service.process_task(response.body)
  end
end

#networkObject



127
128
129
130
131
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 127

def network
  requires :id
  data = service.get_vm_network(id).body
  service.vm_networks.new(data)
end

#power_offObject

Power off the VM.



45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 45

def power_off
  requires :id
  begin
    response = service.post_power_off_vapp(id)
  rescue Fog::Compute::VcloudDirector::BadRequest => ex
    Fog::Logger.debug(ex.message)
    return false
  end
  service.process_task(response.body)
end

#power_onObject

Power on the VM.



57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 57

def power_on
  requires :id
  begin
    response = service.post_power_on_vapp(id)
  rescue Fog::Compute::VcloudDirector::BadRequest => ex
    Fog::Logger.debug(ex.message)
    return false
  end
  service.process_task(response.body)
end

#ready?Boolean

Returns:

  • (Boolean)


158
159
160
161
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 158

def ready?
  reload
  status == 'on'
end

#rebootObject

Reboot the VM.



69
70
71
72
73
74
75
76
77
78
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 69

def reboot
  requires :id
  begin
    response = service.post_reboot_vapp(id)
  rescue Fog::Compute::VcloudDirector::BadRequest => ex
    Fog::Logger.debug(ex.message)
    return false
  end
  service.process_task(response.body)
end

#reloadObject



22
23
24
25
26
27
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 22

def reload
  # when collection.vapp is nil, it means it's fatherless,
  # vms from different vapps are loaded in the same collection.
  # This situation comes from a "query" result
  collection.vapp.nil? ? reload_single_vm : super
end

#reload_single_vmObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 29

def reload_single_vm
  return unless data = begin
    collection.get_single_vm(identity)
  rescue Excon::Errors::SocketError
    nil
  end
  # these two attributes don't exists in the get_single_vm response
  # that's why i use the old attributes
  data.attributes[:vapp_id] = attributes[:vapp_id]
  data.attributes[:vapp_name] = attributes[:vapp_name]
  new_attributes = data.attributes
  merge_attributes(new_attributes)
  self
end

#resetObject

Reset the VM.



81
82
83
84
85
86
87
88
89
90
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 81

def reset
  requires :id
  begin
    response = service.post_reset_vapp(id)
  rescue Fog::Compute::VcloudDirector::BadRequest => ex
    Fog::Logger.debug(ex.message)
    return false
  end
  service.process_task(response.body)
end

#shutdownObject

Shut down the VM.



93
94
95
96
97
98
99
100
101
102
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 93

def shutdown
  requires :id
  begin
    response = service.post_shutdown_vapp(id)
  rescue Fog::Compute::VcloudDirector::BadRequest => ex
    Fog::Logger.debug(ex.message)
    return false
  end
  service.process_task(response.body)
end

#suspendObject

Suspend the VM.



105
106
107
108
109
110
111
112
113
114
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 105

def suspend
  requires :id
  begin
    response = service.post_suspend_vapp(id)
  rescue Fog::Compute::VcloudDirector::BadRequest => ex
    Fog::Logger.debug(ex.message)
    return false
  end
  service.process_task(response.body)
end

#tagsObject



116
117
118
119
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 116

def tags
  requires :id
  service.tags(:vm => self)
end

#vappObject



163
164
165
166
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 163

def vapp
  # get_by_metadata returns a vm collection where every vapp parent is orpahn
  collection.vapp ||= service.vapps.get(vapp_id)
end