deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject [8/14] git commit: CIMI: use a helper to produce correct headers for create responses
Date Tue, 11 Dec 2012 03:48:25 GMT
CIMI: use a helper to produce correct headers for create responses


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

Branch: refs/heads/master
Commit: c04330e2f153e48c115d90af92444c22e47dfd88
Parents: fac338c
Author: David Lutterkort <lutter@redhat.com>
Authored: Tue Dec 4 17:18:21 2012 -0800
Committer: David Lutterkort <lutter@redhat.com>
Committed: Mon Dec 10 17:08:48 2012 -0800

----------------------------------------------------------------------
 server/lib/cimi/collections/credentials.rb       |    2 +-
 server/lib/cimi/collections/machine_templates.rb |    3 +--
 server/lib/cimi/collections/machines.rb          |    5 ++---
 server/lib/cimi/collections/volumes.rb           |    3 +--
 server/lib/cimi/helpers/cimi_helper.rb           |    6 ++++++
 5 files changed, 11 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c04330e2/server/lib/cimi/collections/credentials.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/credentials.rb b/server/lib/cimi/collections/credentials.rb
index f2ca059..28d497d 100644
--- a/server/lib/cimi/collections/credentials.rb
+++ b/server/lib/cimi/collections/credentials.rb
@@ -51,7 +51,7 @@ module CIMI::Collections
           else
             new_admin = Credential.create_from_xml(request.body.read, self)
           end
-          status 201 # Created
+          headers_for_create new_admin
           respond_to do |format|
             format.json { new_admin.to_json }
             format.xml { new_admin.to_xml }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c04330e2/server/lib/cimi/collections/machine_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machine_templates.rb b/server/lib/cimi/collections/machine_templates.rb
index a90f360..9a12915 100644
--- a/server/lib/cimi/collections/machine_templates.rb
+++ b/server/lib/cimi/collections/machine_templates.rb
@@ -50,8 +50,7 @@ module CIMI::Collections
           else
             new_machine_template = CIMI::Model::MachineTemplate.create_from_xml(request.body.read,
self)
           end
-          status 201 # Created
-          headers 'Location' => new_machine_template.id
+          headers_for_create new_machine_template
           respond_to do |format|
             format.json { new_machine_template.to_json }
             format.xml { new_machine_template.to_xml }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c04330e2/server/lib/cimi/collections/machines.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machines.rb b/server/lib/cimi/collections/machines.rb
index 91fbc64..b18fb1c 100644
--- a/server/lib/cimi/collections/machines.rb
+++ b/server/lib/cimi/collections/machines.rb
@@ -51,8 +51,7 @@ module CIMI::Collections
           else
             new_machine = Machine.create_from_xml(request.body.read, self)
           end
-          status 201 # Created
-          headers 'Location' => new_machine.id
+          headers_for_create new_machine
           respond_to do |format|
             format.json { new_machine.to_json }
             format.xml { new_machine.to_xml }
@@ -181,7 +180,7 @@ module CIMI::Collections
             volume_to_attach, location = MachineVolume.find_to_attach_from_xml(request.body.read,
self)
           end
           machine_volume = Machine.attach_volume(volume_to_attach,location, self)
-          status 201
+          headers_for_create machine_volume
           respond_to do |format|
             format.json{ machine_volume.to_json}
             format.xml{machine_volume.to_xml}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c04330e2/server/lib/cimi/collections/volumes.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/volumes.rb b/server/lib/cimi/collections/volumes.rb
index 1078014..c8edf56 100644
--- a/server/lib/cimi/collections/volumes.rb
+++ b/server/lib/cimi/collections/volumes.rb
@@ -51,8 +51,7 @@ module CIMI::Collections
         control do
           content_type = grab_content_type(request.content_type, request.body)
           new_volume = Volume.create(request.body.read, self, content_type)
-          status 201
-          headers 'Location' => new_volume.id
+          headers_for_create new_volume
           respond_to do |format|
             format.json { new_volume.to_json }
             format.xml { new_volume.to_xml }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c04330e2/server/lib/cimi/helpers/cimi_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/helpers/cimi_helper.rb b/server/lib/cimi/helpers/cimi_helper.rb
index 3dd9501..713aeab 100644
--- a/server/lib/cimi/helpers/cimi_helper.rb
+++ b/server/lib/cimi/helpers/cimi_helper.rb
@@ -26,6 +26,12 @@ module CIMI
       status code
     end
 
+    # Set status to 201 and a Location header
+    def headers_for_create(resource)
+      status 201
+      headers 'Location' => resource.id
+    end
+
     def href_id(href, entity)
       split_on = self.send(:"#{entity.to_s}_url")
       href.split("#{split_on}/").last


Mime
View raw message