deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1205816 - in /deltacloud/trunk/server/lib/cimi: model/machine_configuration.rb server.rb
Date Thu, 24 Nov 2011 13:19:41 GMT
Author: mfojtik
Date: Thu Nov 24 13:19:41 2011
New Revision: 1205816

URL: http://svn.apache.org/viewvc?rev=1205816&view=rev
Log:
CIMI: Moved drivers methods into CIMI model itself

Modified:
    deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb
    deltacloud/trunk/server/lib/cimi/server.rb

Modified: deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb?rev=1205816&r1=1205815&r2=1205816&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/machine_configuration.rb Thu Nov 24 13:19:41 2011
@@ -34,4 +34,36 @@ class CIMI::Model::MachineConfiguration 
   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

Modified: deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/server.rb?rev=1205816&r1=1205815&r2=1205816&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ deltacloud/trunk/server/lib/cimi/server.rb Thu Nov 24 13:19:41 2011
@@ -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_configuration
   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_configuration
     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_configuration
           {"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
 



Mime
View raw message