[Ovirt-devel] [PATCH server] API: add a call to list VMs for a user

Scott Seago sseago at redhat.com
Fri Dec 12 20:51:13 UTC 2008


David Lutterkort wrote:
> Going to the URL /vms will return a list of all the VM's for which the
> current user has PRIV_VIEW permission. The VM info contains the host the VM
> is running on (if any)
> ---
>  src/app/controllers/vm_controller.rb |   14 ++++++++++++++
>  src/config/routes.rb                 |    2 +-
>  2 files changed, 15 insertions(+), 1 deletions(-)
>
> diff --git a/src/app/controllers/vm_controller.rb b/src/app/controllers/vm_controller.rb
> index ff74a37..701dea8 100644
> --- a/src/app/controllers/vm_controller.rb
> +++ b/src/app/controllers/vm_controller.rb
> @@ -25,6 +25,20 @@ class VmController < ApplicationController
>  
>    before_filter :pre_vm_action, :only => [:vm_action, :cancel_queued_tasks, :console]
>  
> +  def index
> +      roles = "('" +
> +          Permission::roles_for_privilege(Permission::PRIV_VIEW).join("', '") +
> +          "')"
> +      user = get_login_user
> +      @vms = Vm.find(:all,
> +         :joins => "join permissions p on (vm_resource_pool_id = p.pool_id)",
> +         :conditions => [ "p.uid = :user and p.user_role in #{roles}",
> +                          { :user => user }])
>   
Yeah we won't really be able to improve this much until we put the 
privilege-to-role mapping into the database...


Works for me...
ACK




More information about the ovirt-devel mailing list