deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [3/8] git commit: CIMI: Added support for creating Machine using MachineTemplate
Date Fri, 30 Nov 2012 08:48:24 GMT
CIMI: Added support for creating Machine using MachineTemplate


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

Branch: refs/heads/master
Commit: 6ffe667223ec86ec690ec35cab54b3450dfc5557
Parents: ff59a16
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Thu Nov 29 13:56:09 2012 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Fri Nov 30 09:46:50 2012 +0100

----------------------------------------------------------------------
 server/lib/cimi/models/machine.rb          |   20 +++++++++++++++++---
 server/lib/cimi/models/machine_template.rb |   10 +++++-----
 server/lib/db/machine_template.rb          |    2 +-
 server/lib/db/provider.rb                  |    2 +-
 4 files changed, 24 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6ffe6672/server/lib/cimi/models/machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index 07c5a17..4b5e958 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_templates.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_templates.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 = {}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6ffe6672/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 fbc6326..5236ebf 100644
--- a/server/lib/cimi/models/machine_template.rb
+++ b/server/lib/cimi/models/machine_template.rb
@@ -44,9 +44,9 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
   class << self
     def find(id, context)
       if id == :all
-        context.current_db.machine_template_entities.all.map { |t| from_db(t, context) }
+        context.current_db.machine_templates.all.map { |t| from_db(t, context) }
       else
-        template = context.current_db.machine_template_entities.first(:id => id)
+        template = context.current_db.machine_templates.first(:id => id)
         raise CIMI::Model::NotFound unless template
         from_db(template, context)
       end
@@ -54,7 +54,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
 
     def create_from_json(body, context)
       json = JSON.parse(body)
-      new_template = context.current_db.machine_template_entities.new(
+      new_template = context.current_db.machine_templates.new(
         :name => json['name'],
         :description => json['description'],
         :machine_config => json['machineConfig']['href'],
@@ -69,7 +69,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
 
     def create_from_xml(body, context)
       xml = XmlSimple.xml_in(body)
-      new_template = context.current_db.machine_template_entities.new(
+      new_template = context.current_db.machine_templates.new(
         :name => xml['name'].first,
         :description => xml['description'].first,
         :machine_config => xml['machineConfig'].first['href'],
@@ -83,7 +83,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
     end
 
     def delete!(id, context)
-      context.current_db.machine_template_entities.first(:id => id).destroy
+      context.current_db.machine_templates.first(:id => id).destroy
     end
 
     private

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6ffe6672/server/lib/db/machine_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/db/machine_template.rb b/server/lib/db/machine_template.rb
index 813588d..cb99946 100644
--- a/server/lib/db/machine_template.rb
+++ b/server/lib/db/machine_template.rb
@@ -1,7 +1,7 @@
 module Deltacloud
   module Database
 
-    class MachineTemplateEntity < Entity
+    class MachineTemplate < Entity
       belongs_to :provider
 
       property :machine_config, String

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6ffe6672/server/lib/db/provider.rb
----------------------------------------------------------------------
diff --git a/server/lib/db/provider.rb b/server/lib/db/provider.rb
index e227a73..54fe2d7 100644
--- a/server/lib/db/provider.rb
+++ b/server/lib/db/provider.rb
@@ -9,7 +9,7 @@ module Deltacloud
       property :url, Text
 
       has n, :entities
-      has n, :machine_template_entities
+      has n, :machine_templates
     end
 
   end


Mime
View raw message