deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [2/5] git commit: CIMI: Report sub-collection :href attribute properly (DTACLOUD-433)
Date Tue, 29 Jan 2013 13:40:43 GMT
CIMI: Report sub-collection :href attribute properly (DTACLOUD-433)


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

Branch: refs/heads/master
Commit: 32bdcc23853a50657861cdcf90bb997d5cd664e0
Parents: 0fecb95
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Wed Jan 23 16:49:59 2013 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Tue Jan 29 14:38:53 2013 +0100

----------------------------------------------------------------------
 server/lib/cimi/models/base.rb       |   17 ++++++++++++++---
 server/lib/cimi/models/collection.rb |    6 +++++-
 server/lib/cimi/models/disk.rb       |   23 +++++++++++++++--------
 3 files changed, 34 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/32bdcc23/server/lib/cimi/models/base.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/base.rb b/server/lib/cimi/models/base.rb
index 1393ae4..7995e07 100644
--- a/server/lib/cimi/models/base.rb
+++ b/server/lib/cimi/models/base.rb
@@ -173,8 +173,8 @@ class CIMI::Model::Resource
       if !@filter_attrs.empty? and !@filter_attrs.include?(n)
         @attribute_values[n] = nil
       else
-        self[n].href = "#{self.id}/#{n}" if !self[n].href
-        self[n].id = "#{self.id}/#{n}" if !self[n].entries.empty?
+        self[n].href = "#{self.base_id}/#{n}" if !self[n].href
+        self[n].id = "#{self.base_id}/#{n}" if !self[n].entries.empty?
       end
     end
   end
@@ -185,12 +185,20 @@ class CIMI::Model::Resource
   def initialize(values = {})
     names = self.class.schema.attribute_names
     @filter_attrs = values[:filter_attr_list] || []
+    # Make sure we always have the :id of the entity even
+    # the $select parameter is used and :id is filtered out
+    #
+    @_base_id = values[:base_id] || values[:id]
     @attribute_values = names.inject(OrderedHash.new) do |hash, name|
       hash[name] = self.class.schema.convert(name, values[name])
       hash
     end
   end
 
+  def base_id
+    self.id || @_base_id
+  end
+
   # Construct a new object from the XML representation +xml+
   def self.from_xml(text)
     xml = XmlSimple.xml_in(text, :force_content => true)
@@ -290,7 +298,10 @@ class CIMI::Model::Base < CIMI::Model::Resource
       result[attr.to_sym] = self.send(attr) if self.respond_to?(attr)
       result
     end
-    self.class.new(attrs.merge(:filter_attr_list => attr_list))
+    self.class.new(attrs.merge(
+      :filter_attr_list => attr_list,
+      :base_id => self.send(:id)
+    ))
   end
 
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/32bdcc23/server/lib/cimi/models/collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/collection.rb b/server/lib/cimi/models/collection.rb
index aafa6a5..a4faaa6 100644
--- a/server/lib/cimi/models/collection.rb
+++ b/server/lib/cimi/models/collection.rb
@@ -13,6 +13,7 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+
 module CIMI::Model
   class Collection < Resource
 
@@ -23,8 +24,11 @@ module CIMI::Model
     # Make sure the base schema gets cloned
     self.schema
 
+    # You can initialize collection by passing the Hash representation of the
+    # collection or passing another Collection object.
+    #
     def initialize(values = {})
-      if values.kind_of?(Hash) 
+      if values.kind_of?(Hash)
         if values[:entries]
           values[self.class.entry_name] = values.delete(:entries)
         end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/32bdcc23/server/lib/cimi/models/disk.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/disk.rb b/server/lib/cimi/models/disk.rb
index 218143f..c725721 100644
--- a/server/lib/cimi/models/disk.rb
+++ b/server/lib/cimi/models/disk.rb
@@ -24,11 +24,20 @@ class CIMI::Model::Disk < CIMI::Model::Base
 
   def self.find(instance, machine_config, context, id=:all)
     if id == :all
-      return machine_config.disks if machine_config
+      name = instance.id+"_disk_" #assuming one disk for now...
 
-      capacity = false
-
-      if instance
+      if machine_config
+        mach_config_disks = machine_config.disks
+        return mach_config_disks.map do |d|
+          self.new(
+            :id => context.machine_url(instance.id) + "/disks/#{name}#{d[:capacity]}",
+            :name => "#{name}#{d[:capacity]}",
+            :description => "Disk for Machine #{instance.id}",
+            :created => instance.launch_time.nil? ? Time.now.xmlschema : Time.parse(instance.launch_time).xmlschema,
+            :capacity => d[:capacity]
+          )
+        end
+      else
         if instance.instance_profile.override? :storage
           capacity = context.to_kibibyte(instance.instance_profile.storage, 'MB')
         else
@@ -40,11 +49,9 @@ class CIMI::Model::Disk < CIMI::Model::Base
 
         return [] unless capacity
 
-        name = instance.id+"_disk_#{capacity}" #assuming one disk for now...
-
         [self.new(
-          :id => context.machine_url(instance.id)+"/disks/#{name}",
-          :name => name,
+          :id => context.machine_url(instance.id)+"/disks/#{name}#{capacity}",
+          :name => name + capacity.to_s,
           :description => "Disk for Machine #{instance.id}",
           :created => instance.launch_time.nil? ? Time.now.xmlschema : Time.parse(instance.launch_time).xmlschema,
           :capacity => capacity


Mime
View raw message