Class: Fog::Compute::RackspaceV2::Server
- Defined in:
- lib/fog/rackspace/models/compute_v2/server.rb
Constant Summary collapse
- ACTIVE =
States
'ACTIVE'
- BUILD =
'BUILD'
- DELETED =
'DELETED'
- ERROR =
'ERROR'
- HARD_REBOOT =
'HARD_REBOOT'
- MIGRATING =
'MIGRATING'
- PASSWORD =
'PASSWORD'
- REBOOT =
'REBOOT'
- REBUILD =
'REBUILD'
- RESCUE =
'RESCUE'
- RESIZE =
'RESIZE'
- REVERT_RESIZE =
'REVERT_RESIZE'
- SUSPENDED =
'SUSPENDED'
- UNKNOWN =
'UNKNOWN'
- VERIFY_RESIZE =
'VERIFY_RESIZE'
Instance Attribute Summary collapse
-
#address ⇒ Hash<String, Array[Hash]>
readonly
IP addresses allocated for server by network.
-
#bandwidth ⇒ Array
readonly
The amount of bandwidth used for the specified audit period.
-
#created ⇒ String
readonly
The time stamp for the creation date.
-
#disk_config ⇒ String<AUTO, MANUAL>
The disk configuration value.
-
#flavor_id ⇒ String
readonly
The flavor Id.
-
#host Id(Id) ⇒ Object
readonly
The host Id.
-
#id ⇒ String
readonly
The server id.
-
#image_id ⇒ String
readonly
The image Id.
-
#ipv4_address ⇒ String
(also: #access_ipv4_address)
The public IP version 4 access address.
-
#ipv6_address ⇒ String
(also: #access_ipv6_address)
The public IP version 6 access address.
-
#links ⇒ Array
readonly
Server links.
-
#name ⇒ String
The server name.
-
#password ⇒ String
readonly
Password for system adminstrator account.
-
#personality ⇒ Hash
Hash containing data to inject into the file system of the cloud server instance during server creation.
-
#progress ⇒ Fixnum
readonly
The build completion progress, as a percentage.
-
#state ⇒ String
readonly
Server status.
-
#tenant_id ⇒ String
readonly
The tenant Id.
-
#updated ⇒ String
readonly
The time stamp for the last update.
-
#user_id ⇒ String
readonly
The user Id.
Attributes inherited from Server
#private_key, #private_key_path, #public_key, #public_key_path, #ssh_port, #username
Attributes inherited from Model
Instance Method Summary collapse
-
#attach_volume(volume, device = nil) ⇒ Fog::Compute::RackspaceV2::Attachment
Attaches Cloud Block Volume.
-
#attachments ⇒ Fog::Compute::RackspaceV2::Attachments
Attached Cloud Block Volumes.
-
#change_admin_password(password) ⇒ Boolean
Change admin password * Status Transition: * ACTIVE -> PASSWORD -> ACTIVE * ACTIVE -> PASSWORD -> ERROR (on error).
-
#confirm_resize ⇒ Object
-
VERIFY_RESIZE -> ERROR (on error)å.
-
-
#create(options) ⇒ Boolean
Creates server * requires attributes: service:, :name, :image_id, and :flavor_id * optional attributes :disk_config, :metadata, :personality * State Transitions * BUILD -> ACTIVE * BUILD -> ERROR (on error).
-
#create_image(name, options = {}) ⇒ Fog::ComputeRackspaceV2::Image
Creates Image from server.
-
#destroy ⇒ Boolean
Destroy the server * Status Transition: * ACTIVE -> DELETED * ERROR -> DELETED.
-
#flavor ⇒ Fog::Compute::RackspaceV2::Flavor
Server flavor.
-
#image ⇒ Fog::Compute::RackspaceV2::Image
Server image.
-
#initialize(attributes = {}) ⇒ Server
constructor
A new instance of Server.
-
#metadata ⇒ Fog::Compute::RackspaceV2::Metadata
Server metadata.
-
#metadata=(hash = {}) ⇒ Object
Set server metadata.
-
#private_ip_address ⇒ String
Server’s private IPv4 address.
-
#public_ip_address ⇒ String
Server’s public IPv4 address.
-
#ready?(ready_state = ACTIVE, error_states = [ERROR]) ⇒ Boolean
Is server is in ready state.
-
#reboot(type = 'SOFT') ⇒ Boolean
Reboot server * State transition: * ACTIVE -> REBOOT -> ACTIVE (soft reboot) * ACTIVE -> HARD_REBOOT -> ACTIVE (hard reboot).
-
#rebuild(image_id, options = {}) ⇒ Boolean
Rebuild removes all data on the server and replaces it with the specified image.
-
#rescue ⇒ Boolean
Place existing server into rescue mode, allowing for offline editing of configuration.
-
#resize(flavor_id) ⇒ Boolean
Resize existing server to a different flavor, in essence, scaling the server up or down.
-
#revert_resize ⇒ Boolean
Reverts server resize operation * Status Transition: * VERIFY_RESIZE -> ACTIVE * VERIFY_RESIZE -> ERROR (on error).
-
#save(options = {}) ⇒ Boolean
Saves the server.
-
#setup(credentials = {}) ⇒ Object
Setup server for SSH access This requires public_key_path and private_key_path to be passed into Compute service via Fog::Compute constructor or .fog file.
-
#unrescue ⇒ Boolean
Remove existing server from rescue mode.
-
#update ⇒ Object
Updates server This will update :name, :accessIPv4, and :accessIPv6 attributes.
Methods inherited from Server
#scp, #scp_download, #ssh, #sshable?
Methods inherited from Model
#inspect, #reload, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Fog::Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
140 141 142 143 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 140 def initialize(attributes={}) @service = attributes[:service] super end |
Instance Attribute Details
#address ⇒ Hash<String, Array[Hash]> (readonly)
Returns IP addresses allocated for server by network.
123 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 123 attribute :addresses |
#bandwidth ⇒ Array (readonly)
Returns The amount of bandwidth used for the specified audit period.
111 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 111 attribute :bandwidth, :aliases => 'rax-bandwidth:bandwidth' |
#created ⇒ String (readonly)
Returns The time stamp for the creation date.
35 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 35 attribute :created |
#disk_config ⇒ String<AUTO, MANUAL>
The disk configuration value.
* AUTO - The server is built with a single partition the size of the target flavor disk. The file system is automatically adjusted to fit the entire partition.
This keeps things simple and automated. AUTO is valid only for images and servers with a single partition that use the EXT3 file system.
This is the default setting for applicable Rackspace base images.
* MANUAL - The server is built using whatever partition scheme and file system is in the source image. If the target flavor disk is larger,
the remaining disk space is left unpartitioned. This enables images to have non-EXT3 file systems, multiple partitions,
and so on, and enables you to manage the disk configuration.
106 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 106 attribute :disk_config, :aliases => 'OS-DCF:diskConfig' |
#flavor_id ⇒ String (readonly)
Returns The flavor Id.
128 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 128 attribute :flavor_id, :aliases => 'flavor', :squash => 'id' |
#host Id(Id) ⇒ Object (readonly)
The host Id. The compute provisioning algorithm has an anti-affinity property that attempts to spread customer VMs across hosts. Under certain situations, VMs from the same customer might be placed on the same host. hostId represents the host your server runs on and can be used to determine this scenario if it is relevant to your application. HostId is unique per account and is not globally unique.
48 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 48 attribute :host_id, :aliases => 'hostId' |
#id ⇒ String (readonly)
Returns The server id.
27 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 27 identity :id |
#image_id ⇒ String (readonly)
Returns The image Id.
133 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 133 attribute :image_id, :aliases => 'image', :squash => 'id' |
#ipv4_address ⇒ String Also known as: access_ipv4_address
This field will populate once the server is ready to use.
Returns The public IP version 4 access address.
86 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 86 attribute :ipv4_address, :aliases => 'accessIPv4' |
#ipv6_address ⇒ String Also known as: access_ipv6_address
This field will populate once the server is ready to use.
Returns The public IP version 6 access address.
92 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 92 attribute :ipv6_address, :aliases => 'accessIPv6' |
#links ⇒ Array (readonly)
Returns Server links.
69 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 69 attribute :links |
#name ⇒ String
Returns The server name.
31 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 31 attribute :name |
#password ⇒ String (readonly)
This value is ONLY populated on server creation.
Returns Password for system adminstrator account.
137 138 139 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 137 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.
80 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 80 attribute :personality |
#progress ⇒ Fixnum (readonly)
Returns The build completion progress, as a percentage. Value is from 0 to 100.
57 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 57 attribute :progress |
#state ⇒ String (readonly)
Returns server status.
53 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 53 attribute :state, :aliases => 'status' |
#tenant_id ⇒ String (readonly)
Returns The tenant Id.
65 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 65 attribute :tenant_id |
#updated ⇒ String (readonly)
Returns The time stamp for the last update.
39 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 39 attribute :updated |
#user_id ⇒ String (readonly)
Returns The user Id.
61 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 61 attribute :user_id |
Instance Method Details
#attach_volume(volume, device = nil) ⇒ Fog::Compute::RackspaceV2::Attachment
Attaches Cloud Block Volume
325 326 327 328 329 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 325 def attach_volume(volume, device=nil) requires :identity volume_id = volume.is_a?(String) ? volume : volume.id .create(:server_id => identity, :volume_id => volume_id, :device => device) end |
#attachments ⇒ Fog::Compute::RackspaceV2::Attachments
Attached Cloud Block Volumes
307 308 309 310 311 312 313 314 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 307 def @attachments ||= begin Fog::Compute::RackspaceV2::Attachments.new({ :service => service, :server => self }) end end |
#change_admin_password(password) ⇒ Boolean
Though Rackspace does not enforce complexity requirements for the password, the operating system might. If the password is not complex enough, the server might enter an ERROR state.
Change admin password
-
Status Transition:
-
ACTIVE -> PASSWORD -> ACTIVE
-
ACTIVE -> PASSWORD -> ERROR (on error)
-
506 507 508 509 510 511 512 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 506 def change_admin_password(password) requires :identity service.change_server_password(identity, password) self.state = PASSWORD @password = password true end |
#confirm_resize ⇒ Object
-
VERIFY_RESIZE -> ERROR (on error)å
430 431 432 433 434 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 430 def confirm_resize requires :identity service.confirm_resize_server(identity) true end |
#create(options) ⇒ Boolean
You should use servers.create to create servers instead calling this method directly
Creates server
-
requires attributes: service:, :name, :image_id, and :flavor_id
-
optional attributes :disk_config, :metadata, :personality
-
State Transitions
-
BUILD -> ACTIVE
-
BUILD -> ERROR (on error)
-
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 194 def create() requires :name, :image_id, :flavor_id [:networks] ||= attributes[:networks] [:disk_config] = disk_config unless disk_config.nil? [:metadata] = .to_hash unless @metadata.nil? [:personality] = personality unless personality.nil? if [:networks] [:networks].map! { |id| { :uuid => id } } end data = service.create_server(name, image_id, flavor_id, 1, 1, ) merge_attributes(data.body['server']) true end |
#create_image(name, options = {}) ⇒ Fog::ComputeRackspaceV2::Image
Creates Image from server. Once complete, a new image is available that you can use to rebuild or create servers.
-
State Transition:
-
SAVING -> ACTIVE
-
SAVING -> ERROR (on error)
-
289 290 291 292 293 294 295 296 297 298 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 289 def create_image(name, = {}) requires :identity response = service.create_image(identity, name, ) begin image_id = response.headers["Location"].match(/\/([^\/]+$)/)[1] Fog::Compute::RackspaceV2::Image.new(:collection => service.images, :service => service, :id => image_id) rescue nil end end |
#destroy ⇒ Boolean
Destroy the server
-
Status Transition:
-
ACTIVE -> DELETED
-
ERROR -> DELETED
-
247 248 249 250 251 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 247 def destroy requires :identity service.delete_server(identity) true end |
#flavor ⇒ Fog::Compute::RackspaceV2::Flavor
Server flavor
259 260 261 262 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 259 def flavor requires :flavor_id @flavor ||= service.flavors.get(flavor_id) end |
#image ⇒ Fog::Compute::RackspaceV2::Image
Server image
270 271 272 273 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 270 def image requires :image_id @image ||= service.images.get(image_id) end |
#metadata ⇒ Fog::Compute::RackspaceV2::Metadata
Server metadata
152 153 154 155 156 157 158 159 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 152 def @metadata ||= begin Fog::Compute::RackspaceV2::Metadata.new({ :service => service, :parent => self }) end end |
#metadata=(hash = {}) ⇒ Object
Set server metadata
163 164 165 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 163 def (hash={}) .from_hash(hash) end |
#private_ip_address ⇒ String
Server’s private IPv4 address
333 334 335 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 333 def private_ip_address addresses['private'].select{|a| a["version"] == 4}[0]["addr"] end |
#public_ip_address ⇒ String
Server’s public IPv4 address
339 340 341 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 339 def public_ip_address ipv4_address end |
#ready?(ready_state = ACTIVE, error_states = [ERROR]) ⇒ Boolean
Is server is in ready state
348 349 350 351 352 353 354 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 348 def ready?(ready_state = ACTIVE, error_states=[ERROR]) if error_states error_states = Array(error_states) raise InvalidServerStateException.new(ready_state, state) if error_states.include?(state) end state == ready_state end |
#reboot(type = 'SOFT') ⇒ Boolean
Reboot server
-
State transition:
-
ACTIVE -> REBOOT -> ACTIVE (soft reboot)
-
ACTIVE -> HARD_REBOOT -> ACTIVE (hard reboot)
-
368 369 370 371 372 373 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 368 def reboot(type = 'SOFT') requires :identity service.reboot_server(identity, type) self.state = type == 'SOFT' ? REBOOT : HARD_REBOOT true end |
#rebuild(image_id, options = {}) ⇒ Boolean
Rebuild removes all data on the server and replaces it with the specified image. The id and all IP addresses remain the same.
-
Status Transition:
-
ACTIVE -> REBUILD -> ACTIVE
-
ACTIVE -> REBUILD -> ERROR (on error)
-
388 389 390 391 392 393 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 388 def rebuild(image_id, ={}) requires :identity service.rebuild_server(identity, image_id, ) self.state = REBUILD true end |
#rescue ⇒ Boolean
Rescue mode is only guaranteed to be active for 90 minutes.
Place existing server into rescue mode, allowing for offline editing of configuration. The original server’s disk is attached to a new instance of the same base image for a period of time to facilitate working within rescue mode. The original server will be automatically restored after 90 minutes.
-
Status Transition:
-
ACTIVE -> PREP_RESCUE -> RESCUE
-
467 468 469 470 471 472 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 467 def rescue requires :identity data = service.rescue_server(identity) merge_attributes(data.body) true end |
#resize(flavor_id) ⇒ Boolean
All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
Resize existing server to a different flavor, in essence, scaling the server up or down. The original server is saved for a period of time to allow rollback if there is a problem. All resizes should be tested and explicitly confirmed, at which time the original server is removed. All resizes are automatically confirmed after 24 hours if they are not confirmed or reverted.
-
Status Transition:
-
ACTIVE -> QUEUE_RESIZE -> PREP_RESIZE -> VERIFY_RESIZE
-
ACTIVE -> QUEUE_RESIZE -> ACTIVE (on error)
-
410 411 412 413 414 415 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 410 def resize(flavor_id) requires :identity service.resize_server(identity, flavor_id) self.state = RESIZE true end |
#revert_resize ⇒ Boolean
All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
Reverts server resize operation
-
Status Transition:
-
VERIFY_RESIZE -> ACTIVE
-
VERIFY_RESIZE -> ERROR (on error)
-
449 450 451 452 453 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 449 def revert_resize requires :identity service.revert_resize_server(identity) true end |
#save(options = {}) ⇒ Boolean
Saves the server. Creates server if it is new, otherwise it will update server attributes name, accessIPv4, and accessIPv6.
170 171 172 173 174 175 176 177 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 170 def save( = {}) if persisted? update else create() end true end |
#setup(credentials = {}) ⇒ Object
Setup server for SSH access This requires public_key_path and private_key_path to be passed into Compute service via Fog::Compute constructor or .fog file
517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 517 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.json} ]) rescue Errno::ECONNREFUSED sleep(1) retry end |
#unrescue ⇒ Boolean
Rescue mode is only guaranteed to be active for 90 minutes.
Remove existing server from rescue mode.
-
Status Transition:
-
PREP_UNRESCUE -> ACTIVE
-
486 487 488 489 490 491 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 486 def unrescue requires :identity service.unrescue_server(identity) self.state = ACTIVE true end |
#update ⇒ Object
If you edit the server name, the server host name does not change. Also, server names are not guaranteed to be unique.
Updates server This will update :name, :accessIPv4, and :accessIPv6 attributes.
-
State Transition
-
ACTIVE -> ACTIVE
-
223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 223 def update requires :identity = { 'name' => name, 'accessIPv4' => ipv4_address, 'accessIPv6' => ipv6_address } data = service.update_server(identity, ) merge_attributes(data.body['server']) true end |