You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2012/11/29 14:05:44 UTC

[PATCH core 6/6] CIMI: Added support for creating Machine using MachineTemplate

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@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


Re: [PATCH core 6/6] CIMI: Added support for creating Machine using MachineTemplate

Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2012-11-29 at 14:05 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
>  server/lib/cimi/models/machine.rb | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)

ACK

David