Class: Fog::Compute::HP::Server
- Inherits:
-
Server
show all
- Defined in:
- lib/fog/hp/models/compute/server.rb
Instance Attribute Summary collapse
Attributes inherited from Server
#ssh_port
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
Methods inherited from Server
#scp, #scp_download, #ssh, #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.
42
43
44
45
46
47
48
|
# File 'lib/fog/hp/models/compute/server.rb', line 42
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)
super
end
|
Instance Attribute Details
#flavor_id ⇒ Object
141
142
143
|
# File 'lib/fog/hp/models/compute/server.rb', line 141
def flavor_id
@flavor_id ||= (flavor.nil? ? nil : flavor["id"])
end
|
#image_id ⇒ Object
133
134
135
|
# File 'lib/fog/hp/models/compute/server.rb', line 133
def image_id
@image_id ||= (image.nil? ? nil : image["id"])
end
|
#network_name ⇒ Object
90
91
92
|
# File 'lib/fog/hp/models/compute/server.rb', line 90
def network_name
@network_name ||= "private"
end
|
#password ⇒ Object
Returns the value of attribute password.
37
38
39
|
# File 'lib/fog/hp/models/compute/server.rb', line 37
def password
@password
end
|
#private_key ⇒ Object
104
105
106
|
# File 'lib/fog/hp/models/compute/server.rb', line 104
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
|
#private_key_path ⇒ Object
99
100
101
102
|
# File 'lib/fog/hp/models/compute/server.rb', line 99
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
129
130
131
|
# File 'lib/fog/hp/models/compute/server.rb', line 129
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
|
#public_key_path ⇒ Object
124
125
126
127
|
# File 'lib/fog/hp/models/compute/server.rb', line 124
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
|
#username ⇒ Object
262
263
264
|
# File 'lib/fog/hp/models/compute/server.rb', line 262
def username
@username ||= 'root'
end
|
Instance Method Details
#block_device_mapping=(new_block_device_mapping) ⇒ Object
157
158
159
|
# File 'lib/fog/hp/models/compute/server.rb', line 157
def block_device_mapping=(new_block_device_mapping)
@block_device_mapping = new_block_device_mapping
end
|
#change_password(admin_password) ⇒ Object
165
166
167
168
169
|
# File 'lib/fog/hp/models/compute/server.rb', line 165
def change_password(admin_password)
requires :id
service.change_password_server(id, admin_password)
true
end
|
#confirm_resize ⇒ Object
200
201
202
203
204
|
# File 'lib/fog/hp/models/compute/server.rb', line 200
def confirm_resize
requires :id
service.confirm_resized_server(id)
true
end
|
#console_output(num_lines) ⇒ Object
50
51
52
53
|
# File 'lib/fog/hp/models/compute/server.rb', line 50
def console_output(num_lines)
requires :id
service.get_console_output(id, num_lines)
end
|
#create_image(name, metadata = {}) ⇒ Object
206
207
208
209
|
# File 'lib/fog/hp/models/compute/server.rb', line 206
def create_image(name, metadata={})
requires :id
service.create_image(id, name, metadata)
end
|
#destroy ⇒ Object
74
75
76
77
78
|
# File 'lib/fog/hp/models/compute/server.rb', line 74
def destroy
requires :id
service.delete_server(id)
true
end
|
#key_pair ⇒ Object
80
81
82
83
84
|
# File 'lib/fog/hp/models/compute/server.rb', line 80
def key_pair
requires :key_name
service.key_pairs.get(key_name)
end
|
#key_pair=(new_keypair) ⇒ Object
86
87
88
|
# File 'lib/fog/hp/models/compute/server.rb', line 86
def key_pair=(new_keypair)
self.key_name = new_keypair && new_keypair.name
end
|
#max_count=(new_max_count) ⇒ Object
153
154
155
|
# File 'lib/fog/hp/models/compute/server.rb', line 153
def max_count=(new_max_count)
@max_count = new_max_count
end
|
55
56
57
58
59
60
61
62
|
# File 'lib/fog/hp/models/compute/server.rb', line 55
def metadata
@metadata ||= begin
Fog::Compute::HP::Metadata.new({
:service => service,
:parent => self
})
end
end
|
64
65
66
67
68
|
# File 'lib/fog/hp/models/compute/server.rb', line 64
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
149
150
151
|
# File 'lib/fog/hp/models/compute/server.rb', line 149
def min_count=(new_min_count)
@min_count = new_min_count
end
|
#private_ip_address ⇒ Object
94
95
96
97
|
# File 'lib/fog/hp/models/compute/server.rb', line 94
def private_ip_address
addr = addresses.nil? ? nil : addresses.fetch(network_name, []).first
addr["addr"] if addr
end
|
#public_ip_address ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/fog/hp/models/compute/server.rb', line 108
def public_ip_address
if !addresses.nil?
addr = addresses.fetch(network_name, [])
if addr.count > 1
addr[1]["addr"]
else
nil
end
else
nil
end
end
|
#ready? ⇒ Boolean
161
162
163
|
# File 'lib/fog/hp/models/compute/server.rb', line 161
def ready?
self.state == 'ACTIVE'
end
|
#reboot(type = 'SOFT') ⇒ Object
176
177
178
179
180
|
# File 'lib/fog/hp/models/compute/server.rb', line 176
def reboot(type = 'SOFT')
requires :id
service.reboot_server(id, type)
true
end
|
#rebuild(image_id, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object
182
183
184
185
186
|
# File 'lib/fog/hp/models/compute/server.rb', line 182
def rebuild(image_id, name, admin_pass=nil, metadata=nil, personality=nil)
requires :id
service.rebuild_server(id, image_id, name, admin_pass, metadata, personality)
true
end
|
#resize(flavor_id) ⇒ Object
188
189
190
191
192
|
# File 'lib/fog/hp/models/compute/server.rb', line 188
def resize(flavor_id)
requires :id
service.resize_server(id, flavor_id)
true
end
|
#revert_resize ⇒ Object
194
195
196
197
198
|
# File 'lib/fog/hp/models/compute/server.rb', line 194
def revert_resize
requires :id
service.revert_resized_server(id)
true
end
|
#save ⇒ Object
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/fog/hp/models/compute/server.rb', line 218
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
}
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
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/fog/hp/models/compute/server.rb', line 248
def setup(credentials = {})
requires :public_ip_address, :identity, :public_key, :username
Fog::SSH.new(public_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
|
#user_data=(ascii_userdata) ⇒ Object
70
71
72
|
# File 'lib/fog/hp/models/compute/server.rb', line 70
def user_data=(ascii_userdata)
self.user_data_encoded = [ascii_userdata].pack('m') end
|
#volume_attachments ⇒ Object
211
212
213
214
215
216
|
# File 'lib/fog/hp/models/compute/server.rb', line 211
def volume_attachments
requires :id
if vols = service.list_server_volumes(id).body
vols["volumeAttachments"]
end
end
|
#windows_password ⇒ Object
171
172
173
174
|
# File 'lib/fog/hp/models/compute/server.rb', line 171
def windows_password()
requires :id
service.get_windows_password(id)
end
|