deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH core 01/10] CIMI: Added methods for accessing Machine entities
Date Tue, 29 Nov 2011 15:32:40 GMT
ACK to the entire patch_nuke

On 29/11/11 15:44, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mfojtik@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
> ---
>  server/lib/cimi/model/machine.rb |   12 ++++++++++++
>  server/lib/cimi/server.rb        |   31 ++++++++-----------------------
>  2 files changed, 20 insertions(+), 23 deletions(-)
> 
> diff --git a/server/lib/cimi/model/machine.rb b/server/lib/cimi/model/machine.rb
> index 932acdf..4ad4732 100644
> --- a/server/lib/cimi/model/machine.rb
> +++ b/server/lib/cimi/model/machine.rb
> @@ -54,4 +54,16 @@ class CIMI::Model::Machine < CIMI::Model::Base
>      scalar :rel, :href
>    end
>  
> +  def self.find(id, _self)
> +    instances = []
> +    if id == :all
> +      instances = _self.driver.instances(_self.credentials)
> +      instances.map { |instance| from_instance(instance, _self) }.compact
> +    else
> +      instance = _self.driver.instance(_self.credentials, id)
> +      from_instance(instance, _self)
> +    end
> +  end
> +
> +
>  end
> diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
> index 3b3e7d0..b05fa31 100644
> --- a/server/lib/cimi/server.rb
> +++ b/server/lib/cimi/server.rb
> @@ -159,16 +159,11 @@ global_collection :machines do
>    operation :index do
>      description "List all machines"
>      control do
> -      instances = driver.send(:instances, credentials, {})
> -      @dmtf_col_items = []
> -      if instances
> -        instances.map do |instance|
> -          new_item = { "name" => instance.name,
> -            "href" => machine_url(instance.id) }
> -          @dmtf_col_items.insert 0,  new_item
> -        end
> +      machines = Machine.all(self)
> +      respond_to do |format|
> +        format.xml { machines.to_xml_cimi_collection(self) }
> +        format.json { machines.to_json_cimi_collection(self) }
>        end
> -      respond_to_collection "machine.col.xml"
>      end
>    end
>  
> @@ -177,20 +172,10 @@ global_collection :machines do
>      with_capability :instance
>      param :id,          :string,    :required
>      control do
> -      @machine = driver.send(:instance, credentials, { :id => params[:id]} )
> -      if @machine
> -        #setup the default values for a machine imageion
> -        resource_default = get_resource_default "machine"
> -        #get the actual values from image
> -        resource_value = { "name" => @machine.name,
> -          "status" => @machine.state, "uri" => @machine.id,
> -          "href" => machine_url(@machine.id) }
> -        #mixin actual values get from the specific image
> -        @dmtfitem = resource_default["dmtfitem"].merge resource_value
> -        show_resource "machines/show", "Machine",
> -          {"property" => "properties", "disk" => "disks", "operation" => "operations"}
> -      else
> -        report_error(404)
> +      machine = Machine.find(params[:id], self)
> +      respond_to do |format|
> +        format.xml { machine.to_xml }
> +        format.json { machine.to_json }
>        end
>      end
>    end


Mime
View raw message