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: Fixed namespace error in MachineTemplate collection
Date Fri, 30 Nov 2012 14:55:11 GMT
Updated Branches:
  refs/heads/master 61eab9855 -> 792957f83


CIMI: Fixed namespace error in MachineTemplate collection

* Fixed bugs in parsing MachineTemplate from XML


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

Branch: refs/heads/master
Commit: 015cc8e975523b4b30b1706218f9060c3c99d24b
Parents: 61eab98
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Fri Nov 30 10:47:38 2012 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Fri Nov 30 15:54:49 2012 +0100

----------------------------------------------------------------------
 server/lib/cimi/collections/machine_templates.rb |   10 +++---
 server/lib/cimi/models/machine.rb                |   23 ++++++++---------
 server/lib/cimi/models/machine_template.rb       |    2 +-
 3 files changed, 17 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/015cc8e9/server/lib/cimi/collections/machine_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machine_templates.rb b/server/lib/cimi/collections/machine_templates.rb
index 17dfbd1..bda57a0 100644
--- a/server/lib/cimi/collections/machine_templates.rb
+++ b/server/lib/cimi/collections/machine_templates.rb
@@ -23,7 +23,7 @@ module CIMI::Collections
       operation :index do
         description "List all machine templates"
         control do
-          machine_templates = MachineTemplate.list(self).filter_by(params['$select'])
+          machine_templates = CIMI::Model::MachineTemplate.list(self).filter_by(params['$select'])
           respond_to do |format|
             format.xml { machine_templates.to_xml }
             format.json { machine_templates.to_json }
@@ -34,7 +34,7 @@ module CIMI::Collections
       operation :show do
         description "Show specific machine template"
         control do
-          machine_template = MachineTemplate.find(params[:id], self)
+          machine_template = CIMI::Model::MachineTemplate.find(params[:id], self)
           respond_to do |format|
             format.xml { machine_template.to_xml }
             format.json { machine_template.to_json }
@@ -46,9 +46,9 @@ module CIMI::Collections
         description "Create new machine template"
         control do
           if request.content_type.end_with?("json")
-            new_machine_template = MachineTemplate.create_from_json(request.body.read, self)
+            new_machine_template = CIMI::Model::MachineTemplate.create_from_json(request.body.read,
self)
           else
-            new_machine_template = MachineTemplate.create_from_xml(request.body.read, self)
+            new_machine_template = CIMI::Model::MachineTemplate.create_from_xml(request.body.read,
self)
           end
           status 201 # Created
           headers 'Location' => new_machine_template.id
@@ -62,7 +62,7 @@ module CIMI::Collections
       operation :destroy do
         description "Delete a specified machine template"
         control do
-          MachineTemplate.delete!(params[:id], self)
+          CIMI::Model::MachineTemplate.delete!(params[:id], self)
           no_content_with_status(200)
         end
       end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/015cc8e9/server/lib/cimi/models/machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index 4b5e958..b55d7e3 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -55,12 +55,13 @@ class CIMI::Model::Machine < CIMI::Model::Base
     else
       hardware_profile_id = machine_template['machineConfig']["href"].split('/').last
       image_id = machine_template['machineImage']["href"].split('/').last
+      if machine_template.has_key? 'credential'
+        additional_params[:keyname] = machine_template['credential']["href"].split('/').last
+      end
     end
+
     additional_params = {}
     additional_params[:name] = json['name'] if json['name']
-    if machine_template.has_key? 'credential'
-      additional_params[:keyname] = machine_template['credential']["href"].split('/').last
-    end
     instance = context.driver.create_instance(context.credentials, image_id, {
       :hwp_id => hardware_profile_id
     }.merge(additional_params))
@@ -73,22 +74,20 @@ class CIMI::Model::Machine < CIMI::Model::Base
 
   def self.create_from_xml(body, context)
     xml = XmlSimple.xml_in(body)
-    if !xml['machineTemplate']['href'].nil?
-      template = context.current_db.machine_templates.first(:id => xml['machineTemplate']['href'].split('/').last)
+    if xml['machineTemplate'][0]['href']
+      template = context.current_db.machine_templates.first(:id => xml['machineTemplate'][0]['href'].split('/').last)
       hardware_profile_id = template.machine_config.split('/').last
       image_id = template.machine_image.split('/').last
     else
       machine_template = xml['machineTemplate'][0]
-      hardware_profile_id = machine_template['machineConfig']["href"].split('/').last
-      image_id = machine_template['machineImage']["href"].split('/').last
+      hardware_profile_id = machine_template['machineConfig'].first["href"].split('/').last
+      image_id = machine_template['machineImage'].first["href"].split('/').last
+      if machine_template.has_key? 'credential'
+        additional_params[:keyname] = machine_template['credential'][0]["href"].split('/').last
+      end
     end
-    hardware_profile_id = machine_template['machineConfig'][0]["href"].split('/').last
-    image_id = machine_template['machineImage'][0]["href"].split('/').last
     additional_params = {}
     additional_params[:name] = xml['name'][0] if xml['name']
-    if machine_template.has_key? 'credential'
-      additional_params[:keyname] = machine_template['credential'][0]["href"].split('/').last
-    end
     instance = context.driver.create_instance(context.credentials, image_id, {
       :hwp_id => hardware_profile_id
     }.merge(additional_params))

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/015cc8e9/server/lib/cimi/models/machine_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_template.rb b/server/lib/cimi/models/machine_template.rb
index 5236ebf..64fa26c 100644
--- a/server/lib/cimi/models/machine_template.rb
+++ b/server/lib/cimi/models/machine_template.rb
@@ -74,7 +74,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
         :description => xml['description'].first,
         :machine_config => xml['machineConfig'].first['href'],
         :machine_image => xml['machineImage'].first['href'],
-        :ent_properties => xml['properties'].first.to_json,
+        :ent_properties => xml['property'].inject({}) { |r, p| r[p['name']]=p['content'];
r },
         :be_kind => 'machine_template',
         :be_id => ''
       )


Mime
View raw message