[ovirt-users] Removing all the Users Permission on Data Center

Manuel Luis Aznar manuel.luis.aznar at gmail.com
Wed Feb 22 09:16:31 UTC 2017


Hello there,

I need to remove the specific Users Permission a user have in a DataCenter.

I manage to do it in this way:

username = "..."
dc = "..."

system_service = connection.system_service()
users_service = system_service.users_service()
data_centers_service = system_service.data_centers_service()

# Getting the User object
for user in users_service.list():
    if username in user.user_name:
        break

# Getting the DataCenter object
for data_center in data_centers_service.list():
    if dc in data_center.name:
        break

# Getting DataCenter service and its Permission Service
data_center_service = data_centers_service.data_center_service(id=
data_center.id)
data_center_permissions_service = data_center_service.permissions_service()

# Getting the Permission for the User in the DataCenter
for data_center_permission in data_center_permissions_service.list():
    data_center_permission_user = data_center_permission.user
    if data_center_permission_user:
        if data_center_permission_user.id == user.id:
            data_center_permission_user.remove()

As you can see I can do it, but, I am using the permissions of the
DataCenter and this list could be very long.

In the old ovirtsdk (version 3) this was done by the following:

u = kvm.users.get(id=userid)
for perm in u.permissions.list():
   udc = perm.get_data_center()
      if udc:
         globaldc = kvm.datacenters.get(id=udc.get_id())
         if globaldc.get_name() == dc:
            perm.delete()

that last piece of code iterate by the user permission list and delete the
specific Data Center permission. I have been trying this doing the
following:

user_service = users_service.user_service(id=user.id)

user_permissions_service = user_service.permissions_service()

list = user_permissions_service.list()

Is that last variable, list: the permissions list for the specified user, I
ask that because if I print the size of the list for an specific user, the
number I get is not correct...

Thanks for all in advance to all
Manuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/users/attachments/20170222/0aefbf0b/attachment.html>


More information about the Users mailing list