deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1208437 - in /deltacloud/trunk/server/lib/cimi: ./ model/
Date Wed, 30 Nov 2011 13:58:59 GMT
Author: mfojtik
Date: Wed Nov 30 13:58:57 2011
New Revision: 1208437

URL: http://svn.apache.org/viewvc?rev=1208437&view=rev
Log:
CIMI: Added cloudEntryPoint entity

Added:
    deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb
      - copied, changed from r1208436, deltacloud/trunk/server/lib/cimi/model/machine_image.rb
Modified:
    deltacloud/trunk/server/lib/cimi/model.rb
    deltacloud/trunk/server/lib/cimi/model/base.rb
    deltacloud/trunk/server/lib/cimi/model/machine.rb
    deltacloud/trunk/server/lib/cimi/model/machine_admin.rb
    deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb
    deltacloud/trunk/server/lib/cimi/model/machine_image.rb
    deltacloud/trunk/server/lib/cimi/model/machine_template.rb
    deltacloud/trunk/server/lib/cimi/model/schema.rb
    deltacloud/trunk/server/lib/cimi/model/volume.rb
    deltacloud/trunk/server/lib/cimi/model/volume_configuration.rb
    deltacloud/trunk/server/lib/cimi/model/volume_image.rb
    deltacloud/trunk/server/lib/cimi/model/volume_template.rb
    deltacloud/trunk/server/lib/cimi/server.rb

Modified: deltacloud/trunk/server/lib/cimi/model.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model.rb Wed Nov 30 13:58:57 2011
@@ -22,6 +22,7 @@ end
 
 require 'cimi/model/schema'
 require 'cimi/model/base'
+require 'cimi/model/cloud_entry_point'
 require 'cimi/model/machine_template'
 require 'cimi/model/machine_image'
 require 'cimi/model/machine_configuration'

Modified: deltacloud/trunk/server/lib/cimi/model/base.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/base.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/base.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/base.rb Wed Nov 30 13:58:57 2011
@@ -75,6 +75,19 @@ class CIMI::Model::NotFound < StandardEr
   end
 end
 
+module CIMI::Model
+
+  def self.register_as_root_entity!(name)
+    @root_entities ||= []
+    @root_entities << name
+  end
+
+  def self.root_entities
+    @root_entities || []
+  end
+
+end
+
 class CIMI::Model::Base
 
   #
@@ -191,5 +204,9 @@ class CIMI::Model::Base
     scalar :name
   end
 
+  def self.act_as_root_entity
+    CIMI::Model.register_as_root_entity! xml_tag_name.pluralize.uncapitalize
+  end
+
   def self.all(_self); find(:all, _self); end
 end

Copied: deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb (from r1208436, deltacloud/trunk/server/lib/cimi/model/machine_image.rb)
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb?p2=deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb&p1=deltacloud/trunk/server/lib/cimi/model/machine_image.rb&r1=1208436&r2=1208437&rev=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine_image.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/cloud_entry_point.rb Wed Nov 30 13:58:57 2011
@@ -13,33 +13,29 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-class CIMI::Model::MachineImage < CIMI::Model::Base
+class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
 
-  href :image_location
-  text :image_data
-
-  array :operations do
-    scalar :rel, :href
-  end
-
-  def self.find(id, context)
-    images = []
-    if id == :all
-      images = context.driver.images(context.credentials)
-      images.map { |image| from_image(image, context) }
-    else
-      image = context.driver.image(context.credentials, :id => id)
-      from_image(image, context)
+  def self.create(context)
+    root_entities = CIMI::Model.root_entities.inject({}) do |result, entity|
+      send(:href, entity.underscore) if not href_defined?(entity)
+      if context.respond_to? :"#{entity.underscore}_url"
+        result[entity.underscore] = { :href => context.send(:"#{entity.underscore}_url")
}
+      end
+      result
     end
+    root_entities.merge!({
+      :name => context.driver.name,
+      :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
+      :uri => context.cloudEntryPoint_url,
+      :created => Time.now
+    })
+    self.new(root_entities)
   end
 
-  def self.from_image(image, context)
-    self.new(
-      :name => image.id,
-      :uri => context.machine_image_url(image.id),
-      :description => image.description,
-      :image_location => { :href => "#{context.driver.name}://#{image.id}" } # FIXME
-    )
+  private
+
+  def self.href_defined?(entity)
+    true if schema.attribute_names.include? entity.underscore
   end
 
 end

Modified: deltacloud/trunk/server/lib/cimi/model/machine.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine.rb Wed Nov 30 13:58:57 2011
@@ -17,6 +17,8 @@ require 'deltacloud/models/instance_addr
 
 class CIMI::Model::Machine < CIMI::Model::Base
 
+  act_as_root_entity
+
   text :state
   text :cpu
 

Modified: deltacloud/trunk/server/lib/cimi/model/machine_admin.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine_admin.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine_admin.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine_admin.rb Wed Nov 30 13:58:57 2011
@@ -15,6 +15,8 @@
 
 class CIMI::Model::MachineAdmin < CIMI::Model::Base
 
+  act_as_root_entity
+
   text :username
   text :password
   text :key

Modified: deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb Wed Nov 30 13:58:57 2011
@@ -15,6 +15,8 @@
 
 class CIMI::Model::MachineConfiguration < CIMI::Model::Base
 
+  act_as_root_entity
+
   struct :memory do
     scalar :quantity
     scalar :units

Modified: deltacloud/trunk/server/lib/cimi/model/machine_image.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine_image.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine_image.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine_image.rb Wed Nov 30 13:58:57 2011
@@ -15,6 +15,8 @@
 
 class CIMI::Model::MachineImage < CIMI::Model::Base
 
+  act_as_root_entity
+
   href :image_location
   text :image_data
 

Modified: deltacloud/trunk/server/lib/cimi/model/machine_template.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine_template.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine_template.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine_template.rb Wed Nov 30 13:58:57 2011
@@ -14,6 +14,9 @@
 # under the License.
 
 class CIMI::Model::MachineTemplate < CIMI::Model::Base
+
+  act_as_root_entity
+
   href :machine_config
   href :machine_image
   href :machine_admin

Modified: deltacloud/trunk/server/lib/cimi/model/schema.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/schema.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/schema.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/schema.rb Wed Nov 30 13:58:57 2011
@@ -42,7 +42,7 @@ class CIMI::Model::Schema
     end
 
     def to_json(model, json)
-      json[@json_name] = model[@name] if model[@name]
+      json[@json_name] = model[@name] if model and model[@name]
     end
   end
 

Modified: deltacloud/trunk/server/lib/cimi/model/volume.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/volume.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/volume.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/volume.rb Wed Nov 30 13:58:57 2011
@@ -14,6 +14,9 @@
 # under the License.
 
 class CIMI::Model::Volume < CIMI::Model::Base
+
+  act_as_root_entity
+
   struct :capacity do
     scalar :quantity
     scalar :units

Modified: deltacloud/trunk/server/lib/cimi/model/volume_configuration.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/volume_configuration.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/volume_configuration.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/volume_configuration.rb Wed Nov 30 13:58:57 2011
@@ -14,6 +14,9 @@
 # under the License.
 
 class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
+
+  act_as_root_entity
+
   text :format
   struct :capacity do
     scalar :quantity

Modified: deltacloud/trunk/server/lib/cimi/model/volume_image.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/volume_image.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/volume_image.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/volume_image.rb Wed Nov 30 13:58:57 2011
@@ -14,6 +14,9 @@
 # under the License.
 
 class CIMI::Model::VolumeImage < CIMI::Model::Base
+
+  act_as_root_entity
+
   href :image_location
   text :image_data
   text :bootable

Modified: deltacloud/trunk/server/lib/cimi/model/volume_template.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/volume_template.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/volume_template.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/volume_template.rb Wed Nov 30 13:58:57 2011
@@ -14,6 +14,9 @@
 # under the License.
 
 class CIMI::Model::VolumeTemplate < CIMI::Model::Base
+
+  act_as_root_entity
+
   href :volume_config
   href :volume_image
   array :operations do

Modified: deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/server.rb?rev=1208437&r1=1208436&r2=1208437&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ deltacloud/trunk/server/lib/cimi/server.rb Wed Nov 30 13:58:57 2011
@@ -79,8 +79,11 @@ global_collection  :cloudEntryPoint do
   operation :index do
     description "list all resources of the cloud"
     control do
-      @collections = entry_points.reject { |p| p[0] == :cloudEntryPoint }
-      show_resource "cloudEntryPoint/index", "CloudEntryPoint"
+      entry_point = CloudEntryPoint.create(self)
+      respond_to do |format|
+        format.xml { entry_point.to_xml }
+        format.json { entry_point.to_json }
+      end
     end
   end
 end



Mime
View raw message