deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Koper, Dies" <di...@fast.au.fujitsu.com>
Subject RE: [PATCH core] CIMI: Fixed bug when instance does not have storage defined (DTACLOUD-350)
Date Mon, 22 Oct 2012 14:50:56 GMT
ACK
I've confirmed that with this the error goes away with fgcp.

Thanks!
Dies Koper

> -----Original Message-----
> From: mfojtik@redhat.com [mailto:mfojtik@redhat.com]
> Sent: Tuesday, 23 October 2012 1:15 AM
> To: dev@deltacloud.apache.org
> Subject: [PATCH core] CIMI: Fixed bug when instance does not have
storage
> defined (DTACLOUD-350)
> 
> From: Michal Fojtik <mfojtik@redhat.com>
> 
> * This patch will fix the bug above and also make sure that the
'disks' are
>   reported correctly for instances:
> 
>   1. Check if instance hardware profiles contains :storage override
>   2. If no, then use the hardware_profile storage default value
>   3. If hardware_profile don't have any storage defined, display empty
>      collection.
> 
> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
> ---
>  server/lib/cimi/collections/machines.rb          |  2 +-
>  server/lib/cimi/models.rb                        |  2 +-
>  server/lib/cimi/models/disk.rb                   | 49
+++++++++++++++++++-----
>  server/lib/deltacloud/models/instance_profile.rb |  4 ++
>  4 files changed, 45 insertions(+), 12 deletions(-)
> 
> diff --git a/server/lib/cimi/collections/machines.rb
> b/server/lib/cimi/collections/machines.rb
> index a1d060a..5390140 100644
> --- a/server/lib/cimi/collections/machines.rb
> +++ b/server/lib/cimi/collections/machines.rb
> @@ -123,7 +123,7 @@ module CIMI::Collections
>          description "Retrieve the Machine's DiskCollection"
>          param :id,          :string,    :required
>          control do
> -          disks = DiskCollection.default(params[:id], self)
> +          disks =
CIMI::Model::Disk.collection_for_instance(params[:id], self)
>            respond_to do |format|
>              format.json {disks.to_json}
>              format.xml  {disks.to_xml}
> diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
> index 1eae2c9..3f5dace 100644
> --- a/server/lib/cimi/models.rb
> +++ b/server/lib/cimi/models.rb
> @@ -24,8 +24,8 @@ require_relative './models/base'
>  require_relative './models/collection'
>  require_relative './models/errors'
>  require_relative './models/action'
> -require_relative './models/disk'
>  require_relative './models/machine_volume'
> +require_relative './models/disk'
> 
>  # Toplevel entities; order matters as it determines the order
>  # in which the entities appear in the CEP
> diff --git a/server/lib/cimi/models/disk.rb
b/server/lib/cimi/models/disk.rb
> index d74ec54..b069207 100644
> --- a/server/lib/cimi/models/disk.rb
> +++ b/server/lib/cimi/models/disk.rb
> @@ -24,17 +24,46 @@ class CIMI::Model::Disk < CIMI::Model::Base
> 
>    def self.find(instance, machine_config, context, id=:all)
>      if id == :all
> -      storage_override = instance.instance_profile.overrides.find {
|p, v| p
> == :storage }
> -      capacity = storage_override.nil? ?
machine_config.disks[0][:capacity] :
> context.to_kibibyte(storage_override[1].to_i, "MB")
> -      name = instance.id+"_disk_#{capacity}" #assuming one disk for
now...
> -     [ self.new(
> -       :id => context.machine_url(instance.id)+"/disks/#{name}",
> -       :name => name,
> -       :description => "DiskCollection for Machine #{instance.id}",
> -       :created => instance.launch_time,
> -       :capacity => capacity
> -      ) ]
> +      return machine_config.disks if machine_config
> +
> +      capacity = false
> +
> +      if instance
> +        if instance.instance_profile.override? :storage
> +          capacity =
context.to_kibibyte(instance.instance_profile.storage, 'MB')
> +        else
> +          hw_profile =
context.driver.hardware_profile(context.credentials, :id =>
> instance.instance_profile.name)
> +          if hw_profile.storage
> +            capacity = context.to_kibibyte(hw_profile.storage.value,
'MB')
> +          end
> +        end
> +
> +        return [] unless capacity
> +
> +        name = instance.id+"_disk_#{capacity}" #assuming one disk for
now...
> +
> +        [self.new(
> +          :id => context.machine_url(instance.id)+"/disks/#{name}",
> +          :name => name,
> +          :description => "Disk for Machine #{instance.id}",
> +          :created => instance.launch_time,
> +          :capacity => capacity
> +        )]
> +      end
>      else
>      end
>    end
> +
> +  def self.collection_for_instance(instance_id, context)
> +    instance = context.driver.instance(context.credentials, :id =>
instance_id)
> +    disks = find(instance, nil, context)
> +    CIMI::Model::DiskCollection.new(
> +      :id => context.url("/machines/#{instance_id}/disks"),
> +      :name => 'default',
> +      :count => disks.size,
> +      :description => "Disk collection for Machine #{instance_id}",
> +      :entries => disks
> +    )
> +  end
> +
>  end
> diff --git a/server/lib/deltacloud/models/instance_profile.rb
> b/server/lib/deltacloud/models/instance_profile.rb
> index ccd1d67..3ecaf5d 100644
> --- a/server/lib/deltacloud/models/instance_profile.rb
> +++ b/server/lib/deltacloud/models/instance_profile.rb
> @@ -40,6 +40,10 @@ class InstanceProfile < BaseModel
>      name
>    end
> 
> +  def override?(property)
> +    overrides.find { |p, v| p == property }
> +  end
> +
>    def overrides
>      [:memory, :storage, :architecture, :cpu].inject({}) do |h, p|
>        if v = instance_variable_get("@#{p}")
> --
> 1.7.12.1
> 



Mime
View raw message