1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/ibm/requests/compute/get_instance.rb
2012-03-20 23:37:46 -04:00

76 lines
2.7 KiB
Ruby

module Fog
module Compute
class IBM
class Real
# 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>:
# * 'root-only'<~Boolean>: instance id
# * '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
def get_instance(instance_id)
request(
:method => 'GET',
:expects => 200,
:path => "/instances/#{instance_id}"
)
end
end
class Mock
def get_instance(instance_id)
response = Excon::Response.new
if instance_exists? instance_id
activate_instance(instance_id) # Set it to Active if it's not running
response.status = 200
response.body = self.data[:instances][instance_id]
else
response.status = 404
end
response
end
# Checks if an instance exists
def instance_exists?(instance_id)
self.data[:instances].key? instance_id
end
# Sets instance status to Active if it's not already set.
def activate_instance(instance_id)
self.data[:instances][instance_id]["status"] = 5 unless instance_active? instance_id
end
# Checks if an instance is Active
def instance_active?(instance_id)
self.data[:instances][instance_id]["status"] == 5
end
end
end
end
end