deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [1/2] git commit: CIMI - Fix routes for MachineVolumes - uses rabbit subcollection
Date Wed, 28 Nov 2012 17:30:25 GMT
Updated Branches:
  refs/heads/master 752967294 -> 71b10c3ab


CIMI - Fix routes for MachineVolumes - uses rabbit subcollection


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/042cf319
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/042cf319
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/042cf319

Branch: refs/heads/master
Commit: 042cf3199aa5f8a44c38613d43494d3d16035530
Parents: 7529672
Author: marios <marios@redhat.com>
Authored: Wed Nov 28 12:01:30 2012 +0200
Committer: marios <marios@redhat.com>
Committed: Wed Nov 28 19:29:56 2012 +0200

----------------------------------------------------------------------
 server/lib/cimi/collections/machines.rb |   72 +++++++++++++++-----------
 1 files changed, 41 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/042cf319/server/lib/cimi/collections/machines.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machines.rb b/server/lib/cimi/collections/machines.rb
index 6a896f3..5247577 100644
--- a/server/lib/cimi/collections/machines.rb
+++ b/server/lib/cimi/collections/machines.rb
@@ -131,54 +131,64 @@ module CIMI::Collections
         end
       end
 
-      operation :volumes, :with_capability => :storage_volumes do
-        description "Retrieve the Machine's MachineVolumeCollection"
-        param :id,          :string,    :required
-        control do
-          volumes = CIMI::Model::Volume.collection_for_instance(params[:id], self)
-          respond_to do |format|
-            format.json {volumes.to_json}
-            format.xml  {volumes.to_xml}
+      #use rabbit subcollections for volumes index/show:
+      collection :volumes, :with_id => :vol_id do
+
+        operation :index, :with_capability => :storage_volumes do
+          description "Retrieve the Machine's MachineVolumeCollection"
+          control do
+            volumes = CIMI::Model::MachineVolume.collection_for_instance(params[:id], self)
+            respond_to do |format|
+              format.json {volumes.to_json}
+              format.xml  {volumes.to_xml}
+            end
           end
         end
-      end
 
-      #NOTE: The routes for attach/detach used here are NOT as specified by CIMI
-      #will likely move later. CIMI specifies PUT of the whole Machine description
-      #with inclusion/ommission of the volumes you want [att|det]ached
-      action :attach_volume, :http_method => :put, :with_capability => :attach_storage_volume
do
-        description "Attach CIMI Volume(s) to a machine."
-        param :id,          :string,    :required
-        control do
-          if request.content_type.end_with?("json")
-            volumes_to_attach = Volume.find_to_attach_from_json(request.body.read, self)
-          else
-            volumes_to_attach = Volume.find_to_attach_from_xml(request.body.read, self)
+        operation :show, :with_capability => :storage_volumes do
+          description "Retrieve a Machine's specific MachineVolume"
+          control do
+            volume = CIMI::Model::MachineVolume.find(params[:id], self, params[:vol_id])
+            respond_to do |format|
+              format.json {volume.to_json}
+              format.xml  {volume.to_xml}
+            end
           end
-          machine = Machine.attach_volumes(volumes_to_attach, self)
-          respond_to do |format|
-            format.json{ machine.to_json}
-            format.xml{machine.to_xml}
+        end
+
+        operation :destroy, :with_capability => :detach_storage_volume do
+          description "Remove/detach a volume from the Machine's MachineVolumeCollection"
+          control do
+            machine_volume = CIMI::Model::MachineVolume.find(params[:id], self, params[:vol_id])
+            location = machine_volume.initial_location
+            machine_volumes = Machine.detach_volume(params[:vol_id], location, self)
+            respond_to do |format|
+              format.json{ machine_volumes.to_json}
+              format.xml{ machine_volumes.to_xml}
+            end
           end
         end
+
       end
 
-      action :detach_volume, :http_method => :put, :with_capability => :detach_storage_volume
do
-        description "Detach CIMI Volume(s) from a machine."
+      operation :volume_attach, :http_method => :put, :with_capability => :attach_storage_volume
do
+        description "Attach CIMI Volume(s) to a machine."
         param :id,          :string,    :required
         control do
           if request.content_type.end_with?("json")
-            volumes_to_detach = Volume.find_to_attach_from_json(request.body.read, self)
+            volume_to_attach, location = MachineVolume.find_to_attach_from_json(request.body.read,
self)
           else
-            volumes_to_detach = Volume.find_to_attach_from_xml(request.body.read, self)
+            volume_to_attach, location = MachineVolume.find_to_attach_from_xml(request.body.read,
self)
           end
-          machine = Machine.detach_volumes(volumes_to_detach, self)
+          machine_volume = Machine.attach_volume(volume_to_attach,location, self)
+          status 201
           respond_to do |format|
-            format.json{ machine.to_json}
-            format.xml{machine.to_xml}
+            format.json{ machine_volume.to_json}
+            format.xml{machine_volume.to_xml}
           end
         end
       end
+
     end
 
   end


Mime
View raw message