deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [3/3] git commit: CIMI: Added VolumeTemplateCreate model
Date Fri, 01 Mar 2013 09:38:05 GMT
Updated Branches:
  refs/heads/master 246e62183 -> 6275a4d8e


CIMI: Added VolumeTemplateCreate model


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

Branch: refs/heads/master
Commit: 6275a4d8efb9eb6362b6d3db8d75716f24a04541
Parents: 6216a34
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Wed Feb 27 15:54:31 2013 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Fri Mar 1 10:37:33 2013 +0100

----------------------------------------------------------------------
 server/lib/cimi/collections/volume_templates.rb  |    6 ++--
 server/lib/cimi/models.rb                        |    1 +
 server/lib/cimi/models/volume_template.rb        |   21 ++---------
 server/lib/cimi/models/volume_template_create.rb |   33 +++++++++++++++++
 server/support/cimi/volume_template.xml          |    7 ++++
 5 files changed, 48 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6275a4d8/server/lib/cimi/collections/volume_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/volume_templates.rb b/server/lib/cimi/collections/volume_templates.rb
index 720e73b..b844ed8 100644
--- a/server/lib/cimi/collections/volume_templates.rb
+++ b/server/lib/cimi/collections/volume_templates.rb
@@ -45,9 +45,9 @@ module CIMI::Collections
       operation :create, :with_capability => :create_storage_volume do
         description "Create new VolumeTemplate"
         control do
-          new_template = CIMI::Model::VolumeTemplate.create(
-            request.body.read, self, current_content_type
-          )
+          puts request.body
+          vol = CIMI::Model::VolumeTemplateCreate.parse(request.body, request.content_type)
+          new_template = vol.create(self)
           headers_for_create new_template
           respond_to do |format|
             format.json { new_template.to_json }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6275a4d8/server/lib/cimi/models.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index 2f7e158..edfb0e3 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -69,6 +69,7 @@ require_relative './models/volume_image'
 require_relative './models/volume_template'
 require_relative './models/volume_create'
 require_relative './models/volume_image_create'
+require_relative './models/volume_template_create'
 require_relative './models/machine'
 require_relative './models/machine_configuration'
 require_relative './models/machine_image'

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6275a4d8/server/lib/cimi/models/volume_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_template.rb b/server/lib/cimi/models/volume_template.rb
index 500fa75..15cbcd0 100644
--- a/server/lib/cimi/models/volume_template.rb
+++ b/server/lib/cimi/models/volume_template.rb
@@ -47,26 +47,10 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base
     end
   end
 
-  def self.create(body, context, type)
-    input = (type == :xml)? XmlSimple.xml_in(body, {"ForceArray"=>false,"NormaliseSpace"=>2})
: JSON.parse(body)
-    input['property'] ||= []
-    vol_image = input['volumeImage']['href'] if input['volumeImage']
-    new_template = current_db.add_volume_template(
-      :name => input['name'],
-      :description => input['description'],
-      :volume_config => input['volumeConfig']['href'],
-      :volume_image => vol_image,
-      :ent_properties => type == :xml ? JSON::dump((xml['property'] || {}).inject({}){
|r, p| r[p['key']]=p['content']; r })  : (json['properties'] || {}).to_json
-    )
-    from_db(new_template, context)
-  end
-
   def self.delete!(id, context)
     current_db.volume_templates.first(:id => id).destroy
   end
 
-private
-
   def self.from_db(model, context)
     self.new(
       :id => context.volume_template_url(model.id),
@@ -76,7 +60,10 @@ private
       :volume_image => {:href => model.volume_image},
       :property => (model.ent_properties ? JSON::parse(model.ent_properties) :  nil),
       :operations => [
-        { :href => context.destroy_volume_template_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
}
+        {
+          :href => context.destroy_volume_template_url(model.id),
+          :rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
+        }
       ]
     )
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6275a4d8/server/lib/cimi/models/volume_template_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_template_create.rb b/server/lib/cimi/models/volume_template_create.rb
new file mode 100644
index 0000000..b6dbec2
--- /dev/null
+++ b/server/lib/cimi/models/volume_template_create.rb
@@ -0,0 +1,33 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+class CIMI::Model::VolumeTemplateCreate < CIMI::Model::Base
+
+  ref :volume_config, :required => true
+  ref :volume_image, :required => true
+
+  def create(context)
+    validate!
+    new_template = self.class.current_db.add_volume_template(
+      :name => name,
+      :description => description,
+      :volume_config => volume_config.href,
+      :volume_image => volume_image.href,
+      :ent_properties => property.to_json
+    )
+    CIMI::Model::VolumeTemplate.from_db(new_template, context)
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6275a4d8/server/support/cimi/volume_template.xml
----------------------------------------------------------------------
diff --git a/server/support/cimi/volume_template.xml b/server/support/cimi/volume_template.xml
new file mode 100644
index 0000000..0e1d4fa
--- /dev/null
+++ b/server/support/cimi/volume_template.xml
@@ -0,0 +1,7 @@
+<VolumeTemplateCreate>
+  <name>myXMLVolumeTemplate</name>
+  <description>Description of VolumeTemplate</description>
+  <property key="test">value</property>
+  <volumeConfig href="http://localhost:3001/cimi/volume_configurations/1"/>
+  <volumeImage href="http://localhost:3001/cimi/volume_images/snap1"/>
+</VolumeTemplateCreate>


Mime
View raw message