You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/12/06 03:42:47 UTC
[PATCH 03/13] CIMI: use a helper to produce correct headers for create responses
From: David Lutterkort <lu...@redhat.com>
---
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(-)
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 }
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 }
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}
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 }
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
--
1.7.7.6