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, #username
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.
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/fog/openstack/models/compute/server.rb', line 46
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)
self.os_scheduler_hints = attributes.delete(:os_scheduler_hints)
super
end
|
Instance Attribute Details
#flavor_ref ⇒ Object
116
117
118
|
# File 'lib/fog/openstack/models/compute/server.rb', line 116
def flavor_ref
@flavor_ref
end
|
#image_ref ⇒ Object
108
109
110
|
# File 'lib/fog/openstack/models/compute/server.rb', line 108
def image_ref
@image_ref
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
#associate_address(floating_ip) ⇒ Object
188
189
190
191
|
# File 'lib/fog/openstack/models/compute/server.rb', line 188
def associate_address(floating_ip)
requires :id
connection.associate_address id, floating_ip
end
|
#change_password(admin_password) ⇒ Object
128
129
130
131
132
|
# File 'lib/fog/openstack/models/compute/server.rb', line 128
def change_password(admin_password)
requires :id
connection.change_server_password(id, admin_password)
true
end
|
#confirm_resize ⇒ Object
152
153
154
155
156
|
# File 'lib/fog/openstack/models/compute/server.rb', line 152
def confirm_resize
requires :id
connection.confirm_resize_server(id)
true
end
|
#console(log_length = nil) ⇒ Object
173
174
175
176
|
# File 'lib/fog/openstack/models/compute/server.rb', line 173
def console(log_length = nil)
requires :id
connection.get_console_output(id, log_length)
end
|
#create_image(name, metadata = {}) ⇒ Object
168
169
170
171
|
# File 'lib/fog/openstack/models/compute/server.rb', line 168
def create_image(name, metadata={})
requires :id
connection.create_image(id, name, metadata)
end
|
#destroy ⇒ Object
77
78
79
80
81
|
# File 'lib/fog/openstack/models/compute/server.rb', line 77
def destroy
requires :id
connection.delete_server(id)
true
end
|
#disassociate_address(floating_ip) ⇒ Object
193
194
195
196
|
# File 'lib/fog/openstack/models/compute/server.rb', line 193
def disassociate_address(floating_ip)
requires :id
connection.disassociate_address id, floating_ip
end
|
#images ⇒ Object
83
84
85
86
|
# File 'lib/fog/openstack/models/compute/server.rb', line 83
def images
requires :id
connection.images(:server => self)
end
|
#live_migrate(host, block_migration, disk_over_commit) ⇒ Object
183
184
185
186
|
# File 'lib/fog/openstack/models/compute/server.rb', line 183
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
207
208
209
|
# File 'lib/fog/openstack/models/compute/server.rb', line 207
def max_count=(new_max_count)
@max_count = new_max_count
end
|
58
59
60
61
62
63
64
65
|
# File 'lib/fog/openstack/models/compute/server.rb', line 58
def metadata
@metadata ||= begin
Fog::Compute::OpenStack::Metadata.new({
:connection => connection,
:parent => self
})
end
end
|
67
68
69
70
71
|
# File 'lib/fog/openstack/models/compute/server.rb', line 67
def metadata=(new_metadata={})
metas = []
new_metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} }
metadata.load(metas)
end
|
#migrate ⇒ Object
178
179
180
181
|
# File 'lib/fog/openstack/models/compute/server.rb', line 178
def migrate
requires :id
connection.migrate_server(id)
end
|
#min_count=(new_min_count) ⇒ Object
203
204
205
|
# File 'lib/fog/openstack/models/compute/server.rb', line 203
def min_count=(new_min_count)
@min_count = new_min_count
end
|
#networks ⇒ Object
211
212
213
|
# File 'lib/fog/openstack/models/compute/server.rb', line 211
def networks
connection.networks(:server => self)
end
|
#private_ip_address ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/fog/openstack/models/compute/server.rb', line 88
def private_ip_address
if addresses['private']
return addresses['private'].first
elsif addresses['internet']
return addresses['internet'].first
end
end
|
#public_ip_address ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/fog/openstack/models/compute/server.rb', line 98
def public_ip_address
if addresses['public']
return addresses['public'].last
elsif addresses['internet']
return addresses['internet'].first
end
end
|
#ready? ⇒ Boolean
124
125
126
|
# File 'lib/fog/openstack/models/compute/server.rb', line 124
def ready?
self.state == 'ACTIVE'
end
|
#reboot(type = 'SOFT') ⇒ Object
162
163
164
165
166
|
# File 'lib/fog/openstack/models/compute/server.rb', line 162
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
134
135
136
137
138
|
# File 'lib/fog/openstack/models/compute/server.rb', line 134
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
|
#reset_vm_state(vm_state) ⇒ Object
198
199
200
201
|
# File 'lib/fog/openstack/models/compute/server.rb', line 198
def reset_vm_state(vm_state)
requires :id
connection.reset_server_state id, vm_state
end
|
#resize(flavor_ref) ⇒ Object
140
141
142
143
144
|
# File 'lib/fog/openstack/models/compute/server.rb', line 140
def resize(flavor_ref)
requires :id
connection.resize_server(id, flavor_ref)
true
end
|
#revert_resize ⇒ Object
146
147
148
149
150
|
# File 'lib/fog/openstack/models/compute/server.rb', line 146
def revert_resize
requires :id
connection.revert_resize_server(id)
true
end
|
#save ⇒ Object
TODO: Implement /os-volumes-boot support with ‘block_device_mapping’
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
# File 'lib/fog/openstack/models/compute/server.rb', line 216
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,
'os:scheduler_hints' => @os_scheduler_hints
}
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
158
159
160
|
# File 'lib/fog/openstack/models/compute/server.rb', line 158
def security_groups=(new_security_groups)
@security_groups = new_security_groups
end
|
#setup(credentials = {}) ⇒ Object
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/fog/openstack/models/compute/server.rb', line 240
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
73
74
75
|
# File 'lib/fog/openstack/models/compute/server.rb', line 73
def user_data=(ascii_userdata)
self.user_data_encoded = [ascii_userdata].pack('m')
end
|