Class: Fog::Compute::OpenStack::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::OpenStack::Server
- Defined in:
- lib/fog/openstack/models/compute/server.rb
Instance Attribute Summary collapse
-
#block_device_mapping ⇒ Object
Returns the value of attribute block_device_mapping.
- #flavor_ref ⇒ Object
- #image_ref ⇒ Object
-
#nics ⇒ Object
writeonly
Sets the attribute nics.
-
#os_scheduler_hints ⇒ Object
writeonly
Sets the attribute os_scheduler_hints.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#personality ⇒ Hash
Hash containing data to inject into the file system of the cloud server instance during server creation.
Instance Method Summary collapse
- #all_addresses ⇒ Object
- #associate_address(floating_ip) ⇒ Object
- #attach_volume(volume_id, device_name) ⇒ Object
- #change_password(admin_password) ⇒ Object
- #confirm_resize ⇒ Object
- #console(log_length = nil) ⇒ Object
- #create_image(name, metadata = {}) ⇒ Object
- #destroy ⇒ Object
- #detach_volume(volume_id) ⇒ Object
- #disassociate_address(floating_ip) ⇒ Object
- #failed? ⇒ Boolean
- #floating_ip_address ⇒ Object (also: #public_ip_address)
- #floating_ip_addresses ⇒ Object (also: #public_ip_addresses)
- #images ⇒ Object
-
#initialize(attributes = {}) ⇒ Server
constructor
A new instance of Server.
-
#ip_addresses ⇒ Object
returns all ip_addresses for a given instance this includes both the fixed ip(s) and the floating ip(s).
- #live_migrate(host, block_migration, disk_over_commit) ⇒ Object
- #max_count=(new_max_count) ⇒ Object
- #metadata ⇒ Object
- #metadata=(new_metadata = {}) ⇒ Object
- #migrate ⇒ Object
- #min_count=(new_min_count) ⇒ Object
- #networks ⇒ Object
- #private_ip_address ⇒ Object
- #private_ip_addresses ⇒ Object
- #ready? ⇒ Boolean
- #reboot(type = 'SOFT') ⇒ Object
- #rebuild(image_ref, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object
- #reload ⇒ Object
- #reset_vm_state(vm_state) ⇒ Object
- #resize(flavor_ref) ⇒ Object
- #revert_resize ⇒ Object
- #save ⇒ Object
- #security_groups ⇒ Object
- #security_groups=(new_security_groups) ⇒ Object
- #setup(credentials = {}) ⇒ Object
- #user_data=(ascii_userdata) ⇒ Object
- #volume_attachments ⇒ Object
- #volumes ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fog/openstack/models/compute/server.rb', line 58 def initialize(attributes={}) # Old 'connection' is renamed as service and should be used instead 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.
55 56 57 |
# File 'lib/fog/openstack/models/compute/server.rb', line 55 def block_device_mapping @block_device_mapping end |
#flavor_ref ⇒ Object
164 165 166 |
# File 'lib/fog/openstack/models/compute/server.rb', line 164 def flavor_ref @flavor_ref end |
#image_ref ⇒ Object
156 157 158 |
# File 'lib/fog/openstack/models/compute/server.rb', line 156 def image_ref @image_ref end |
#nics=(value) ⇒ Object (writeonly)
Sets the attribute nics
54 55 56 |
# File 'lib/fog/openstack/models/compute/server.rb', line 54 def nics=(value) @nics = value end |
#os_scheduler_hints=(value) ⇒ Object (writeonly)
Sets the attribute os_scheduler_hints
54 55 56 |
# File 'lib/fog/openstack/models/compute/server.rb', line 54 def os_scheduler_hints=(value) @os_scheduler_hints = value end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
53 54 55 |
# File 'lib/fog/openstack/models/compute/server.rb', line 53 def password @password end |
#personality ⇒ Hash
This attribute is only used for server creation. This field will be nil on subsequent retrievals.
Returns Hash containing data to inject into the file system of the cloud server instance during server creation.
30 |
# File 'lib/fog/openstack/models/compute/server.rb', line 30 attribute :personality |
Instance Method Details
#all_addresses ⇒ Object
103 104 105 106 107 108 |
# File 'lib/fog/openstack/models/compute/server.rb', line 103 def all_addresses # currently openstack API does not tell us what is a floating ip vs a fixed ip for the vm listing, # we fall back to get all addresses and filter sadly. # Only includes manually-assigned addresses, not auto-assigned @all_addresses ||= service.list_all_addresses.body["floating_ips"].select{|data| data['instance_id'] == id} end |
#associate_address(floating_ip) ⇒ Object
250 251 252 253 |
# File 'lib/fog/openstack/models/compute/server.rb', line 250 def associate_address(floating_ip) requires :id service.associate_address id, floating_ip end |
#attach_volume(volume_id, device_name) ⇒ Object
289 290 291 292 293 |
# File 'lib/fog/openstack/models/compute/server.rb', line 289 def attach_volume(volume_id, device_name) requires :id service.attach_volume(volume_id, id, device_name) true end |
#change_password(admin_password) ⇒ Object
180 181 182 183 184 |
# File 'lib/fog/openstack/models/compute/server.rb', line 180 def change_password(admin_password) requires :id service.change_server_password(id, admin_password) true end |
#confirm_resize ⇒ Object
204 205 206 207 208 |
# File 'lib/fog/openstack/models/compute/server.rb', line 204 def confirm_resize requires :id service.confirm_resize_server(id) true end |
#console(log_length = nil) ⇒ Object
235 236 237 238 |
# File 'lib/fog/openstack/models/compute/server.rb', line 235 def console(log_length = nil) requires :id service.get_console_output(id, log_length) end |
#create_image(name, metadata = {}) ⇒ Object
230 231 232 233 |
# File 'lib/fog/openstack/models/compute/server.rb', line 230 def create_image(name, ={}) requires :id service.create_image(id, name, ) end |
#destroy ⇒ Object
92 93 94 95 96 |
# File 'lib/fog/openstack/models/compute/server.rb', line 92 def destroy requires :id service.delete_server(id) true end |
#detach_volume(volume_id) ⇒ Object
295 296 297 298 299 |
# File 'lib/fog/openstack/models/compute/server.rb', line 295 def detach_volume(volume_id) requires :id service.detach_volume(id, volume_id) true end |
#disassociate_address(floating_ip) ⇒ Object
255 256 257 258 |
# File 'lib/fog/openstack/models/compute/server.rb', line 255 def disassociate_address(floating_ip) requires :id service.disassociate_address id, floating_ip end |
#failed? ⇒ Boolean
176 177 178 |
# File 'lib/fog/openstack/models/compute/server.rb', line 176 def failed? self.state == 'ERROR' end |
#floating_ip_address ⇒ Object Also known as: public_ip_address
142 143 144 |
# File 'lib/fog/openstack/models/compute/server.rb', line 142 def floating_ip_address floating_ip_addresses.first end |
#floating_ip_addresses ⇒ Object Also known as: public_ip_addresses
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/fog/openstack/models/compute/server.rb', line 121 def floating_ip_addresses all_floating=addresses.values.flatten.select{ |data| data["OS-EXT-IPS:type"]=="floating" }.map{|addr| addr["addr"] } # Return them all, leading with manually assigned addresses manual = all_addresses.map{|addr| addr["ip"]} all_floating.sort{ |a,b| a_manual = manual.include? a b_manual = manual.include? b if a_manual and !b_manual -1 elsif !a_manual and b_manual 1 else 0 end } end |
#images ⇒ Object
98 99 100 101 |
# File 'lib/fog/openstack/models/compute/server.rb', line 98 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)
117 118 119 |
# File 'lib/fog/openstack/models/compute/server.rb', line 117 def ip_addresses addresses.values.flatten.map{|x| x['addr']} end |
#live_migrate(host, block_migration, disk_over_commit) ⇒ Object
245 246 247 248 |
# File 'lib/fog/openstack/models/compute/server.rb', line 245 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
269 270 271 |
# File 'lib/fog/openstack/models/compute/server.rb', line 269 def max_count=(new_max_count) @max_count = new_max_count end |
#metadata ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/fog/openstack/models/compute/server.rb', line 72 def @metadata ||= begin Fog::Compute::OpenStack::Metadata.new({ :service => service, :parent => self }) end end |
#metadata=(new_metadata = {}) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/fog/openstack/models/compute/server.rb', line 81 def (={}) return unless = [] .each_pair {|k,v| << {"key" => k, "value" => v} } @metadata = .load() end |
#migrate ⇒ Object
240 241 242 243 |
# File 'lib/fog/openstack/models/compute/server.rb', line 240 def migrate requires :id service.migrate_server(id) end |
#min_count=(new_min_count) ⇒ Object
265 266 267 |
# File 'lib/fog/openstack/models/compute/server.rb', line 265 def min_count=(new_min_count) @min_count = new_min_count end |
#networks ⇒ Object
273 274 275 |
# File 'lib/fog/openstack/models/compute/server.rb', line 273 def networks service.networks(:server => self) end |
#private_ip_address ⇒ Object
152 153 154 |
# File 'lib/fog/openstack/models/compute/server.rb', line 152 def private_ip_address private_ip_addresses.first end |
#private_ip_addresses ⇒ Object
148 149 150 |
# File 'lib/fog/openstack/models/compute/server.rb', line 148 def private_ip_addresses ip_addresses - floating_ip_addresses end |
#ready? ⇒ Boolean
172 173 174 |
# File 'lib/fog/openstack/models/compute/server.rb', line 172 def ready? self.state == 'ACTIVE' end |
#reboot(type = 'SOFT') ⇒ Object
224 225 226 227 228 |
# File 'lib/fog/openstack/models/compute/server.rb', line 224 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
186 187 188 189 190 |
# File 'lib/fog/openstack/models/compute/server.rb', line 186 def rebuild(image_ref, name, admin_pass=nil, =nil, personality=nil) requires :id service.rebuild_server(id, image_ref, name, admin_pass, , personality) true end |
#reload ⇒ Object
110 111 112 113 |
# File 'lib/fog/openstack/models/compute/server.rb', line 110 def reload @all_addresses = nil super end |
#reset_vm_state(vm_state) ⇒ Object
260 261 262 263 |
# File 'lib/fog/openstack/models/compute/server.rb', line 260 def reset_vm_state(vm_state) requires :id service.reset_server_state id, vm_state end |
#resize(flavor_ref) ⇒ Object
192 193 194 195 196 |
# File 'lib/fog/openstack/models/compute/server.rb', line 192 def resize(flavor_ref) requires :id service.resize_server(id, flavor_ref) true end |
#revert_resize ⇒ Object
198 199 200 201 202 |
# File 'lib/fog/openstack/models/compute/server.rb', line 198 def revert_resize requires :id service.revert_resize_server(id) true end |
#save ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/fog/openstack/models/compute/server.rb', line 301 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 = { 'personality' => personality, 'accessIPv4' => accessIPv4, 'accessIPv6' => accessIPv6, 'availability_zone' => availability_zone, 'user_data' => user_data_encoded, 'key_name' => key_name, 'config_drive' => config_drive, '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 } ['metadata'] = .to_hash unless @metadata.nil? = .reject {|key, value| value.nil?} data = service.create_server(name, image_ref, flavor_ref, ) merge_attributes(data.body['server']) true end |
#security_groups ⇒ Object
210 211 212 213 214 215 216 217 218 |
# File 'lib/fog/openstack/models/compute/server.rb', line 210 def security_groups requires :id groups = service.list_security_groups(id).body['security_groups'] groups.map do |group| Fog::Compute::OpenStack::SecurityGroup.new group.merge({:service => service}) end end |
#security_groups=(new_security_groups) ⇒ Object
220 221 222 |
# File 'lib/fog/openstack/models/compute/server.rb', line 220 def security_groups=(new_security_groups) @security_groups = new_security_groups end |
#setup(credentials = {}) ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/fog/openstack/models/compute/server.rb', line 327 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.json} ]) rescue Errno::ECONNREFUSED sleep(1) retry end |
#user_data=(ascii_userdata) ⇒ Object
88 89 90 |
# File 'lib/fog/openstack/models/compute/server.rb', line 88 def user_data=(ascii_userdata) self.user_data_encoded = [ascii_userdata].pack('m') end |
#volume_attachments ⇒ Object
284 285 286 287 |
# File 'lib/fog/openstack/models/compute/server.rb', line 284 def requires :id service.get_server_volumes(id).body['volumeAttachments'] end |
#volumes ⇒ Object
277 278 279 280 281 282 |
# File 'lib/fog/openstack/models/compute/server.rb', line 277 def volumes requires :id service.volumes.find_all do |vol| vol..find { || ["serverId"] == id } end end |