Class: Fog::Vcloud::Compute::Server
Instance Attribute Summary
Attributes inherited from Model
#loaded
Instance Method Summary
collapse
#friendly_status, #off?, #on?
Methods inherited from Model
has_up, #link_up, #load_unless_loaded!
Instance Method Details
#add_disk(size) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 158
def add_disk(size)
if @disk_change == :deleted
raise RuntimeError, "Can't add a disk w/o saving changes or reloading"
else
load_unless_loaded!
@disk_change = :added
@add_disk = {
:'rasd:HostResource' => {:vcloud_capacity => size},
:'rasd:AddressOnParent' => (disk_mess.map { |dm| dm[:'rasd:AddressOnParent'] }.sort.last.to_i + 1).to_s,
:'rasd:ResourceType' => '17'
}
end
true
end
|
#computer_name ⇒ Object
44
45
46
47
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 44
def computer_name
load_unless_loaded!
self.guest_customization[:ComputerName]
end
|
#cpus ⇒ Object
113
114
115
116
117
118
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 113
def cpus
if cpu_mess
{ :count => cpu_mess[:"rasd:VirtualQuantity"].to_i,
:units => cpu_mess[:"rasd:AllocationUnits"] }
end
end
|
#cpus=(qty) ⇒ Object
120
121
122
123
124
125
126
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 120
def cpus=(qty)
return if qty.nil? or qty.size == 0
@changed = true
@update_cpu_value = qty
qty
end
|
#customization_script ⇒ Object
34
35
36
37
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 34
def customization_script
load_unless_loaded!
self.guest_customization[:CustomizationScript]
end
|
#customization_script=(custom_script) ⇒ Object
39
40
41
42
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 39
def customization_script=(custom_script)
@changed = true
@update_custom_script = custom_script
end
|
#delete_disk(number) ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 174
def delete_disk(number)
if @disk_change == :added
raise RuntimeError, "Can't delete a disk w/o saving changes or reloading"
else
load_unless_loaded!
unless number == 0
@disk_change = :deleted
@remove_disk = number
end
end
true
end
|
#description=(description) ⇒ Object
187
188
189
190
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 187
def description=(description)
@description_changed = true unless attributes[:description] == description || attributes[:description] == nil
attributes[:description] = description
end
|
#destroy ⇒ Object
Also known as:
delete
268
269
270
271
272
273
274
275
276
277
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 268
def destroy
if on?
undeploy
wait_for { off? }
end
wait_for { off? } wait_for { ready? } sleep 2 service.delete_vapp(href).body[:status] == "running"
end
|
#disks ⇒ Object
152
153
154
155
156
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 152
def disks
disk_mess.map do |dm|
{ :number => dm[:"rasd:AddressOnParent"].to_i, :size => dm[:"rasd:HostResource"][:vcloud_capacity].to_i, :resource => dm[:"rasd:HostResource"], :disk_data => dm }
end
end
|
#graceful_restart ⇒ Object
91
92
93
94
95
96
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 91
def graceful_restart
requires :href
shutdown
wait_for { off? }
power_on
end
|
#ip_addresses ⇒ Object
59
60
61
62
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 59
def ip_addresses
load_unless_loaded!
[self.network_connections].flatten.map{|n| n[:IpAddress] }
end
|
#memory ⇒ Object
128
129
130
131
132
133
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 128
def memory
if memory_mess
{ :amount => memory_mess[:"rasd:VirtualQuantity"].to_i,
:units => memory_mess[:"rasd:AllocationUnits"] }
end
end
|
#memory=(amount) ⇒ Object
135
136
137
138
139
140
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 135
def memory=(amount)
return if amount.nil? or amount.size == 0
@changed = true
@update_memory_value = amount
amount
end
|
#name=(name) ⇒ Object
98
99
100
101
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 98
def name=(new_name)
attributes[:name] = new_name
@changed = true
end
|
#network ⇒ Object
142
143
144
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 142
def network
network_connections[:NetworkConnection] if network_connections
end
|
#network=(network_info) ⇒ Object
146
147
148
149
150
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 146
def network=(network_info)
@changed = true
@update_network = network_info
network_info
end
|
#os_desc ⇒ Object
49
50
51
52
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 49
def os_desc
load_unless_loaded!
self.operating_system[:'ovf:Description']
end
|
#os_type ⇒ Object
54
55
56
57
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 54
def os_type
load_unless_loaded!
self.operating_system[:vmw_osType]
end
|
#password ⇒ Object
103
104
105
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 103
def password
guest_customization[:AdminPassword]
end
|
#password=(password) ⇒ Object
107
108
109
110
111
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 107
def password=(password)
return if password.nil? or password.size == 0
@changed = true
@update_password = password
end
|
#power_off ⇒ Object
74
75
76
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 74
def power_off
power_operation( :power_off => :powerOff )
end
|
#power_on ⇒ Object
70
71
72
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 70
def power_on
power_operation( :power_on => :powerOn )
end
|
#power_reset ⇒ Object
82
83
84
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 82
def power_reset
power_operation( :power_reset => :reset )
end
|
#ready? ⇒ Boolean
64
65
66
67
68
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 64
def ready?
reload_status running_tasks = self.tasks && self.tasks.flatten.any? {|ti| ti.kind_of?(Hash) && ti[:status] == 'running' }
status != '0' && !running_tasks end
|
#reload ⇒ Object
197
198
199
200
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 197
def reload
reset_tracking
super
end
|
#save ⇒ Object
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 202
def save
unless persisted?
raise RuntimeError, "Should not be here"
else
if on?
if @changed
raise RuntimeError, "Can't save cpu, name or memory changes while the VM is on."
end
end
if @update_custom_script
guest_customization[:CustomizationScript] = @update_custom_script.to_s
service.configure_vm_customization_script(guest_customization)
wait_for { ready? }
end
if @update_password
guest_customization[:AdminPassword] = @update_password.to_s
service.configure_vm_password(guest_customization)
wait_for { ready? }
end
if @update_cpu_value
cpu_mess[:"rasd:VirtualQuantity"] = @update_cpu_value.to_s
service.configure_vm_cpus(cpu_mess)
wait_for { ready? }
end
if @update_memory_value
memory_mess[:"rasd:VirtualQuantity"] = @update_memory_value.to_s
service.configure_vm_memory(memory_mess)
wait_for { ready? }
end
if @update_network
network_connections[:NetworkConnection][:network] = @update_network[:network_name]
network_connections[:NetworkConnection][:IpAddressAllocationMode] = @update_network[:network_mode]
service.configure_vm_network(network_connections)
wait_for { ready? }
end
if @disk_change == :deleted
data = disk_mess.delete_if do |vh|
vh[:'rasd:ResourceType'] == '17' &&
vh[:'rasd:AddressOnParent'].to_s == @remove_disk.to_s
end
service.configure_vm_disks(self.href, data)
wait_for { ready? }
end
if @disk_change == :added
data = disk_mess
data << @add_disk
service.configure_vm_disks(self.href, data)
wait_for { ready? }
end
if @name_changed || @description_changed
edit_uri = links.select {|i| i[:rel] == 'edit'}
edit_uri = edit_uri.kind_of?(Array) ? edit_uri.flatten[0][:href] : edit_uri[:href]
service.configure_vm_name_description(edit_uri, self.name, self.description)
wait_for { ready? }
end
end
reset_tracking
true
end
|
#shutdown ⇒ Object
78
79
80
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 78
def shutdown
power_operation( :power_shutdown => :shutdown )
end
|
30
31
32
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 30
def tags
Fog::Vcloud::Compute::Tags.new(:service => service, :href => href + '/metadata')
end
|
#undeploy ⇒ Object
This is the real power-off operation
87
88
89
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 87
def undeploy
service.undeploy href
end
|