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 Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Server
#scp, #scp_download, #ssh, #ssh_port, #sshable?
Methods inherited from Model
#inspect, #reload, #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
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/fog/openstack/models/compute/server.rb', line 44
def initialize(attributes={})
@connection = attributes[:connection]
attributes[:metadata] = {}
self.security_groups = attributes.delete(:security_groups)
self.min_count = attributes.delete(:min_count)
self.max_count = attributes.delete(:max_count)
super
end
|
Instance Attribute Details
#flavor_ref ⇒ Object
131
132
133
|
# File 'lib/fog/openstack/models/compute/server.rb', line 131
def flavor_ref
@flavor_ref
end
|
#image_ref ⇒ Object
123
124
125
|
# File 'lib/fog/openstack/models/compute/server.rb', line 123
def image_ref
@image_ref
end
|
#password ⇒ Object
Returns the value of attribute password.
40
41
42
|
# File 'lib/fog/openstack/models/compute/server.rb', line 40
def password
@password
end
|
#private_key ⇒ Object
100
101
102
|
# File 'lib/fog/openstack/models/compute/server.rb', line 100
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
|
#private_key_path ⇒ Object
95
96
97
98
|
# File 'lib/fog/openstack/models/compute/server.rb', line 95
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
119
120
121
|
# File 'lib/fog/openstack/models/compute/server.rb', line 119
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
|
#public_key_path ⇒ Object
114
115
116
117
|
# File 'lib/fog/openstack/models/compute/server.rb', line 114
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
|
#username ⇒ Object
263
264
265
|
# File 'lib/fog/openstack/models/compute/server.rb', line 263
def username
@username ||= 'root'
end
|
Instance Method Details
#associate_address(floating_ip) ⇒ Object
203
204
205
206
|
# File 'lib/fog/openstack/models/compute/server.rb', line 203
def associate_address(floating_ip)
requires :id
connection.associate_address id, floating_ip
end
|
#change_password(admin_password) ⇒ Object
143
144
145
146
147
|
# File 'lib/fog/openstack/models/compute/server.rb', line 143
def change_password(admin_password)
requires :id
connection.change_server_password(id, admin_password)
true
end
|
#confirm_resize ⇒ Object
167
168
169
170
171
|
# File 'lib/fog/openstack/models/compute/server.rb', line 167
def confirm_resize
requires :id
connection.confirm_resize_server(id)
true
end
|
#console(log_length = nil) ⇒ Object
188
189
190
191
|
# File 'lib/fog/openstack/models/compute/server.rb', line 188
def console(log_length = nil)
requires :id
connection.get_console_output(id, log_length)
end
|
#create_image(name, metadata = {}) ⇒ Object
183
184
185
186
|
# File 'lib/fog/openstack/models/compute/server.rb', line 183
def create_image(name, metadata={})
requires :id
connection.create_image(id, name, metadata)
end
|
#destroy ⇒ Object
74
75
76
77
78
|
# File 'lib/fog/openstack/models/compute/server.rb', line 74
def destroy
requires :id
connection.delete_server(id)
true
end
|
#disassociate_address(floating_ip) ⇒ Object
208
209
210
211
|
# File 'lib/fog/openstack/models/compute/server.rb', line 208
def disassociate_address(floating_ip)
requires :id
connection.disassociate_address id, floating_ip
end
|
#images ⇒ Object
80
81
82
83
|
# File 'lib/fog/openstack/models/compute/server.rb', line 80
def images
requires :id
connection.images(:server => self)
end
|
#live_migrate(host, block_migration, disk_over_commit) ⇒ Object
198
199
200
201
|
# File 'lib/fog/openstack/models/compute/server.rb', line 198
def live_migrate(host, block_migration, disk_over_commit)
requires :id
connection.live_migrate_server(id, host, block_migration, disk_over_commit)
end
|
#max_count=(new_max_count) ⇒ Object
217
218
219
|
# File 'lib/fog/openstack/models/compute/server.rb', line 217
def max_count=(new_max_count)
@max_count = new_max_count
end
|
55
56
57
58
59
60
61
62
|
# File 'lib/fog/openstack/models/compute/server.rb', line 55
def metadata
@metadata ||= begin
Fog::Compute::OpenStack::Metadata.new({
:connection => connection,
:parent => self
})
end
end
|
64
65
66
67
68
|
# File 'lib/fog/openstack/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
|
#migrate ⇒ Object
193
194
195
196
|
# File 'lib/fog/openstack/models/compute/server.rb', line 193
def migrate
requires :id
connection.migrate_server(id)
end
|
#min_count=(new_min_count) ⇒ Object
213
214
215
|
# File 'lib/fog/openstack/models/compute/server.rb', line 213
def min_count=(new_min_count)
@min_count = new_min_count
end
|
#networks ⇒ Object
221
222
223
|
# File 'lib/fog/openstack/models/compute/server.rb', line 221
def networks
connection.networks(:server => self)
end
|
#private_ip_address ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/fog/openstack/models/compute/server.rb', line 85
def private_ip_address
if addresses['private']
return addresses['private'].first
elsif addresses['internet']
return addresses['internet'].first
end
end
|
#public_ip_address ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'lib/fog/openstack/models/compute/server.rb', line 104
def public_ip_address
if addresses['public']
return addresses['public'].last
elsif addresses['internet']
return addresses['internet'].first
end
end
|
#ready? ⇒ Boolean
139
140
141
|
# File 'lib/fog/openstack/models/compute/server.rb', line 139
def ready?
self.state == 'ACTIVE'
end
|
#reboot(type = 'SOFT') ⇒ Object
177
178
179
180
181
|
# File 'lib/fog/openstack/models/compute/server.rb', line 177
def reboot(type = 'SOFT')
requires :id
connection.reboot_server(id, type)
true
end
|
#rebuild(image_ref, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object
149
150
151
152
153
|
# File 'lib/fog/openstack/models/compute/server.rb', line 149
def rebuild(image_ref, name, admin_pass=nil, metadata=nil, personality=nil)
requires :id
connection.rebuild_server(id, image_ref, name, admin_pass, metadata, personality)
true
end
|
#resize(flavor_ref) ⇒ Object
155
156
157
158
159
|
# File 'lib/fog/openstack/models/compute/server.rb', line 155
def resize(flavor_ref)
requires :id
connection.resize_server(id, flavor_ref)
true
end
|
#revert_resize ⇒ Object
161
162
163
164
165
|
# File 'lib/fog/openstack/models/compute/server.rb', line 161
def revert_resize
requires :id
connection.revert_resize_server(id)
true
end
|
#save ⇒ Object
TODO: Implement /os-volumes-boot support with ‘block_device_mapping’
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/fog/openstack/models/compute/server.rb', line 226
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :flavor_ref, :image_ref, :name
meta_hash = {}
metadata.each { |meta| meta_hash.store(meta.key, meta.value) }
options = {
'metadata' => meta_hash,
'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,
}
options = options.reject {|key, value| value.nil?}
data = connection.create_server(name, image_ref, flavor_ref, options)
merge_attributes(data.body['server'])
true
end
|
#security_groups=(new_security_groups) ⇒ Object
173
174
175
|
# File 'lib/fog/openstack/models/compute/server.rb', line 173
def security_groups=(new_security_groups)
@security_groups = new_security_groups
end
|
#setup(credentials = {}) ⇒ Object
249
250
251
252
253
254
255
256
257
258
259
260
261
|
# File 'lib/fog/openstack/models/compute/server.rb', line 249
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/openstack/models/compute/server.rb', line 70
def user_data=(ascii_userdata)
self.user_data_encoded = [ascii_userdata].pack('m')
end
|