Class: Fog::Terremark::Shared::Server
- Inherits:
-
Model
- Object
- Model
- Fog::Terremark::Shared::Server
show all
- Defined in:
- lib/fog/terremark/models/shared/server.rb
Instance Attribute Summary
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
Methods inherited from Model
#initialize, #inspect, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#connection, #connection=, #prepare_service_value
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Method Details
#create_internet_services(internet_spec) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/fog/terremark/models/shared/server.rb', line 135
def create_internet_services(internet_spec)
public_ip_info = nil
internet_service_id = nil
internet_spec.each do |proto, ports|
for port in ports
if not public_ip_info
inet_services = service.internetservices.create({
"Name" => self.name,
"Protocol" => proto,
"Port" => port,
})
internet_service_id = inet_services.Id
public_ip_info = inet_services.PublicIpAddress
else
inet_services = service.internetservices.create({
"public_ip_address_id" => public_ip_info["Id"],
"Name" => self.name,
"Protocol" => proto,
"Port" => port,
}
)
internet_service_id = inet_services.Id
end
service.nodeservices.create({"Name" => self.name,
"IpAddress" => self.IpAddress,
"Port" => port,
"InternetServiceId" => internet_service_id
})
end
end
true
end
|
#delete_internet_services ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/fog/terremark/models/shared/server.rb', line 62
def delete_internet_services
while (inet_service = internet_services.pop) do
nodes = service.nodeservices.all(inet_service.Id)
nodes.select { |item| item.destroy }
inet_service.destroy(delete_public_ip = !(internet_services.size > 0))
end
true
end
|
#destroy ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/fog/terremark/models/shared/server.rb', line 36
def destroy
case self.status
when VAppStatus::BEING_CREATED, VAppStatus::BEING_DEPLOYED
return false
when VAppStatus::POWERED_ON
data = service.power_off(self.id).body
wait_for { off? }
end
wait_for { ready? }
service.delete_vapp(self.id)
true
end
|
#graceful_restart ⇒ Object
128
129
130
131
132
133
|
# File 'lib/fog/terremark/models/shared/server.rb', line 128
def graceful_restart
requires :id
shutdown
wait_for { off? }
power_on
end
|
#internet_services ⇒ Object
58
59
60
|
# File 'lib/fog/terremark/models/shared/server.rb', line 58
def internet_services
@internet_services ||= service.internetservices.all.select {|item| item.Name == self.name}
end
|
#off? ⇒ Boolean
85
86
87
|
# File 'lib/fog/terremark/models/shared/server.rb', line 85
def off?
status == VAppStatus::POWERED_OFF
end
|
#on? ⇒ Boolean
81
82
83
|
# File 'lib/fog/terremark/models/shared/server.rb', line 81
def on?
status == VAppStatus::POWERED_ON
end
|
#power_off ⇒ Object
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/fog/terremark/models/shared/server.rb', line 100
def power_off
requires :id
begin
service.power_off(id)
rescue Excon::Errors::InternalServerError => e
raise e unless e.to_s =~ /because it is already powered off/
end
true
end
|
#power_on(options = {}) ⇒ Object
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/fog/terremark/models/shared/server.rb', line 89
def power_on(options = {})
requires :id
begin
service.power_on(id)
rescue Excon::Errors::InternalServerError => e
raise e unless e.to_s =~ /because it is already powered on/
end
true
end
|
#power_reset ⇒ Object
122
123
124
125
126
|
# File 'lib/fog/terremark/models/shared/server.rb', line 122
def power_reset
requires :id
service.power_reset(id)
true
end
|
#PublicIpAddress ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/fog/terremark/models/shared/server.rb', line 50
def PublicIpAddress
@PublicIpAddress ||=
if internet_services.size > 0
internet_services[0].PublicIpAddress["Name"]
end
@PublicIpAddress
end
|
#ready? ⇒ Boolean
{ ‘0’ => ‘Being created’, ‘2’ => ‘Powered Off’, ‘4’ => ‘Powered On’}
77
78
79
|
# File 'lib/fog/terremark/models/shared/server.rb', line 77
def ready?
status == VAppStatus::POWERED_OFF
end
|
#reload ⇒ Object
33
34
35
|
# File 'lib/fog/terremark/models/shared/server.rb', line 33
def reload
merge_attributes(service.get_vapp(id).body)
end
|
#save ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/fog/terremark/models/shared/server.rb', line 173
def save
requires :name
if powerOn
end
data = service.instantiate_vapp_template(
server_name=name,
vapp_template=image,
options={
'ssh_key_fingerprint' => sshkeyFingerPrint,
'cpus' => vcpus,
'memory' => memory
})
merge_attributes(data.body)
wait_for { ready? }
if powerOn
power_on
wait_for { ready? }
end
true
end
|
#shutdown ⇒ Object
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/fog/terremark/models/shared/server.rb', line 111
def shutdown
requires :id
begin
service.power_shutdown(id)
rescue Excon::Errors::InternalServerError => e
raise e unless e.to_s =~ /because it is already powered off/
end
true
end
|