deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject [4/9] git commit: CIMI: Added VolumeCreate model
Date Mon, 25 Feb 2013 19:23:01 GMT
CIMI: Added VolumeCreate model

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
TrackedAt: http://tracker.deltacloud.org/patch/15544d24bd245a6d5ecee21e0efb3aaa2f3856f2


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

Branch: refs/heads/master
Commit: e8942f4576501bcad5870f6a077fd5e698413eba
Parents: 103bbf5
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Fri Feb 22 13:35:05 2013 +0100
Committer: David Lutterkort <lutter@redhat.com>
Committed: Mon Feb 25 11:22:37 2013 -0800

----------------------------------------------------------------------
 server/lib/cimi/collections/volumes.rb         |    3 +-
 server/lib/cimi/models.rb                      |    3 +-
 server/lib/cimi/models/volume.rb               |   40 -------------
 server/lib/cimi/models/volume_configuration.rb |    3 +-
 server/lib/cimi/models/volume_create.rb        |   58 +++++++++++++++++++
 server/lib/cimi/models/volume_template.rb      |    4 +-
 server/support/cimi/volume.xml                 |    6 +-
 server/support/cimi/volume_by_value.xml        |   10 +++
 8 files changed, 77 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e8942f45/server/lib/cimi/collections/volumes.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/volumes.rb b/server/lib/cimi/collections/volumes.rb
index 74f8c69..3f46591 100644
--- a/server/lib/cimi/collections/volumes.rb
+++ b/server/lib/cimi/collections/volumes.rb
@@ -49,7 +49,8 @@ module CIMI::Collections
       operation :create, :with_capability => :create_storage_volume do
         description "Create a new Volume."
         control do
-          new_volume = Volume.create(request.body.read, self, current_content_type)
+          vol = CIMI::Model::VolumeCreate.parse(request.body, request.content_type)
+          new_volume = vol.create(self)
           headers_for_create new_volume
           respond_to do |format|
             format.json { new_volume.to_json }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e8942f45/server/lib/cimi/models.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index a86d6a9..b41cb8f 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -64,9 +64,10 @@ require_relative './models/credential'
 require_relative './models/credential_template'
 require_relative './models/credential_create'
 require_relative './models/volume'
-require_relative './models/volume_template'
 require_relative './models/volume_configuration'
 require_relative './models/volume_image'
+require_relative './models/volume_template'
+require_relative './models/volume_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/e8942f45/server/lib/cimi/models/volume.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume.rb b/server/lib/cimi/models/volume.rb
index 19827a9..888589a 100644
--- a/server/lib/cimi/models/volume.rb
+++ b/server/lib/cimi/models/volume.rb
@@ -51,24 +51,6 @@ class CIMI::Model::Volume < CIMI::Model::Base
 
   def self.all(context); find(:all, context); end
 
-  def self.create(request_body, context, type)
-    #json = JSON.parse(json_in)
-    input = (type == :xml)? XmlSimple.xml_in(request_body, {"ForceArray"=>false,"NormaliseSpace"=>2})
: JSON.parse(request_body)
-    if input["volumeTemplate"]["href"]  #template by reference
-      #FIXME - don't have volumeTemplates yet - datamapper   volume_config =
-    else #template by value
-      volume_image_id = (input["volumeTemplate"].has_key?("volumeImage") ?
-                input["volumeTemplate"]["volumeImage"]["href"].split("/").last  : nil)
-      if input["volumeTemplate"]["volumeConfig"]["href"] #with config by reference
-        volume_config_id = input["volumeTemplate"]["volumeConfig"]["href"].split("/").last
-        create_volume({:volume_config_id=>volume_config_id, :volume_image_id=>volume_image_id},
input, context)
-      else #with config by value
-        capacity = input["volumeTemplate"]["volumeConfig"]["capacity"]
-        create_volume({:capacity=>capacity, :volume_image_id=>volume_image_id}, input,
context)
-      end
-    end
-  end
-
   def self.delete!(id, context)
     context.driver.destroy_storage_volume(context.credentials, {:id=>id} )
     new(:id => id).destroy
@@ -86,28 +68,6 @@ class CIMI::Model::Volume < CIMI::Model::Base
                            :initial_location=>v["initialLocation"] }}
   end
 
-  private
-
-  def self.create_volume(params, data, context)
-    if params[:volume_config_id]
-      volume_config = CIMI::Model::VolumeConfiguration.find(params[:volume_config_id], context)
-      opts = {:capacity=>context.from_kibibyte(volume_config.capacity, "GB"),
-              :snapshot_id=>params[:volume_image_id],
-              :name=>data["name"]}
-    elsif params[:capacity]
-      opts = {:capacity=>context.from_kibibyte(params[:capacity], "GB"),
-              :snapshot_id=>params[:volume_image_id],
-              :name=>data["name"]}
-    end
-    storage_volume = context.driver.create_storage_volume(context.credentials, opts)
-    result = from_storage_volume(storage_volume, context)
-    result.name = data['name'] if data['name']
-    result.description = data['description']
-    result.extract_properties!(data)
-    result.save
-    result
-  end
-
   def self.from_storage_volume(volume, context)
     self.new( { :name => volume.id,
                 :created => volume.created.nil? ? nil : Time.parse(volume.created).xmlschema,

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e8942f45/server/lib/cimi/models/volume_configuration.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_configuration.rb b/server/lib/cimi/models/volume_configuration.rb
index 10ce146..7f67051 100644
--- a/server/lib/cimi/models/volume_configuration.rb
+++ b/server/lib/cimi/models/volume_configuration.rb
@@ -18,8 +18,7 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
   acts_as_root_entity :as => "volumeConfigs"
 
   text :format
-
-  text :capacity
+  text :capacity, :required => true
 
   array :operations do
     scalar :rel, :href

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e8942f45/server/lib/cimi/models/volume_create.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_create.rb b/server/lib/cimi/models/volume_create.rb
new file mode 100644
index 0000000..607c407
--- /dev/null
+++ b/server/lib/cimi/models/volume_create.rb
@@ -0,0 +1,58 @@
+# 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::VolumeCreate < CIMI::Model::Base
+
+  ref :volume_template, :required => true
+
+  def create(context)
+    validate!
+
+    if volume_template.href?
+      template = volume_template.find(context)
+    else
+      template = CIMI::Model::VolumeTemplate.from_xml(volume_template.to_xml)
+    end
+
+    volume_image = template.volume_image.href? ?
+      template.volume_image.find(context) : template.volume_image
+
+    volume_config = template.volume_config.href? ?
+      template.volume_config.find(context) : template.volume_config
+
+    params = {
+      :name => name,
+      :capacity => volume_config.capacity,
+      :snapshot_id => ref_id(volume_image.id),
+    }
+
+    unless context.driver.respond_to? :create_storage_volume
+       raise Deltacloud::Exceptions.exception_from_status(
+         501,
+         "Creating Volume is not supported by the current driver"
+       )
+    end
+
+    volume = context.driver.create_storage_volume(context.credentials, params)
+
+    result = CIMI::Model::Volume.from_storage_volume(volume, context)
+    result.name = name if result.name.nil?
+    result.description = description if description
+    result.property = property if property
+    result.save
+    result
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e8942f45/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 c00ffc8..500fa75 100644
--- a/server/lib/cimi/models/volume_template.rb
+++ b/server/lib/cimi/models/volume_template.rb
@@ -17,8 +17,8 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base
 
   acts_as_root_entity
 
-  href :volume_config
-  href :volume_image
+  ref :volume_config, :required => true
+  ref :volume_image, :required => true
 
   array :meter_templates do
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e8942f45/server/support/cimi/volume.xml
----------------------------------------------------------------------
diff --git a/server/support/cimi/volume.xml b/server/support/cimi/volume.xml
index 030dcce..62d9e08 100644
--- a/server/support/cimi/volume.xml
+++ b/server/support/cimi/volume.xml
@@ -1,10 +1,8 @@
 <VolumeCreate>
   <name>myVolume1</name>
   <description>Description of my new volume</description>
-  <type>http://schemas.dmtf.org/cimi/1/mapped</type>
-  <capacity>1048576</capacity>
-  <bootable>false</bootable>
   <volumeTemplate>
-    <volumeConfig href="http://localhost:3001/cimi/volume_configurations/2"/>
+    <volumeConfig href="http://localhost:3001/cimi/volume_configurations/1" />
+    <volumeImage href="http://localhost:3001/cimi/volume_images/snap1" />
   </volumeTemplate>
 </VolumeCreate>

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e8942f45/server/support/cimi/volume_by_value.xml
----------------------------------------------------------------------
diff --git a/server/support/cimi/volume_by_value.xml b/server/support/cimi/volume_by_value.xml
new file mode 100644
index 0000000..389cc2d
--- /dev/null
+++ b/server/support/cimi/volume_by_value.xml
@@ -0,0 +1,10 @@
+<VolumeCreate>
+  <name>myVolume2</name>
+  <description>Description of my new volume</description>
+  <volumeTemplate>
+    <volumeConfig>
+      <capacity>9999</capacity>
+    </volumeConfig>
+    <volumeImage href="http://localhost:3001/cimi/volume_images/snap1" />
+  </volumeTemplate>
+</VolumeCreate>


Mime
View raw message