2012-04-27 08:25:40 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Serverlove
|
|
|
|
|
2012-04-29 12:36:16 -04:00
|
|
|
class Image < Fog::Model
|
2012-04-27 08:25:40 -04:00
|
|
|
|
2012-04-29 12:36:16 -04:00
|
|
|
identity :id, :aliases => 'drive'
|
2012-04-27 08:25:40 -04:00
|
|
|
|
|
|
|
attribute :name
|
|
|
|
attribute :user
|
|
|
|
attribute :size
|
2012-04-27 09:01:42 -04:00
|
|
|
attribute :claimed
|
|
|
|
attribute :status
|
2012-04-27 09:55:06 -04:00
|
|
|
attribute :encryption_cipher, :aliases => 'encryption:cipher'
|
2012-04-27 08:25:40 -04:00
|
|
|
|
|
|
|
def save
|
2012-04-29 12:00:13 -04:00
|
|
|
attributes = {}
|
|
|
|
|
|
|
|
if(identity)
|
2012-04-29 12:36:16 -04:00
|
|
|
attributes = connection.update_image(identity, allowed_attributes).body
|
2012-04-29 12:00:13 -04:00
|
|
|
else
|
|
|
|
requires :name
|
|
|
|
requires :size
|
2012-04-29 12:36:16 -04:00
|
|
|
attributes = connection.create_image(allowed_attributes).body
|
2012-04-29 12:00:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
merge_attributes(attributes)
|
2012-04-29 12:11:19 -04:00
|
|
|
self
|
2012-04-27 16:53:39 -04:00
|
|
|
end
|
2012-04-29 12:36:16 -04:00
|
|
|
|
|
|
|
def ready?
|
|
|
|
status.upcase == 'ACTIVE'
|
|
|
|
end
|
2012-04-27 16:53:39 -04:00
|
|
|
|
2012-04-27 08:25:40 -04:00
|
|
|
def destroy
|
|
|
|
requires :identity
|
2012-04-29 12:36:16 -04:00
|
|
|
connection.destroy_image(identity)
|
2012-04-29 12:11:19 -04:00
|
|
|
self
|
2012-04-29 09:14:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_attributes
|
|
|
|
allowed = [:name, :size]
|
|
|
|
attributes.select {|k,v| allowed.include? k}
|
|
|
|
end
|
|
|
|
|
2012-04-27 08:25:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|