2012-01-10 17:20:56 -05:00
|
|
|
require 'fog/core/model'
|
2012-01-19 14:29:48 -05:00
|
|
|
require 'fog/ibm/models/compute/instance-types'
|
2012-01-10 17:20:56 -05:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class IBM
|
|
|
|
class Image < Fog::Model
|
2012-02-29 02:01:27 -05:00
|
|
|
|
|
|
|
STATES = {
|
|
|
|
0 => 'New',
|
|
|
|
1 => 'Available',
|
|
|
|
2 => 'Unavailable',
|
|
|
|
3 => 'Deleted',
|
|
|
|
4 => 'Capturing',
|
|
|
|
5 => 'Importing',
|
|
|
|
6 => 'Copying',
|
|
|
|
7 => 'Failed',
|
|
|
|
}
|
|
|
|
|
2012-01-10 17:20:56 -05:00
|
|
|
identity :id
|
2012-02-29 02:01:27 -05:00
|
|
|
|
2012-01-10 17:20:56 -05:00
|
|
|
attribute :architecture
|
|
|
|
attribute :created_at, :aliases => 'createdTime'
|
|
|
|
attribute :description
|
|
|
|
attribute :documentation
|
|
|
|
attribute :location
|
|
|
|
attribute :manifest
|
|
|
|
attribute :name
|
|
|
|
attribute :owner
|
|
|
|
attribute :platform
|
|
|
|
attribute :product_codes, :aliases => 'productCodes'
|
|
|
|
attribute :state
|
|
|
|
attribute :supported_instance_types, :aliases => 'supportedInstanceTypes'
|
|
|
|
attribute :visibility
|
|
|
|
|
|
|
|
attribute :volume_id
|
|
|
|
|
2012-01-19 14:29:48 -05:00
|
|
|
def initialize(new_attributes = {})
|
|
|
|
super(new_attributes)
|
|
|
|
attributes[:supported_instance_types] = Fog::Compute::IBM::InstanceTypes.new.load(attributes[:supported_instance_types]) if attributes[:supported_instance_types]
|
|
|
|
end
|
|
|
|
|
2012-01-10 17:20:56 -05:00
|
|
|
def save
|
|
|
|
requires :id, :volume_id
|
|
|
|
data = connection.create_image(id, volume_id)
|
|
|
|
merge_attributes(data.body)
|
|
|
|
data.body['success']
|
|
|
|
end
|
|
|
|
|
2012-02-29 02:01:27 -05:00
|
|
|
def state
|
|
|
|
STATES[attributes[:state]]
|
|
|
|
end
|
|
|
|
|
|
|
|
def ready?
|
|
|
|
state == 'Available'
|
|
|
|
end
|
|
|
|
|
2012-01-10 17:20:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|