ACK

On 14/11/12 12:10, [email protected] wrote:
> From: Michal Fojtik <[email protected]>
> 
> * For disks, subcollection class was not generated yet
> * Fixed capacity in Volumes
> * Use generated VolumeCollection as subcollection
> 
> Signed-off-by: Michal fojtik <[email protected]>
> ---
>  server/lib/cimi/collections/machines.rb |  2 +-
>  server/lib/cimi/models/disk.rb          |  7 ++++++-
>  server/lib/cimi/models/volume.rb        | 16 +++++++++++++++-
>  3 files changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/server/lib/cimi/collections/machines.rb 
> b/server/lib/cimi/collections/machines.rb
> index 1ae71e6..6a896f3 100644
> --- a/server/lib/cimi/collections/machines.rb
> +++ b/server/lib/cimi/collections/machines.rb
> @@ -135,7 +135,7 @@ module CIMI::Collections
>          description "Retrieve the Machine's MachineVolumeCollection"
>          param :id,          :string,    :required
>          control do
> -          volumes = MachineVolumeCollection.default(params[:id], self)
> +          volumes = CIMI::Model::Volume.collection_for_instance(params[:id], 
> self)
>            respond_to do |format|
>              format.json {volumes.to_json}
>              format.xml  {volumes.to_xml}
> diff --git a/server/lib/cimi/models/disk.rb b/server/lib/cimi/models/disk.rb
> index 40bd6e1..218143f 100644
> --- a/server/lib/cimi/models/disk.rb
> +++ b/server/lib/cimi/models/disk.rb
> @@ -57,7 +57,12 @@ class CIMI::Model::Disk < CIMI::Model::Base
>    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(
> +    unless CIMI::Model.const_defined?('DiskCollection')
> +      collection_class = CIMI::Model::Collection.generate(self)
> +    else
> +      collection_class = CIMI::Model::DiskCollection
> +    end
> +    collection_class.new(
>        :id => context.url("/machines/#{instance_id}/disks"),
>        :name => 'default',
>        :count => disks.size,
> diff --git a/server/lib/cimi/models/volume.rb 
> b/server/lib/cimi/models/volume.rb
> index 5ce0fbc..eca5cc1 100644
> --- a/server/lib/cimi/models/volume.rb
> +++ b/server/lib/cimi/models/volume.rb
> @@ -94,7 +94,7 @@ class CIMI::Model::Volume < CIMI::Model::Base
>                  :description => volume.id,
>                  :created => Time.parse(volume.created).xmlschema,
>                  :id => context.volume_url(volume.id),
> -                :capacity => { :quantity=>volume.capacity, 
> :units=>"gibibyte"  }, #FIXME... units will vary
> +                :capacity => context.to_kibibyte(volume.capacity, 'MB'),
>                  :bootable => "false", #fixme ... will vary... ec2 doesn't 
> expose this
>                  :snapshots => [], #fixme...
>                  :type => 'http://schemas.dmtf.org/cimi/1/mapped',
> @@ -103,4 +103,18 @@ class CIMI::Model::Volume < CIMI::Model::Base
>              } )
>    end
>  
> +  def self.collection_for_instance(instance_id, context)
> +    instance = context.driver.instance(context.credentials, :id => 
> instance_id)
> +    volumes = instance.storage_volumes.map do |mappings|
> +      mappings.keys.map { |volume_id| 
> from_storage_volume(context.driver.storage_volume(context.credentials, :id => 
> volume_id), context) }
> +    end.flatten
> +    CIMI::Model::VolumeCollection.new(
> +      :id => context.url("/machines/#{instance_id}/volumes"),
> +      :name => 'default',
> +      :count => volumes.size,
> +      :description => "Volume collection for Machine #{instance_id}",
> +      :entries => volumes
> +    )
> +  end
> +
>  end
> 

Reply via email to