You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2012/12/20 18:21:06 UTC
CIMI: create machine image
We already (correctly) advertise the 'create image' operation on Machines:
...
<operation rel="http://schemas.dmtf.org/cimi/1/action/capture"
href="http://localhost:3001/cimi/machine_images" />
...
This patch adds the ability to do the actual image creation from a
running machine - as per CIMI we do a POST to machine image collection,
with the imageLocation attribute referencing the Machine resource:
XML:
curl --user "mockuser:mockpassword" -H "Content-Type: application/xml"
-H "Accept: application/xml" -d "<MachineImage><name>some_name</name>
<description>my new machine image</description><type>IMAGE</type>
<imageLocation>http://localhost:3001/cimi/machines/inst1</imageLocation>
</MachineImage>" http://localhost:3001/cimi/machine_images
JSON:
curl --user "mockuser:mockpassword" -H "Content-Type: application/json"
-H "Accept: application/json" -d '{"resourceURI":"http://schemas.dmtf.org/cimi/1/MachineImage",
"name":"new_image","description":"my new machine image","type":"IMAGE",
"imageLocation":"http://localhost:3001/cimi/machines/inst1"}'
http://localhost:3001/cimi/machine_images
tracked at http://tracker.deltacloud.org/set/216
marios
Re: [PATCH] CIMI: adds create_image (from a running server)
Posted by "marios@redhat.com" <ma...@redhat.com>.
On 21/12/12 02:09, David Lutterkort wrote:
> On Thu, 2012-12-20 at 19:21 +0200, marios@redhat.com wrote:
>> From: marios <ma...@redhat.com>
>>
>>
>> Signed-off-by: marios <ma...@redhat.com>
>
> ACK, once you add a unit test, pretty please.
>
..well, since " 'tis the season " and all....
done, plus added the (ever useful) delete functionality,
marios
> David
>
>
Re: [PATCH] CIMI: adds create_image (from a running server)
Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2012-12-20 at 19:21 +0200, marios@redhat.com wrote:
> From: marios <ma...@redhat.com>
>
>
> Signed-off-by: marios <ma...@redhat.com>
ACK, once you add a unit test, pretty please.
David
[PATCH] CIMI: adds create_image (from a running server)
Posted by ma...@redhat.com.
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/cimi/collections/machine_images.rb | 11 +++++++++++
server/lib/cimi/models/machine_image.rb | 8 ++++++++
2 files changed, 19 insertions(+)
diff --git a/server/lib/cimi/collections/machine_images.rb b/server/lib/cimi/collections/machine_images.rb
index 822a7d5..21632fb 100644
--- a/server/lib/cimi/collections/machine_images.rb
+++ b/server/lib/cimi/collections/machine_images.rb
@@ -43,6 +43,17 @@ module CIMI::Collections
end
end
+ operation :create, :with_capability => :create_image do
+ description "Create a new machine image."
+ control do
+ machine_image = CIMI::Model::MachineImage.create(request.body, self)
+ respond_to do |format|
+ format.xml { machine_image.to_xml }
+ format.json { machine_image.to_json }
+ end
+ end
+ end
+
end
end
diff --git a/server/lib/cimi/models/machine_image.rb b/server/lib/cimi/models/machine_image.rb
index 6034e5b..763b9bd 100644
--- a/server/lib/cimi/models/machine_image.rb
+++ b/server/lib/cimi/models/machine_image.rb
@@ -49,4 +49,12 @@ class CIMI::Model::MachineImage < CIMI::Model::Base
)
end
+ def self.create(request_body, context)
+ type = context.grab_content_type(context.request.content_type, request_body)
+ input = (type == :xml)? XmlSimple.xml_in(request_body.read, {"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(request_body.read)
+ params = {:id => context.href_id(input["imageLocation"], :machines), :name=>input["name"], :description=>input["description"]}
+ image = context.driver.create_image(context.credentials, params)
+ from_image(image, context)
+ end
+
end
--
1.7.11.7