deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [1/3] git commit: CIMI: sorts out collections - include :count and each member of the collection inline as an element
Date Tue, 04 Sep 2012 12:52:40 GMT
Updated Branches:
  refs/heads/master 5af799371 -> 78e981597


CIMI: sorts out collections - include :count and each member of
the collection inline as an element


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

Branch: refs/heads/master
Commit: 30c895d8cb8013ac102832722de1ada07f0f069b
Parents: 5af7993
Author: marios <marios@redhat.com>
Authored: Fri Aug 31 22:24:54 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Tue Sep 4 12:55:49 2012 +0300

----------------------------------------------------------------------
 server/lib/cimi/models/machine_collection.rb       |   11 +++++---
 .../models/machine_configuration_collection.rb     |   10 +++++---
 server/lib/cimi/models/machine_image_collection.rb |   10 +++++---
 .../lib/cimi/models/machine_template_collection.rb |   10 +++++---
 server/lib/cimi/models/network_collection.rb       |   11 +++++----
 server/lib/cimi/models/schema.rb                   |   18 +++++++++++++++
 server/lib/cimi/models/volume_collection.rb        |   10 +++++---
 .../cimi/models/volume_configuration_collection.rb |   10 +++++---
 server/lib/cimi/models/volume_image_collection.rb  |   10 +++++---
 .../lib/cimi/models/volume_template_collection.rb  |   10 +++++---
 10 files changed, 73 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/machine_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_collection.rb b/server/lib/cimi/models/machine_collection.rb
index 9154aa9..27c721d 100644
--- a/server/lib/cimi/models/machine_collection.rb
+++ b/server/lib/cimi/models/machine_collection.rb
@@ -17,17 +17,20 @@ class CIMI::Model::MachineCollection < CIMI::Model::Base
 
   act_as_root_entity :machine
 
-  array :machines do
-    scalar :href
-  end
+  text :count
+
+  #add machines array:
+  self.schema.add_collection_member_array(CIMI::Model::Machine)
 
   def self.default(context)
+    machines = CIMI::Model::Machine.all(context)
     self.new(
       :id => context.machines_url,
       :name => 'default',
       :created => Time.now,
       :description => "#{context.driver.name.capitalize} MachineCollection",
-      :machines => CIMI::Model::Machine.all_uri(context)
+      :count => machines.size,
+      :machines => machines
     )
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/machine_configuration_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_configuration_collection.rb b/server/lib/cimi/models/machine_configuration_collection.rb
index 6d7ebad..e75bbb4 100644
--- a/server/lib/cimi/models/machine_configuration_collection.rb
+++ b/server/lib/cimi/models/machine_configuration_collection.rb
@@ -17,17 +17,19 @@ class CIMI::Model::MachineConfigurationCollection < CIMI::Model::Base
 
   act_as_root_entity :machine_configuration
 
-  array :machine_configurations do
-    scalar :href
-  end
+  text :count
+
+  self.schema.add_collection_member_array(CIMI::Model::MachineConfiguration)
 
   def self.default(context)
+    machine_configurations = CIMI::Model::MachineConfiguration.all(context)
     self.new(
       :id => context.machine_configurations_url,
       :name => 'default',
       :created => Time.now,
       :description => "#{context.driver.name.capitalize} MachineConfigurationCollection",
-      :machine_configurations => CIMI::Model::MachineConfiguration.all_uri(context)
+      :count => machine_configurations.count,
+      :machine_configurations => machine_configurations
     )
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/machine_image_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_image_collection.rb b/server/lib/cimi/models/machine_image_collection.rb
index 70bdc7b..703e515 100644
--- a/server/lib/cimi/models/machine_image_collection.rb
+++ b/server/lib/cimi/models/machine_image_collection.rb
@@ -17,17 +17,19 @@ class CIMI::Model::MachineImageCollection < CIMI::Model::Base
 
   act_as_root_entity :machine_image
 
-  array :machine_images do
-    scalar :href
-  end
+  text :count
+
+  self.schema.add_collection_member_array(CIMI::Model::MachineImage)
 
   def self.default(context)
+    machine_images = CIMI::Model::MachineImage.all(context)
     self.new(
       :id => context.machine_images_url,
       :name => 'default',
       :created => Time.now,
       :description => "#{context.driver.name.capitalize} MachineImageCollection",
-      :machine_images => CIMI::Model::MachineImage.all_uri(context)
+      :count => machine_images.count,
+      :machine_images => machine_images
     )
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/machine_template_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_template_collection.rb b/server/lib/cimi/models/machine_template_collection.rb
index d2a3f23..bef9aaf 100644
--- a/server/lib/cimi/models/machine_template_collection.rb
+++ b/server/lib/cimi/models/machine_template_collection.rb
@@ -17,17 +17,19 @@ class CIMI::Model::MachineTemplateCollection < CIMI::Model::Base
 
   act_as_root_entity :machine_template
 
-  array :machine_templates do
-    scalar :href
-  end
+  text :count
+
+  self.schema.add_collection_member_array(CIMI::Model::MachineTemplate)
 
   def self.default(context)
+    machine_templates = CIMI::Model::MachineTemplate.all(context)
     self.new(
       :id => context.machine_template_url,
       :name => 'default',
       :created => Time.now,
       :description => "#{context.driver.name.capitalize} MachineTemplateCollection",
-      :machine_templates => CIMI::Model::MachineTemplate.all_uri(context)
+      :count => machine_templates.size,
+      :machine_templates => machine_templates
     )
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/network_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/network_collection.rb b/server/lib/cimi/models/network_collection.rb
index d76a3dd..c17c3f7 100644
--- a/server/lib/cimi/models/network_collection.rb
+++ b/server/lib/cimi/models/network_collection.rb
@@ -12,22 +12,23 @@
 # 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::NetworkCollection < CIMI::Model::Base
 
   act_as_root_entity :network
+  text :count
 
-  array :networks do
-    scalar :href
-  end
+#add networks Array:
+  self.schema.add_collection_member_array(CIMI::Model::Network)
 
   def self.default(context)
+    networks = CIMI::Model::Network.all(context)
     self.new(
       :id => context.networks_url,
       :name => 'default',
       :created => Time.now,
       :description => "#{context.driver.name.capitalize} NetworkCollection",
-      :networks => CIMI::Model::Network.all(context).map { |c| { :href => c.id } }
+      :count => networks.size,
+      :networks => networks
     )
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/schema.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
index 57a190d..088e111 100644
--- a/server/lib/cimi/models/schema.rb
+++ b/server/lib/cimi/models/schema.rb
@@ -81,6 +81,9 @@ class CIMI::Model::Schema
   end
 
   class Struct < Attribute
+
+    attr_accessor :schema
+
     def initialize(name, opts, &block)
       content = opts[:content]
       super(name, opts)
@@ -146,6 +149,9 @@ class CIMI::Model::Schema
   end
 
   class Array < Attribute
+
+    attr_accessor :struct
+
     # For an array :funThings, we collect all <funThing/> elements (XmlSimple
     # actually does the collecting)
     def initialize(name, opts = {}, &block)
@@ -208,6 +214,9 @@ class CIMI::Model::Schema
   #
   # The actual Schema class
   #
+
+  attr_accessor :attributes
+
   def initialize
     @attributes = []
   end
@@ -230,6 +239,15 @@ class CIMI::Model::Schema
     xml
   end
 
+  #For MachineCollection, copy over the schema of Machine to hold
+  #each member of the collection - avoid duplicating the schemas
+  def add_collection_member_array(model)
+    member_symbol = model.name.split("::").last.underscore.pluralize.to_sym
+    members = CIMI::Model::Schema::Array.new(member_symbol)
+    members.struct.schema.attributes = model.schema.attributes
+    self.attributes << members
+  end
+
   def to_json(model, json = {})
     @attributes.freeze
     @attributes.each { |attr| attr.to_json(model, json) }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/volume_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_collection.rb b/server/lib/cimi/models/volume_collection.rb
index 1f4152e..6bec78f 100644
--- a/server/lib/cimi/models/volume_collection.rb
+++ b/server/lib/cimi/models/volume_collection.rb
@@ -17,17 +17,19 @@ class CIMI::Model::VolumeCollection < CIMI::Model::Base
 
   act_as_root_entity :volume
 
-  array :volumes do
-    scalar :href
-  end
+  text :count
+
+  self.schema.add_collection_member_array(CIMI::Model::Volume)
 
   def self.default(context)
+    volumes = CIMI::Model::Volume.all(context)
     self.new(
       :id => context.volumes_url,
       :name => 'default',
       :created => Time.now,
       :description => "#{context.driver.name.capitalize} VolumeCollection",
-      :volumes => CIMI::Model::Volume.all_uri(context)
+      :count => volumes.count,
+      :volumes => volumes
     )
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/volume_configuration_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_configuration_collection.rb b/server/lib/cimi/models/volume_configuration_collection.rb
index 2120ae6..8800e35 100644
--- a/server/lib/cimi/models/volume_configuration_collection.rb
+++ b/server/lib/cimi/models/volume_configuration_collection.rb
@@ -17,17 +17,19 @@ class CIMI::Model::VolumeConfigurationCollection < CIMI::Model::Base
 
   act_as_root_entity :volume_configuration
 
-  array :volume_configurations do
-    scalar :href
-  end
+  text :count
+
+  self.schema.add_collection_member_array(CIMI::Model::VolumeConfiguration)
 
   def self.default(context)
+    volume_configurations = CIMI::Model::VolumeConfiguration.all(context)
     self.new(
       :id => context.volume_configurations_url,
       :name => 'default',
       :created => Time.now,
       :description => "#{context.driver.name.capitalize} VolumeConfigurationCollection",
-      :volume_configurations => CIMI::Model::VolumeConfiguration.all_uri(context)
+      :count => volume_configurations.size,
+      :volume_configurations => volume_configurations
     )
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/volume_image_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_image_collection.rb b/server/lib/cimi/models/volume_image_collection.rb
index f3da877..78881d5 100644
--- a/server/lib/cimi/models/volume_image_collection.rb
+++ b/server/lib/cimi/models/volume_image_collection.rb
@@ -17,17 +17,19 @@ class CIMI::Model::VolumeImageCollection < CIMI::Model::Base
 
   act_as_root_entity :volume_image
 
-  array :volume_images do
-    scalar :href
-  end
+  text :count 
+
+  self.schema.add_collection_member_array(CIMI::Model::VolumeImage)
 
   def self.default(context)
+      volume_images = CIMI::Model::VolumeImage.all(context)
     self.new(
       :id => context.volume_images_url,
       :name => 'default',
       :created => Time.now,
       :description => "#{context.driver.name.capitalize} VolumeImageCollection",
-      :volume_images => CIMI::Model::VolumeImage.all_uri(context)
+      :count => volume_images.count,
+      :volume_images => volume_images
     )
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/30c895d8/server/lib/cimi/models/volume_template_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_template_collection.rb b/server/lib/cimi/models/volume_template_collection.rb
index f53547c..3f2ae02 100644
--- a/server/lib/cimi/models/volume_template_collection.rb
+++ b/server/lib/cimi/models/volume_template_collection.rb
@@ -17,17 +17,19 @@ class CIMI::Model::VolumeTemplateCollection < CIMI::Model::Base
 
   act_as_root_entity :volume_template
 
-  array :volume_templates do
-    scalar :href
-  end
+  text :count
+
+  self.schema.add_collection_member_array(CIMI::Model::VolumeTemplate)
 
   def self.default(context)
+    volume_templates = CIMI::Model::VolumeTemplate.all(context)
     self.new(
       :id => context.volume_template_url,
       :name => 'default',
       :created => Time.now,
       :description => "#{context.driver.name.capitalize} VolumeTemplateCollection",
-      :volume_templates => CIMI::Model::VolumeTemplate.all_uri(context)
+      :count => volume_templates.size,
+      :volume_templates => volume_templates
     )
   end
 


Mime
View raw message