You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2011/05/18 15:11:37 UTC

svn commit: r1124251 - in /incubator/deltacloud/trunk/server/lib/deltacloud/models: image.rb instance.rb

Author: mfojtik
Date: Wed May 18 13:11:37 2011
New Revision: 1124251

URL: http://svn.apache.org/viewvc?rev=1124251&view=rev
Log:
Improved actions reporting in JSON

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/models/image.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/models/image.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/models/image.rb?rev=1124251&r1=1124250&r2=1124251&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/models/image.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/models/image.rb Wed May 18 13:11:37 2011
@@ -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

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb?rev=1124251&r1=1124250&r2=1124251&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb Wed May 18 13:11:37 2011
@@ -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