[Users] Problems using the PythonSDK

Karli Sjöberg Karli.Sjoberg at slu.se
Tue Jun 4 09:05:19 EDT 2013


Hello everyone!

I´m almost done with Python for now. But the last thing I sitll can´t seem to get any hang on is how to change the name of a VM´s disk:

>>> from ovirtsdk.api import API
>>> from ovirtsdk.xml import params
>>> api = API(url='https://${OVIRT}:443<https://storm.slu.se:443>', ca_file='/etc/pki/ovirt-engine/ca.pem', username='admin at internal<mailto:'admin at internal>', password='letmein!')
>>> VM_NAME = 'FedoraTest'
>>> DISK_NAME = '%s_Disk1' % (VM_NAME)
>>> vm = api.vms.get(VM_NAME)
>>> vmdisk = vm.disks.list()[0]
>>> vmdisk.alias = 'foobar'
>>> vmdisk.name = 'foobar'
>>> vmdisk.update()
<ovirtsdk.infrastructure.brokers.VMDisk object at 0x25d7ad0>

But the name/alias/whatev never changes...

Could you please give me an exact, and working example of how to change the name of a VM´s disk. This is the last simple thing I would like to accomplish before sharing a little something back with y´all(teaser, teaser).

/Karli

sön 2013-05-26 klockan 02:48 -0400 skrev Ilia Meerovich:


Hi,

Lets follow http://www.ovirt.org/Python-sdk

In [1]: from ovirtsdk.xml import params

In [2]: from ovirtsdk.api import API

In [3]:

In [4]: api = API(***, ***, ***)

In [5]: user_name = "***"

In [6]: domain = "***.***.***.redhat.com"

In [7]: user_domain = params.Domain(name=domain)

In [8]: user_name = "{0}@{1}".format(user_name, domain)
# creating user
In [9]: new_user = params.User(domain=user_domain, user_name=user_name)
# adding user to users resource
In [10]: user = api.users.add(new_user)
# adding role to user
In [11]: user.roles.add(api.roles.get('UserRole'))
Out[11]: <ovirtsdk.infrastructure.brokers.UserRole object at 0x30c7590>

Thanks
Ilia

----- Original Message -----
From: "Karli Sjöberg" <Karli.Sjoberg at slu.se<mailto:Karli.Sjoberg at slu.se>>
To: "Ilia Meerovich" <imeerovi at redhat.com<mailto:imeerovi at redhat.com>>
Cc: "Michael Pasternak" <mpastern at redhat.com<mailto:mpastern at redhat.com>>, "users" <users at ovirt.org<mailto:users at ovirt.org>>, "Elena Dolinin" <edolinin at redhat.com<mailto:edolinin at redhat.com>>
Sent: Friday, May 24, 2013 8:04:43 AM
Subject: Re: [Users] Problems using the PythonSDK

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?



----- 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 slu.se>


--

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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/users/attachments/20130604/66d2ed2d/attachment-0001.html>


More information about the Users mailing list