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/30 10:49:51 UTC
[PATCH core 1/3] CIMI: Fixed namespace error in MachineTemplate collection
From: Michal Fojtik <mf...@redhat.com>
* Fixed bugs in parsing MachineTemplate from XML
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/collections/machine_templates.rb | 10 +++++-----
server/lib/cimi/models/machine.rb | 23 +++++++++++------------
server/lib/cimi/models/machine_template.rb | 3 ++-
3 files changed, 18 insertions(+), 18 deletions(-)
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
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))
diff --git a/server/lib/cimi/models/machine_template.rb b/server/lib/cimi/models/machine_template.rb
index 5236ebf..b0a0aad 100644
--- a/server/lib/cimi/models/machine_template.rb
+++ b/server/lib/cimi/models/machine_template.rb
@@ -69,12 +69,13 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
def create_from_xml(body, context)
xml = XmlSimple.xml_in(body)
+ puts xml.inspect
new_template = context.current_db.machine_templates.new(
:name => xml['name'].first,
: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 => ''
)
--
1.8.0
[PATCH core 2/3] Tests: Do not explicitely require 'require_relative' on MRI 1.9
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
tests/cimi/test_helper.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index ace38bd..63398c1 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -15,7 +15,7 @@
# under the License.
require 'rubygems'
-require 'require_relative'
+require 'require_relative' if RUBY_VERSION < '1.9'
require_relative '../helpers/common.rb'
require 'singleton'
require_relative "../../server/lib/cimi/models"
--
1.8.0