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