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 2011/11/24 12:10:28 UTC
[PATCH core 5/5] CIMI: Moved drivers methods into CIMI model itself
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/model/machine_configuration.rb | 32 ++++++++++++++++++++++++
server/lib/cimi/server.rb | 26 ++++++++++++-------
2 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/server/lib/cimi/model/machine_configuration.rb b/server/lib/cimi/model/machine_configuration.rb
index ebb616a..e4f8ace 100644
--- a/server/lib/cimi/model/machine_configuration.rb
+++ b/server/lib/cimi/model/machine_configuration.rb
@@ -34,4 +34,36 @@ class CIMI::Model::MachineConfiguration < CIMI::Model::Base
array :operations do
scalar :rel, :href
end
+
+ def self.find(id, _self)
+ profiles = []
+ if id == :all
+ profiles = _self.driver.hardware_profiles(_self.credentials)
+ profiles.map { |profile| from_hardware_profile(profile, _self) }.compact
+ else
+ profile = _self.driver.hardware_profile(_self.credentials, id)
+ from_hardware_profile(profile, _self)
+ end
+ end
+
+ def self.all(_self); find(:all, _self); end
+
+ private
+
+ def self.from_hardware_profile(profile, _self)
+ # We accept just profiles with all properties set
+ return unless profile.memory or profile.cpu or profile.storage
+ machine_hash = {
+ :name => profile.name,
+ :description => "Machine Configuration with #{profile.memory.value} #{profile.memory.unit} "+
+ "of memory and #{profile.cpu.value} CPU",
+ :cpu => profile.cpu.value,
+ :created => Time.now.to_s, # FIXME: DC hardware_profile has no mention about created_at
+ :memory => { :quantity => profile.memory.value, :units => profile.memory.unit },
+ :disks => [ { :capacity => { :quantity => profile.storage.value, :units => profile.storage.unit } } ],
+ :uri => _self.machine_configuration_url(profile.name)
+ }
+ self.new(machine_hash)
+ end
+
end
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index b179c8f..5dac921 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -16,10 +16,14 @@
require 'cimi/helpers/dmtfdep'
require 'cimi/helpers/cmwgapp_helper'
+require 'cimi/helpers/cimi_helper'
+require 'deltacloud/core_ext'
+require 'cimi/model'
set :version, '0.1.0'
-include CIMI::Drivers
+include Deltacloud::Drivers
+include CIMI::Model
set :drivers, Proc.new { driver_config }
STOREROOT = File.join($top_srcdir, 'lib', 'cimi', 'data')
@@ -94,16 +98,11 @@ global_collection :machine_configurations do
operation :index do
description "List all machine configurations"
control do
- profiles = driver.hardware_profiles(credentials, nil)
- @dmtf_col_items = []
- if profiles
- profiles.map do |profile|
- new_item = { "name" => profile.name,
- "href" => machine_configuration_url(profile.name) }
- @dmtf_col_items.insert 0, new_item
- end
+ machine_configs = MachineConfiguration.all(self)
+ respond_to do |format|
+ format.xml { machine_configs.to_xml_cimi_collection(self) }
+ format.json { machine_configs.to_json_cimi_collection(self) }
end
- respond_to_collection "machine_configuration.col.xml"
end
end
@@ -115,6 +114,7 @@ global_collection :machine_configurations do
param :id, :string, :required
control do
+<<<<<<< HEAD
@profile = driver.hardware_profile(credentials, params[:id])
if @profile
#setup the default values for a machine configuration
@@ -128,6 +128,12 @@ global_collection :machine_configurations do
{"property" => "properties", "disk" => "disks", "operation" => "operations"}
else
report_error(404)
+=======
+ machine_conf = MachineConfiguration.find(params[:id], self)
+ respond_to do |format|
+ format.xml { machine_conf.to_xml }
+ format.json { machine_conf.to_json }
+>>>>>>> 814f2ce... CIMI: Moved drivers methods into CIMI model itself
end
end
--
1.7.4.4