deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 6/6] CIMI: Added support for creating Machine using MachineTemplate
Date Thu, 29 Nov 2012 13:05:44 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/models/machine.rb | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index 07c5a17..f6d19b5 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -48,8 +48,14 @@ class CIMI::Model::Machine < CIMI::Model::Base
   def self.create_from_json(body, context)
     json = JSON.parse(body)
     machine_template = json['machineTemplate']
-    hardware_profile_id = machine_template['machineConfig']["href"].split('/').last
-    image_id = machine_template['machineImage']["href"].split('/').last
+    if !machine_template['href'].nil?
+      template = context.current_db.machine_template_entities.first(:id => machine_template['href'].split('/').last)
+      hardware_profile_id = template.machine_config.split('/').last
+      image_id = template.machine_image.split('/').last
+    else
+      hardware_profile_id = machine_template['machineConfig']["href"].split('/').last
+      image_id = machine_template['machineImage']["href"].split('/').last
+    end
     additional_params = {}
     additional_params[:name] = json['name'] if json['name']
     if machine_template.has_key? 'credential'
@@ -67,7 +73,15 @@ class CIMI::Model::Machine < CIMI::Model::Base
 
   def self.create_from_xml(body, context)
     xml = XmlSimple.xml_in(body)
-    machine_template = xml['machineTemplate'][0]
+    if !xml['machineTemplate']['href'].nil?
+      template = context.current_db.machine_template_entities.first(:id => xml['machineTemplate']['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
+    end
     hardware_profile_id = machine_template['machineConfig'][0]["href"].split('/').last
     image_id = machine_template['machineImage'][0]["href"].split('/').last
     additional_params = {}
-- 
1.8.0


Mime
View raw message