2010-11-08 07:21:31 -05:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class Brightbox
|
2010-11-08 07:21:31 -05:00
|
|
|
|
|
|
|
class Image < Fog::Model
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
attribute :url
|
2011-08-22 12:41:18 -04:00
|
|
|
attribute :resource_type
|
|
|
|
|
2010-11-08 07:21:31 -05:00
|
|
|
attribute :name
|
|
|
|
attribute :status
|
2011-08-22 12:41:18 -04:00
|
|
|
attribute :description
|
|
|
|
|
2010-11-08 07:21:31 -05:00
|
|
|
attribute :source
|
|
|
|
attribute :source_type
|
|
|
|
attribute :arch
|
2011-08-22 12:41:18 -04:00
|
|
|
attribute :virtual_size
|
|
|
|
attribute :disk_size
|
2010-11-08 07:21:31 -05:00
|
|
|
|
2011-08-22 12:41:18 -04:00
|
|
|
# Boolean flags
|
2010-11-08 07:21:31 -05:00
|
|
|
attribute :public
|
|
|
|
attribute :official
|
2011-04-28 05:14:13 -04:00
|
|
|
attribute :compatibility_mode
|
2011-08-22 12:41:18 -04:00
|
|
|
|
|
|
|
# Times
|
2011-08-26 11:00:24 -04:00
|
|
|
attribute :created_at, :type => :time
|
2010-11-08 07:21:31 -05:00
|
|
|
|
2011-08-22 12:41:18 -04:00
|
|
|
# Links - to be replaced
|
|
|
|
attribute :ancestor_id, :aliases => "ancestor", :squash => "id"
|
|
|
|
attribute :owner_id, :aliases => "owner", :squash => "id"
|
|
|
|
|
2010-12-06 09:50:59 -05:00
|
|
|
def ready?
|
|
|
|
status == "available"
|
|
|
|
end
|
|
|
|
|
2010-11-08 07:21:31 -05:00
|
|
|
def save
|
2011-08-23 12:22:07 -04:00
|
|
|
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
2010-11-08 07:21:31 -05:00
|
|
|
requires :source, :arch
|
|
|
|
options = {
|
2010-11-19 16:45:45 -05:00
|
|
|
:source => source,
|
|
|
|
:arch => arch,
|
|
|
|
:name => name,
|
|
|
|
:description => description
|
2010-11-08 07:21:31 -05:00
|
|
|
}.delete_if {|k,v| v.nil? || v == "" }
|
2010-11-09 12:40:04 -05:00
|
|
|
data = connection.create_image(options)
|
2010-11-08 07:21:31 -05:00
|
|
|
merge_attributes(data)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :identity
|
|
|
|
connection.destroy_image(identity)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|