From: Michal Fojtik <[email protected]>
Signed-off-by: Michal fojtik <[email protected]> --- server/lib/deltacloud/models/image.rb | 12 ++++++++++++ server/lib/deltacloud/models/instance.rb | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server/lib/deltacloud/models/image.rb b/server/lib/deltacloud/models/image.rb index ec596b5..ca75717 100644 --- a/server/lib/deltacloud/models/image.rb +++ b/server/lib/deltacloud/models/image.rb @@ -23,4 +23,16 @@ class Image < BaseModel attr_accessor :architecture attr_accessor :state + alias :to_hash_original :to_hash + + def to_hash + h = self.to_hash_original + h.merge({ + :actions => [ :create_instance => { + :method => 'post', + :href => "/api/instances;image_id=#{self.id}" # FIXME: Figure out how instances_url should be called here + }] + }) + end + end diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb index 479ed0c..922f79b 100644 --- a/server/lib/deltacloud/models/instance.rb +++ b/server/lib/deltacloud/models/instance.rb @@ -59,13 +59,25 @@ class Instance < BaseModel if name =~ /is_(\w+)\?/ return true if self.state.downcase.eql?($1) else - raise NoMethodError + raise NoMethodError.new(name.to_s) end end def authn_feature_failed? return true unless authn_error.nil? end - + + alias :to_hash_original :to_hash + + def to_hash + h = self.to_hash_original + h[:actions] = self.actions.collect do |action| + { :"#{action}" => { + :method => collections[:instances].operations[action.to_sym].method, + :href => collections[:instances].operations[action.to_sym].path.gsub(':id', self.id) + }} + end + h + end end -- 1.7.4.1
