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, #connection
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
#_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
#create_internet_services(internet_spec) ⇒ Object
133
134
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
|
# File 'lib/fog/terremark/models/shared/server.rb', line 133
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 = connection.internetservices.create({
"Name" => self.name,
"Protocol" => proto,
"Port" => port,
})
internet_service_id = inet_services.Id
public_ip_info = inet_services.PublicIpAddress
else
inet_services = connection.internetservices.create({
"public_ip_address_id" => public_ip_info["Id"],
"Name" => self.name,
"Protocol" => proto,
"Port" => port,
}
)
internet_service_id = inet_services.Id
end
connection.nodeservices.create({"Name" => self.name,
"IpAddress" => self.IpAddress,
"Port" => port,
"InternetServiceId" => internet_service_id
})
end
end
true
end
|
#delete_internet_services ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/fog/terremark/models/shared/server.rb', line 60
def delete_internet_services
while (service = internet_services.pop) do
nodes = connection.nodeservices.all(service.Id)
nodes.select { |item| item.destroy }
service.destroy(delete_public_ip = !(internet_services.size > 0))
end
true
end
|
#graceful_restart ⇒ Object
126
127
128
129
130
131
|
# File 'lib/fog/terremark/models/shared/server.rb', line 126
def graceful_restart
requires :id
shutdown
wait_for { off? }
power_on
end
|
#internet_services ⇒ Object
56
57
58
|
# File 'lib/fog/terremark/models/shared/server.rb', line 56
def internet_services
@internet_services ||= connection.internetservices.all.select {|item| item.Name == self.name}
end
|
#off? ⇒ Boolean
83
84
85
|
# File 'lib/fog/terremark/models/shared/server.rb', line 83
def off?
status == VAppStatus::POWERED_OFF
end
|
#on? ⇒ Boolean
79
80
81
|
# File 'lib/fog/terremark/models/shared/server.rb', line 79
def on?
status == VAppStatus::POWERED_ON
end
|
#power_off ⇒ Object
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/fog/terremark/models/shared/server.rb', line 98
def power_off
requires :id
begin
connection.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
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/fog/terremark/models/shared/server.rb', line 87
def power_on(options = {})
requires :id
begin
connection.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
120
121
122
123
124
|
# File 'lib/fog/terremark/models/shared/server.rb', line 120
def power_reset
requires :id
connection.power_reset(id)
true
end
|
#PublicIpAddress ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/fog/terremark/models/shared/server.rb', line 48
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’}
75
76
77
|
# File 'lib/fog/terremark/models/shared/server.rb', line 75
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(connection.get_vapp(id).body)
end
|
#save ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/fog/terremark/models/shared/server.rb', line 171
def save
requires :name
if powerOn
end
data = connection.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
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/fog/terremark/models/shared/server.rb', line 109
def shutdown
requires :id
begin
connection.power_shutdown(id)
rescue Excon::Errors::InternalServerError => e
raise e unless e.to_s =~ /because it is already powered off/
end
true
end
|