[Users] Problems using the PythonSDK

Itamar Heim iheim at redhat.com
Fri May 24 12:18:03 UTC 2013


On 05/24/2013 08:04 AM, Karli Sjöberg wrote:
> tor 2013-05-23 klockan 08:53 -0400 skrev Ilia Meerovich:
>> It should be like:
>>
>> from ovirtsdk.xml import params
>> from ovirtsdk.api import API
>>
>> api = API('*', '*', '*')
>> vm = api.vms.list()[0]
>> user =  api.users.list()[1]
>> role = api.roles.list()[1]
>> permit = params.Permission()
>> permit.set_role(role)
>> permit.set_vm(vm)
>> user.permissions.add(permit)
>
> Thank you very much, I´m going to test this out today! Could you also
> show me how to first add a user that isn´t in the system yet, please?

from api or ui?
(you need to add an external directory first using the 
engine-manage-domains utility, then choose users from it)

>
>>
>>
>> ----- Original Message -----
>> From: "Ilia Meerovich" <imeerovi at redhat.com  <mailto:imeerovi at redhat.com>>
>> To: "Michael Pasternak" <mpastern at redhat.com  <mailto:mpastern at redhat.com>>
>> Cc: "users" <users at ovirt.org  <mailto:users at ovirt.org>>, "Karli Sjöberg" <Karli.Sjoberg at slu.se  <mailto:Karli.Sjoberg at slu.se>>, "Elena Dolinin" <edolinin at redhat.com  <mailto:edolinin at redhat.com>>
>> Sent: Thursday, May 23, 2013 3:30:27 PM
>> Subject: Re: [Users] Problems using the PythonSDK
>>
>> Hi,
>>
>> We have several tests like:
>> "Add VM permission to user", that are using ART's art/rhevm_api/tests_lib/low_level/mla.py addPermitsToUser function.
>> This is generic function but it shouldn't be hard to prepare SDK code with the same functionality.
>>
>> Thanks
>> Ilia
>>
>> ----- Original Message -----
>> From: "Michael Pasternak" <mpastern at redhat.com  <mailto:mpastern at redhat.com>>
>> To: "Karli Sjöberg" <Karli.Sjoberg at slu.se  <mailto:Karli.Sjoberg at slu.se>>, "Elena Dolinin" <edolinin at redhat.com  <mailto:edolinin at redhat.com>>, "Ilia Meerovich" <imeerovi at redhat.com  <mailto:imeerovi at redhat.com>>
>> Cc: "users" <users at ovirt.org  <mailto:users at ovirt.org>>
>> Sent: Thursday, May 23, 2013 3:10:21 PM
>> Subject: Re: [Users] Problems using the PythonSDK
>>
>>
>> Hi Karli,
>>
>> On 05/23/2013 12:35 PM, Karli Sjöberg wrote:
>> > Hi!
>> >
>> > We´re in the process of building an orderportal where our customers will be able to log in, select a virtual machine template, type in a desired hostname and it will be
>> > automatically created, and they recieve a mail explaining what they´ve gotten themselves into:). For this I figured the PythonSDK would be the best choice but I´m having
>> > trouble using it. What we´ve done so far is:
>> >
>> > 1) Create a new VM from a template; OK. I found an example and it worked OOTB
>> > 2) Rename the new VM´s disk from ${TemplateName}_Disk1 to ${VMName}_Disk1; Not OK. I found an example of how to change the name of a VMNic and that works, but using the
>> > same method to change VMDisk´s name does not (FYI, the VM only has one VNic and VDisk):
>> >>>> from ovirtsdk.xml import params
>> >>>> from ovirtsdk.api import API
>> >>>> api = API(url='https://${ENGINE}:443/api', <https://storm.slu.se:443/api',> ca_file='${CACERT}', username='admin at internal <mailto:'admin at internal>', password='letmein!')
>> >>>> vm = api.vms.get(name='VMName')
>> >
>> >>>> vmnic = vm.nics.get(name='*')
>> >>>> vmnic.name
>> > 'nic1'
>> >>>> api.vms.get(name='VMName').nics.get(name='*')
>> > 'nic1'
>> >>>> vmnic.name='nic2'
>> >>>> vmnic.update()
>> >>>> api.vms.get(name='VMName').nics.get(name='*')
>> > 'nic2'
>> >>>> vmnic.name
>> > 'nic2'
>> >
>> >>>> vmdisk = vm.disks.get(name='*')
>> >>>> vmdisk.name
>> > 'TemplateName_Disk1'
>> >>>> api.vms.get(name='VMName').disks.get(name='*')
>>
>> this kind of call is not efficient, by fetching the disk
>> you also fetch the vm,
>>
>> i'd suggest fetch vm, store it in local variable and then
>> reuse it for any sub-collection manipulations.
>>
>>
>> > 'TemplateName_Disk1'
>> >>>> vmdisk.name='VMName_Disk1'
>> >>>> vmdisk.update()
>> >>>> vmdisk.name
>> > 'VMName_Disk1'
>> >>>> api.vms.get(name='VMName').disks.get(name='*')
>> > 'TemplateName_Disk1'
>> >
>> > See? Am I holding it wrong?
>>
>> disk.name is deprecated, please use 'alias' instead.
>>
>> >
>> > 3) Create a snapshot called "Origin", so if a customer calls in and says they´ve borked it completely, we´ll just revert to it´s "Origin" and they´re up and running again;
>> > OK, found another OOTB example, thank you.
>> > 4) Add the customer to VM´s Permissions with an appropriate role; Not OK. I have found no examples on how to do this and just don´t know where to start looking. BTW,
>> > creating a new VM with Python results in Permissions completely empty, no inheritance either. Don´t know if that is intended...
>>
>> elena, ilia,
>>
>> guys, do you have any permission related code to share?
>>
>> >
>> > client# rpm -qa | grep ovirt
>> > ovirt-engine-cli-3.2.0.11-1.fc17.noarch
>> > ovirt-engine-sdk-3.2.0.10-1.fc17.noarch
>> >
>> > engine# rpm -qa | grep ovirt
>> > ovirt-engine-config-3.1.0-4.fc17.noarch
>> > ovirt-engine-dbscripts-3.1.0-4.fc17.noarch
>> > ovirt-log-collector-3.1.0-0.git10d719.fc17.noarch
>> > ovirt-engine-restapi-3.1.0-4.fc17.noarch
>> > ovirt-image-uploader-3.1.0-0.git9c42c8.fc17.noarch
>> > ovirt-engine-genericapi-3.1.0-4.fc17.noarch
>> > ovirt-iso-uploader-3.1.0-0.git1841d9.fc17.noarch
>> > ovirt-engine-webadmin-portal-3.1.0-4.fc17.noarch
>> > ovirt-engine-setup-3.1.0-4.fc17.noarch
>> > ovirt-engine-sdk-3.2.0.2-1.fc17.noarch
>> > ovirt-engine-backend-3.1.0-4.fc17.noarch
>> > ovirt-engine-tools-common-3.1.0-4.fc17.noarch
>> > ovirt-engine-3.1.0-4.fc17.noarch
>> > ovirt-engine-userportal-3.1.0-4.fc17.noarch
>> > ovirt-engine-notification-service-3.1.0-4.fc17.noarch
>> >
>> > --
>> >
>> > Best Regards
>> > -------------------------------------------------------------------------------
>> > Karli Sjöberg
>> > Swedish University of Agricultural Sciences
>> > Box 7079 (Visiting Address Kronåsvägen 8)
>> > S-750 07 Uppsala, Sweden
>> > Phone:  +46-(0)18-67 15 66
>> >karli.sjoberg at slu.se  <mailto:karli.sjoberg at slu.se>  <mailto:karli.sjoberg at adm.slu.se>
>> >
>> >
>> >
>> > _______________________________________________
>> > Users mailing list
>> >Users at ovirt.org  <mailto:Users at ovirt.org>
>> >http://lists.ovirt.org/mailman/listinfo/users
>> >
>>
>>
>
> --
>
> Med Vänliga Hälsningar
> -------------------------------------------------------------------------------
> Karli Sjöberg
> Swedish University of Agricultural Sciences
> Box 7079 (Visiting Address Kronåsvägen 8)
> S-750 07 Uppsala, Sweden
> Phone:  +46-(0)18-67 15 66
> karli.sjoberg at slu.se <mailto:karli.sjoberg at adm.slu.se>
>
>
>
> _______________________________________________
> Users mailing list
> Users at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/users
>




More information about the Users mailing list