1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[rackspace|compute] Adding API documentation

This commit is contained in:
Kyle Rames 2013-01-30 09:05:10 -06:00
parent 9543504ba7
commit 66e9833a99
40 changed files with 754 additions and 29 deletions

View file

@ -4,8 +4,17 @@ module Fog
module Compute
class RackspaceV2
class Attachment < Fog::Model
# @!attribute [r] server_id
# @return [String] The server id
attribute :server_id, :aliases => 'serverId'
# @!attribute [r] volume_id
# @return [String] The volume id
attribute :volume_id, :aliases => 'volumeId'
# @!attribute [r] device
# @return [String]device name of the device /dev/xvd[a-p]
attribute :device
def initialize(new_attributes = {})
@ -14,6 +23,10 @@ module Fog
self
end
# Attaches volume to volume to server.
# Requires :server_id, :volume_id, and device to be populated
# @return [Boolean] true if volume is attaching
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Attach_Volume_to_Server.html
def save
requires :server_id, :volume_id, :device
data = service.attach_volume(server_id, volume_id, device)
@ -21,6 +34,9 @@ module Fog
true
end
# Detaches volume from server
# @return [Boolean] true if volume is detaching
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Volume_Attachment.html
def destroy
requires :server_id, :volume_id
service.delete_attachment(server_id, volume_id)

View file

@ -10,11 +10,17 @@ module Fog
attr_accessor :server
# Retrieves attachments belonging to server
# @return [Array<Fog::Compute::RackspaceV2::Attachment>] list of attachments
# @see Server#attachments
def all
data = service.list_attachments(server.id).body['volumeAttachments']
load(data)
end
# Retrieves attachment belonging to server
# @param [String] volume_id
# @return [Fog::Compute::RackspaceV2::Attachment] attachment for volume id
def get(volume_id)
data = service.get_attachment(server.id, volume_id).body['volumeAttachment']
data && new(data)

View file

@ -4,12 +4,30 @@ module Fog
module Compute
class RackspaceV2
class Flavor < Fog::Model
# @!attribute [r] id
# @return [String] The flavor id
identity :id
# @!attribute [r] name
# @return [String] flavor name
attribute :name
# @!attribute [r] rame
# @return [Fixnum] ram in MB
attribute :ram
# @!attribute [r] disk
# @return [String] disk space in GB
attribute :disk
# @!attribute [r] vcpus
# @return [Fixnum] number of virtual CPUs
attribute :vcpus
# @!attribute [r] links
# @return [Array] flavor links.
attribute :links
end
end

View file

@ -8,12 +8,20 @@ module Fog
model Fog::Compute::RackspaceV2::Flavor
# Retrieves information for all available flavors
# @return [Array<Fog::Compute::RackspaceV2::Flavor>] list of flavors
# @note Fog's currentl implementation only returns 1000 flavors.
# @note Fog does not retrieve all flavor details. Please use #get to retrieve all details for a specific flavor.
def all
data = service.list_flavors.body['flavors']
load(data)
end
def get(flavor_id)
# Retrieve image
# @param [String] flavor_id id of flavor
# @return [Fog::Compute::RackspaceV2::Flavor] flavor
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Flavor_Details-d1e4317.html
def get(flavor_id)
data = service.get_flavor(flavor_id).body['flavor']
new(data)
rescue Fog::Compute::RackspaceV2::NotFound

View file

@ -10,18 +10,57 @@ module Fog
ERROR = 'ERROR'
DELETED = 'DELETED'
# @!attribute [r] id
# @return [String] The server id
identity :id
# @!attribute [r] name
# @return [String] The image name.
attribute :name
# @!attribute [r] created
# @return [String] The time stamp for the creation date.
attribute :created
# @!attribute [r] updated
# @return [String] The time stamp for the last update.
attribute :updated
# @!attribute [r] state
# @return [String] image status.
attribute :state, :aliases => 'status'
# @!attribute [r] user_id
# @return [String] The user Id.
attribute :user_id
# @!attribute [r] tenant_id
# @return [String] The tenant Id.
attribute :tenant_id
# @!attribute [r] progress
# @return [Fixnum] The build completion progress, as a percentage. Value is from 0 to 100.
attribute :progress
attribute :minDisk
attribute :minRam
# @!attribute [rw] disk_config
# @return [String<AUTO, MANUAL>] The disk configuration value.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#diskconfig_attribute
#
# 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.
attribute :disk_config, :aliases => 'OS-DCF:diskConfig'
# @!attribute [r] links
# @return [Array] image links.
attribute :links
def initialize(attributes={})
@ -29,6 +68,8 @@ module Fog
super
end
# Image metadata
# @return [Fog::Compute::RackspaceV2::Metadata] Collection of Fog::Compute::RackspaceV2::Metadatum objects containing metadata key value pairs.
def metadata
@metadata ||= begin
Fog::Compute::RackspaceV2::Metadata.new({
@ -38,10 +79,17 @@ module Fog
end
end
# Set server metadata
# @param [Hash] hash contains key value pairs
def metadata=(hash={})
metadata.from_hash(hash)
end
# Is image 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 [RuntimeException] if server state is an error state
def ready?(ready_state = ACTIVE, error_states=[ERROR])
if error_states
error_states = Array(error_states)
@ -51,6 +99,7 @@ module Fog
end
# Destroy image
def destroy
requires :identity
service.delete_image(identity)

View file

@ -8,11 +8,20 @@ module Fog
model Fog::Compute::RackspaceV2::Image
# Returns list of images
# @return [Array<Fog::Compute::RackspaceV2::Image>] Retrieves a list images.
# @note Fog's current implementation only returns 1000 images.
# @note Fog does not retrieve all image details. Please use get to retrieve all details for a specific image.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Images-d1e4435.html
def all
data = service.list_images.body['images']
load(data)
end
# Retrieve image
# @param [String] image_id id of image
# @return [Fog::Compute::RackspaceV2:Image] image
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Image_Details-d1e4848.html
def get(image_id)
data = service.get_image(image_id).body['image']
new(data)

View file

@ -3,14 +3,21 @@ module Fog
class RackspaceV2
module MetaParent
# Parent of metadata
# @return [#parent] parent of metadata
def parent
@parent
end
# Sets parent of metadata
# @param [#parent] new_parent of metadata
def parent=(new_parent)
@parent = new_parent
end
# Collection type for parent
# @return [String] collection type
# @raise [RuntimeException] raises excpetion if collection type for parent is unknown
def collection_name
if parent.class == Fog::Compute::RackspaceV2::Image
return "images"
@ -21,6 +28,8 @@ module Fog
end
end
# Converts metadata to hash
# @return [Hash] hash containing key value pairs for metadata
def metas_to_hash(metas)
hash = {}
metas.each { |meta| hash[meta.key] = meta.value }

View file

@ -14,6 +14,8 @@ module Fog
include Fog::Compute::RackspaceV2::MetaParent
# Retrieves all of the metadata from server
# @return [Array<Fog::Compute::RackspaceV2::Metadatum>] list of metadatum
def all
requires :parent
return unless parent.identity
@ -21,6 +23,9 @@ module Fog
from_hash(data)
end
# Retrieves specific metadata from server
# @param [String] key for metadatum
# @return [Fog::Compute::RackspaceV2::Metadatum] metadatum
def get(key)
requires :parent
data = connection.get_metadata_item(collection_name, parent.id, key).body["meta"]
@ -30,13 +35,23 @@ module Fog
nil
end
# Retrieve specific value for key from Metadata.
# * If key is of type String, this method will return the value of the metadatum
# * If key is of type Fixnum, this method will return a Fog::Compute::RackspaceV2::Metadatum object (legacy)
# @param [#key] key
# @return [#value]
def [](key)
return super(key) if key.is_a?(Integer)
return nil unless key
datum = self.find {|datum| datum.key == key || datum.key == key.to_sym }
datum ? datum.value : nil
end
# Set value for key.
# * If key is of type String, this method will set/add the value to Metadata
# * If key is of type Fixnum, this method will set a Fog::Compute::RackspaceV2::Metadatum object (legacy)
# @param [#key] key
# @return [String]
def []=(key, value)
return super(key,value) if key.is_a?(Integer)
return nil unless key
@ -49,16 +64,21 @@ module Fog
value
end
# Saves the current metadata on server
def save
requires :parent
connection.set_metadata(collection_name, parent.id, to_hash)
end
# Creates new metadata
def new(attributes = {})
requires :parent
super({ :parent => parent }.merge!(attributes))
end
# Resets metadata using data from hash
# @param hash hash containing key value pairs used to populate metadata.
# @note This will remove existing data
def from_hash(hash)
return unless hash
metas = []
@ -66,6 +86,8 @@ module Fog
load(metas)
end
# Converts metadata object to hash
# @return [Hash] hash of metadata key value pairs
def to_hash
h = {}
self.each { |datum| h[datum.key] = datum.value }

View file

@ -11,12 +11,16 @@ module Fog
identity :key
attribute :value
# Remove metadatum from server
# @return [Boolean] return true if metadatum is deleting
def destroy
requires :identity
connection.delete_metadata_item(collection_name, parent.id, key)
true
end
# Save metadatum on server
# @return [Boolean] return true if metadatum is saving
def save
requires :identity, :value
connection.set_metadata_item(collection_name, parent.id, key, value)

View file

@ -22,26 +22,120 @@ module Fog
UNKNOWN = 'UNKNOWN'
VERIFY_RESIZE = 'VERIFY_RESIZE'
# @!attribute [r] id
# @return [String] The server id
identity :id
# @!attribute [rw] name
# @return [String] The server name.
attribute :name
# @!attribute [r] created
# @return [String] The time stamp for the creation date.
attribute :created
# @!attribute [r] updated
# @return [String] The time stamp for the last update.
attribute :updated
# @!attribute [r] host Id
# 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.
# @return [String] host id.
attribute :host_id, :aliases => 'hostId'
# @!attribute [r] state
# @return [String] server status.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Servers-d1e2078.html#server_status
attribute :state, :aliases => 'status'
attribute :progress
attribute :user_id
attribute :tenant_id
attribute :links
attribute :personality
attribute :ipv4_address, :aliases => 'accessIPv4'
attribute :ipv6_address, :aliases => 'accessIPv6'
attribute :disk_config, :aliases => 'OS-DCF:diskConfig'
attribute :bandwidth, :aliases => 'rax-bandwidth:bandwidth'
attribute :addresses
attribute :flavor_id, :aliases => 'flavor', :squash => 'id'
attribute :image_id, :aliases => 'image', :squash => 'id'
# @!attribute [r] progress
# @return [Fixnum] The build completion progress, as a percentage. Value is from 0 to 100.
attribute :progress
# @!attribute [r] user_id
# @return [String] The user Id.
attribute :user_id
# @!attribute [r] tenant_id
# @return [String] The tenant Id.
attribute :tenant_id
# @!attribute [r] links
# @return [Array] Server links.
attribute :links
# @!attribute [rw] personality
# @note This attribute is only used for server creation. This field will be nil on subsequent retrievals.
# @return [Hash] Hash containing data to inject into the file system of the cloud server instance during server creation.
# @example To inject fog.txt into file system
# :personality => [{ :path => '/root/fog.txt',
# :contents => Base64.encode64('Fog was here!')
# }]
# @see #create
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Personality-d1e2543.html
attribute :personality
# @!attribute [rw] ipv4_address
# @return [String] The public IP version 4 access address.
# @note This field will populate once the server is ready to use.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Primary_Addresses-d1e2558.html
attribute :ipv4_address, :aliases => 'accessIPv4'
# @!attribute [rw] ipv6_address
# @return [String] The public IP version 6 access address.
# @note This field will populate once the server is ready to use.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Primary_Addresses-d1e2558.html
attribute :ipv6_address, :aliases => 'accessIPv6'
# @!attribute [rw] disk_config
# @return [String<AUTO, MANUAL>] The disk configuration value.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#diskconfig_attribute
#
# 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.
attribute :disk_config, :aliases => 'OS-DCF:diskConfig'
# @!attribute [r] bandwidth
# @return [Array] The amount of bandwidth used for the specified audit period.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#bandwidth_extension
attribute :bandwidth, :aliases => 'rax-bandwidth:bandwidth'
# @!attribute [r] address
# @return [Hash<String, Array[Hash]>] IP addresses allocated for server by network
# @example
# {
# "public" => [
# {"version"=>4, "addr"=>"166.78.105.63"},
# {"version"=>6, "addr"=>"2001:4801:7817:0072:0fe1:75e8:ff10:61a9"}
# ],
# "private"=> [{"version"=>4, "addr"=>"10.177.18.209"}]
# }
attribute :addresses
# @!attribute [r] flavor_id
# @return [String] The flavor Id.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Flavors-d1e4188.html
attribute :flavor_id, :aliases => 'flavor', :squash => 'id'
# @!attribute [r] image_id
# @return [String] The image Id.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Images-d1e4435.html
attribute :image_id, :aliases => 'image', :squash => 'id'
# @!attribute [r] password
# @return [String] Password for system adminstrator account.
# @note This value is ONLY populated on server creation.
attr_reader :password
def initialize(attributes={})
@ -54,6 +148,8 @@ module Fog
alias :access_ipv6_address :ipv6_address
alias :access_ipv6_address= :ipv6_address=
# Server metadata
# @return [Fog::Compute::RackspaceV2::Metadata] metadata key value pairs.
def metadata
@metadata ||= begin
Fog::Compute::RackspaceV2::Metadata.new({
@ -63,10 +159,15 @@ module Fog
end
end
# Set server metadata
# @param [Hash] hash contains key value pairs
def metadata=(hash={})
metadata.from_hash(hash)
end
# 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
def save
if persisted?
update
@ -76,6 +177,17 @@ module Fog
true
end
# Creates server
# * requires attributes: service:, :name, :image_id, and :flavor_id
# * optional attributes :disk_config, :metadata, :personality
# @return [Boolean] returns true if server is being created
# @note You should use servers.create to create servers instead calling this method directly
# @see Servers#create
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/CreateServers.html
#
# * State Transitions
# * BUILD -> ACTIVE
# * BUILD -> ERROR (on error)
def create
requires :name, :image_id, :flavor_id
@ -89,6 +201,14 @@ module Fog
true
end
# 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
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ServerUpdate.html
#
# * State Transition
# * ACTIVE -> ACTIVE
def update
requires :identity
options = {
@ -102,22 +222,43 @@ module Fog
true
end
# Destroy the server
# @return [Boolean] returns true if server has started deleting
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Server-d1e2883.html
#
# * Status Transition:
# * ACTIVE -> DELETED
# * ERROR -> DELETED
def destroy
requires :identity
service.delete_server(identity)
true
end
# Server flavor
# @return [Fog::Compute::RackspaceV2::Flavor] server flavor
def flavor
requires :flavor_id
@flavor ||= service.flavors.get(flavor_id)
end
# Server image
# @return [Fog::Compute::RackspaceV2::Image] server image
def image
requires :image_id
@image ||= service.images.get(image_id)
end
# 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
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_Image-d1e4655.html
#
# * State Transition:
# * SAVING -> ACTIVE
# * SAVING -> ERROR (on error)
def create_image(name, options = {})
requires :identity
response = service.create_image(identity, name, options)
@ -129,6 +270,9 @@ module Fog
end
end
# Attached Cloud Block Volumes
# @return [Fog::Compute::RackspaceV2::Attachments] attached Cloud Block Volumes
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Volume_Attachments.html
def attachments
@attachments ||= begin
Fog::Compute::RackspaceV2::Attachments.new({
@ -138,20 +282,34 @@ module Fog
end
end
# 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
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Attach_Volume_to_Server.html
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
# Server's private IPv4 address
# @return [String] private IPv4 address
def private_ip_address
addresses['private'].select{|a| a["version"] == 4}[0]["addr"]
end
# Server's public IPv4 address
# @return [String] public IPv4 address
def public_ip_address
ipv4_address
end
# 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 [RuntimeException] if server state is an error state
def ready?(ready_state = ACTIVE, error_states=[ERROR])
if error_states
error_states = Array(error_states)
@ -160,6 +318,13 @@ module Fog
state == ready_state
end
# Reboot server
# @param [String<SOFT, HARD>] type 'SOFT' will do a soft reboot. 'HARD' will do a hard reboot.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Reboot_Server-d1e3371.html
#
# * State transition:
# * ACTIVE -> REBOOT -> ACTIVE (soft reboot)
# * ACTIVE -> HARD_REBOOT -> ACTIVE (hard reboot)
def reboot(type = 'SOFT')
requires :identity
service.reboot_server(identity, type)
@ -167,13 +332,15 @@ module Fog
true
end
def resize(flavor_id)
requires :identity
service.resize_server(identity, flavor_id)
self.state = RESIZE
true
end
# 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
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Rebuild_Server-d1e3538.html
#
# * Status Transition:
# * ACTIVE -> REBUILD -> ACTIVE
# * ACTIVE -> REBUILD -> ERROR (on error)
def rebuild(image_id, options={})
requires :identity
service.rebuild_server(identity, image_id, options)
@ -181,18 +348,61 @@ module Fog
true
end
# 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 to resize
# @return [Boolean] returns true if resize is in process
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Resize_Server-d1e3707.html
# @see #confirm_resize
# @see #revert_resize
#
# * Status Transition:
# * ACTIVE -> QUEUE_RESIZE -> PREP_RESIZE -> VERIFY_RESIZE
# * ACTIVE -> QUEUE_RESIZE -> ACTIVE (on error)
def resize(flavor_id)
requires :identity
service.resize_server(identity, flavor_id)
self.state = RESIZE
true
end
# Confirms server resize operation
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Confirm_Resized_Server-d1e3868.html
# @see #resize
#
# * Status Transition:
# * VERIFY_RESIZE -> ACTIVE
# * VERIFY_RESIZE -> ERROR (on error)
def confirm_resize
requires :identity
service.confirm_resize_server(identity)
true
end
# Reverts server resize operation
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Revert_Resized_Server-d1e4024.html
# @see #resize
#
# * Status Transition:
# * VERIFY_RESIZE -> ACTIVE
# * VERIFY_RESIZE -> ERROR (on error)
def revert_resize
requires :identity
service.revert_resize_server(identity)
true
end
# Change admin password
# @param [String] password The administrator password.
# @return [Boolean] returns true if operation was scheduled
# @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 http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Change_Password-d1e3234.html
#
# * Status Transition:
# * ACTIVE -> PASSWORD -> ACTIVE
# * ACTIVE -> PASSWORD -> ERROR (on error)
def change_admin_password(password)
requires :identity
service.change_server_password(identity, password)
@ -201,6 +411,9 @@ module Fog
true
end
# 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
# @see Servers#bootstrap
def setup(credentials = {})
requires :public_ip_address, :identity, :public_key, :username
Fog::SSH.new(public_ip_address, username, credentials).run([

View file

@ -9,11 +9,26 @@ module Fog
model Fog::Compute::RackspaceV2::Server
# Returns list of servers
# @return [Array<Fog::Compute::RackspaceV2::Server>] Retrieves a list servers.
# @note Fog's current implementation only returns 1000 servers
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Servers-d1e2078.html
def all
data = service.list_servers.body['servers']
load(data)
end
# Creates a new server and populates ssh keys
# @example
# service = Fog::Compute.new(:provider => 'rackspace',
# :version => :v2,
# :public_key_path => '~/.ssh/fog_rsa.pub',
# :private_key_path => '~/.ssh/fog_rsa')
#
# service.servers.bootstrap :name => 'bootstap-server',
# :flavor_id => service.flavors.first.id
# :image_id => service.servers.first.id
#
def bootstrap(new_attributes = {})
server = create(new_attributes)
server.wait_for { ready? }
@ -21,6 +36,10 @@ module Fog
server
end
# Retrieves server
# @param [String] server_id for server to be returned
# @return [Fog::Compute::RackspaceV2:Server]
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Server_Details-d1e2623.html
def get(server_id)
data = service.get_server(server_id).body['server']
new(data)

View file

@ -2,6 +2,19 @@ module Fog
module Compute
class RackspaceV2
class Real
# This operation attaches a volume to the specified server.
# @param [String] server_id
# @param [String] volume_id
# @param [String] device name of the device /dev/xvd[a-p] (optional)
# @return [Excon::Response] response:
# * body [Hash]:
# * volumeAttachment [Hash]:
# * device [String] - The name of the device, such as /dev/xvdb. Specify auto for auto-assignment.
# * serverId [String] - The id of the server that attached the volume
# * id [String] - The id of the attachment
# * volumeId [String] - The id of the volume that was attached
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Attach_Volume_to_Server.html
def attach_volume(server_id, volume_id, device)
data = {
'volumeAttachment' => {

View file

@ -2,6 +2,13 @@ module Fog
module Compute
class RackspaceV2
class Real
# Changes server admin password
# @param [String] server_id
# @param [String] password
# @return [Excon::Response] response
# @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 http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Change_Password-d1e3234.html
def change_server_password(server_id, password)
data = {
'changePassword' => {

View file

@ -2,6 +2,15 @@ module Fog
module Compute
class RackspaceV2
class Real
# Confirm server resize operation
# @param [String] server_id The id of the server to revert
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Revert_Resized_Server-d1e4024.html
#
# * Status Transition:
# * VERIFY_RESIZE -> ACTIVE
# * VERIFY_RESIZE -> ERROR (on error)
def confirm_resize_server(server_id)
data = {
'confirmResize' => nil

View file

@ -5,11 +5,15 @@ module Fog
# Create an image from a running server
#
# ==== Parameters
# * server_id<~Integer> - Id of server to create image from
# * name - Name of image
# * options<~Hash> - Name
# @param [String] server_id Id of server to create image from
# @param [String] name name for created image
# @param [Hash] options
# @option options [Hash ]:metadata - key value pairs of image metadata
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_Image-d1e4655.html
#
# * State Transition:
# * SAVING -> ACTIVE
# * SAVING -> ERROR (on error)
def create_image(server_id, name, options = {})
data = {
'createImage' => {

View file

@ -2,6 +2,40 @@ module Fog
module Compute
class RackspaceV2
class Real
# Create server
# @param [String] name name of server
# @param [String] image_id id of the image used to create server
# @param [String] flavor_id id of the flavor of the image
# @param [String] min_count
# @param [String] max_count
# @param [Hash] options
# @option options [Hash] metadata key value pairs of server metadata
# @option options [String] OS-DCF:diskConfig The disk configuration value. (AUTO or MANUAL)
# @option options [Hash] personality Hash containing data to inject into the file system of the cloud server instance during server creation.
# @return [Excon::Response] response:
# * body [Hash]:
# * server [Hash]:
# * name [String] - name of server
# * imageRef [String] - id of image used to create server
# * flavorRef [String] - id of flavor used to create server
# * OS-DCF:diskConfig [String] - The disk configuration value.
# * name [String] - name of server
# * metadata [Hash] - Metadata key and value pairs.
# * personality [Array]:
# * [Hash]:
# * path - path of the file created
# * contents - Base 64 encoded file contents
# * networks [Array]:
# * [Hash]:
# * uuid [String] - uuid of attached network
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/CreateServers.html
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Metadata-d1e2529.html
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Personality-d1e2543.html
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#diskconfig_attribute
#
# * State Transitions
# * BUILD -> ACTIVE
# * BUILD -> ERROR (on error)
def create_server(name, image_id, flavor_id, min_count, max_count, options = {})
data = {
'server' => {

View file

@ -2,6 +2,11 @@ module Fog
module Compute
class RackspaceV2
class Real
# Deletes a specified volume attachment from a specified server instance.
# @param [String] server_id id of server containing volume to delete
# @param [String] volume_id id of volume on server to delete
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Volume_Attachment.html
def delete_attachment(server_id, volume_id)
request(
:expects => [202],

View file

@ -4,10 +4,8 @@ module Fog
class Real
# Delete an image
#
# ==== Parameters
# * image_id<~Integer> - Id of image to delete
#
# @param [String] image_id Id of image to delete
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Image-d1e4957.html
def delete_image(image_id)
request(
:expects => 204,

View file

@ -2,6 +2,12 @@ module Fog
module Compute
class RackspaceV2
class Real
# Deletes a metadata item.
# @param [String<images, servers>] collection type of metadata
# @param [String] obj_id id of the object where the metadata is attached
# @param [String] key the key of the metadata to delete
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Metadata_Item-d1e5790.html
def delete_metadata_item(collection, obj_id, key)
request(
:expects => 204,

View file

@ -2,6 +2,10 @@ module Fog
module Compute
class RackspaceV2
class Real
# Deletes a specified server instance from the system.
# @param [String] server_id the id of the server to delete
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Server-d1e2883.html
def delete_server(server_id)
request(
:expects => [204],

View file

@ -2,6 +2,18 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves attachment
# @param [String] server_id
# @param [String] volume_id
# @return [Excon::Response] response:
# * body [Hash]:
# * volumeAttachment [Hash]:
# * device [String] - The name of the device, such as /dev/xvdb. Specify auto for auto-assignment.
# * serverId [String] - The id of the server that attached the volume
# * id [String] - The id of the attachment
# * volumeId [String] - The id of the volume that was attached
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Volume_Attachment_Details.html
def get_attachment(server_id, volume_id)
request(
:expects => [200, 203, 300],

View file

@ -2,6 +2,20 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves flavor detail
# @param [Sring] flavor_id
# @return [Excon::Response] response:
# * body [Hash]:
# * flavor [Hash]:
# * disk [Fixnum] - disk size in GB
# * id [String] - id of flavor
# * name [String] - name of flavor
# * ram [Fixnum] - amount of ram in MB
# * swap [Fixnum] - amount of swap in GB
# * vcpus [Fixnum] - number of virtual CPUs
# * links [Array] - links to flavor
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Flavor_Details-d1e4317.html
def get_flavor(flavor_id)
request(
:expects => [200, 203],

View file

@ -2,6 +2,24 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves image detail
# @param [String] image_id
# @return [Excon::Response] response:
# * body [Hash]:
# * image [Hash]:
# * OS-DCF:diskConfig [String] - The disk configuration value.
# * created [String] - created timestamp
# * id [String] - id of image
# * metadata [Hash] - image metadata
# * minDisk [Fixnum]
# * minRam [Fixnum]
# * name [String] - name of image
# * progress [Fixnum] - progress complete. Value is from 0 to 100.
# * status [String] - status of current image
# * updated [String] - updated timestamp
# * links [Array] - links to flavor
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Image_Details-d1e4848.html
def get_image(image_id)
request(
:expects => [200, 203],

View file

@ -2,6 +2,15 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves single metadatum item by key.
# @param [String<images, servers>] collection type of metadata
# @param [String] obj_id id of the object where the metadata is attached
# @param [String] key the key of the metadata to retrieve
# @return [Excon::Response] response:
# * body [Hash]:
# * meta [Hash]:
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Metadata_Item-d1e5507.html
def get_metadata_item(collection, obj_id, key)
request(
:expects => 200,

View file

@ -2,6 +2,38 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves server detail
# @param [String] server_id
# @return [Excon::Response] response:
# * body [Hash]:
# * server [Hash]:
# * OS-DCF:diskConfig [String] - The disk configuration value.
# * OS-EXT-STS:power_state [Fixnum] - The power state.
# * OS-EXT-STS:task_state [String] - The task state.
# * OS-EXT-STS:vm_state [String] - The VM state.
# * accessIPv4 [String] - The public IP version 4 access address.
# * accessIPv6 [String] - The public IP version 6 access address.
# * addresses [Hash] - Public and private IP addresses, The version field indicates whether the IP address is version 4 or 6.
# * created [String] - created timestamp
# * hostId [String] - The host id.
# * id [String] - id of image
# * image [Hash]:
# * id [String] - id of the image
# * links [Hash] - links to image
# * flavor [Hash]:
# * id [String] - id of the flavor
# * links [Hash] - links to flavor
# * links [Hash] - links to server
# * metadata [Hash] - server metadata
# * name [String] - name of server
# * progress [Fixnum] - progress complete. Value is from 0 to 100.
# * rax-bandwidth:bandwidth [Array] - The amount of bandwidth used for the specified audit period.
# * status [String] - The server status.
# * tenant_id [String] - The tenant ID.
# * updated [String] - updated timestamp
# * user_id [Array] - The user ID.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Server_Details-d1e2623.html
def get_server(server_id)
request(
:expects => [200, 203, 300],

View file

@ -3,6 +3,11 @@ module Fog
class RackspaceV2
class Real
# Lists all networks and addresses associated with a specified server.
# @param [String] server_id
# @return [Excon::Response] response:
# * body [Hash]:
# * addresses [Hash] - key is the network name and the value are an array of addresses allocated for that network
def list_addresses(server_id)
request(
:method => 'GET',

View file

@ -3,6 +3,18 @@ module Fog
class RackspaceV2
class Real
# Lists all addresses associated with a specified server and network
# @param [String] server_id
# @param [String] network_id
# @return [Excon::Response] response:
# * body [Hash]:
# * network [Hash]:
# * id [String] - id of network
# * ip [Array]:
# * [Hash]:
# * version [Fixnum] - version of the address
# * addr [String] - ip address
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Addresses_by_Network-d1e3118.html
def list_addresses_by_network(server_id, network_id)
request(
:method => 'GET',

View file

@ -2,6 +2,18 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves list of attached volumes
# @param [String] server_id
# @return [Excon::Response] response:
# * body [Hash]:
# * volumeAttachment [Array]:
# * [Hash]:
# * device [String] - The name of the device, such as /dev/xvdb. Specify auto for auto-assignment.
# * serverId [String] - The id of the server that attached the volume
# * id [String] - The id of the attachment
# * volumeId [String] - The id of the volume that was attached
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Volume_Attachments.html
def list_attachments(server_id)
request(
:expects => [200, 203, 300],

View file

@ -2,6 +2,16 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves a list of flavors
# @return [Excon::Response] response:
# * body [Hash]:
# * flavors [Array]:
# * [Hash]:
# * id [String] - flavor id
# * links [Array] - flavor links
# * name [String] - flavor name
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Flavors-d1e4188.html
def list_flavors
request(
:expects => [200, 203],

View file

@ -2,6 +2,16 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves a list of images
# @return [Excon::Response] response:
# * body [Hash]:
# * images [Array]:
# * [Hash]:
# * id [String] - flavor id
# * links [Array] - image links
# * name [String] - image name
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Flavors-d1e4188.html
def list_images
request(
:expects => [200, 203],

View file

@ -2,6 +2,14 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves all metadata associated with a server or an image.
# @param [String<images, servers>] collection type of metadata
# @param [String] obj_id id of the object where the metadata is attached
# @return [Excon::Response] response:
# * body [Hash]:
# * meta [Hash]:
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Metadata-d1e5089.html
def list_metadata(collection, obj_id)
request(
:expects => [200, 203],

View file

@ -2,6 +2,37 @@ module Fog
module Compute
class RackspaceV2
class Real
# Retrieves list of servers
# @return [Excon::Response] response:
# * body [Hash]:
# * server [Hash]:
# * OS-DCF:diskConfig [String] - The disk configuration value.
# * OS-EXT-STS:power_state [Fixnum] - The power state.
# * OS-EXT-STS:task_state [String] - The task state.
# * OS-EXT-STS:vm_state [String] - The VM state.
# * accessIPv4 [String] - The public IP version 4 access address.
# * accessIPv6 [String] - The public IP version 6 access address.
# * addresses [Hash] - Public and private IP addresses, The version field indicates whether the IP address is version 4 or 6.
# * created [String] - created timestamp
# * hostId [String] - The host id.
# * id [String] - id of image
# * image [Hash]:
# * id [String] - id of the image
# * links [Hash] - links to image
# * flavor [Hash]:
# * id [String] - id of the flavor
# * links [Hash] - links to flavor
# * links [Hash] - links to server
# * metadata [Hash] - server metadata
# * name [String] - name of server
# * progress [Fixnum] - progress complete. Value is from 0 to 100.
# * rax-bandwidth:bandwidth [Array] - The amount of bandwidth used for the specified audit period.
# * status [String] - The server status.
# * tenant_id [String] - The tenant ID.
# * updated [String] - updated timestamp
# * user_id [Array] - The user ID.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Servers-d1e2078.html
def list_servers
request(
:expects => [200, 203, 300],

View file

@ -2,6 +2,11 @@ module Fog
module Compute
class RackspaceV2
class Real
# Reboots server
# @param [String] server_id
# @param [String<SOFT,HARD>] type type of reboot
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Reboot_Server-d1e3371.html
def reboot_server(server_id, type)
data = {
'reboot' => {

View file

@ -2,6 +2,43 @@ module Fog
module Compute
class RackspaceV2
class Real
# The rebuild operation removes all data on the server and replaces it with the specified image.
# The serverRef and all IP addresses remain the same. If you specify name, metadata, accessIPv4,
# or accessIPv6 in the rebuild request, new values replace existing values. Otherwise, these values do not change.
# @param [String] server_id id of the server to rebuild
# @param [String] image_id id of image used to rebuild the server
# @param [Hash] options
# @option options [String] accessIPv4 The IP version 4 address.
# @option options [String] accessIPv6 The IP version 6 address.
# @option options [String] adminPass The administrator password.
# @option options [Hash] metadata key value pairs of server metadata
# @option options [String] OS-DCF:diskConfig The disk configuration value. (AUTO or MANUAL)
# @option options [Hash] personality Hash containing data to inject into the file system of the cloud server instance during server creation.
# @return [Excon::Response] response:
# * body [Hash]:
# * server [Hash]:
# * name [String] - name of server
# * imageRef [String] - id of image used to create server
# * flavorRef [String] - id of flavor used to create server
# * OS-DCF:diskConfig [String] - The disk configuration value.
# * name [String] - name of server
# * metadata [Hash] - Metadata key and value pairs.
# * personality [Array]:
# * [Hash]:
# * path - path of the file created
# * contents - Base 64 encoded file contents
# * networks [Array]:
# * [Hash]:
# * uuid [String] - uuid of attached network
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Rebuild_Server-d1e3538.html
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Metadata-d1e2529.html
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Personality-d1e2543.html
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#diskconfig_attribute
#
# * Status Transition:
# * ACTIVE -> REBUILD -> ACTIVE
# * ACTIVE -> REBUILD -> ERROR (on error)
def rebuild_server(server_id, image_id, options={})
data = {
'rebuild' => options || {}

View file

@ -2,6 +2,16 @@ module Fog
module Compute
class RackspaceV2
class Real
# Reverts server resize operation
# @param [String] server_id id of server to resize
# @param [String] flavor_id id of the desired flavor
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Revert_Resized_Server-d1e4024.html
#
# * Status Transition:
# * VERIFY_RESIZE -> ACTIVE
# * VERIFY_RESIZE -> ERROR (on error)
def resize_server(server_id, flavor_id)
data = {
'resize' => {

View file

@ -2,6 +2,16 @@ module Fog
module Compute
class RackspaceV2
class Real
# Reverts server resize operation
# @param [String] server_id
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Revert_Resized_Server-d1e4024.html
# @see #resize
#
# * Status Transition:
# * VERIFY_RESIZE -> ACTIVE
# * VERIFY_RESIZE -> ERROR (on error)
def revert_resize_server(server_id)
data = {
'revertResize' => nil

View file

@ -2,6 +2,15 @@ module Fog
module Compute
class RackspaceV2
class Real
# Sets metadata associated with a server or an image.
# @param [String<images, servers>] collection type of metadata
# @param [String] obj_id id of the object where the metadata is attached
# @param [Hash] metadata key value pairs of metadata
# @return [Excon::Response] response:
# * body [Hash]:
# * metadata [Hash]:
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_or_Replace_Metadata-d1e5358.html
def set_metadata(collection, obj_id, metadata = {})
request(
:expects => [200, 203],

View file

@ -2,6 +2,16 @@ module Fog
module Compute
class RackspaceV2
class Real
# Sets a single metadatum item by key.
# @param [String<images, servers>] collection type of metadata
# @param [String] obj_id id of the object where the metadata is attached
# @param [String] key the key of the metadata to set
# @param [String] value the value of the metadata to set
# @return [Excon::Response] response:
# * body [Hash]:
# * meta [Hash]:
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_or_Update_a_Metadata_Item-d1e5633.html
def set_metadata_item(collection, obj_id, key, value)
request(
:expects => 200,

View file

@ -2,6 +2,15 @@ module Fog
module Compute
class RackspaceV2
class Real
# Updates metadata items for a specified server or image.
# @param [String<images, servers>] collection type of metadata
# @param [String] obj_id id of the object where the metadata is attached
# @param [Hash] metadata key value pairs of metadata
# @return [Excon::Response] response:
# * body [Hash]:
# * metadata [Hash]:
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Update_Metadata-d1e5208.html
def update_metadata(collection, obj_id, metadata = {})
request(
:expects => [200, 203],

View file

@ -2,6 +2,15 @@ module Fog
module Compute
class RackspaceV2
class Real
# Update the editable attributes of a specified server.
# @param [String] server_id
# @param [Hash] options
# @option options [Hash] name name for server
# @option options [String] accessIPv4 The IP version 4 address.
# @option options [Hash] accessIPv6 The IP version 6 address.
# @note If you edit the server name, the server host name does not change. Also, server names are not guaranteed to be unique.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ServerUpdate.html
def update_server(server_id, options={})
data = options.is_a?(Hash) ? options : { 'name' => options } #LEGACY - second parameter was previously server name