Class: Fog::Compute::OpenStack::Server
- Inherits:
-
Server
show all
- Defined in:
- lib/fog/openstack/models/compute/server.rb
Instance Attribute Summary collapse
Attributes inherited from Server
#private_key, #private_key_path, #public_key, #public_key_path, #ssh_options, #ssh_port, #username
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
Methods inherited from Server
#scp, #scp_download, #ssh, #sshable?
Methods inherited from Model
#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
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/fog/openstack/models/compute/server.rb', line 47
def initialize(attributes={})
prepare_service_value(attributes)
self.security_groups = attributes.delete(:security_groups)
self.min_count = attributes.delete(:min_count)
self.max_count = attributes.delete(:max_count)
self.nics = attributes.delete(:nics)
self.os_scheduler_hints = attributes.delete(:os_scheduler_hints)
self.block_device_mapping = attributes.delete(:block_device_mapping)
super
end
|
Instance Attribute Details
#block_device_mapping ⇒ Object
Returns the value of attribute block_device_mapping.
44
45
46
|
# File 'lib/fog/openstack/models/compute/server.rb', line 44
def block_device_mapping
@block_device_mapping
end
|
#flavor_ref ⇒ Object
137
138
139
|
# File 'lib/fog/openstack/models/compute/server.rb', line 137
def flavor_ref
@flavor_ref
end
|
#image_ref ⇒ Object
129
130
131
|
# File 'lib/fog/openstack/models/compute/server.rb', line 129
def image_ref
@image_ref
end
|
#nics=(value) ⇒ Object
43
44
45
|
# File 'lib/fog/openstack/models/compute/server.rb', line 43
def nics=(value)
@nics = value
end
|
#os_scheduler_hints=(value) ⇒ Object
Sets the attribute os_scheduler_hints
43
44
45
|
# File 'lib/fog/openstack/models/compute/server.rb', line 43
def os_scheduler_hints=(value)
@os_scheduler_hints = value
end
|
#password ⇒ Object
Returns the value of attribute password.
42
43
44
|
# File 'lib/fog/openstack/models/compute/server.rb', line 42
def password
@password
end
|
Instance Method Details
#all_addresses ⇒ Object
92
93
94
95
96
|
# File 'lib/fog/openstack/models/compute/server.rb', line 92
def all_addresses
@all_addresses ||= service.list_all_addresses.body["floating_ips"].select{|data| data['instance_id'] == id}
end
|
#associate_address(floating_ip) ⇒ Object
221
222
223
224
|
# File 'lib/fog/openstack/models/compute/server.rb', line 221
def associate_address(floating_ip)
requires :id
service.associate_address id, floating_ip
end
|
#attach_volume(volume_id, device_name) ⇒ Object
260
261
262
263
264
|
# File 'lib/fog/openstack/models/compute/server.rb', line 260
def attach_volume(volume_id, device_name)
requires :id
service.attach_volume(volume_id, id, device_name)
true
end
|
#change_password(admin_password) ⇒ Object
149
150
151
152
153
|
# File 'lib/fog/openstack/models/compute/server.rb', line 149
def change_password(admin_password)
requires :id
service.change_server_password(id, admin_password)
true
end
|
#confirm_resize ⇒ Object
173
174
175
176
177
|
# File 'lib/fog/openstack/models/compute/server.rb', line 173
def confirm_resize
requires :id
service.confirm_resize_server(id)
true
end
|
#console(log_length = nil) ⇒ Object
206
207
208
209
|
# File 'lib/fog/openstack/models/compute/server.rb', line 206
def console(log_length = nil)
requires :id
service.get_console_output(id, log_length)
end
|
#create_image(name, metadata = {}) ⇒ Object
201
202
203
204
|
# File 'lib/fog/openstack/models/compute/server.rb', line 201
def create_image(name, metadata={})
requires :id
service.create_image(id, name, metadata)
end
|
#destroy ⇒ Object
81
82
83
84
85
|
# File 'lib/fog/openstack/models/compute/server.rb', line 81
def destroy
requires :id
service.delete_server(id)
true
end
|
#detach_volume(volume_id) ⇒ Object
266
267
268
269
270
|
# File 'lib/fog/openstack/models/compute/server.rb', line 266
def detach_volume(volume_id)
requires :id
service.detach_volume(id, volume_id)
true
end
|
#disassociate_address(floating_ip) ⇒ Object
226
227
228
229
|
# File 'lib/fog/openstack/models/compute/server.rb', line 226
def disassociate_address(floating_ip)
requires :id
service.disassociate_address id, floating_ip
end
|
#floating_ip_address ⇒ Object
Also known as:
public_ip_address
115
116
117
|
# File 'lib/fog/openstack/models/compute/server.rb', line 115
def floating_ip_address
floating_ip_addresses.first
end
|
#floating_ip_addresses ⇒ Object
Also known as:
public_ip_addresses
109
110
111
|
# File 'lib/fog/openstack/models/compute/server.rb', line 109
def floating_ip_addresses
all_addresses.map{|addr| addr["ip"]}
end
|
#images ⇒ Object
87
88
89
90
|
# File 'lib/fog/openstack/models/compute/server.rb', line 87
def images
requires :id
service.images(:server => self)
end
|
#ip_addresses ⇒ Object
returns all ip_addresses for a given instance this includes both the fixed ip(s) and the floating ip(s)
105
106
107
|
# File 'lib/fog/openstack/models/compute/server.rb', line 105
def ip_addresses
addresses.values.flatten.map{|x| x['addr']}
end
|
#live_migrate(host, block_migration, disk_over_commit) ⇒ Object
216
217
218
219
|
# File 'lib/fog/openstack/models/compute/server.rb', line 216
def live_migrate(host, block_migration, disk_over_commit)
requires :id
service.live_migrate_server(id, host, block_migration, disk_over_commit)
end
|
#max_count=(new_max_count) ⇒ Object
240
241
242
|
# File 'lib/fog/openstack/models/compute/server.rb', line 240
def max_count=(new_max_count)
@max_count = new_max_count
end
|
61
62
63
64
65
66
67
68
|
# File 'lib/fog/openstack/models/compute/server.rb', line 61
def metadata
@metadata ||= begin
Fog::Compute::OpenStack::Metadata.new({
:service => service,
:parent => self
})
end
end
|
70
71
72
73
74
75
|
# File 'lib/fog/openstack/models/compute/server.rb', line 70
def metadata=(new_metadata={})
return unless new_metadata
metas = []
new_metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} }
@metadata = metadata.load(metas)
end
|
#migrate ⇒ Object
211
212
213
214
|
# File 'lib/fog/openstack/models/compute/server.rb', line 211
def migrate
requires :id
service.migrate_server(id)
end
|
#min_count=(new_min_count) ⇒ Object
236
237
238
|
# File 'lib/fog/openstack/models/compute/server.rb', line 236
def min_count=(new_min_count)
@min_count = new_min_count
end
|
#networks ⇒ Object
244
245
246
|
# File 'lib/fog/openstack/models/compute/server.rb', line 244
def networks
service.networks(:server => self)
end
|
#private_ip_address ⇒ Object
125
126
127
|
# File 'lib/fog/openstack/models/compute/server.rb', line 125
def private_ip_address
private_ip_addresses.first
end
|
#private_ip_addresses ⇒ Object
121
122
123
|
# File 'lib/fog/openstack/models/compute/server.rb', line 121
def private_ip_addresses
ip_addresses - floating_ip_addresses
end
|
#ready? ⇒ Boolean
145
146
147
|
# File 'lib/fog/openstack/models/compute/server.rb', line 145
def ready?
self.state == 'ACTIVE'
end
|
#reboot(type = 'SOFT') ⇒ Object
195
196
197
198
199
|
# File 'lib/fog/openstack/models/compute/server.rb', line 195
def reboot(type = 'SOFT')
requires :id
service.reboot_server(id, type)
true
end
|
#rebuild(image_ref, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object
155
156
157
158
159
|
# File 'lib/fog/openstack/models/compute/server.rb', line 155
def rebuild(image_ref, name, admin_pass=nil, metadata=nil, personality=nil)
requires :id
service.rebuild_server(id, image_ref, name, admin_pass, metadata, personality)
true
end
|
#reload ⇒ Object
98
99
100
101
|
# File 'lib/fog/openstack/models/compute/server.rb', line 98
def reload
@all_addresses = nil
super
end
|
#reset_vm_state(vm_state) ⇒ Object
231
232
233
234
|
# File 'lib/fog/openstack/models/compute/server.rb', line 231
def reset_vm_state(vm_state)
requires :id
service.reset_server_state id, vm_state
end
|
#resize(flavor_ref) ⇒ Object
161
162
163
164
165
|
# File 'lib/fog/openstack/models/compute/server.rb', line 161
def resize(flavor_ref)
requires :id
service.resize_server(id, flavor_ref)
true
end
|
#revert_resize ⇒ Object
167
168
169
170
171
|
# File 'lib/fog/openstack/models/compute/server.rb', line 167
def revert_resize
requires :id
service.revert_resize_server(id)
true
end
|
#save ⇒ Object
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
# File 'lib/fog/openstack/models/compute/server.rb', line 272
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :flavor_ref, :name
requires_one :image_ref, :block_device_mapping
options = {
'personality' => personality,
'accessIPv4' => accessIPv4,
'accessIPv6' => accessIPv6,
'availability_zone' => availability_zone,
'user_data' => user_data_encoded,
'key_name' => key_name,
'security_groups' => @security_groups,
'min_count' => @min_count,
'max_count' => @max_count,
'nics' => @nics,
'os:scheduler_hints' => @os_scheduler_hints,
'block_device_mapping' => @block_device_mapping
}
options['metadata'] = metadata.to_hash unless @metadata.nil?
options = options.reject {|key, value| value.nil?}
data = service.create_server(name, image_ref, flavor_ref, options)
merge_attributes(data.body['server'])
true
end
|
#security_groups ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/fog/openstack/models/compute/server.rb', line 179
def security_groups
requires :id
groups = service.list_security_groups(id).body['security_groups']
groups.map do |group|
sg = Fog::Compute::OpenStack::SecurityGroup.new group
sg.connection = service
sg
end
end
|
#security_groups=(new_security_groups) ⇒ Object
191
192
193
|
# File 'lib/fog/openstack/models/compute/server.rb', line 191
def security_groups=(new_security_groups)
@security_groups = new_security_groups
end
|
#setup(credentials = {}) ⇒ Object
297
298
299
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/fog/openstack/models/compute/server.rb', line 297
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
77
78
79
|
# File 'lib/fog/openstack/models/compute/server.rb', line 77
def user_data=(ascii_userdata)
self.user_data_encoded = [ascii_userdata].pack('m')
end
|
#volume_attachments ⇒ Object
255
256
257
258
|
# File 'lib/fog/openstack/models/compute/server.rb', line 255
def volume_attachments
requires :id
service.get_server_volumes(id).body['volumeAttachments']
end
|
#volumes ⇒ Object
248
249
250
251
252
253
|
# File 'lib/fog/openstack/models/compute/server.rb', line 248
def volumes
requires :id
service.volumes.find_all do |vol|
vol.attachments.find { |attachment| attachment["serverId"] == id }
end
end
|