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 2011/12/09 19:55:31 UTC
[PATCH 1/2] Tidy up CIMI::Volume creation code
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/cimi/model/volume.rb | 22 +++++++++++++++++++---
server/lib/cimi/server.rb | 12 ++----------
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/server/lib/cimi/model/volume.rb b/server/lib/cimi/model/volume.rb
index 4c19889..63dcf86 100644
--- a/server/lib/cimi/model/volume.rb
+++ b/server/lib/cimi/model/volume.rb
@@ -44,15 +44,31 @@ class CIMI::Model::Volume < CIMI::Model::Base
def self.all(context); find(:all, context); end
- def self.create(params, context)
+ def self.create_from_json(json_in, context)
+ json = JSON.parse(json_in)
+ volume_config_id = json["volumeTemplate"]["volumeConfig"]["href"].split("/").last
+ volume_image_id = (json["volumeTemplate"].has_key?("volumeImage") ?
+ json["volumeTemplate"]["volumeImage"]["href"].split("/").last : nil)
+ create_volume({:volume_config_id=>volume_config_id, :volume_image_id=>volume_image_id}, context)
+ end
+
+ def self.create_from_xml(xml_in, context)
+ xml = XmlSimple.xml_in(xml_in)
+ volume_config_id = xml["volumeTemplate"][0]["volumeConfig"][0]["href"].split("/").last
+ volume_image_id = (xml["volumeTemplate"][0].has_key?("volumeImage") ?
+ xml["volumeTemplate"][0]["volumeImage"][0]["href"].split("/").last : nil)
+ create_volume({:volume_config_id=>volume_config_id, :volume_image_id=>volume_image_id}, context)
+ end
+
+ private
+
+ def self.create_volume(params, context)
volume_config = VolumeConfiguration.find(params[:volume_config_id], context)
opts = {:capacity=>volume_config.capacity[:quantity], :snapshot_id=>params[:volume_image_id] }
storage_volume = self.driver.create_storage_volume(context.credentials, opts)
from_storage_volume(storage_volume, context)
end
- private
-
def self.from_storage_volume(volume, context)
self.new( { :name => volume.id,
:description => volume.id,
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 9671df2..c0d2627 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -345,18 +345,10 @@ global_collection :volumes do
#((request.content_type.end_with?("+xml")) ? :xml : report_error(415) ) FIXME
case content_type
when :json
- json = JSON.parse(request.body.read)
- volume_config_id = json["volumeTemplate"]["volumeConfig"]["href"].split("/").last
- volume_image_id = (json["volumeTemplate"].has_key?("volumeImage") ?
- json["volumeTemplate"]["volumeImage"]["href"].split("/").last : nil)
+ new_volume = Volume.create_from_json(request.body.read, self)
when :xml
- xml = XmlSimple.xml_in(request.body.read)
- volume_config_id = xml["volumeTemplate"][0]["volumeConfig"][0]["href"].split("/").last
- volume_image_id = (xml["volumeTemplate"][0].has_key?("volumeImage") ?
- xml["volumeTemplate"][0]["volumeImage"][0]["href"].split("/").last : nil)
+ new_volume = Volume.create_from_xml(request.body.read, self)
end
- params.merge!( {:volume_config_id => volume_config_id, :volume_image_id => volume_image_id} )
- new_volume = Volume.create(params, self)
respond_to do |format|
format.json { new_volume.to_json }
format.xml { new_volume.to_xml }
--
1.7.6.4
Re: [PATCH 2/2] Add CIMI::Volume delete operation
Posted by Michal Fojtik <mf...@redhat.com>.
Hi,
ACK to both patches.
-- Michal
On Dec 9, 2011, at 7:55 PM, marios@redhat.com wrote:
> From: marios <ma...@redhat.com>
>
>
> Signed-off-by: marios <ma...@redhat.com>
> ---
> server/lib/cimi/model/machine.rb | 2 +-
> server/lib/cimi/model/volume.rb | 4 ++++
> server/lib/cimi/server.rb | 13 +++++++++++--
> 3 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/server/lib/cimi/model/machine.rb b/server/lib/cimi/model/machine.rb
> index 8f31bc6..d2673e7 100644
> --- a/server/lib/cimi/model/machine.rb
> +++ b/server/lib/cimi/model/machine.rb
> @@ -85,7 +85,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
> if machine_template.has_key? 'MachineAdmin'
> additional_params[:keyname] = machine_template['machineAdmin'][0]["href"].split('/').last
> end
> - instance = context.driver.create_instance(context.credentials, image_id, {
> + instance = context.driver.create_instance(context.credentials, image_id, {
> :hwp_id => hardware_profile_id
> }.merge(additional_params))
> from_instance(instance, context)
> diff --git a/server/lib/cimi/model/volume.rb b/server/lib/cimi/model/volume.rb
> index 63dcf86..cb9a34f 100644
> --- a/server/lib/cimi/model/volume.rb
> +++ b/server/lib/cimi/model/volume.rb
> @@ -60,6 +60,10 @@ class CIMI::Model::Volume < CIMI::Model::Base
> create_volume({:volume_config_id=>volume_config_id, :volume_image_id=>volume_image_id}, context)
> end
>
> + def self.delete!(id, context)
> + context.driver.destroy_storage_volume(context.credentials, {:id=>id} )
> + end
> +
> private
>
> def self.create_volume(params, context)
> diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
> index c0d2627..77a8d04 100644
> --- a/server/lib/cimi/server.rb
> +++ b/server/lib/cimi/server.rb
> @@ -249,8 +249,8 @@ global_collection :machines do
> end
> end
>
> - operation :delete, :method => :delete, :member => true do
> - description "Reboot specific machine."
> + operation :destroy do
> + description "Delete a specified machine."
> param :id, :string, :required
> control do
> Machine.delete!(params[:id], self)
> @@ -356,6 +356,15 @@ global_collection :volumes do
> end
> end
>
> + operation :destroy do
> + description "Delete a specified Volume"
> + param :id, :string, :required
> + control do
> + Volume.delete!(params[:id], self)
> + no_content_with_status(200)
> + end
> + end
> +
> end
>
> global_collection :volume_configurations do
> --
> 1.7.6.4
>
------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
[PATCH 2/2] Add CIMI::Volume delete operation
Posted by ma...@redhat.com.
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/cimi/model/machine.rb | 2 +-
server/lib/cimi/model/volume.rb | 4 ++++
server/lib/cimi/server.rb | 13 +++++++++++--
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/server/lib/cimi/model/machine.rb b/server/lib/cimi/model/machine.rb
index 8f31bc6..d2673e7 100644
--- a/server/lib/cimi/model/machine.rb
+++ b/server/lib/cimi/model/machine.rb
@@ -85,7 +85,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
if machine_template.has_key? 'MachineAdmin'
additional_params[:keyname] = machine_template['machineAdmin'][0]["href"].split('/').last
end
- instance = context.driver.create_instance(context.credentials, image_id, {
+ instance = context.driver.create_instance(context.credentials, image_id, {
:hwp_id => hardware_profile_id
}.merge(additional_params))
from_instance(instance, context)
diff --git a/server/lib/cimi/model/volume.rb b/server/lib/cimi/model/volume.rb
index 63dcf86..cb9a34f 100644
--- a/server/lib/cimi/model/volume.rb
+++ b/server/lib/cimi/model/volume.rb
@@ -60,6 +60,10 @@ class CIMI::Model::Volume < CIMI::Model::Base
create_volume({:volume_config_id=>volume_config_id, :volume_image_id=>volume_image_id}, context)
end
+ def self.delete!(id, context)
+ context.driver.destroy_storage_volume(context.credentials, {:id=>id} )
+ end
+
private
def self.create_volume(params, context)
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index c0d2627..77a8d04 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -249,8 +249,8 @@ global_collection :machines do
end
end
- operation :delete, :method => :delete, :member => true do
- description "Reboot specific machine."
+ operation :destroy do
+ description "Delete a specified machine."
param :id, :string, :required
control do
Machine.delete!(params[:id], self)
@@ -356,6 +356,15 @@ global_collection :volumes do
end
end
+ operation :destroy do
+ description "Delete a specified Volume"
+ param :id, :string, :required
+ control do
+ Volume.delete!(params[:id], self)
+ no_content_with_status(200)
+ end
+ end
+
end
global_collection :volume_configurations do
--
1.7.6.4