deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject git commit: CIMI: Fixed problem when generating subcollection
Date Wed, 14 Nov 2012 10:42:43 GMT
Updated Branches:
  refs/heads/master ac7f2672f -> b5680d8cd


CIMI: Fixed problem when generating subcollection

* For disks, subcollection class was not generated yet
* Fixed capacity in Volumes
* Use generated VolumeCollection as subcollection

Signed-off-by: Michal fojtik <mfojtik@redhat.com>


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

Branch: refs/heads/master
Commit: b5680d8cdb45a38168da3bbdcb0dd71dc55b984a
Parents: ac7f267
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Wed Nov 14 11:07:01 2012 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Wed Nov 14 11:09:48 2012 +0100

----------------------------------------------------------------------
 server/lib/cimi/collections/machines.rb |    2 +-
 server/lib/cimi/models/disk.rb          |    7 ++++++-
 server/lib/cimi/models/volume.rb        |   16 +++++++++++++++-
 3 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b5680d8c/server/lib/cimi/collections/machines.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machines.rb b/server/lib/cimi/collections/machines.rb
index 1ae71e6..6a896f3 100644
--- a/server/lib/cimi/collections/machines.rb
+++ b/server/lib/cimi/collections/machines.rb
@@ -135,7 +135,7 @@ module CIMI::Collections
         description "Retrieve the Machine's MachineVolumeCollection"
         param :id,          :string,    :required
         control do
-          volumes = MachineVolumeCollection.default(params[:id], self)
+          volumes = CIMI::Model::Volume.collection_for_instance(params[:id], self)
           respond_to do |format|
             format.json {volumes.to_json}
             format.xml  {volumes.to_xml}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b5680d8c/server/lib/cimi/models/disk.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/disk.rb b/server/lib/cimi/models/disk.rb
index 40bd6e1..218143f 100644
--- a/server/lib/cimi/models/disk.rb
+++ b/server/lib/cimi/models/disk.rb
@@ -57,7 +57,12 @@ class CIMI::Model::Disk < CIMI::Model::Base
   def self.collection_for_instance(instance_id, context)
     instance = context.driver.instance(context.credentials, :id => instance_id)
     disks = find(instance, nil, context)
-    CIMI::Model::DiskCollection.new(
+    unless CIMI::Model.const_defined?('DiskCollection')
+      collection_class = CIMI::Model::Collection.generate(self)
+    else
+      collection_class = CIMI::Model::DiskCollection
+    end
+    collection_class.new(
       :id => context.url("/machines/#{instance_id}/disks"),
       :name => 'default',
       :count => disks.size,

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b5680d8c/server/lib/cimi/models/volume.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume.rb b/server/lib/cimi/models/volume.rb
index 5ce0fbc..eca5cc1 100644
--- a/server/lib/cimi/models/volume.rb
+++ b/server/lib/cimi/models/volume.rb
@@ -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 => { :quantity=>volume.capacity, :units=>"gibibyte"  },
#FIXME... units will vary
+                :capacity => context.to_kibibyte(volume.capacity, 'MB'),
                 :bootable => "false", #fixme ... will vary... ec2 doesn't expose this
                 :snapshots => [], #fixme...
                 :type => 'http://schemas.dmtf.org/cimi/1/mapped',
@@ -103,4 +103,18 @@ class CIMI::Model::Volume < CIMI::Model::Base
             } )
   end
 
+  def self.collection_for_instance(instance_id, context)
+    instance = context.driver.instance(context.credentials, :id => instance_id)
+    volumes = instance.storage_volumes.map do |mappings|
+      mappings.keys.map { |volume_id| from_storage_volume(context.driver.storage_volume(context.credentials,
:id => volume_id), context) }
+    end.flatten
+    CIMI::Model::VolumeCollection.new(
+      :id => context.url("/machines/#{instance_id}/volumes"),
+      :name => 'default',
+      :count => volumes.size,
+      :description => "Volume collection for Machine #{instance_id}",
+      :entries => volumes
+    )
+  end
+
 end


Mime
View raw message