[Ovirt-devel] [PATCH 4/6] hardware_pool: search by path

Scott Seago sseago at redhat.com
Mon Aug 18 13:25:21 UTC 2008


David Lutterkort wrote:
> Signed-off-by: David Lutterkort <dlutter at redhat.com>
> ---
>  wui/src/app/models/hardware_pool.rb |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)
>
> diff --git a/wui/src/app/models/hardware_pool.rb b/wui/src/app/models/hardware_pool.rb
> index 276779f..249d744 100644
> --- a/wui/src/app/models/hardware_pool.rb
> +++ b/wui/src/app/models/hardware_pool.rb
> @@ -97,4 +97,16 @@ class HardwarePool < Pool
>      return {:total => total, :labels => labels}
>    end
>  
> +  def self.find_by_path(path)
> +      segs = path.split("/")
> +      unless segs.shift.empty?
> +          raise "Path must be absolute, but is #{path}"
> +      end
> +      if segs.shift == "default"
> +          segs.inject(get_default_pool) do |pool, seg|
> +              pool.sub_hardware_pools.find { |p| p.name == seg } if pool
> +          end
> +      end
> +  end
> +
>  end
>   
We shouldn't assume that the default pool happens to be named 'default'. 
I'm not sure the best way to do this, but one way is to treat the 
default pool as having path "/". So Pool.find_by_path("/") would return 
the default pool, and Pool.find_by_path("/engineering/QA") would start 
with the default pool, find a subpool named "engineering" and a subpool 
of engineering called "QA".

Scott




More information about the ovirt-devel mailing list