class Fog::Compute::IBM::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/ibm/compute.rb, line 62
def initialize(options={})
  @connection = Fog::IBM::Connection.new(options[:ibm_username], options[:ibm_password])
end

Public Instance Methods

clone_image(image_id, name, description) click to toggle source

Clones image specified by image_id

Parameters

  • image_id<~String> - id of image to be cloned

  • name<~String> - name of new image

  • description<~String> - description of new image

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'ImageID'<~String>: id of new image

# File lib/fog/ibm/requests/compute/clone_image.rb, line 16
def clone_image(image_id, name, description)
  request(
    :method   => 'POST',
    :expects  => 200,
    :path     => "/offerings/image/#{image_id}",
    :body     => {
      'name' => name,
      'description' => description
    }
  )
end
create_address(location, offering_id, options={}) click to toggle source

Requests a new static IP address to be created

Parameters

  • location_id<~String> - id of location

  • offering_id<~String> - id for offering

  • vlan_id<~String> - id of vlan

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'location'<~String>: location of new address

      • 'offeringId'<~String>: offering id of new address

      • 'id'<~String>: id

      • 'ip'<~String>: returns string of spaces (ip not yet allocated right after creation)

      • 'state'<~Integer>: status of address (0 when new)

# File lib/fog/ibm/requests/compute/create_address.rb, line 20
def create_address(location, offering_id, options={})
  request(
    :method   => 'POST',
    :expects  => 200,
    :path     => '/addresses',
    :body     => {
      'offeringID' => offering_id,
      'location'   => location,
      'vlanID'     => options[:vlan_id]
    }
  )
end
create_image(instance_id, name, description) click to toggle source

Requests an image to be created from an Instance

Parameters

  • instance_id<~String> - id of instance to save

  • name<~String> - name of image to be created

  • description<~String> - description of image to be created

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'name'<~String>: name of new image

      • 'createdTime'<~Integer>: epoch time at creation

      • 'productCodes'<~Array>:

      • 'id'<~String>: id of new image

      • 'description'<~String>: description

      • 'visibility'<~String>: visibility level (“PRIVATE”, etc)

      • 'state'<~Integer>: status of image

# File lib/fog/ibm/requests/compute/create_image.rb, line 22
def create_image(instance_id, name, description)
  request(
    :method   => 'PUT',
    :expects  => 200,
    :path     => "/instances/#{instance_id}",
    :body     => {
      'state'       => 'save',
      'name'        => name,
      'description' => description
    }
  )
end
create_instance(name, image_id, instance_type, location, options={}) click to toggle source

Requests a new Instance to be created.

Parameters

  • name<~String> - The alias to use to reference this instance

  • image_id<~String> - The id of the image to create this instance from

  • instance_type<~String> - The instance type to use for this instance

  • location<~String> - The id of the Location where this instance will be created

  • options<~Hash>:

    • :key_name<~String> - The public key to use for accessing the created instance

    • :ip<~String> - The ID of a static IP address to associate with this instance

    • :volume_id<~String> - The ID of a storage volume to associate with this instance

    • :vlan_id<~String> - The ID of a Vlan offering to associate with this instance.

    • :secondary_ip<~String> - Comma separated list of static IP IDs to associate with this instance.

    • :is_mini_ephermal<~Boolean> - Whether or not the instance should be provisioned with the root segment only

    • :configuration_data<~Hash> - Arbitrary name/value pairs defined by the image being created

    • :anti_collocation_instance<~String> - The ID of an existing anti-collocated instance.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'name'<~String>: instance name

      • 'location'<~String>: instance location id

      • 'keyName'<~String>: instance assigned keypair

      • 'primaryIP'<~Hash>: assigned ip address, type, and hostname

      • 'productCodes'<~Array>: associated product codes

      • 'requestId'<~String>:

      • 'imageId'<~String>:

      • 'launchTime'<~Integer>: epoch time in ms representing when the instance was launched

# File lib/fog/ibm/requests/compute/create_instance.rb, line 33
def create_instance(name, image_id, instance_type, location, options={})
  body_data     = {
    'name'                    => name,
    'imageID'                 => image_id,
    'instanceType'            => instance_type,
    'location'                => location,
    'publicKey'               => options[:key_name],
    'ip'                      => options[:ip],
    'volumeID'                => options[:volume_id],
    'vlanID'                  => options[:vlan_id],
    'isMiniEphemeral'        => options[:is_mini_ephemeral],
    'Configuration Data'      => options[:configuration_data],
    'antiCollocationInstance' => options[:anti_collocation_instance]
  }
  if options[:secondary_ip]
    options[:secondary_ip].split(',').map(&:strip).each_with_index do |n, idx|
      body_data.merge!({"secondary.ip.#{idx}" => n})
    end
  end
  request(
    :method   => 'POST',
    :expects  => 200,
    :path     => '/instances',
    :body     => body_data
  )
end
create_key(name, public_key=nil) click to toggle source

Requests a new keypair to be created

Parameters

  • name<~String> - name to give new key

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'keyName'<~String>: name of new key

      • 'lastModifiedTime'<~Integer>: epoch time of last modification

      • 'default'<~Bool>: is default?

      • 'instanceIds'<~Array>: id's of instances using key (should be empty upon creation)

      • 'keyMaterial'<~String>: private key contents

# File lib/fog/ibm/requests/compute/create_key.rb, line 18
def create_key(name, public_key=nil)
  request(
    :method   => 'POST',
    :expects  => 200,
    :path     => '/keys',
    :body => {
      'name' => name,
      'publicKey' => public_key
    }
  )
end
delete_address(address_id) click to toggle source

Deletes the Address that the authenticated user manages with the specified :address_id

Parameters

  • address_id<~String> - Id of address

Returns

  • response<~Excon::Response>:

    • body<~Hash>: *'success'<~Bool>: true or false for success

# File lib/fog/ibm/requests/compute/delete_address.rb, line 14
def delete_address(address_id)
  request(
    :method   => 'DELETE',
    :expects  => 200,
    :path     => "/addresses/#{address_id}"
  )
end
delete_image(image_id) click to toggle source

Deletes the image that the authenticated user manages with the specified :image_id

Parameters

  • image_id<~String> - Id of image

Returns

  • response<~Excon::Response>:

    • body<~Hash>: *'success'<~Bool>: true or false for success

# File lib/fog/ibm/requests/compute/delete_image.rb, line 14
def delete_image(image_id)
  request(
    :method   => 'DELETE',
    :expects  => 200,
    :path     => "/offerings/image/#{image_id}"
  )
end
delete_instance(instance_id) click to toggle source

Deletes the Instance that the authenticated user manages with the specified :instance_id

Parameters

  • instance_id<~String> - Id of instance

Returns

  • response<~Excon::Response>:

    • body<~Hash>: *'success'<~Bool>: true or false for success

# File lib/fog/ibm/requests/compute/delete_instance.rb, line 14
def delete_instance(instance_id)
  request(
    :method   => 'DELETE',
    :expects  => 200,
    :path     => "/instances/#{instance_id}"
  )
end
delete_key(key_name) click to toggle source

Deletes the key specified with key_name

Parameters

  • key_name<~String> - name of key to be deleted

Returns

  • response<~Excon::Response>:

    • body<~Hash>: *'success'<~Bool>: true or false for success

# File lib/fog/ibm/requests/compute/delete_key.rb, line 14
def delete_key(key_name)
  request(
    :method   => 'DELETE',
    :expects  => 200,
    :path     => "/keys/#{key_name}"
  )
end
get_image(image_id) click to toggle source

Returns details of image specified by id

Parameters

'image_id'<~String>: id of desired image

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'name'<~String>: image name

      • 'location'<~String>: instance location id

      • 'createdTime'<~Integer>: time created in epoch time

      • 'supportedInstanceTypes'<~Array>: list of prices per image

        • 'pricePerQuantity'<~Integer>:

        • 'effectiveDate'<~Fixnum>:

        • 'rate'<~Float>: price per unit

        • 'countryCode'<~String>:

        • 'unitOfMeasure'<~String>: unit of measurement

        • 'currencyCode'<~String>: currency billed in

      • 'productCodes'<~Array>:

      • 'id'<~String>:

      • 'documentation'<~String>: link to documentation for image

      • 'manifest'<~String>: link to xml manifest file

      • 'description'<~String>: text description of image

      • 'visibility'<~String>: status of visibilty of image. known values so far are “PUBLIC” and “PRIVATE”

      • 'platform'<~String>: operating system

      • 'architecture'<~String>: architecture supported by image

      • 'documentation'<~String>: link to documentation for image

      • 'owner'<~String>: owner of image

      • 'state'<~Integer>: state of availability of image

# File lib/fog/ibm/requests/compute/get_image.rb, line 34
def get_image(image_id)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/offerings/image/#{image_id}"
  )
end
get_image_agreement(image_id) click to toggle source

Returns license agreement of image specified by id

Parameters

'image_id'<~String>: id of desired image

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'text'<~String>: text of license

      • 'id'<~String>: id of image

      • 'attachments'<~Array>: Additional agreements attached to image

        • 'label'<~String>: description of attachment

        • 'url'<~String>: url to retrieve attachment

        • 'type'<~Integer>: type of attachment

# File lib/fog/ibm/requests/compute/get_image_agreement.rb, line 19
def get_image_agreement(image_id)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/offerings/image/#{image_id}/agreement"
  )
end
get_image_manifest(image_id) click to toggle source

Returns manifest of image specified by id

Parameters

'image_id'<~String>: id of desired image

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'manifest'<~String>: manifest of image in xml

# File lib/fog/ibm/requests/compute/get_image_manifest.rb, line 14
def get_image_manifest(image_id)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/offerings/image/#{image_id}/manifest"
  )
end
get_instance(instance_id) click to toggle source

Returns the Instance that the authenticated user manages with the specified :instance_id

Parameters

  • instance_id<~String> - Id of instance

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'name'<~String>: instance name

      • 'location'<~String>: instance location id

      • 'keyName'<~String>: instance assigned keypair

      • 'primaryIP'<~Hash>: assigned ip address, type, and hostname

      • 'productCodes'<~Array>: associated product codes

      • 'requestId'<~String>:

      • 'imageId'<~String>:

      • 'launchTime'<~Integer>: UNIX time integer representing when the instance was launched

      • 'id'<~String>: instance id

      • 'volumes'<~Array>:

      • 'isMiniEphemeral'<~Boolean>: minimal local storage

      • 'instanceType'<~String>: instance type

      • 'diskSize'<~String>: instance disk size

      • 'requestName'<~String>: instance request name

      • 'secondaryIP'<~Array>: additional IP Addresses associated with this instance

      • 'status'<~Integer>: instance status flag

      • 'software'<~Array>: Software associated with this instance

        • 'application'<~Hash>: Application name, type, and version (primarily OS information)

      • 'expirationTime'<~Integer>: UNIX timestamp representing when the instance expires

      • 'owner'<~String>: instance owner

# File lib/fog/ibm/requests/compute/get_instance.rb, line 33
def get_instance(instance_id)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/instances/#{instance_id}"
  )
end
get_instance_logs(instance_id, start_index=nil) click to toggle source

Get an instance's logs

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • logs<~Array>:

TODO: docs

# File lib/fog/ibm/requests/compute/get_instance_logs.rb, line 12
def get_instance_logs(instance_id, start_index=nil)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/instances/#{instance_id}/logs" +
                 (start_index ? "?startIndex=#{start_index}" : '')
  )
end
get_key(key_name) click to toggle source

Returns details of key by name specified

Parameters

'key_name'<~String>: name of key to request

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'keyName'<~String>: Name of key

      • 'lastModifiedTime'<~Integer>: epoch time of last modification

      • 'default'<~Bool>: bool if key is default for user

      • 'instanceIds'<~Array>: list of instances associated with key

      • 'keyMaterial'<~String>: public key

# File lib/fog/ibm/requests/compute/get_key.rb, line 18
def get_key(key_name)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/keys/#{key_name}"
  )
end
get_location(location_id) click to toggle source

Get a location

Parameters

  • location_id<~String> - Id of location

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'name'<~String>: location name

      • 'location'<~String>:

      • 'capabilities'<~Array>:

        • 'oss.storage.format'<~Hash>:

          • 'entries'<~Array>: list of supported volume formats

          • 'oss.instance.spec.i386'<~Array>: unsure.. returns empty array

          • 'oss.instance.spec.x86_64'<~Array>: unsure.. returns empty array

          • 'oss.storage.availabilityarea'<~Array>: availability area unsupported

      • 'id'<~String>: id of location

      • 'description'<~String>: description including geographic location

      • 'state'<~String>: state of datacenter

# File lib/fog/ibm/requests/compute/get_location.rb, line 24
def get_location(location_id)
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/locations/#{location_id}"
  )
end
get_request(request_id) click to toggle source

Returns list of instances created with request specified by request_id

Parameters

  • request_id<~String> - Id of request

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • instances<~Array>: array of instances created with request

      • 'name'<~String>: instance name

      • 'location'<~String>: instance location id

      • 'keyName'<~String>: instance assigned keypair

      • 'primaryIP'<~Hash>: assigned ip address, type, and hostname

      • 'productCodes'<~Array>: associated product codes

      • 'requestId'<~String>:

      • 'imageId'<~String>:

      • 'launchTime'<~Integer>: UNIX time integer representing when the instance was launched

      • 'id'<~String>: instance id

      • 'volumes'<~Array>:

      • 'isMiniEphemeral'<~Boolean>: minimal local storage

      • 'instanceType'<~String>: instance type

      • 'diskSize'<~String>: instance disk size

      • 'requestName'<~String>: instance request name

      • 'secondaryIP'<~Array>: additional IP Addresses associated with this instance

      • 'status'<~Integer>: instance status flag

      • 'software'<~Array>: Software associated with this instance

        • 'application'<~Hash>: Application name, type, and version (primarily OS information)

      • 'expirationTime'<~Integer>: UNIX timestamp representing when the instance expires

      • 'owner'<~String>: instance owner

# File lib/fog/ibm/requests/compute/get_request.rb, line 34
def get_request(request_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "computecloud/enterprise/api/rest/20100331/requests/#{request_id}"
  )
end
list_address_offerings() click to toggle source

Returns the offerings of static address types/pricing for the authenticated user

Parameters

No parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'addresses'<~Array>: list of address offerings

        • 'price'<~Hash>: pricing info for specific address offering

        • 'price'<~Hash>: hash containing pricing information

          • 'pricePerQuantity'<~Integer>:

          • 'effectiveDate'<~Integer>: starting date price is effective

          • 'rate'<~Float>: rate per unit

          • 'countryCode'<~String>:

          • 'unitOfMeasure'<~String>:

          • 'currencyCode'<~String>: currency used

        • 'location'<~String>: datacenter location string

        • 'ipType'<~Integer>: type of ip address

        • 'id'<~String>: id of offering

# File lib/fog/ibm/requests/compute/list_address_offerings.rb, line 25
def list_address_offerings
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => '/offerings/address'
  )
end
list_addresses() click to toggle source

Returns the list of static IP addresses for current user

Parameters

No parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'addresses'<~Array>: list of addresses

        • 'location'<~String>: location of address

        • 'mode'<~Integer>:

        • 'offeringId'<~String>: offering ID

        • 'id'<~String>: id

        • 'type'<~Integer>: TODO unsure

        • 'ip'<~String>: IP address.. with space at the end

        • 'hostname'<~String>: seems to be same as ip

        • 'state'<~Integer>: state of address

# File lib/fog/ibm/requests/compute/list_addresses.rb, line 22
def list_addresses
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => '/addresses'
  )
end
list_images() click to toggle source

Returns the list of Images available to be provisioned on the IBM DeveloperCloud.

Parameters

No parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'images'<~Array>: list of images

        • 'name'<~String>: image name

        • 'location'<~String>: instance location id

        • 'createdTime'<~Integer>: time created in epoch time

        • 'supportedInstanceTypes'<~Array>: list of prices per image

          • 'pricePerQuantity'<~Integer>:

          • 'effectiveDate'<~Fixnum>:

          • 'rate'<~Float>: price per unit

          • 'countryCode'<~String>:

          • 'unitOfMeasure'<~String>: unit of measurement

          • 'currencyCode'<~String>: currency billed in

        • 'productCodes'<~Array>:

        • 'id'<~String>:

        • 'documentation'<~String>: link to documentation for image

        • 'manifest'<~String>: link to xml manifest file

        • 'description'<~String>: text description of image

        • 'visibility'<~String>: status of visibilty of image. known values so far are “PUBLIC” and “PRIVATE”

        • 'platform'<~String>: operating system

        • 'architecture'<~String>: architecture supported by image

        • 'documentation'<~String>: link to documentation for image

        • 'owner'<~String>: owner of image

        • 'state'<~Integer>: state of availability of image

# File lib/fog/ibm/requests/compute/list_images.rb, line 35
def list_images
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => '/offerings/image'
  )
end
list_instances() click to toggle source

Returns list of instances that the authenticated user manages.

Parameters

No parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'instances'<~Array>: list of instances

        • 'name'<~String>: instance name

        • 'location'<~String>: instance location id

        • 'keyName'<~String>: instance assigned keypair

        • 'primaryIP'<~Hash>: assigned ip address, type, and hostname

        • 'productCodes'<~Array>: associated product codes

        • 'requestId'<~String>:

        • 'imageId'<~String>:

        • 'launchTime'<~Integer>: UNIX time integer representing when the instance was launched

        • 'id'<~String>: instance id

        • 'volumes'<~Array>:

        • 'isMiniEphemeral'<~Boolean>: minimal local storage

        • 'instanceType'<~String>: instance type

        • 'diskSize'<~String>: instance disk size

        • 'requestName'<~String>: instance request name

        • 'secondaryIP'<~Array>: additional IP Addresses associated with this instance

        • 'status'<~Integer>: instance status flag

        • 'software'<~Array>: Software associated with this instance

          • 'application'<~Hash>: Application name, type, and version (primarily OS information)

        • 'expirationTime'<~Integer>: UNIX timestamp representing when the instance expires

        • 'owner'<~String>: instance owner

# File lib/fog/ibm/requests/compute/list_instances.rb, line 34
def list_instances
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => '/instances'
  )
end
list_keys() click to toggle source

Returns list of instances that the authenticated user manages.

Parameters

No parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'instances'<~Array>: list of instances

        • 'name'<~String>: instance name

        • 'location'<~String>: instance location id

        • 'keyName'<~String>: instance assigned keypair

        • 'primaryIP'<~Hash>: assigned ip address, type, and hostname

        • 'productCodes'<~Array>: associated product codes

        • 'requestId'<~String>:

        • 'imageId'<~String>:

        • 'launchTime'<~Integer>: UNIX time integer representing when the instance was launched

        • 'id'<~String>: instance id

        • 'volumes'<~Array>:

        • 'isMiniEphemeral'<~Boolean>: minimal local storage

        • 'instanceType'<~String>: instance type

        • 'diskSize'<~String>: instance disk size

        • 'requestName'<~String>: instance request name

        • 'secondaryIP'<~Array>: additional IP Addresses associated with this instance

        • 'status'<~Integer>: instance status flag

        • 'software'<~Array>: Software associated with this instance

          • 'application'<~Hash>: Application name, type, and version (primarily OS information)

        • 'expirationTime'<~Integer>: UNIX timestamp representing when the instance expires

        • 'owner'<~String>: instance owner

# File lib/fog/ibm/requests/compute/list_keys.rb, line 34
def list_keys
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => '/keys'
  )
end
list_locations() click to toggle source

Returns the list of Images available to be provisioned on the IBM DeveloperCloud.

Parameters

No parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'locations'<~Array>: list of locations

# File lib/fog/ibm/requests/compute/list_locations.rb, line 14
def list_locations
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => "/locations"
  )
end
list_vlans() click to toggle source

Returns the vlan offerings for user

Parameters

No parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'addresses'<~Array>: list of addresses

        • 'location'<~String>: location of address

        • 'mode'<~Integer>:

        • 'offeringId'<~String>: offering ID

        • 'id'<~String>: id

        • 'type'<~Integer>: TODO unsure

        • 'ip'<~String>: IP address.. with space at the end

        • 'hostname'<~String>: seems to be same as ip

        • 'state'<~Integer>: state of address

# File lib/fog/ibm/requests/compute/list_vlans.rb, line 22
def list_vlans
  request(
    :method   => 'GET',
    :expects  => 200,
    :path     => '/offerings/vlan'
  )
end
modify_instance(instance_id, options={}) click to toggle source

Modify an instance

Parameters

  • instance_id<~String> - id of instance to rename

  • params<~Hash> - depends on type of request

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'success'<~Bool>:

OR

  • response<~Excon::Response>:

    • body<~Hash>: ????

      • 'expirationTime'<~Integer>: new expiration time of instance (epoch)

Note: The feature of dynamically attaching or detaching storage is only
supported by data centers where the KVM host version is RHEL 6.1. If the
feature is not supported by the data center, you will get an exception like
"Unsupported exception. Dynamic features are not supported on the KVM
Host".
# File lib/fog/ibm/requests/compute/modify_instance.rb, line 26
def modify_instance(instance_id, options={})
  request(
    :method   => 'PUT',
    :expects  => 200,
    :path     => "/instances/#{instance_id}",
    :body     => options
  )
end
modify_key(key_name, params={}) click to toggle source

Modify a key

Parameters

  • key_name<~String> - name of key to be modified

  • params<~Hash> - depends on type of request

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'success'<~Bool>: success status of update request

# File lib/fog/ibm/requests/compute/modify_key.rb, line 15
def modify_key(key_name, params={})
  request(
    :method   => 'PUT',
    :expects  => 200,
    :path     => "/keys/#{key_name}",
    :body     => params
  )
end

Private Instance Methods

request(options) click to toggle source
# File lib/fog/ibm/compute.rb, line 68
def request(options)
  begin
    @connection.request(options)
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
    when Excon::Errors::NotFound
      Fog::Compute::IBM::NotFound.slurp(error)
    else
      error
    end
  end
end