Class: Fog::Compute::HPV2::Server
- Inherits:
-
Server
show all
- Defined in:
- lib/fog/hp/models/compute_v2/server.rb
Instance Attribute Summary collapse
Attributes inherited from Server
#ssh_options, #ssh_port
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
Methods inherited from Server
#scp, #scp_download, #ssh, #ssh_ip_address, #ssh_ip_address=, #sshable?
Methods inherited from Model
#inspect, #reload, #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
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
45
46
47
48
49
50
51
52
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 45
def initialize(attributes = {})
self.min_count = attributes.delete(:min_count)
self.max_count = attributes.delete(:max_count)
self.block_device_mapping = attributes.delete(:block_device_mapping)
self.networks = attributes.delete(:networks)
super
end
|
Instance Attribute Details
#network_name ⇒ Object
103
104
105
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 103
def network_name
@network_name ||= get_first_network_with_public_ip
end
|
#password ⇒ Object
Returns the value of attribute password.
40
41
42
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 40
def password
@password
end
|
#private_key ⇒ Object
131
132
133
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 131
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
|
#private_key_path ⇒ Object
126
127
128
129
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 126
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
|
#public_key ⇒ Object
159
160
161
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 159
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
|
#public_key_path ⇒ Object
154
155
156
157
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 154
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
|
#username ⇒ Object
312
313
314
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 312
def username
@username ||= 'ubuntu'
end
|
Instance Method Details
#add_security_group(sg_name) ⇒ Object
254
255
256
257
258
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 254
def add_security_group(sg_name)
requires :id
service.add_security_group(id, sg_name)
true
end
|
#block_device_mapping=(new_block_device_mapping) ⇒ Object
181
182
183
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 181
def block_device_mapping=(new_block_device_mapping)
@block_device_mapping = new_block_device_mapping
end
|
#console_output(num_lines) ⇒ Object
73
74
75
76
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 73
def console_output(num_lines)
requires :id
service.get_console_output(id, num_lines)
end
|
#create_image(name, metadata = {}) ⇒ Object
def revert_resize
requires :id
service.revert_resized_server(id)
true
end
def confirm_resize
requires :id
service.confirm_resized_server(id)
true
end
228
229
230
231
232
233
234
235
236
237
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 228
def create_image(name, metadata = {})
requires :id
response = service.create_image(id, name, metadata)
begin
image_id = response.["Location"].match(/\/([^\/]+$)/)[1]
Fog::Compute::HPV2::Image.new(:collection => service.images, :service => service, :id => image_id)
rescue
nil
end
end
|
#destroy ⇒ Object
87
88
89
90
91
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 87
def destroy
requires :id
service.delete_server(id)
true
end
|
#flavor ⇒ Object
163
164
165
166
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 163
def flavor
requires :flavor_id
@flavor ||= service.flavors.get(flavor_id)
end
|
#image ⇒ Object
168
169
170
171
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 168
def image
requires :image_id
@image ||= service.images.get(image_id)
end
|
#key_pair ⇒ Object
93
94
95
96
97
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 93
def key_pair
requires :key_name
service.key_pairs.get(key_name)
end
|
#key_pair=(new_keypair) ⇒ Object
99
100
101
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 99
def key_pair=(new_keypair)
self.key_name = new_keypair && new_keypair.name
end
|
#max_count=(new_max_count) ⇒ Object
177
178
179
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 177
def max_count=(new_max_count)
@max_count = new_max_count
end
|
54
55
56
57
58
59
60
61
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 54
def metadata
@metadata ||= begin
Fog::Compute::HPV2::Metadata.new({
:service => service,
:parent => self
})
end
end
|
63
64
65
66
67
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 63
def metadata=(new_metadata={})
metas = []
new_metadata.each_pair {|k,v| metas << {'key' => k, 'value' => v} }
metadata.load(metas)
end
|
#min_count=(new_min_count) ⇒ Object
173
174
175
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 173
def min_count=(new_min_count)
@min_count = new_min_count
end
|
#network_names ⇒ Object
derive the network names from the addresses hash
108
109
110
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 108
def network_names
self.addresses.keys unless self.addresses.nil?
end
|
#networks=(new_networks) ⇒ Object
185
186
187
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 185
def networks=(new_networks)
@networks = new_networks
end
|
#private_ip_address ⇒ Object
122
123
124
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 122
def private_ip_address
private_ip_addresses.first if private_ip_addresses
end
|
#private_ip_addresses ⇒ Object
112
113
114
115
116
117
118
119
120
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 112
def private_ip_addresses
return nil if addresses.nil?
addr = []
addresses.each { |key, value|
ipaddr = value.first
addr << ipaddr["addr"] unless ipaddr.nil?
}
addr
end
|
#public_ip_address ⇒ Object
150
151
152
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 150
def public_ip_address
public_ip_addresses.first if public_ip_addresses
end
|
#public_ip_addresses ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 135
def public_ip_addresses
return nil if addresses.nil?
addr = []
addresses.each { |key, value|
if value.count > 1
value = value.dup
value.delete_at(0)
value.each { |ipaddr|
addr << ipaddr["addr"]
}
end
}
addr
end
|
#ready? ⇒ Boolean
189
190
191
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 189
def ready?
self.state == 'ACTIVE'
end
|
#reboot(type = 'SOFT') ⇒ Object
198
199
200
201
202
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 198
def reboot(type = 'SOFT')
requires :id
service.reboot_server(id, type)
true
end
|
#rebuild(image_id, name, options = {}) ⇒ Object
204
205
206
207
208
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 204
def rebuild(image_id, name, options={})
requires :id
service.rebuild_server(id, image_id, name, options)
true
end
|
#remove_security_group(sg_name) ⇒ Object
260
261
262
263
264
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 260
def remove_security_group(sg_name)
requires :id
service.remove_security_group(id, sg_name)
true
end
|
#save ⇒ Object
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 266
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :flavor_id, :name
meta_hash = {}
metadata.each { |meta| meta_hash.store(meta.key, meta.value) }
options = {
'metadata' => meta_hash,
'personality' => personality,
'accessIPv4' => accessIPv4,
'accessIPv6' => accessIPv6,
'min_count' => @min_count,
'max_count' => @max_count,
'key_name' => key_name,
'security_groups' => security_groups,
'config_drive' => config_drive,
'user_data' => user_data_encoded,
'availability_zone' => availability_zone,
'networks' => @networks
}
options = options.reject {|key, value| value.nil?}
if image_id
data = service.create_server(name, flavor_id, image_id, options)
elsif image_id.nil? && !@block_device_mapping.nil? && !@block_device_mapping.empty?
data = service.create_persistent_server(name, flavor_id, @block_device_mapping, options)
end
merge_attributes(data.body['server'])
true
end
|
#setup(credentials = {}) ⇒ Object
298
299
300
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 298
def setup(credentials = {})
requires :ssh_ip_address, :identity, :public_key, :username
Fog::SSH.new(ssh_ip_address, username, credentials).run([
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
%{passwd -l #{username}},
%{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
%{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
])
rescue Errno::ECONNREFUSED
sleep(1)
retry
end
|
#update_name(new_name) ⇒ Object
248
249
250
251
252
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 248
def update_name(new_name)
requires :id
service.update_server(id, :name => new_name)
true
end
|
#user_data=(ascii_userdata) ⇒ Object
69
70
71
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 69
def user_data=(ascii_userdata)
self.user_data_encoded = [ascii_userdata].pack('m') end
|
#vnc_console_url(type = 'novnc') ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 78
def vnc_console_url(type='novnc')
requires :id
if resp = service.get_vnc_console(id, type).body
resp['console']['url']
else
nil
end
end
|
#volume_attachments ⇒ Object
239
240
241
242
243
244
245
246
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 239
def volume_attachments
@volume_attachments ||= begin
Fog::Compute::HPV2::VolumeAttachments.new({
:service => service,
:server => self
})
end
end
|
#windows_password ⇒ Object
193
194
195
196
|
# File 'lib/fog/hp/models/compute_v2/server.rb', line 193
def windows_password
requires :id
service.get_windows_password(id)
end
|