2012-07-30 16:50:16 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class RackspaceV2
|
|
|
|
class Image < Fog::Model
|
|
|
|
UNKNOWN = 'UNKNOWN'
|
|
|
|
ACTIVE = 'ACTIVE'
|
|
|
|
SAVING = 'SAVING'
|
|
|
|
ERROR = 'ERROR'
|
|
|
|
DELETED = 'DELETED'
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :name
|
|
|
|
attribute :created
|
|
|
|
attribute :updated
|
|
|
|
attribute :state, :aliases => 'status'
|
|
|
|
attribute :user_id
|
|
|
|
attribute :tenant_id
|
|
|
|
attribute :progress
|
|
|
|
attribute :minDisk
|
|
|
|
attribute :minRam
|
|
|
|
attribute :disk_config, :aliases => 'OS-DCF:diskConfig'
|
|
|
|
attribute :links
|
2013-01-07 16:00:50 -06:00
|
|
|
|
|
|
|
ignore_attributes :metadata
|
2013-01-07 11:10:17 -06:00
|
|
|
|
|
|
|
def initialize(attributes={})
|
|
|
|
@connection = attributes[:connection]
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def metadata
|
|
|
|
raise "Please save image before accessing metadata" unless identity
|
|
|
|
@metadata ||= begin
|
|
|
|
Fog::Compute::RackspaceV2::Metadata.new({
|
|
|
|
:connection => connection,
|
|
|
|
:parent => self
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def metadata=(hash={})
|
|
|
|
raise "Please save image before accessing metadata" unless identity
|
|
|
|
metadata.from_hash(hash)
|
|
|
|
end
|
2012-12-11 08:35:06 -06:00
|
|
|
|
2013-01-15 08:04:56 -06:00
|
|
|
def ready?(ready_state = ACTIVE, error_states=[ERROR])
|
|
|
|
if error_states
|
|
|
|
error_states = Array(error_states)
|
|
|
|
raise "Image should have transitioned to '#{ready_state}' not '#{state}'" if error_states.include?(state)
|
|
|
|
end
|
|
|
|
state == ready_state
|
2012-12-11 08:35:06 -06:00
|
|
|
end
|
2013-01-15 08:04:56 -06:00
|
|
|
|
2012-12-11 08:35:06 -06:00
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :identity
|
2012-12-22 23:24:03 +00:00
|
|
|
service.delete_image(identity)
|
2012-12-11 08:35:06 -06:00
|
|
|
end
|
2012-07-30 16:50:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|