deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [1/3] git commit: CIMI - Add support for $expand on cloudEntryPoint Addresses Jira DTACLOUD-502
Date Tue, 30 Apr 2013 14:41:23 GMT
Updated Branches:
  refs/heads/master 7feb3a0f3 -> aa9a232aa


CIMI - Add support for $expand on cloudEntryPoint
Addresses Jira DTACLOUD-502


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

Branch: refs/heads/master
Commit: 223aed091f0f6907e40161cb2d6a70f41b182b45
Parents: 7feb3a0
Author: Joe VLcek <jvlcek@redhat.com>
Authored: Tue Apr 23 18:44:56 2013 -0400
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Tue Apr 30 16:40:24 2013 +0200

----------------------------------------------------------------------
 server/lib/cimi/collections/cloud_entry_point.rb   |    2 +-
 server/lib/cimi/models.rb                          |    1 +
 server/lib/cimi/models/cloud_entry_point.rb        |   26 +-----
 .../cimi/models/cloud_entry_point_collections.rb   |   58 ++++++++++++
 server/lib/cimi/service/cloud_entry_point.rb       |   69 ++++++++++++---
 5 files changed, 121 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/223aed09/server/lib/cimi/collections/cloud_entry_point.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/cloud_entry_point.rb b/server/lib/cimi/collections/cloud_entry_point.rb
index 37b47b2..ede248e 100644
--- a/server/lib/cimi/collections/cloud_entry_point.rb
+++ b/server/lib/cimi/collections/cloud_entry_point.rb
@@ -28,7 +28,7 @@ module CIMI::Collections
           if params[:force_auth]
             halt 401 unless driver.valid_credentials?(credentials)
           end
-          entry_point = CIMI::Service::CloudEntryPoint.create(self)
+          entry_point = CIMI::Service::CloudEntryPoint.new(self)
           respond_to do |format|
             format.xml { entry_point.to_xml }
             format.json { entry_point.to_json }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/223aed09/server/lib/cimi/models.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index 99b3545..96a91f5 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -93,3 +93,4 @@ require_relative './models/system_credential'
 require_relative './models/system_system'
 require_relative './models/system'
 require_relative './models/system_create'
+require_relative './models/cloud_entry_point_collections'

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/223aed09/server/lib/cimi/models/cloud_entry_point.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/cloud_entry_point.rb b/server/lib/cimi/models/cloud_entry_point.rb
index adadb62..dacb1ca 100644
--- a/server/lib/cimi/models/cloud_entry_point.rb
+++ b/server/lib/cimi/models/cloud_entry_point.rb
@@ -13,32 +13,14 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
-
-  text :driver
-  text :provider
-
-  # All possible CIMI collections, in the order in which they should appear
-  # in the CEP
-  COLLECTIONS = [ "resourceMetadata", "systems", "systemTemplates",
-            "machines" , "machineTemplates", "machineConfigs",
-            "machineImages", "credentials", "credentialTemplates",
-            "volumes", "volumeTemplates", "volumeConfigs", "volumeImages",
-            "networks", "networkTemplates", "networkConfigs", "networkPorts",
-            "networkPortTemplates", "networkPortConfigs",
-            "addresses", "addressTemplates", "forwardingGroups",
-            "forwardingGroupTemplates",
-            "jobs", "meters", "meterTemplates", "meterConfigs",
-            "eventLogs", "eventLogTemplates" ]
 
-  text  :base_uri, :xml_name => "baseURI", :json_name => "baseURI"
+class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
 
-  COLLECTIONS.each do |coll|
-    href coll.underscore
-  end
+  text :driver, :required => true
+  text :provider, :required => true
+  text :base_uri, :xml_name => "baseURI", :json_name => "baseURI"
 
   private
-
   def self.href_defined?(resource)
     true if schema.attribute_names.include? resource.underscore
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/223aed09/server/lib/cimi/models/cloud_entry_point_collections.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/cloud_entry_point_collections.rb b/server/lib/cimi/models/cloud_entry_point_collections.rb
new file mode 100644
index 0000000..c518e48
--- /dev/null
+++ b/server/lib/cimi/models/cloud_entry_point_collections.rb
@@ -0,0 +1,58 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# 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::CloudEntryPoint < CIMI::Model::Base
+
+  # All possible CIMI collections, in the order in which they should appear
+  # in the CEP
+  COLLECTIONS = {
+    "resourceMetadata" => CIMI::Model::ResourceMetadata,
+    "systems" => CIMI::Model::System,
+    "systemTemplates" => CIMI::Model::SystemTemplate,
+    "machines" => CIMI::Model::Machine,
+    "machineTemplates" => CIMI::Model::MachineTemplate,
+    "machineConfigurations" => CIMI::Model::MachineConfiguration,
+    "machineImages" => CIMI::Model::MachineImage,
+    "credentials" => CIMI::Model::Credential,
+    "credentialTemplates" => CIMI::Model::CredentialTemplate,
+    "volumes" => CIMI::Model::Volume,
+    "volumeTemplates" => CIMI::Model::VolumeTemplate,
+    "volumeConfigurations" => CIMI::Model::VolumeConfiguration,
+    "volumeImages" => CIMI::Model::VolumeImage,
+    "networks" => CIMI::Model::Network,
+    "networkTemplates" => CIMI::Model::NetworkTemplate,
+    "networkConfigurations" => CIMI::Model::NetworkConfiguration,
+    "networkPorts" => CIMI::Model::NetworkPort,
+    "networkPortTemplates" => CIMI::Model::NetworkTemplate,
+    "networkPortConfigurations" => CIMI::Model::NetworkPortConfiguration,
+    "addresses" => CIMI::Model::Address,
+    "addressTemplates" => CIMI::Model::AddressTemplate,
+    "forwardingGroups" => CIMI::Model::ForwardingGroup,
+    "forwardingGroupTemplates" => CIMI::Model::ForwardingGroupTemplate,
+    "jobs" =>  nil,
+    "meters" => nil,
+    "meterTemplates" => nil,
+    "meterConfigs" => nil,
+    "eventLogs" => nil,
+    "eventLogTemplates" => nil
+  }
+
+  COLLECTIONS.each do |coll|
+    coll_entry = coll
+    collection coll_entry[0].underscore.to_sym, :class => coll_entry[1] unless coll_entry[1]
== nil
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/223aed09/server/lib/cimi/service/cloud_entry_point.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/cloud_entry_point.rb b/server/lib/cimi/service/cloud_entry_point.rb
index a61eec7..900581d 100644
--- a/server/lib/cimi/service/cloud_entry_point.rb
+++ b/server/lib/cimi/service/cloud_entry_point.rb
@@ -13,13 +13,47 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+# JoeV - If I don't include these here the associated CIMI::Service::<x>
+# JoeV   class referenced below is undefined even though these are specified
+# JoeV   in service.rb.
+require_relative './resource_metadata'
+require_relative './credential'
+require_relative './network_template'
+require_relative './network_port_template'
+require_relative './address'
+require_relative './address_template'
+
 class CIMI::Service::CloudEntryPoint < CIMI::Service::Base
 
   metadata :driver, :type => 'text'
   metadata :provider, :type => 'text'
 
-  def self.create(context)
-    self.new(context, :values => entities(context).merge({
+  SERVICES = {
+    "resource_metadata" => CIMI::Service::ResourceMetadata,
+    "systems" =>  CIMI::Service::System,
+    "system_templates" => CIMI::Service::SystemTemplate,
+    "machines" => CIMI::Service::Machine,
+    "machine_templates" => CIMI::Service::MachineTemplate,
+    "machine_configurations" => CIMI::Service::MachineConfiguration,
+    "machine_images" => CIMI::Service::MachineImage,
+    "credentials" => CIMI::Service::Credential,
+    "volumes" => CIMI::Service::Volume,
+    "volume_templates" => CIMI::Service::VolumeTemplate,
+    "volume_configurations" => CIMI::Service::VolumeConfiguration,
+    "volume_images" => CIMI::Service::VolumeImage,
+    "networks" =>  CIMI::Service::Network,
+    "network_templates" => CIMI::Service::NetworkTemplate,
+    "network_configurations" => CIMI::Service::NetworkPortConfiguration,
+    "network_port_template" =>  CIMI::Service::NetworkPortTemplate,
+    "network_port_configurations" => CIMI::Service::NetworkPortConfiguration,
+    "addresses" => CIMI::Service::Address,
+    "address_templates" =>  CIMI::Service::AddressTemplate,
+    "forwarding_groups" => CIMI::Service::ForwardingGroup,
+    "forwarding_group_templates" => CIMI::Service::ForwardingGroupTemplate
+  }
+
+  def initialize(context)
+    super(context, :values => {
       :name => context.driver.name,
       :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
       :driver => context.driver.name,
@@ -27,27 +61,38 @@ class CIMI::Service::CloudEntryPoint < CIMI::Service::Base
       :id => context.cloudEntryPoint_url,
       :base_uri => context.base_uri + "/",
       :created => Time.now.xmlschema
-    }))
+    })
+    fill_entities context
   end
 
-  # Return an Hash of the CIMI root entities used in CloudEntryPoint
-  def self.entities(context)
+  private
+  def fill_entities(context)
     CIMI::Collections.modules(:cimi).inject({}) do |supported_entities, m|
       m.collections.each do |c|
         if c.operation(:index).nil?
           warn "#{c} does not have :index operation."
           next
         end
+        if c.collection_name == :cloudEntryPoint
+          warn "#{c} is cloudEntryPoint"
+          next
+        end
+
         index_operation_capability = c.operation(:index).required_capability
-        next if m.settings.respond_to?(:capability) and !m.settings.capability(index_operation_capability)
-        supported_entities[c.collection_name.to_s] = { :href => context.send(:"#{c.collection_name}_url")
}
+        next if  m.settings.respond_to?(:capability) and \
+                !m.settings.capability(index_operation_capability)
+
+        coll = self[c.collection_name]
+        coll.href = context.send(:"#{c.collection_name.to_s}_url")
+
+        if context.expand? c.collection_name.to_s.camelize(:lower).to_sym
+          coll[c.collection_name] = \
+            SERVICES[c.collection_name.to_s].find(:all, context)
+        end
+
       end
-      supported_entities
     end
   end
 
-  def entities
-    @attribute_values.clone.delete_if { |key, value| !value.respond_to? :href }
-  end
-
 end
+


Mime
View raw message