class Fog::Compute::Slicehost::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/slicehost/compute.rb, line 59
def initialize(options={})
  require 'fog/core/parser'

  @slicehost_password = options[:slicehost_password]
  @connection_options = options[:connection_options] || {}
  @host       = options[:host]        || "api.slicehost.com"
  @persistent = options[:persistent]  || false
  @port       = options[:port]        || 443
  @scheme     = options[:scheme]      || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Public Instance Methods

create_slice(flavor_id, image_id, name) click to toggle source

Create a new slice

Parameters

  • flavor_id<~Integer> - Id of flavor to create slice with

  • image_id<~Integer> - Id of image to create slice with

  • name<~String> - Name of slice

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'addresses'<~Array> - Ip addresses for the slice

      • 'backup-id'<~Integer> - Id of backup slice was booted from

      • 'bw-in'<~Integer> - Incoming bandwidth total for current billing cycle, in Gigabytes

      • 'bw-out'<~Integer> - Outgoing bandwidth total for current billing cycle, in Gigabytes

      • 'flavor-id'<~Integer> - Id of flavor slice was booted from

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

      • 'image-id'<~Integer> - Id of image slice was booted from

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

      • 'progress'<~Integer> - Progress of current action, in percentage

      • 'root-password'<~String> - Root password of slice

      • 'status'<~String> - Current status of the slice

# File lib/fog/slicehost/requests/compute/create_slice.rb, line 28
def create_slice(flavor_id, image_id, name)
  request(
    :body     => %Q{<?xml version="1.0" encoding="UTF-8"?><slice><flavor-id type="integer">#{flavor_id}</flavor-id><image-id type="integer">#{image_id}</image-id><name>#{name}</name></slice>},
    :expects  => 201,
    :method   => 'POST',
    :parser   => Fog::Parsers::Compute::Slicehost::CreateSlice.new,
    :path     => 'slices.xml'
  )
end
delete_slice(slice_id) click to toggle source

Delete a given slice

Parameters

  • slice_id<~Integer> - Id of slice to delete

Returns

  • response<~Excon::Response>: - HTTP status code is the return value

# File lib/fog/slicehost/requests/compute/delete_slice.rb, line 12
def delete_slice(slice_id)
  request(
    :expects  => 200,
    :method   => 'DELETE',
    :path     => "slices/#{slice_id}.xml"
  )
end
get_backups() click to toggle source

Get list of backups

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • 'date'<~Time> - Timestamp of backup creation

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

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

      • 'slice-id'<~Integer> - Id of slice the backup was made from

# File lib/fog/slicehost/requests/compute/get_backups.rb, line 17
def get_backups
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Compute::Slicehost::GetBackups.new,
    :path     => 'backups.xml'
  )
end
get_flavor(flavor_id) click to toggle source

Get details of a flavor

Parameters

  • flavor_id<~Integer> - Id of flavor to lookup

Returns

  • response<~Excon::Response>:

    • body<~Array>:

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

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

      • 'price'<~Integer> - Price in cents

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

# File lib/fog/slicehost/requests/compute/get_flavor.rb, line 20
def get_flavor(flavor_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Compute::Slicehost::GetFlavor.new,
    :path     => "flavors/#{flavor_id}.xml"
  )
end
get_flavors() click to toggle source

Get list of flavors

Returns

  • response<~Excon::Response>:

    • body<~Array>:

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

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

      • 'price'<~Integer> - Price in cents

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

# File lib/fog/slicehost/requests/compute/get_flavors.rb, line 17
def get_flavors
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Compute::Slicehost::GetFlavors.new,
    :path     => 'flavors.xml'
  )
end
get_image(image_id) click to toggle source

Get details of an image

Parameters

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

Returns

  • response<~Excon::Response>:

    • body<~Array>:

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

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

# File lib/fog/slicehost/requests/compute/get_image.rb, line 18
def get_image(image_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Compute::Slicehost::GetImage.new,
    :path     => "images/#{image_id}.xml"
  )
end
get_images() click to toggle source

Get list of images

Returns

  • response<~Excon::Response>:

    • body<~Array>:

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

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

# File lib/fog/slicehost/requests/compute/get_images.rb, line 15
def get_images
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Compute::Slicehost::GetImages.new,
    :path     => 'images.xml'
  )
end
get_slice(slice_id) click to toggle source

Get details of a slice

Parameters

  • slice_id<~Integer> - Id of slice to lookup

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'addresses'<~Array> - Ip addresses for the slice

      • 'backup-id'<~Integer> - Id of backup slice was booted from

      • 'bw-in'<~Float> - Incoming bandwidth total for current billing cycle, in Gigabytes

      • 'bw-out'<~Float> - Outgoing bandwidth total for current billing cycle, in Gigabytes

      • 'flavor_id'<~Integer> - Id of flavor slice was booted from

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

      • 'image-id'<~Integer> - Id of image slice was booted from

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

      • 'progress'<~Integer> - Progress of current action, in percentage

      • 'status'<~String> - Current status of the slice

# File lib/fog/slicehost/requests/compute/get_slice.rb, line 26
def get_slice(slice_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Compute::Slicehost::GetSlice.new,
    :path     => "/slices/#{slice_id}.xml"
  )
end
get_slices() click to toggle source

Get list of slices

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • 'addresses'<~Array> - Ip addresses for the slice

      • 'backup-id'<~Integer> - Id of backup slice was booted from

      • 'bw-in'<~Float> - Incoming bandwidth total for current billing cycle, in Gigabytes

      • 'bw-out'<~Float> - Outgoing bandwidth total for current billing cycle, in Gigabytes

      • 'flavor_id'<~Integer> - Id of flavor slice was booted from

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

      • 'image-id'<~Integer> - Id of image slice was booted from

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

      • 'progress'<~Integer> - Progress of current action, in percentage

      • 'status'<~String> - Current status of the slice

# File lib/fog/slicehost/requests/compute/get_slices.rb, line 23
def get_slices
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Compute::Slicehost::GetSlices.new,
    :path     => 'slices.xml'
  )
end
reboot_slice(slice_id, type = 'SOFT') click to toggle source

Reboot slice

Parameters

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

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

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'addresses'<~Array> - Ip addresses for the slice

      • 'backup-id'<~Integer> - Id of backup slice was booted from

      • 'bw-in'<~Float> - Incoming bandwidth total for current billing cycle, in Gigabytes

      • 'bw-out'<~Float> - Outgoing bandwidth total for current billing cycle, in Gigabytes

      • 'flavor_id'<~Integer> - Id of flavor slice was booted from

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

      • 'image-id'<~Integer> - Id of image slice was booted from

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

      • 'progress'<~Integer> - Progress of current action, in percentage

      • 'status'<~String> - Current status of the slice

# File lib/fog/slicehost/requests/compute/reboot_slice.rb, line 24
def reboot_slice(slice_id, type = 'SOFT')
  request(
    :expects  => 200,
    :method   => 'PUT',
    :parser   => Fog::Parsers::Compute::Slicehost::GetSlice.new,
    :path     => "/slices/#{slice_id}/#{'hard_' if type == 'HARD'}reboot.xml"
  )
end
reload() click to toggle source
# File lib/fog/slicehost/compute.rb, line 71
def reload
  @connection.reset
end
request(params) click to toggle source
# File lib/fog/slicehost/compute.rb, line 75
def request(params)
  params[:headers] ||= {}
  params[:headers].merge!({
    'Authorization' => "Basic #{Base64.encode64(@slicehost_password).delete("\r\n")}"
  })
  case params[:method]
  when 'DELETE', 'GET', 'HEAD'
    params[:headers]['Accept'] = 'application/xml'
  when 'POST', 'PUT'
    params[:headers]['Content-Type'] = 'application/xml'
  end

  begin
    response = @connection.request(params.merge!({:host => @host}))
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
    when Excon::Errors::NotFound
      Fog::Compute::Slicehost::NotFound.slurp(error)
    else
      error
    end
  end

  response
end