deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [1/2] git commit: CIMI: Added syntax sugar for collection members
Date Mon, 10 Sep 2012 09:21:47 GMT
Updated Branches:
  refs/heads/master cfe30412e -> 731eae93a


CIMI: Added syntax sugar for collection members


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

Branch: refs/heads/master
Commit: 731eae93a55597135bb432f809f07afe854df56f
Parents: 66c55d1
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Thu Sep 6 14:39:13 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Mon Sep 10 11:22:22 2012 +0200

----------------------------------------------------------------------
 server/lib/cimi/models/base.rb                     |   14 ++++++++++++++
 server/lib/cimi/models/disk_collection.rb          |    3 +--
 server/lib/cimi/models/machine_collection.rb       |    2 +-
 .../models/machine_configuration_collection.rb     |    4 +---
 server/lib/cimi/models/machine_image_collection.rb |    2 +-
 .../lib/cimi/models/machine_template_collection.rb |    4 +---
 .../lib/cimi/models/machine_volume_collection.rb   |    2 +-
 server/lib/cimi/models/network_collection.rb       |    4 ++--
 server/lib/cimi/models/schema.rb                   |    4 +---
 server/lib/cimi/models/volume_collection.rb        |    2 +-
 .../cimi/models/volume_configuration_collection.rb |    2 +-
 server/lib/cimi/models/volume_image_collection.rb  |    4 ++--
 .../lib/cimi/models/volume_template_collection.rb  |    2 +-
 13 files changed, 28 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/server/lib/cimi/models/base.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/base.rb b/server/lib/cimi/models/base.rb
index b375ce0..b627b82 100644
--- a/server/lib/cimi/models/base.rb
+++ b/server/lib/cimi/models/base.rb
@@ -94,6 +94,20 @@ class CIMI::Model::Base
   # attribute, we also define a getter and a setter to access/change the
   # value for that attribute
   class << self
+
+    def <<(model)
+      clone_base_schema unless base_schema_cloned?
+      member_name = model.name.split("::").last
+      if ::Struct.const_defined?("CIMI_#{member_name}")
+        puts "Removing struct"
+        ::Struct.send(:remove_const, "CIMI_#{member_name}")
+      end
+      member_symbol = member_name.underscore.pluralize.to_sym
+      members = CIMI::Model::Schema::Array.new(member_symbol)
+      members.struct.schema.attributes = model.schema.attributes
+      base_schema.attributes << members
+    end
+
     def base_schema
       @schema ||= CIMI::Model::Schema.new
     end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/server/lib/cimi/models/disk_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/disk_collection.rb b/server/lib/cimi/models/disk_collection.rb
index b86a3c9..7dbff39 100644
--- a/server/lib/cimi/models/disk_collection.rb
+++ b/server/lib/cimi/models/disk_collection.rb
@@ -16,7 +16,7 @@ class CIMI::Model::DiskCollection < CIMI::Model::Base
   text :count
 
   #add disks array:
-  self.schema.add_collection_member_array(CIMI::Model::Disk)
+  self << CIMI::Model::Disk
 
   array :operations do
     scalar :rel, :href
@@ -26,7 +26,6 @@ class CIMI::Model::DiskCollection < CIMI::Model::Base
     instance = context.driver.instance(context.credentials, :id=>instance_id)
     machine_conf = CIMI::Model::MachineConfiguration.find(instance.instance_profile.name,
context)
     disks = CIMI::Model::Disk.find(instance, machine_conf, context, :all)
-    storage_override = instance.instance_profile.overrides.find { |p, v| p == :storage }
     self.new(
       :id => context.machine_url(instance_id)+"/disks",
       :description => "DiskCollection for Machine #{instance_id}",

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/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 27c721d..9c57301 100644
--- a/server/lib/cimi/models/machine_collection.rb
+++ b/server/lib/cimi/models/machine_collection.rb
@@ -20,7 +20,7 @@ class CIMI::Model::MachineCollection < CIMI::Model::Base
   text :count
 
   #add machines array:
-  self.schema.add_collection_member_array(CIMI::Model::Machine)
+  self << CIMI::Model::Machine
 
   def self.default(context)
     machines = CIMI::Model::Machine.all(context)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/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 e75bbb4..051e1b9 100644
--- a/server/lib/cimi/models/machine_configuration_collection.rb
+++ b/server/lib/cimi/models/machine_configuration_collection.rb
@@ -15,11 +15,9 @@
 
 class CIMI::Model::MachineConfigurationCollection < CIMI::Model::Base
 
-  act_as_root_entity :machine_configuration
-
   text :count
 
-  self.schema.add_collection_member_array(CIMI::Model::MachineConfiguration)
+  self << CIMI::Model::MachineConfiguration
 
   def self.default(context)
     machine_configurations = CIMI::Model::MachineConfiguration.all(context)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/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 703e515..cd4b5b4 100644
--- a/server/lib/cimi/models/machine_image_collection.rb
+++ b/server/lib/cimi/models/machine_image_collection.rb
@@ -19,7 +19,7 @@ class CIMI::Model::MachineImageCollection < CIMI::Model::Base
 
   text :count
 
-  self.schema.add_collection_member_array(CIMI::Model::MachineImage)
+  self << CIMI::Model::MachineImage
 
   def self.default(context)
     machine_images = CIMI::Model::MachineImage.all(context)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/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 bef9aaf..289c984 100644
--- a/server/lib/cimi/models/machine_template_collection.rb
+++ b/server/lib/cimi/models/machine_template_collection.rb
@@ -15,11 +15,9 @@
 
 class CIMI::Model::MachineTemplateCollection < CIMI::Model::Base
 
-  act_as_root_entity :machine_template
-
   text :count
 
-  self.schema.add_collection_member_array(CIMI::Model::MachineTemplate)
+  self << CIMI::Model::MachineTemplate
 
   def self.default(context)
     machine_templates = CIMI::Model::MachineTemplate.all(context)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/server/lib/cimi/models/machine_volume_collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_volume_collection.rb b/server/lib/cimi/models/machine_volume_collection.rb
index 85483ff..b9dfcad 100644
--- a/server/lib/cimi/models/machine_volume_collection.rb
+++ b/server/lib/cimi/models/machine_volume_collection.rb
@@ -16,7 +16,7 @@ class CIMI::Model::MachineVolumeCollection < CIMI::Model::Base
 
   text :count
 
-  self.schema.add_collection_member_array(CIMI::Model::MachineVolume)
+  self << CIMI::Model::MachineVolume
 
   array :operations do
     scalar :rel, :href

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/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 c17c3f7..7c746b4 100644
--- a/server/lib/cimi/models/network_collection.rb
+++ b/server/lib/cimi/models/network_collection.rb
@@ -17,8 +17,8 @@ class CIMI::Model::NetworkCollection < CIMI::Model::Base
   act_as_root_entity :network
   text :count
 
-#add networks Array:
-  self.schema.add_collection_member_array(CIMI::Model::Network)
+  #add networks Array:
+  self << CIMI::Model::Network
 
   def self.default(context)
     networks = CIMI::Model::Network.all(context)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/server/lib/cimi/models/schema.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
index 4aa512a..03914b6 100644
--- a/server/lib/cimi/models/schema.rb
+++ b/server/lib/cimi/models/schema.rb
@@ -138,9 +138,7 @@ class CIMI::Model::Schema
 
     private
     def struct
-      cname = "CIMI_#{json_name.upcase_first}"
-      ::Struct.send(:remove_const, cname) if ::Struct.const_defined?(cname)
-      @struct_class ||= ::Struct.new(cname, *@schema.attribute_names)
+      @struct_class ||= ::Struct.new(nil, *@schema.attribute_names)
     end
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/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 6bec78f..e780845 100644
--- a/server/lib/cimi/models/volume_collection.rb
+++ b/server/lib/cimi/models/volume_collection.rb
@@ -19,7 +19,7 @@ class CIMI::Model::VolumeCollection < CIMI::Model::Base
 
   text :count
 
-  self.schema.add_collection_member_array(CIMI::Model::Volume)
+  self << CIMI::Model::Volume
 
   def self.default(context)
     volumes = CIMI::Model::Volume.all(context)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/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 8800e35..d8ac229 100644
--- a/server/lib/cimi/models/volume_configuration_collection.rb
+++ b/server/lib/cimi/models/volume_configuration_collection.rb
@@ -19,7 +19,7 @@ class CIMI::Model::VolumeConfigurationCollection < CIMI::Model::Base
 
   text :count
 
-  self.schema.add_collection_member_array(CIMI::Model::VolumeConfiguration)
+  self << CIMI::Model::VolumeConfiguration
 
   def self.default(context)
     volume_configurations = CIMI::Model::VolumeConfiguration.all(context)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/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 78881d5..d411431 100644
--- a/server/lib/cimi/models/volume_image_collection.rb
+++ b/server/lib/cimi/models/volume_image_collection.rb
@@ -17,9 +17,9 @@ class CIMI::Model::VolumeImageCollection < CIMI::Model::Base
 
   act_as_root_entity :volume_image
 
-  text :count 
+  text :count
 
-  self.schema.add_collection_member_array(CIMI::Model::VolumeImage)
+  self << CIMI::Model::VolumeImage
 
   def self.default(context)
       volume_images = CIMI::Model::VolumeImage.all(context)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/731eae93/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 3f2ae02..90462a0 100644
--- a/server/lib/cimi/models/volume_template_collection.rb
+++ b/server/lib/cimi/models/volume_template_collection.rb
@@ -19,7 +19,7 @@ class CIMI::Model::VolumeTemplateCollection < CIMI::Model::Base
 
   text :count
 
-  self.schema.add_collection_member_array(CIMI::Model::VolumeTemplate)
+  self << CIMI::Model::VolumeTemplate
 
   def self.default(context)
     volume_templates = CIMI::Model::VolumeTemplate.all(context)


Mime
View raw message