Hi David,

> I am not 100% sure I understand what you are suggesting, but I think you
> are saying that the instances method in each driver should support an
> additional filter param 'system_id' .. is that correct ?

Yes. Well... In each driver that supports systems natively.
I think for drivers that don't support systems natively, e.g. where the system 
concept is implemented as a collection of resource ids in DC's DB, there is no 
point in adding this param to the driver class.

> If so, I am all for it. Do we need a way to introspect whether instances
> accepts a :system_id param ?

Yes, that will be the way how we can tell whether to call its instances method 
with the system_id, or get the instance ids from the DB?

> As I understand it, the find method in CIMI::Model::SystemMachine needs
> to accept a system_id param to indicate what system we're looking at,
> and that param would be passed to driver.instances, i.e.
> SystemMachine#find would like something like
> 
>         def find(system_id, ctx)
>           ctx.driver.instances(ctx.credentials, :system_id =>
> system_id).map do |sm|
>             convert_system_machine(sm)
>           end
>         end

The convert method needs to convert from DC instance to CIMI Machine first, 
which can then be inlined in a SystemMachine.
And there would be the case of whether we want to find a particular instance in 
a particular system, or all instances in a particular system.
So the code would be almost exactly the same as machine#find, hence my 
suggestion to call machine#find from SystemMachine#find and passing the 
system_id to it. It saves some code duplication.

Machine.rb:

  def self.find(id, context)
    instances = []
    if id == :all
      instances = context.driver.instances(context.credentials, :system_id => 
context.params[:system_id])
      instances.map { |instance| from_instance(instance, context) }.compact
    else
      instance = context.driver.instance(context.credentials, {:id => id, 
:system_id => context.params[:system_id]})
      raise CIMI::Model::NotFound unless instance
      from_instance(instance, context)
    end
  end


Called from SystemMachine.rb:

    context.params[:system_id] = system_id
    machines = CIMI::Model::Machine.find(:all, context)

Are you still all for it now? :)

Regards,
Dies Koper


> -----Original Message-----
> From: David Lutterkort [mailto:lut...@redhat.com]
> Sent: Wednesday, 27 February 2013 9:27 AM
> To: dev@deltacloud.apache.org
> Subject: Re: design question about cimi system's subcollection
> implementations
> 
> Hi Dies,
> 
> I am not 100% sure I understand what you are suggesting, but I think you
> are saying that the instances method in each driver should support an
> additional filter param 'system_id' .. is that correct ?
> 
> As I understand it, the find method in CIMI::Model::SystemMachine needs
> to accept a system_id param to indicate what system we're looking at,
> and that param would be passed to driver.instances, i.e.
> SystemMachine#find would like something like
> 
>         def find(system_id, ctx)
>           ctx.driver.instances(ctx.credentials, :system_id =>
> system_id).map do |sm|
>             convert_system_machine(sm)
>           end
>         end
> 
> If so, I am all for it. Do we need a way to introspect whether instances
> accepts a :system_id param ?
> 
> David
> 
> On Tue, 2013-02-26 at 21:46 +1100, Koper, Dies wrote:
> > I'm looking at what the best way would be to design a cimi system's
> subcollections (SystemMachine and SystemVolume in particular), and their
> mapping to the drivers.
> >
> > Retrieval of a system (or collection of systems), gives a response that
> includes e.g. its machines:
> >
> >   <machines href="http://cimi.example.org/systems/system1/machines";
> />
> >
> > Listing the system's machines, should return a collection of
> SystemMachines, with references to the actual machines.
> >
> > <Collection xmlns="http://schemas.dmtf.org/cimi/1";
> resourceURI="http://schemas.dmtf.org/cimi/1/SystemMachineCollection";
> >
> >   <id>http://localhost:3001/cimi/systems/system1/machines</id>
> >   <count>2</count>
> >   <SystemMachine>
> >
> <id>http://localhost:3001/cimi/systems/system1/machines/inst0</id>
> >     <name>Mock Instance With Profile Change</name>
> >     <description>SystemMachine inst0 for System
> system1</description>
> >     <machine href="http://localhost:3001/cimi/machines/inst0"; />
> >    <operation rel="delete"
> href="http://localhost:3001/cimi/systems/system1/machines/inst0"; />
> >   </SystemMachine>
> > ...
> >
> > I'm considering several ways to implement this:
> > 1. From system_machine#self.find, passing the system_id to the existing
> driver.instances method to list only the instances of that system, then
> convert the instances into a SystemMachineCollection. This would be the
> most efficient way for fgcp.
> >
> > 2. Introduce a driver.system_machines method and leave it up to the
> driver how to retrieve the instances. A disadvantage is that each
> supporting driver relying on instances() would have to do the
> instance->machine conversion themselves.
> >
> > 3. Introduce a driver.system_instances method and leave it up to the
> driver how to retrieve the instances belonging to this system. The
> instance->machine conversion would be done in system_machine#self.find
> as in 1. A disadvantage of this is the mixture of cimi and DC concepts.
> >
> > I prefer 1. Possibly by adding a "system" feature for the drivers that
> support this in their instances (and storage_volumes, keys?) methods,
> so that we can use the DB for drivers that don't.
> >
> > What do you think?
> >
> > Regards,
> > Dies Koper
> >
> > --
> > Dies KÖPER
> > Software & Solutions Architect
> >
> > Fujitsu Australia Software Technology (FAST) - Cloud Computing
> > Tel. +61 2 9452 9061 (Fujitsu internal 7985-29061)
> > di...@fast.au.fujitsu.com
> >
> >
> 
> 

Reply via email to