You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by ma...@apache.org on 2012/11/21 11:19:12 UTC

git commit: CIMI - tidy up nits in Volumes/VolumeConfigs - especially creation

Updated Branches:
  refs/heads/master ac8a13b16 -> 3b8f296ec


CIMI - tidy up nits in Volumes/VolumeConfigs - especially creation

related to DTACLOUD-375

https://issues.apache.org/jira/browse/DTACLOUD-375


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

Branch: refs/heads/master
Commit: 3b8f296ec707c50d35acb769c9e2faac8b22fc5d
Parents: ac8a13b
Author: marios <ma...@redhat.com>
Authored: Wed Nov 21 11:33:28 2012 +0200
Committer: marios <ma...@redhat.com>
Committed: Wed Nov 21 12:18:24 2012 +0200

----------------------------------------------------------------------
 server/lib/cimi/collections/volumes.rb         |    2 +-
 server/lib/cimi/helpers/cimi_helper.rb         |    8 ++++++++
 server/lib/cimi/models/volume.rb               |    4 ++--
 server/lib/cimi/models/volume_configuration.rb |    5 +++--
 4 files changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3b8f296e/server/lib/cimi/collections/volumes.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/volumes.rb b/server/lib/cimi/collections/volumes.rb
index 319390e..59fd69d 100644
--- a/server/lib/cimi/collections/volumes.rb
+++ b/server/lib/cimi/collections/volumes.rb
@@ -46,7 +46,7 @@ module CIMI::Collections
         end
       end
 
-      operation :create do
+      operation :create, :with_capability => :create_storage_volume do
         description "Create a new Volume."
         control do
           content_type = (request.content_type.end_with?("json") ? :json  : :xml)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3b8f296e/server/lib/cimi/helpers/cimi_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/helpers/cimi_helper.rb b/server/lib/cimi/helpers/cimi_helper.rb
index c4d081e..99af08a 100644
--- a/server/lib/cimi/helpers/cimi_helper.rb
+++ b/server/lib/cimi/helpers/cimi_helper.rb
@@ -42,6 +42,14 @@ module CIMI
       end
     end
 
+    def from_kibibyte(value, unit="GB")
+      case unit
+        when "GB" then ((value.to_i)/1024/1024).to_i
+        when "MB" then ((value.to_i)/1024).to_i
+        else nil
+      end
+    end
+
   end
 end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3b8f296e/server/lib/cimi/models/volume.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume.rb b/server/lib/cimi/models/volume.rb
index eca5cc1..c89835c 100644
--- a/server/lib/cimi/models/volume.rb
+++ b/server/lib/cimi/models/volume.rb
@@ -84,7 +84,7 @@ class CIMI::Model::Volume < CIMI::Model::Base
 
   def self.create_volume(params, context)
     volume_config = CIMI::Model::VolumeConfiguration.find(params[:volume_config_id], context)
-    opts = {:capacity=>volume_config.capacity[:quantity], :snapshot_id=>params[:volume_image_id] }
+    opts = {:capacity=>context.from_kibibyte(volume_config.capacity, "GB"), :snapshot_id=>params[:volume_image_id] }
     storage_volume = context.driver.create_storage_volume(context.credentials, opts)
     from_storage_volume(storage_volume, context)
   end
@@ -94,7 +94,7 @@ class CIMI::Model::Volume < CIMI::Model::Base
                 :description => volume.id,
                 :created => Time.parse(volume.created).xmlschema,
                 :id => context.volume_url(volume.id),
-                :capacity => context.to_kibibyte(volume.capacity, 'MB'),
+                :capacity => context.to_kibibyte(volume.capacity, 'GB'),
                 :bootable => "false", #fixme ... will vary... ec2 doesn't expose this
                 :snapshots => [], #fixme...
                 :type => 'http://schemas.dmtf.org/cimi/1/mapped',

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3b8f296e/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 7b7860d..383aac3 100644
--- a/server/lib/cimi/models/volume_configuration.rb
+++ b/server/lib/cimi/models/volume_configuration.rb
@@ -45,12 +45,13 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
   private
 
   def self.create(size, context)
+    size_kib = context.to_kibibyte(size, "GB")
     self.new( {
                 :id => context.volume_configuration_url(size),
                 :name => "volume-#{size}",
-                :description => "Volume configuration with #{size} kilobytes",
+                :description => "Volume configuration with #{size_kib} kibibytes",
                 :created => Time.now.xmlschema,
-                :capacity => context.to_kibibyte(size, "MB"),
+                :capacity => size_kib,
                 :supports_snapshots => "true"
                 # FIXME :guest_interface => "NFS"
             } )