[ovirt-users] Request for oVirt Ansible modules testing feedback

Juan Hernández jhernand at redhat.com
Tue Jan 10 15:38:32 UTC 2017


On 01/06/2017 02:44 PM, Nathanaël Blanchet wrote:
> 
> 
> Le 06/01/2017 à 13:39, Juan Hernández a écrit :
>> On 01/06/2017 12:20 PM, Nathanaël Blanchet wrote:
>>>
>>> Le 04/01/2017 à 18:55, Juan Hernández a écrit :
>>>> On 01/04/2017 05:38 PM, Nathanaël Blanchet wrote:
>>>>> Le 04/01/2017 à 15:41, Juan Hernández a écrit :
>>>>>> On 01/04/2017 12:30 PM, Yaniv Kaul wrote:
>>>>>>> On Wed, Jan 4, 2017 at 1:04 PM, Nicolas Ecarnot <nicolas at ecarnot.net
>>>>>>> <mailto:nicolas at ecarnot.net>> wrote:
>>>>>>>
>>>>>>>        Hello,
>>>>>>>
>>>>>>>        Le 04/01/2017 à 11:49, Nathanaël Blanchet a écrit :
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>            Le 04/01/2017 à 10:09, Andrea Ghelardi a écrit :
>>>>>>>
>>>>>>>
>>>>>>>                Personally I don’t think ansible and ovirt-shell are
>>>>>>>                mutually exclusive.
>>>>>>>
>>>>>>>                Those who are in ansible and devops realms are not
>>>>>>> really
>>>>>>>                scared by
>>>>>>>                making python/ansible work with ovirt.
>>>>>>>
>>>>>>>                From what I gather, playbooks are quite a de-facto
>>>>>>>                pre-requisite to
>>>>>>>                build up a real SaaC “Software as a Code”
>>>>>>> environment.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>                On the other hand, ovirt-shell can and is a fast/easy
>>>>>>> way to
>>>>>>>                perform
>>>>>>>                “normal daily tasks”.
>>>>>>>
>>>>>>>            totally agree but ovirt-shell is deprecated in 4.1 et
>>>>>>> will be
>>>>>>>            removed in
>>>>>>>            4.2. Ansible or sdk4 are proposed as an alternative.
>>>>>>>
>>>>>>>
>>>>>>>        Could someone point me to an URL where sdk4 is fully
>>>>>>> documented, as
>>>>>>>        I have to get ready for ovirt-shell deprecation?
>>>>>>>
>>>>>>>
>>>>>>> The Rest API is partially documented under
>>>>>>> https://<engine>/api/model .
>>>>>>> It's not complete yet. All new features in 4.0 are documented and
>>>>>>> we are
>>>>>>> working on the 'older' features now.
>>>>>>> (contributions are welcome!)
>>>>>>>
>>>>>>>
>>>>>>>        I'm sure no one at Redhat thought about deprecating a tool in
>>>>>>> favor
>>>>>>>        of a new one before providing a complete user doc!
>>>>>>>
>>>>>>>
>>>>>>> In addition, the SDK RPM itself contains many examples. See [1].
>>>>>>> (contributions are welcome!)
>>>>>>>
>>>>>>> Y.
>>>>>>>
>>>>>>> [1]
>>>>>>> https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples
>>>>>>>
>>>>> Although these examples, I can successfully create a snapshot, but I
>>>>> didn't find the way to delete it...
>>>>> Regarding many example, it should be possible to locate any service
>>>>> by :
>>>>> name_service = connection.system_service().name.service()
>>>>>
>>>>> So logically it should be doable with snapshot like
>>>>> snapshots_service = connection.system_service().snapshots.service()
>>>>> but : AttributeError: 'SystemService' object has no attribute
>>>>> 'snapshots
>>>>>
>>>> In the SDK the services are arranged in a tree structure that mimics
>>>> the
>>>> URL structure of the API. For example, if you want to get the service
>>>> that manages a particular snapshot, in the API you would use an URL
>>>> like
>>>> this:
>>>>
>>>>     /ovirt-engine/api/vms/123/snapshots/456
>>>>
>>>> In the Python SDK that translates into this:
>>>>
>>>>     snap_service = connection.system_service() \
>>>>       .vms_service() \
>>>>       .vm_service('123') \
>>>>       .snapshots_service() \
>>>>       .snapshot_service('456')
>>>>
>>>> There is also a generic "service" method that is useful when you
>>>> already
>>>> have all that path as an string:
>>>>
>>>>     snap_service = connection.service("vms/123/snapshots/456")
>>>>
>>>> Both return exactly the same object. The first is usually better when
>>>> you are calculating the path of the object step by step, and I
>>>> generally
>>>> prefer it as it is less error prone.
>>>>
>>>> Once you have the reference to the service, you can use the 'remove'
>>>> method:
>>>>
>>>>     snap_service.remove()
>>>>
>>>> If you need to search by the names of the objects, then you can use the
>>>> 'search' methods, which are only available for the top level objects,
>>>> like VM, data centers, clusters, etc. For example, to find your virtual
>>>> machine and then the snapshot:
>>>>
>>>>     # Get the root service:
>>>>     system_service = connection.system_service()
>>>>
>>>>     # Find the virtual machine:
>>>>     vms_service = system_service.vms_service()
>>>>     vm = vms_service.list(search='name=myvm')[0]
>>>>
>>>>     # Find the snapshot:
>>>>     vm_service = vms_service.vm_service(vm.id)
>>>>     snaps_service = vm_service.snapshots_service()
>>>>     snaps = snaps_service.list()
>>>>     snap = [s for s in snaps where s.description == 'My snap'][0]
>>> sounds good, thank so much for taking time to explain, but for the last
>>> entry, I get ;
>>>
>>> snap = [s for s in snaps where s.description == 'My snapshot2'][0]
>>>                                             ^
>>> SyntaxError: invalid syntax
>> I apologize, I wrote that too fast. That is SQL syntax, not Python. In
>> python should be "if" instead of "where":
>>
>>    snap = [s for s in snaps if s.description == 'My snapshot2'][0]
> Thank you, it's ok for now.
>>
>>> May I use a version 3 of python?
>> You SDK supports both Python 2 and Python 3. If you are using the RPMs
>> make sure to install the 'python3-ovirt-engine-sdk4' package.
> 
> python3-ovirt-engine-sdk4 doesn't exist in repos, only
> python-ovirt-engine-sdk4

Maybe you are using CentOS 7, where there is no Python 3. For
distributions that are supported by oVirt, and where there is Python 3
available, we have the RPMs. For example for Fedora 23:


http://resources.ovirt.org/pub/ovirt-4.0/rpm/fc23/x86_64/python3-ovirt-engine-sdk4-4.0.4-1.fc23.x86_64.rpm

However, the primary distribution mechanism of the SDK is not RPM, but PyPI:

  https://pypi.python.org/pypi/ovirt-engine-sdk-python

If you managed to get Python 3 installed in your environment, then you
can install the Python 3 SDK like this:

  pip3 install ovirt-engine-sdk

Note that installing the SDK in this way will require to build the C
extensions that it contains, so before installing it make sure to
install the 'gcc', 'python3-devel' and 'libxml2-devel' packages, as
described here:

  https://github.com/oVirt/ovirt-engine-sdk#building

> Thanks to your explanations, I begin to understand the philosophy of
> this sdk, it's far different from sdk3.
> What's was wrong with the v3, what was the motivation to write a new
> version?

The implementation of version 3 of the SDK was based on a tool called
'generateDS.py', which generates Python code from XML schema. The XML
schema used by the engine was in turn tuned for its own internal
implementation details, which uses Java and the JAXB XML schema
compiler. The result was Python code that was difficult to maintain,
performs poorly, and doesn't support Python 3. To fix those issues, and
many other issues (in the server side, in the Java SDK, etc), we needed
to introduce a new mechanism to specify the API, and that requires a
different SDK, that does not use the 'generateDS.py' tool.

> Will it be possible to use the old sdk3 (manually installed) for old
> scripts in ovirt 4.2 ?
> 

No, we will remove version 3 of the API from the server, so no client
will be able to use the API unless it uses version 4.

>>
>> Note that both are supported, but Python 3 doesn't get a lot of
>> attention yet, so you may find issues. If you find any issue with Python
>> 3 let as know, as we are committed to make it work.
>>
>>>>     # Remove the snapshot:
>>>>     snap_service = snaps_service.snap_service(snap.id)
>>>>     snap_service.remove()
>>>>
>>>>> I saw an example into the ansible [ working ] way to do the same thing
>>>>> and I found this :
>>>>> snapshot =
>>>>> snapshots_service.snapshot_service(module.params['snapshot_id']).get()
>>>>>
>>>>> How can I get this working with sdk, I mean giving snapshot_id as a
>>>>> parameter?
>>>>>
>>>>>
>>>>>> Also the complete reference documentation of the Python SDK is
>>>>>> available
>>>>>> here:
>>>>>>
>>>>>>      http://ovirt.github.io/ovirt-engine-sdk/v4.0/4.0.3/index.html
>>>>>>
>>>>>> There also SDKs for Ruby and Java, in case Python is not your
>>>>>> preferred
>>>>>> language:
>>>>>>
>>>>>>      Ruby:
>>>>>>      https://github.com/oVirt/ovirt-engine-sdk-ruby/tree/master/sdk
>>>>>>   
>>>>>> https://github.com/oVirt/ovirt-engine-sdk-ruby/tree/master/sdk/examples
>>>>>>
>>>>>>      http://www.rubydoc.info/gems/ovirt-engine-sdk
>>>>>>
>>>>>>      Java:
>>>>>>      https://github.com/oVirt/ovirt-engine-sdk-java/tree/master/sdk
>>>>>>
>>>>>> https://github.com/oVirt/ovirt-engine-sdk-java/tree/master/sdk/src/test/java/org/ovirt/engine/sdk4/examples
>>>>>>
>>>>>>
>>>>>>
>>>>>>      http://www.javadoc.io/doc/org.ovirt.engine.api/sdk
>>>>>>
>>>>>>>        --
>>>>>>>        Nicolas ECARNOT
>>>>>>>
>>>>>>>        _______________________________________________
>>>>>>>        Users mailing list
>>>>>>>        Users at ovirt.org <mailto:Users at ovirt.org>
>>>>>>>        http://lists.ovirt.org/mailman/listinfo/users
>>>>>>>        <http://lists.ovirt.org/mailman/listinfo/users>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Users mailing list
>>>>>>> Users at ovirt.org
>>>>>>> http://lists.ovirt.org/mailman/listinfo/users
>>>>>>>
>>>>>> _______________________________________________
>>>>>> Users mailing list
>>>>>> Users at ovirt.org
>>>>>> http://lists.ovirt.org/mailman/listinfo/users
> 



More information about the Users mailing list