Parent

Class/Module Index [+]

Quicksearch

Fog::Compute::RackspaceV2::Server

Public Class Methods

new(attributes={}) click to toggle source
# File lib/fog/rackspace/models/compute_v2/server.rb, line 161
def initialize(attributes={})
  @service = attributes[:service]
  super
end

Public Instance Methods

attach_volume(volume, device=nil) click to toggle source

Attaches Cloud Block Volume @param [Fog::Rackspace::BlockStorage::Volume, String] volume object or the volume id of volume to mount @param [String] device name of the device /dev/xvd[a-p] (optional) @return [Fog::Compute::RackspaceV2::Attachment] resulting attachment object @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @see docs.rackspace.com/servers/api/v2/cs-devguide/content/Attach_Volume_to_Server.html

# File lib/fog/rackspace/models/compute_v2/server.rb, line 376
def attach_volume(volume, device=nil)
  requires :identity
  volume_id = volume.is_a?(String) ? volume : volume.id
  attachments.create(:server_id => identity, :volume_id => volume_id, :device => device)
end
attachments() click to toggle source

Attached Cloud Block Volumes @return [Fog::Compute::RackspaceV2::Attachments] attached Cloud Block Volumes @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @see docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Volume_Attachments.html

# File lib/fog/rackspace/models/compute_v2/server.rb, line 358
def attachments
  @attachments ||= begin
    Fog::Compute::RackspaceV2::Attachments.new({
      :service => service,
      :server => self
    })
  end
end
change_admin_password(password) click to toggle source

Change admin password @param [String] password The administrator password. @return [Boolean] returns true if operation was scheduled @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @note 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. @see docs.rackspace.com/servers/api/v2/cs-devguide/content/Change_Password-d1e3234.html

# File lib/fog/rackspace/models/compute_v2/server.rb, line 556
def change_admin_password(password)
  requires :identity
  service.change_server_password(identity, password)
  self.state = PASSWORD
  self.password = password
  true
end
confirm_resize() click to toggle source

Confirms server resize operation @return [Boolean] returns true if resize has been confirmed @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize. @see docs.rackspace.com/servers/api/v2/cs-devguide/content/Confirm_Resized_Server-d1e3868.html @see resize

# File lib/fog/rackspace/models/compute_v2/server.rb, line 480
def confirm_resize
  requires :identity
  service.confirm_resize_server(identity)
  true
end
create(options) click to toggle source

Creates server

  • requires attributes: service:, :name, :image_id, and :flavor_id

  • optional attributes :disk_config, :metadata, :personality, :config_drive

@return [Boolean] returns true if server is being created @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @note You should use servers.create to create servers instead calling this method directly @see Servers#create @see docs.rackspace.com/servers/api/v2/cs-devguide/content/CreateServers.html

# File lib/fog/rackspace/models/compute_v2/server.rb, line 236
def create(options)
  requires :name, :image_id, :flavor_id
  modified_options = Marshal.load(Marshal.dump(options))

  if attributes[:keypair]
    Fog::Logger.deprecation(":keypair has been depreciated. Please use :key_name instead.")
    modified_options[:key_name] = attributes[:keypair]
  end

  modified_options[:password] ||= attributes[:password] unless password.nil?
  modified_options[:networks] ||= attributes[:networks]
  modified_options[:disk_config] = disk_config unless disk_config.nil?
  modified_options[:metadata] = metadata.to_hash unless @metadata.nil?
  modified_options[:personality] = personality unless personality.nil?
  modified_options[:config_drive] = config_drive unless config_drive.nil?
  modified_options[:user_data] = user_data_encoded unless user_data_encoded.nil?
  modified_options[:key_name] ||= attributes[:key_name]

  if modified_options[:networks]
    modified_options[:networks].map! { |id| { :uuid => id } }
  end
  data = service.create_server(name, image_id, flavor_id, 1, 1, modified_options)
  merge_attributes(data.body['server'])
  true
end
create_image(name, options = {}) click to toggle source

Creates Image from server. Once complete, a new image is available that you can use to rebuild or create servers. @param name [String] name of image to create @param options [Hash]: @option options [Hash<String, String>] metadata hash of containing metadata key value pairs. @return [Fog::ComputeRackspaceV2::Image] image being created @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @see docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_Image-d1e4655.html

  • State Transition:

# File lib/fog/rackspace/models/compute_v2/server.rb, line 340
def create_image(name, options = {})
  requires :identity
  response = service.create_image(identity, name, options)
  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() click to toggle source

Destroy the server @return [Boolean] returns true if server has started deleting @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @see docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Server-d1e2883.html

# File lib/fog/rackspace/models/compute_v2/server.rb, line 298
def destroy
  requires :identity
  service.delete_server(identity)
  true
end
flavor() click to toggle source

Server flavor @return [Fog::Compute::RackspaceV2::Flavor] server flavor @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError]

# File lib/fog/rackspace/models/compute_v2/server.rb, line 310
def flavor
  requires :flavor_id
  @flavor ||= service.flavors.get(flavor_id)
end
image() click to toggle source

Server image @return [Fog::Compute::RackspaceV2::Image] server image @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError]

# File lib/fog/rackspace/models/compute_v2/server.rb, line 321
def image
  requires :image_id
  @image ||= service.images.get(image_id)
end
key_pair() click to toggle source

Returns the key pair based on the key_name of the server @return [KeyPair] @note The key_pair/key_name is used to specify the keypair used for server creation. It is not populated by cloud servers.

# File lib/fog/rackspace/models/compute_v2/server.rb, line 191
def key_pair
  requires :key_name

  service.key_pairs.get(key_name)
end
key_pair=(new_keypair) click to toggle source

Sets the key_pair used by the server. @param new_keypair [KeyPair] key_pair object for server @note The key_pair/key_name is used to specify the keypair used for server creation. It is not populated by cloud servers.

# File lib/fog/rackspace/models/compute_v2/server.rb, line 200
def key_pair=(new_keypair)
  if new_keypair.is_a?(String)
     Fog::Logger.deprecation("#key_pair= should be used to set KeyPair objects. Please use #key_name method instead")
    self.key_name = new_keypair
  else
    self.key_name = new_keypair && new_keypair.name
  end
end
metadata() click to toggle source

Server metadata @return [Fog::Compute::RackspaceV2::Metadata] metadata key value pairs.

# File lib/fog/rackspace/models/compute_v2/server.rb, line 173
def metadata
  @metadata ||= begin
    Fog::Compute::RackspaceV2::Metadata.new({
      :service => service,
      :parent => self
    })
  end
end
metadata=(hash={}) click to toggle source

Set server metadata @param [Hash] hash contains key value pairs

# File lib/fog/rackspace/models/compute_v2/server.rb, line 184
def metadata=(hash={})
  metadata.from_hash(hash)
end
private_ip_address() click to toggle source

Server’s private IPv4 address @return [String] private IPv4 address

# File lib/fog/rackspace/models/compute_v2/server.rb, line 384
def private_ip_address
  addresses['private'].select{|a| a["version"] == 4}[0]["addr"] rescue ''
end
public_ip_address() click to toggle source

Server’s public IPv4 address @return [String] public IPv4 address

# File lib/fog/rackspace/models/compute_v2/server.rb, line 390
def public_ip_address
  ipv4_address
end
ready?(ready_state = ACTIVE, error_states=[ERROR]) click to toggle source

Is server is in ready state @param [String] ready_state By default state is ACTIVE @param [Array,String] error_states By default state is ERROR @return [Boolean] returns true if server is in a ready state @raise [Fog::Compute::RackspaceV2::InvalidServerStateException] if server state is an error state

# File lib/fog/rackspace/models/compute_v2/server.rb, line 399
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') click to toggle source

Reboot server @param [String<SOFT, HARD>] type ‘SOFT’ will do a soft reboot. ‘HARD’ will do a hard reboot. @return [Boolean] returns true if server is being rebooted @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @see docs.rackspace.com/servers/api/v2/cs-devguide/content/Reboot_Server-d1e3371.html

# File lib/fog/rackspace/models/compute_v2/server.rb, line 419
def reboot(type = 'SOFT')
  requires :identity
  service.reboot_server(identity, type)
  self.state = type == 'SOFT' ? REBOOT : HARD_REBOOT
  true
end
rebuild(image_id, options={}) click to toggle source

Rebuild removes all data on the server and replaces it with the specified image. The id and all IP addresses remain the same. @param [String] image_id image to use for rebuild @return [Boolean] returns true if rebuild is in process @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @see docs.rackspace.com/servers/api/v2/cs-devguide/content/Rebuild_Server-d1e3538.html

# File lib/fog/rackspace/models/compute_v2/server.rb, line 438
def rebuild(image_id, options={})
  requires :identity
  service.rebuild_server(identity, image_id, options)
  self.state = REBUILD
  true
end
rescue() click to toggle source

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. @return [Boolean] returns true if call to put server in rescue mode reports success @raise [Fog::Rackspace::Errors::NotFound] - HTTP 404 @raise [Fog::Rackspace::Errors::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Errors::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Errors::ServiceError] @note Rescue mode is only guaranteed to be active for 90 minutes. @see docs.rackspace.com/servers/api/v2/cs-devguide/content/rescue_mode.html @see unrescue

# File lib/fog/rackspace/models/compute_v2/server.rb, line 517
def rescue
  requires :identity
  data = service.rescue_server(identity)
  merge_attributes(data.body)
  true
end
resize(flavor_id) click to toggle source

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. @param [String] flavor_id to resize @return [Boolean] returns true if resize is in process @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize. @see docs.rackspace.com/servers/api/v2/cs-devguide/content/Resize_Server-d1e3707.html @see confirm_resize @see revert_resize

# File lib/fog/rackspace/models/compute_v2/server.rb, line 460
def resize(flavor_id)
  requires :identity
  service.resize_server(identity, flavor_id)
  self.state = RESIZE
  true
end
revert_resize() click to toggle source

Reverts server resize operation @return [Boolean] returns true if resize is being reverted @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize. @see docs.rackspace.com/servers/api/v2/cs-devguide/content/Revert_Resized_Server-d1e4024.html @see resize

# File lib/fog/rackspace/models/compute_v2/server.rb, line 499
def revert_resize
  requires :identity
  service.revert_resize_server(identity)
  true
end
save(options = {}) click to toggle source

Saves the server. Creates server if it is new, otherwise it will update server attributes name, accessIPv4, and accessIPv6. @return [Boolean] true if server has started saving

# File lib/fog/rackspace/models/compute_v2/server.rb, line 212
def save(options = {})
  if persisted?
    update
  else
    create(options)
  end
  true
end
setup(credentials = {}) click to toggle source

Setup server for SSH access @see Servers#bootstrap

# File lib/fog/rackspace/models/compute_v2/server.rb, line 566
def setup(credentials = {})
  requires :ssh_ip_address, :identity, :public_key, :username

  retried_disconnect = false

  commands = [
    %{mkdir .ssh},
    %{echo "#{public_key}" >> ~/.ssh/authorized_keys},
    password_lock,
    %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
    %{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
  ]
  commands.compact

  self.password = nil if password_lock

  Fog::SSH.new(ssh_ip_address, username, credentials).run(commands)
rescue Errno::ECONNREFUSED
  sleep(1)
  retry
# Ubuntu 12.04 images seem to be disconnecting during the ssh setup process.
# This rescue block is an effort to address that issue.
rescue Net::SSH::Disconnect
  unless retried_disconnect
    retried_disconnect = true
    sleep(1)
    retry
  end
end
unrescue() click to toggle source

Remove existing server from rescue mode. @return [Boolean] returns true if call to remove server from rescue mode reports success @raise [Fog::Rackspace::Errors::NotFound] - HTTP 404 @raise [Fog::Rackspace::Errors::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Errors::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Errors::ServiceError] @note Rescue mode is only guaranteed to be active for 90 minutes. @see docs.rackspace.com/servers/api/v2/cs-devguide/content/exit_rescue_mode.html @see rescue

  • Status Transition:

# File lib/fog/rackspace/models/compute_v2/server.rb, line 536
def unrescue
  requires :identity
  service.unrescue_server(identity)
  self.state = ACTIVE
  true
end
update() click to toggle source

Updates server This will update :name, :accessIPv4, and :accessIPv6 attributes. @note If you edit the server name, the server host name does not change. Also, server names are not guaranteed to be unique. @return true if update has started updating @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError] @see docs.rackspace.com/servers/api/v2/cs-devguide/content/ServerUpdate.html

# File lib/fog/rackspace/models/compute_v2/server.rb, line 274
def update
  requires :identity
  options = {
    'name' => name,
    'accessIPv4' => ipv4_address,
    'accessIPv6' => ipv6_address
  }

  data = service.update_server(identity, options)
  merge_attributes(data.body['server'])
  true
end
virtual_interfaces() click to toggle source
# File lib/fog/rackspace/models/compute_v2/server.rb, line 596
def virtual_interfaces
  @virtual_interfaces ||= Fog::Compute::RackspaceV2::VirtualInterfaces.new :server => self, :service => service
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.