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/brightbox/models/compute/image.rb
Paul Thornthwaite 40c0cd7122 Make use of #persisted? method
In many places we were checking for identity which was the shorthand for
checking if the resource had been saved by the service.

The #persisted? method was added to show a clearer intent and also offer
minimal ActiveModel interface
2012-12-23 02:45:05 +00:00

66 lines
1.5 KiB
Ruby

require 'fog/core/model'
module Fog
module Compute
class Brightbox
class Image < Fog::Model
identity :id
attribute :url
attribute :resource_type
attribute :name
attribute :username
attribute :status
attribute :description
attribute :source
attribute :source_type
attribute :arch
attribute :virtual_size
attribute :disk_size
attribute :licence_name
# Boolean flags
attribute :public
attribute :official
attribute :compatibility_mode
# Times
attribute :created_at, :type => :time
# Links - to be replaced
attribute :ancestor_id, :aliases => "ancestor", :squash => "id"
attribute :owner_id, :aliases => "owner", :squash => "id"
def ready?
status == "available"
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
requires :source, :arch
options = {
:source => source,
:arch => arch,
:name => name,
:username => username,
:description => description
}.delete_if {|k,v| v.nil? || v == "" }
data = connection.create_image(options)
merge_attributes(data)
true
end
def destroy
requires :identity
connection.destroy_image(identity)
true
end
end
end
end
end