Class: Fog::Vcloud::Terremark::Ecloud::Server
- Inherits:
-
Model
- Object
- Model
- Model
- Fog::Vcloud::Terremark::Ecloud::Server
show all
- Defined in:
- lib/fog/vcloud/terremark/ecloud/models/server.rb
Instance Attribute Summary
Attributes inherited from Model
#loaded
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Model
#load_unless_loaded!
Methods inherited from Model
#initialize, #inspect, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires
Constructor Details
This class inherits a constructor from Fog::Model
Instance Method Details
#add_disk(size) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 112
def add_disk(size)
if @disk_change == :deleted
raise RuntimeError, "Can't add a disk w/o saving changes or reloading"
else
@disk_change = :added
load_unless_loaded!
virtual_hardware[:Item] << { :ResourceType => '17',
:AddressOnParent => (disk_mess.map { |dm| dm[:AddressOnParent] }.sort.last.to_i + 1).to_s,
:VirtualQuantity => size.to_s }
end
true
end
|
#cpus ⇒ Object
82
83
84
85
86
87
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 82
def cpus
if cpu_mess
{ :count => cpu_mess[:VirtualQuantity].to_i,
:units => cpu_mess[:AllocationUnits] }
end
end
|
#cpus=(qty) ⇒ Object
89
90
91
92
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 89
def cpus=(qty)
@changed = true
cpu_mess[:VirtualQuantity] = qty.to_s
end
|
#delete ⇒ Object
72
73
74
75
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 72
def delete
requires :href
connection.delete_vapp( href)
end
|
#delete_disk(number) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 125
def delete_disk(number)
if @disk_change == :added
raise RuntimeError, "Can't delete a disk w/o saving changes or reloading"
else
@disk_change = :deleted
load_unless_loaded!
unless number == 0
virtual_hardware[:Item].delete_if { |vh| vh[:ResourceType] == '17' && vh[:AddressOnParent].to_i == number }
end
end
true
end
|
#disks ⇒ Object
106
107
108
109
110
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 106
def disks
disk_mess.map do |dm|
{ :number => dm[:AddressOnParent], :size => dm[:VirtualQuantity].to_i, :resource => dm[:HostResource] }
end
end
|
#friendly_status ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 20
def friendly_status
load_unless_loaded!
case status
when '0'
'creating'
when '2'
'off'
when '4'
'on'
else
'unkown'
end
end
|
#graceful_restart ⇒ Object
65
66
67
68
69
70
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 65
def graceful_restart
requires :href
shutdown
wait_for { off? }
power_on
end
|
#memory ⇒ Object
94
95
96
97
98
99
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 94
def memory
if memory_mess
{ :amount => memory_mess[:VirtualQuantity].to_i,
:units => memory_mess[:AllocationUnits] }
end
end
|
#memory=(amount) ⇒ Object
101
102
103
104
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 101
def memory=(amount)
@changed = true
memory_mess[:VirtualQuantity] = amount.to_s
end
|
#name=(new_name) ⇒ Object
77
78
79
80
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 77
def name=(new_name)
attributes[:name] = new_name
@changed = true
end
|
#off? ⇒ Boolean
44
45
46
47
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 44
def off?
load_unless_loaded!
status == '2'
end
|
#on? ⇒ Boolean
39
40
41
42
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 39
def on?
load_unless_loaded!
status == '4'
end
|
#power_off ⇒ Object
53
54
55
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 53
def power_off
power_operation( :power_off => :powerOff )
end
|
#power_on ⇒ Object
49
50
51
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 49
def power_on
power_operation( :power_on => :powerOn )
end
|
#power_reset ⇒ Object
61
62
63
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 61
def power_reset
power_operation( :power_reset => :reset )
end
|
#ready? ⇒ Boolean
34
35
36
37
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 34
def ready?
load_unless_loaded!
status == '2'
end
|
#reload ⇒ Object
138
139
140
141
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 138
def reload
reset_tracking
super
end
|
#save ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 143
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
connection.configure_vapp( href, _compose_vapp_data )
end
reset_tracking
end
|
#shutdown ⇒ Object
57
58
59
|
# File 'lib/fog/vcloud/terremark/ecloud/models/server.rb', line 57
def shutdown
power_operation( :power_shutdown => :shutdown )
end
|