Class/Module Index [+]

Quicksearch

Fog::Compute::Rackspace::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/rackspace/compute.rb, line 186
def initialize(options={})
  @rackspace_api_key = options[:rackspace_api_key]
  @rackspace_username = options[:rackspace_username]
  @rackspace_auth_url = options[:rackspace_auth_url]
  @rackspace_servicenet = options[:rackspace_servicenet]
  @rackspace_auth_token = options[:rackspace_auth_token]
  @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_compute_v1_url] || options[:rackspace_management_url])
  @rackspace_must_reauthenticate = false
  @connection_options = options[:connection_options] || {}
  authenticate
  Excon.defaults[:ssl_verify_peer] = false if service_net?
  @persistent = options[:persistent] || false
  @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end

Public Instance Methods

authenticate() click to toggle source
# File lib/fog/rackspace/compute.rb, line 242
def authenticate
  if @rackspace_must_reauthenticate || @rackspace_auth_token.nil?
    options = {
      :rackspace_api_key  => @rackspace_api_key,
      :rackspace_username => @rackspace_username,
      :rackspace_auth_url => @rackspace_auth_url
    }
    super(options)
  else
    @auth_token = @rackspace_auth_token
    @uri = URI.parse(@rackspace_endpoint)
  end
end
confirm_resized_server(server_id) click to toggle source

Confirm resizing

Parameters

  • server_id<~Integer> - Id of server to confirm

# File lib/fog/rackspace/requests/compute/confirm_resized_server.rb, line 11
def confirm_resized_server(server_id)
  body = { 'confirmResize' => nil }
  server_action(server_id, body, 204)
end
create_image(server_id, options = {}) click to toggle source

Create an image from a running server

Parameters

  • server_id<~Integer> - Id of server to create image from

  • options<~Hash> - Name

Returns

  • response<~Excon::Response>:

    • 'image'<~Hash>:

      • 'id'<~Integer> - Id of image

      • 'name'<~String> - Name of image

      • 'serverId'<~Integer> - Id of server

# File lib/fog/rackspace/requests/compute/create_image.rb, line 18
def create_image(server_id, options = {})
  data = {
    'image' => {
      'serverId' => server_id
    }
  }
  data['image'].merge!(options)
  request(
    :body     => Fog::JSON.encode(data),
    :expects  => 202,
    :method   => 'POST',
    :path     => "images"
  )
end
create_server(flavor_id, image_id, options = {}) click to toggle source

Create a new server

Parameters

  • flavor_id<~Integer> - Id of flavor for server

  • image_id<~Integer> - Id of image for server

  • name<~String> - Name of server

  • options<~Hash>:

    • 'metadata'<~Hash> - Up to 5 key value pairs containing 255 bytes of info

    • 'name'<~String> - Name of server, defaults to "slice#{id}"

    • 'personality'<~Array>: Up to 5 files to customize server

      • file<~Hash>:

        • 'contents'<~String> - Contents of file (10kb total of contents)

        • 'path'<~String> - Path to file (255 bytes total of path strings)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • 'server'<~Hash>:

      • 'addresses'<~Hash>:

        • 'public'<~Array> - public address strings

        • 'private'<~Array> - private address strings

      • 'adminPass'<~String> - Admin password for server

      • 'flavorId'<~Integer> - Id of servers current flavor

      • 'hostId'<~String>

      • 'id'<~Integer> - Id of server

      • 'imageId'<~Integer> - Id of image used to boot server

      • 'metadata'<~Hash> - metadata

      • 'name<~String> - Name of server

      • 'progress'<~Integer> - Progress through current status

      • 'status'<~String> - Current server status

# File lib/fog/rackspace/requests/compute/create_server.rb, line 36
def create_server(flavor_id, image_id, options = {})
  data = {
    'server' => {
      'flavorId'  => flavor_id,
      'imageId'   => image_id
    }
  }
  if options['metadata']
    data['server']['metadata'] = options['metadata']
  end
  if options['name']
    data['server']['name'] = options['name']
  end
  if options['personality']
    data['server']['personality'] = []
    for file in options['personality']
      data['server']['personality'] << {
        'contents'  => Base64.encode64(file['contents']),
        'path'      => file['path']
      }
    end
  end
  request(
    :body     => Fog::JSON.encode(data),
    :expects  => [200, 202],
    :method   => 'POST',
    :path     => 'servers.json'
  )
end
delete_image(image_id) click to toggle source

Delete an image

Parameters

  • image_id<~Integer> - Id of image to delete

# File lib/fog/rackspace/requests/compute/delete_image.rb, line 11
def delete_image(image_id)
  request(
    :expects  => 204,
    :method   => 'DELETE',
    :path     => "images/#{image_id}"
  )
end
delete_server(server_id) click to toggle source

Delete an existing server

Parameters

  • id<~Integer> - Id of server to delete

# File lib/fog/rackspace/requests/compute/delete_server.rb, line 11
def delete_server(server_id)
  request(
    :expects => 202,
    :method => 'DELETE',
    :path   => "servers/#{server_id}"
  )
end
endpoint_uri(service_endpoint_url=nil) click to toggle source
# File lib/fog/rackspace/compute.rb, line 264
def endpoint_uri(service_endpoint_url=nil)
  return @uri if @uri

  @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_compute_v1_url)
  @uri.host = "snet-#{@uri.host}" if service_net?
  @uri
end
get_flavor_details(flavor_id) click to toggle source

Get details for flavor by id

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'id'<~Integer> - Id of the flavor

      • 'name'<~String> - Name of the flavor

      • 'ram'<~Integer> - Amount of ram for the flavor

      • 'disk'<~Integer> - Amount of diskspace for the flavor

# File lib/fog/rackspace/requests/compute/get_flavor_details.rb, line 15
def get_flavor_details(flavor_id)
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => "flavors/#{flavor_id}.json"
  )
end
get_image_details(image_id) click to toggle source

Get details for image by id

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'id'<~Integer> - Id of the image

      • 'name'<~String> - Name of the image

      • 'serverId'<~Integer> - Id of server image was created from

      • 'status'<~Integer> - Status of image

      • 'updated'<~String> - Timestamp of last update

# File lib/fog/rackspace/requests/compute/get_image_details.rb, line 16
def get_image_details(image_id)
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => "images/#{image_id}.json"
  )
end
get_server_details(server_id) click to toggle source

Get details about a server

Parameters

  • server_id<~Integer> - Id of server to get details for

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • 'server'<~Hash>:

      • 'addresses'<~Hash>:

        • 'public'<~Array> - public address strings

        • 'private'<~Array> - private address strings

      • 'flavorId'<~Integer> - Id of servers current flavor

      • 'hostId'<~String>

      • 'id'<~Integer> - Id of server

      • 'imageId'<~Integer> - Id of image used to boot server

      • 'metadata'<~Hash> - metadata

      • 'name<~String> - Name of server

      • 'progress'<~Integer> - Progress through current status

      • 'status'<~String> - Current server status

# File lib/fog/rackspace/requests/compute/get_server_details.rb, line 26
def get_server_details(server_id)
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => "servers/#{server_id}.json"
  )
end
list_addresses(server_id) click to toggle source

List all server addresses

Parameters

  • server_id<~Integer> - Id of server to list addresses for

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • 'addresses'<~Array>:

      • 'public'<~Array> - Public ip addresses

      • 'private'<~Array> - Private ip addresses

# File lib/fog/rackspace/requests/compute/list_addresses.rb, line 17
def list_addresses(server_id)
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => "servers/#{server_id}/ips.json"
  )
end
list_flavors() click to toggle source

List all flavors (IDs and names only)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'id'<~Integer> - Id of the flavor

      • 'name'<~String> - Name of the flavor

# File lib/fog/rackspace/requests/compute/list_flavors.rb, line 13
def list_flavors
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => 'flavors.json'
  )
end
list_flavors_detail() click to toggle source

List all flavors

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'id'<~Integer> - Id of the flavor

      • 'name'<~String> - Name of the flavor

      • 'ram'<~Integer> - Amount of ram for the flavor

      • 'disk'<~Integer> - Amount of diskspace for the flavor

# File lib/fog/rackspace/requests/compute/list_flavors_detail.rb, line 15
def list_flavors_detail
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => 'flavors/detail.json'
  )
end
list_images() click to toggle source

List all images (IDs and names only)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'id'<~Integer> - Id of the image

      • 'name'<~String> - Name of the image

# File lib/fog/rackspace/requests/compute/list_images.rb, line 13
def list_images
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => 'images.json'
  )
end
list_images_detail() click to toggle source

List all images

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'id'<~Integer> - Id of the image

      • 'name'<~String> - Name of the image

      • 'updated'<~String> - Last update timestamp for image

      • 'created'<~String> - Creation timestamp for image

      • 'status'<~String> - Status of image

# File lib/fog/rackspace/requests/compute/list_images_detail.rb, line 16
def list_images_detail
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => 'images/detail.json'
  )
end
list_private_addresses(server_id) click to toggle source

List private server addresses

Parameters

  • server_id<~Integer> - Id of server to list addresses for

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'private'<~Array> - Public ip addresses

# File lib/fog/rackspace/requests/compute/list_private_addresses.rb, line 15
def list_private_addresses(server_id)
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => "servers/#{server_id}/ips/private.json"
  )
end
list_public_addresses(server_id) click to toggle source

List public server addresses

Parameters

  • server_id<~Integer> - Id of server to list addresses for

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'public'<~Array> - Public ip addresses

# File lib/fog/rackspace/requests/compute/list_public_addresses.rb, line 15
def list_public_addresses(server_id)
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => "servers/#{server_id}/ips/public.json"
  )
end
list_servers() click to toggle source

List all servers (IDs and names only)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • 'servers'<~Array>:

      • 'id'<~Integer> - Id of server

      • 'name<~String> - Name of server

# File lib/fog/rackspace/requests/compute/list_servers.rb, line 14
def list_servers
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => 'servers.json'
  )
end
list_servers_detail() click to toggle source

List all servers details

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • 'servers'<~Array>:

      • 'id'<~Integer> - Id of server

      • 'name<~String> - Name of server

      • 'imageId'<~Integer> - Id of image used to boot server

      • 'flavorId'<~Integer> - Id of servers current flavor

      • 'hostId'<~String>

      • 'status'<~String> - Current server status

      • 'progress'<~Integer> - Progress through current status

      • 'addresses'<~Hash>:

        • 'public'<~Array> - public address strings

        • 'private'<~Array> - private address strings

      • 'metadata'<~Hash> - metadata

# File lib/fog/rackspace/requests/compute/list_servers_detail.rb, line 23
def list_servers_detail
  request(
    :expects  => [200, 203],
    :method   => 'GET',
    :path     => 'servers/detail.json'
  )
end
reboot_server(server_id, type = 'SOFT') click to toggle source

Reboot an existing server

Parameters

  • server_id<~Integer> - Id of server to reboot

  • type<~String> - Type of reboot, must be in ['HARD', 'SOFT']

# File lib/fog/rackspace/requests/compute/reboot_server.rb, line 12
def reboot_server(server_id, type = 'SOFT')
  body = { 'reboot' => { 'type' => type }}
  server_action(server_id, body)
end
region() click to toggle source
# File lib/fog/rackspace/compute.rb, line 260
def region
  @rackspace_region
end
reload() click to toggle source
# File lib/fog/rackspace/compute.rb, line 201
def reload
  @connection.reset
end
request(params) click to toggle source
# File lib/fog/rackspace/compute.rb, line 205
def request(params)
  begin
    response = @connection.request(params.merge({
      :headers  => {
        'Content-Type' => 'application/json',
        'X-Auth-Token' => auth_token
      }.merge!(params[:headers] || {}),
      :host     => endpoint_uri.host,
      :path     => "#{endpoint_uri.path}/#{params[:path]}",
    }))
  rescue Excon::Errors::Unauthorized => error
    if error.response.body != 'Bad username or password' # token expiration
      @rackspace_must_reauthenticate = true
      authenticate
      retry
    else # bad credentials
      raise error
    end
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
    when Excon::Errors::NotFound
      NotFound.slurp(error, region)
    else
      error
    end
  end
  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
  end
  response
end
resize_server(server_id, flavor_id) click to toggle source

Reboot an existing server

Parameters

  • server_id<~Integer> - Id of server to resize

  • size<~String> - new size. call list_flavors to get available flavors

# File lib/fog/rackspace/requests/compute/resize_server.rb, line 12
def resize_server(server_id, flavor_id)
  body = { 'resize' => { 'flavorId' => flavor_id }}
  server_action(server_id, body)
end
revert_resized_server(server_id) click to toggle source

Revert resizing

Parameters

  • server_id<~Integer> - Id of server to revert

# File lib/fog/rackspace/requests/compute/revert_resized_server.rb, line 11
def revert_resized_server(server_id)
  body = { 'revertResize' => nil }
  server_action(server_id, body)
end
server_action(server_id, body, expects=202) click to toggle source

Reboot an existing server

Parameters

  • server_id<~Integer> - Id of server to reboot

  • body<~String> - Body of the request, describes the action (see reboot_server as an example)

  • expect<~Integer> - expected return, 202 except for confirm resize (204)

# File lib/fog/rackspace/requests/compute/server_action.rb, line 13
def server_action(server_id, body, expects=202)
  request(
    :body     => Fog::JSON.encode(body),
    :expects  => expects,
    :method   => 'POST',
    :path     => "servers/#{server_id}/action.json"
  )
end
service_name() click to toggle source
# File lib/fog/rackspace/compute.rb, line 256
def service_name
  :cloudServers
end
service_net?() click to toggle source
# File lib/fog/rackspace/compute.rb, line 238
def service_net?
   @rackspace_servicenet == true
end
update_server(server_id, options = {}) click to toggle source

Update an existing server

Parameters

# server_id<~Integer> - Id of server to update

  • options<~Hash>:

    • adminPass<~String> - New admin password for server

    • name<~String> - New name for server

# File lib/fog/rackspace/requests/compute/update_server.rb, line 13
def update_server(server_id, options = {})
  request(
    :body     => Fog::JSON.encode({ 'server' => options }),
    :expects  => 204,
    :method   => 'PUT',
    :path     => "servers/#{server_id}.json"
  )
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.