Class: Fog::Vcloud::Compute::Server
Instance Attribute Summary
Attributes inherited from Model
#loaded
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
#friendly_status, #off?, #on?
Methods inherited from Model
has_up, #link_up, #load_unless_loaded!
Methods inherited from Model
#initialize, #inspect, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Method Details
permalink
#add_disk(size) ⇒ Object
[View source]
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 121
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
|
permalink
#computer_name ⇒ Object
[View source]
31
32
33
34
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 31
def computer_name
load_unless_loaded!
self.guest_customization[:ComputerName]
end
|
[View source]
90
91
92
93
94
95
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 90
def cpus
if cpu_mess
{ :count => cpu_mess[:"rasd:VirtualQuantity"].to_i,
:units => cpu_mess[:"rasd:AllocationUnits"] }
end
end
|
permalink
#cpus=(qty) ⇒ Object
[View source]
97
98
99
100
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 97
def cpus=(qty)
@changed = true
cpu_mess[:"rasd:VirtualQuantity"] = qty.to_s
end
|
permalink
#delete_disk(number) ⇒ Object
[View source]
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 137
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
|
permalink
#description=(description) ⇒ Object
[View source]
150
151
152
153
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 150
def description=(description)
@description_changed = true unless attributes[:description] == description || attributes[:description] == nil
attributes[:description] = description
end
|
permalink
#destroy ⇒ Object
Also known as:
delete
[View source]
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 201
def destroy
if on?
undeploy
wait_for { off? }
end
wait_for { off? }
wait_for { ready? }
sleep 2
connection.delete_vapp(href).body[:status] == "running"
end
|
[View source]
115
116
117
118
119
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 115
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
|
permalink
#graceful_restart ⇒ Object
[View source]
78
79
80
81
82
83
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 78
def graceful_restart
requires :href
shutdown
wait_for { off? }
power_on
end
|
permalink
#ip_addresses ⇒ Object
[View source]
46
47
48
49
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 46
def ip_addresses
load_unless_loaded!
[self.network_connections].flatten.collect{|n| n[:IpAddress] }
end
|
[View source]
102
103
104
105
106
107
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 102
def memory
if memory_mess
{ :amount => memory_mess[:"rasd:VirtualQuantity"].to_i,
:units => memory_mess[:"rasd:AllocationUnits"] }
end
end
|
permalink
#memory=(amount) ⇒ Object
[View source]
109
110
111
112
113
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 109
def memory=(amount)
@changed = true
@update_memory_value = amount
amount
end
|
permalink
#name=(name) ⇒ Object
[View source]
85
86
87
88
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 85
def name=(new_name)
attributes[:name] = new_name
@changed = true
end
|
[View source]
36
37
38
39
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 36
def os_desc
load_unless_loaded!
self.operating_system[:'ovf:Description']
end
|
[View source]
41
42
43
44
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 41
def os_type
load_unless_loaded!
self.operating_system[:vmw_osType]
end
|
permalink
#power_off ⇒ Object
[View source]
61
62
63
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 61
def power_off
power_operation( :power_off => :powerOff )
end
|
permalink
#power_on ⇒ Object
[View source]
57
58
59
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 57
def power_on
power_operation( :power_on => :powerOn )
end
|
permalink
#power_reset ⇒ Object
[View source]
69
70
71
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 69
def power_reset
power_operation( :power_reset => :reset )
end
|
[View source]
51
52
53
54
55
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 51
def ready?
reload_status
running_tasks = tasks && tasks.flatten.any? {|ti| ti.kind_of?(Hash) && ti[:status] == 'running' }
status != '0' && !running_tasks
end
|
[View source]
160
161
162
163
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 160
def reload
reset_tracking
super
end
|
[View source]
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 165
def save
if new_record?
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_memory_value
memory_mess[:"rasd:VirtualQuantity"] = @update_memory_value.to_s
connection.configure_vm_memory(memory_mess)
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
connection.configure_vm_disks(self.href, data)
end
if @disk_change == :added
data = disk_mess
data << @add_disk
connection.configure_vm_disks(self.href, data)
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]
connection.configure_vm_name_description(edit_uri, self.name, self.description)
end
end
reset_tracking
true
end
|
permalink
#shutdown ⇒ Object
[View source]
65
66
67
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 65
def shutdown
power_operation( :power_shutdown => :shutdown )
end
|
permalink
#undeploy ⇒ Object
This is the real power-off operation
[View source]
74
75
76
|
# File 'lib/fog/vcloud/models/compute/server.rb', line 74
def undeploy
connection.undeploy href
end
|