You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2012/06/28 12:10:17 UTC

[PATCH] CIMI: Adds guards in conversion of hardware_profile to machineConfig

From: marios <ma...@redhat.com>

CIMI spec allows for non-existent cpu and disks (provider/consumer
support optional) - as demonstrated by FGCP cloud.

Addresses JIRA DTACLOUD_245 - thanks Dies Kopper for reporting.

https://issues.apache.org/jira/browse/DTACLOUD-245

Signed-off-by: marios <ma...@redhat.com>
---
 server/lib/cimi/models/machine_configuration.rb |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/server/lib/cimi/models/machine_configuration.rb b/server/lib/cimi/models/machine_configuration.rb
index f9d98f2..28bf3ab 100644
--- a/server/lib/cimi/models/machine_configuration.rb
+++ b/server/lib/cimi/models/machine_configuration.rb
@@ -52,16 +52,16 @@ class CIMI::Model::MachineConfiguration < CIMI::Model::Base
     # We accept just profiles with all properties set
     return unless profile.memory or profile.cpu or profile.storage
     memory = profile.memory.value || profile.memory.default
-    cpu = profile.cpu.value || profile.cpu.default
-    storage = profile.storage.value || profile.storage.default
+    cpu = (profile.cpu ? (profile.cpu.value || profile.cpu.default) : nil )
+    storage = (profile.storage ? (profile.storage.value || profile.storage.default) :  nil )
     machine_hash = {
       :name => profile.name,
       :description => "Machine Configuration with #{memory} #{profile.memory.unit} "+
         "of memory and #{cpu} CPU",
-      :cpu => cpu,
+      :cpu => ( cpu if cpu ) ,
       :created => Time.now.to_s,  # FIXME: DC hardware_profile has no mention about created_at
       :memory => { :quantity => profile.memory.value || profile.memory.default, :units => profile.memory.unit },
-      :disks => [ { :capacity => { :quantity => profile.storage.value || profile.storage.default, :units => profile.storage.unit } } ],
+      :disks => (  [ { :capacity => { :quantity => profile.storage.value || profile.storage.default, :units => profile.storage.unit } } ] if storage ),
       :id => context.machine_configuration_url(profile.name)
     }
     self.new(machine_hash)
-- 
1.7.6.5


Re: [PATCH] CIMI: Adds guards in conversion of hardware_profile to machineConfig

Posted by Michal Fojtik <mf...@redhat.com>.
ACK.

Good catch!

  -- Michal

Michal Fojtik
http://deltacloud.org
mfojtik@redhat.com



On Jun 28, 2012, at 12:10 PM, marios@redhat.com wrote:

> From: marios <ma...@redhat.com>
> 
> CIMI spec allows for non-existent cpu and disks (provider/consumer
> support optional) - as demonstrated by FGCP cloud.
> 
> Addresses JIRA DTACLOUD_245 - thanks Dies Kopper for reporting.
> 
> https://issues.apache.org/jira/browse/DTACLOUD-245
> 
> Signed-off-by: marios <ma...@redhat.com>
> ---
> server/lib/cimi/models/machine_configuration.rb |    8 ++++----
> 1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/server/lib/cimi/models/machine_configuration.rb b/server/lib/cimi/models/machine_configuration.rb
> index f9d98f2..28bf3ab 100644
> --- a/server/lib/cimi/models/machine_configuration.rb
> +++ b/server/lib/cimi/models/machine_configuration.rb
> @@ -52,16 +52,16 @@ class CIMI::Model::MachineConfiguration < CIMI::Model::Base
>     # We accept just profiles with all properties set
>     return unless profile.memory or profile.cpu or profile.storage
>     memory = profile.memory.value || profile.memory.default
> -    cpu = profile.cpu.value || profile.cpu.default
> -    storage = profile.storage.value || profile.storage.default
> +    cpu = (profile.cpu ? (profile.cpu.value || profile.cpu.default) : nil )
> +    storage = (profile.storage ? (profile.storage.value || profile.storage.default) :  nil )
>     machine_hash = {
>       :name => profile.name,
>       :description => "Machine Configuration with #{memory} #{profile.memory.unit} "+
>         "of memory and #{cpu} CPU",
> -      :cpu => cpu,
> +      :cpu => ( cpu if cpu ) ,
>       :created => Time.now.to_s,  # FIXME: DC hardware_profile has no mention about created_at
>       :memory => { :quantity => profile.memory.value || profile.memory.default, :units => profile.memory.unit },
> -      :disks => [ { :capacity => { :quantity => profile.storage.value || profile.storage.default, :units => profile.storage.unit } } ],
> +      :disks => (  [ { :capacity => { :quantity => profile.storage.value || profile.storage.default, :units => profile.storage.unit } } ] if storage ),
>       :id => context.machine_configuration_url(profile.name)
>     }
>     self.new(machine_hash)
> -- 
> 1.7.6.5
>