<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 6, 2017 at 3:51 PM, Nathanaël Blanchet <span dir="ltr"><<a href="mailto:blanchet@abes.fr" target="_blank">blanchet@abes.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">There was a last error in the script :<br>
<br>
snap_service = snaps_service.snapshot_service<wbr>(<a href="http://snap.id" rel="noreferrer" target="_blank">snap.id</a>) instead of snap_service = snaps_service.snap_service(<a href="http://snap.id" rel="noreferrer" target="_blank">sna<wbr>p.id</a>)<br>
<br>
For those who are interested in using a full remove_vm_snapshot working script:<br></blockquote><div><br></div><div>Perhaps worth contributing to the examples[1] of the SDK?</div><div>Y.</div><div><br></div><div>[1] <a href="https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples">https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples</a></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
# Create the connection to the server:<br>
connection = sdk.Connection(<br>
url='<a href="https://engine/ovirt-engine/api" rel="noreferrer" target="_blank">https://engine/ovirt-engi<wbr>ne/api</a>',<br>
username='admin@internal',<br>
password='passwd',<br>
# ca_file='ca.pem',<br>
insecure=True,<br>
debug=True,<br>
log=logging.getLogger(),<br>
)<br>
<br>
# Locate the virtual machines service and use it to find the virtual<br>
# machine:<br>
vms_service = connection.system_service().vm<wbr>s_service()<span class="gmail-"><br>
vm = vms_service.list(search='name=<wbr>myvm')[0]<br>
<br></span>
# Locate the service that manages the snapshots of the virtual machine:<span class="gmail-"><br>
vm_service = vms_service.vm_service(<a href="http://vm.id" rel="noreferrer" target="_blank">vm.id</a>)<br>
snaps_service = vm_service.snapshots_service()<br>
snaps = snaps_service.list()<br></span><span class="gmail-">
snap = [s for s in snaps if s.description == 'My snapshot2'][0]<br>
<br></span>
# Remove the snapshot:<br>
snap_service = snaps_service.snapshot_service<wbr>(<a href="http://snap.id" rel="noreferrer" target="_blank">snap.id</a>)<br>
snap_service.remove()<br>
<br>
# Close the connection to the server:<br>
connection.close()<div class="gmail-HOEnZb"><div class="gmail-h5"><br>
<br>
Le 06/01/2017 à 14:44, Nathanaël Blanchet a écrit :<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
Le 06/01/2017 à 13:39, Juan Hernández a écrit :<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On 01/06/2017 12:20 PM, Nathanaël Blanchet wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Le 04/01/2017 à 18:55, Juan Hernández a écrit :<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On 01/04/2017 05:38 PM, Nathanaël Blanchet wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Le 04/01/2017 à 15:41, Juan Hernández a écrit :<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On 01/04/2017 12:30 PM, Yaniv Kaul wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On Wed, Jan 4, 2017 at 1:04 PM, Nicolas Ecarnot <<a href="mailto:nicolas@ecarnot.net" target="_blank">nicolas@ecarnot.net</a><br>
<mailto:<a href="mailto:nicolas@ecarnot.net" target="_blank">nicolas@ecarnot.net</a>>> wrote:<br>
<br>
Hello,<br>
<br>
Le 04/01/2017 à 11:49, Nathanaël Blanchet a écrit :<br>
<br>
<br>
<br>
Le 04/01/2017 à 10:09, Andrea Ghelardi a écrit :<br>
<br>
<br>
Personally I don’t think ansible and ovirt-shell are<br>
mutually exclusive.<br>
<br>
Those who are in ansible and devops realms are not<br>
really<br>
scared by<br>
making python/ansible work with ovirt.<br>
<br>
From what I gather, playbooks are quite a de-facto<br>
pre-requisite to<br>
build up a real SaaC “Software as a Code” environment.<br>
<br>
<br>
<br>
On the other hand, ovirt-shell can and is a fast/easy<br>
way to<br>
perform<br>
“normal daily tasks”.<br>
<br>
totally agree but ovirt-shell is deprecated in 4.1 et<br>
will be<br>
removed in<br>
4.2. Ansible or sdk4 are proposed as an alternative.<br>
<br>
<br>
Could someone point me to an URL where sdk4 is fully<br>
documented, as<br>
I have to get ready for ovirt-shell deprecation?<br>
<br>
<br>
The Rest API is partially documented under<br>
https://<engine>/api/model .<br>
It's not complete yet. All new features in 4.0 are documented and<br>
we are<br>
working on the 'older' features now.<br>
(contributions are welcome!)<br>
<br>
<br>
I'm sure no one at Redhat thought about deprecating a tool in<br>
favor<br>
of a new one before providing a complete user doc!<br>
<br>
<br>
In addition, the SDK RPM itself contains many examples. See [1].<br>
(contributions are welcome!)<br>
<br>
Y.<br>
<br>
[1] <a href="https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples" rel="noreferrer" target="_blank">https://github.com/oVirt/ovirt<wbr>-engine-sdk/tree/master/sdk/<wbr>examples</a><br>
<br>
</blockquote></blockquote>
Although these examples, I can successfully create a snapshot, but I<br>
didn't find the way to delete it...<br>
Regarding many example, it should be possible to locate any service by :<br>
name_service = connection.system_service().na<wbr>me.service()<br>
<br>
So logically it should be doable with snapshot like<br>
snapshots_service = connection.system_service().sn<wbr>apshots.service()<br>
but : AttributeError: 'SystemService' object has no attribute 'snapshots<br>
<br>
</blockquote>
In the SDK the services are arranged in a tree structure that mimics the<br>
URL structure of the API. For example, if you want to get the service<br>
that manages a particular snapshot, in the API you would use an URL like<br>
this:<br>
<br>
/ovirt-engine/api/vms/123/snap<wbr>shots/456<br>
<br>
In the Python SDK that translates into this:<br>
<br>
snap_service = connection.system_service() \<br>
.vms_service() \<br>
.vm_service('123') \<br>
.snapshots_service() \<br>
.snapshot_service('456')<br>
<br>
There is also a generic "service" method that is useful when you already<br>
have all that path as an string:<br>
<br>
snap_service = connection.service("vms/123/sn<wbr>apshots/456")<br>
<br>
Both return exactly the same object. The first is usually better when<br>
you are calculating the path of the object step by step, and I generally<br>
prefer it as it is less error prone.<br>
<br>
Once you have the reference to the service, you can use the 'remove'<br>
method:<br>
<br>
snap_service.remove()<br>
<br>
If you need to search by the names of the objects, then you can use the<br>
'search' methods, which are only available for the top level objects,<br>
like VM, data centers, clusters, etc. For example, to find your virtual<br>
machine and then the snapshot:<br>
<br>
# Get the root service:<br>
system_service = connection.system_service()<br>
<br>
# Find the virtual machine:<br>
vms_service = system_service.vms_service()<br>
vm = vms_service.list(search='name=<wbr>myvm')[0]<br>
<br>
# Find the snapshot:<br>
vm_service = vms_service.vm_service(<a href="http://vm.id" rel="noreferrer" target="_blank">vm.id</a>)<br>
snaps_service = vm_service.snapshots_service()<br>
snaps = snaps_service.list()<br>
snap = [s for s in snaps where s.description == 'My snap'][0]<br>
</blockquote>
sounds good, thank so much for taking time to explain, but for the last<br>
entry, I get ;<br>
<br>
snap = [s for s in snaps where s.description == 'My snapshot2'][0]<br>
^<br>
SyntaxError: invalid syntax<br>
</blockquote>
I apologize, I wrote that too fast. That is SQL syntax, not Python. In<br>
python should be "if" instead of "where":<br>
<br>
snap = [s for s in snaps if s.description == 'My snapshot2'][0]<br>
</blockquote>
Thank you, it's ok for now.<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
May I use a version 3 of python?<br>
</blockquote>
You SDK supports both Python 2 and Python 3. If you are using the RPMs<br>
make sure to install the 'python3-ovirt-engine-sdk4' package.<br>
</blockquote>
<br>
python3-ovirt-engine-sdk4 doesn't exist in repos, only python-ovirt-engine-sdk4<br>
Thanks to your explanations, I begin to understand the philosophy of this sdk, it's far different from sdk3.<br>
What's was wrong with the v3, what was the motivation to write a new version?<br>
Will it be possible to use the old sdk3 (manually installed) for old scripts in ovirt 4.2 ?<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Note that both are supported, but Python 3 doesn't get a lot of<br>
attention yet, so you may find issues. If you find any issue with Python<br>
3 let as know, as we are committed to make it work.<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
# Remove the snapshot:<br>
snap_service = snaps_service.snap_service(<a href="http://snap.id" rel="noreferrer" target="_blank">sna<wbr>p.id</a>)<br>
snap_service.remove()<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I saw an example into the ansible [ working ] way to do the same thing<br>
and I found this :<br>
snapshot =<br>
snapshots_service.snapshot_ser<wbr>vice(module.params['snapshot_<wbr>id']).get() <br>
<br>
How can I get this working with sdk, I mean giving snapshot_id as a<br>
parameter?<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Also the complete reference documentation of the Python SDK is<br>
available<br>
here:<br>
<br>
<a href="http://ovirt.github.io/ovirt-engine-sdk/v4.0/4.0.3/index.html" rel="noreferrer" target="_blank">http://ovirt.github.io/ovirt-e<wbr>ngine-sdk/v4.0/4.0.3/index.htm<wbr>l</a><br>
<br>
There also SDKs for Ruby and Java, in case Python is not your preferred<br>
language:<br>
<br>
Ruby:<br>
<a href="https://github.com/oVirt/ovirt-engine-sdk-ruby/tree/master/sdk" rel="noreferrer" target="_blank">https://github.com/oVirt/ovirt<wbr>-engine-sdk-ruby/tree/master/<wbr>sdk</a><br>
<a href="https://github.com/oVirt/ovirt-engine-sdk-ruby/tree/master/sdk/examples" rel="noreferrer" target="_blank">https://github.com/oVirt/ovirt<wbr>-engine-sdk-ruby/tree/master/<wbr>sdk/examples</a> <br>
<a href="http://www.rubydoc.info/gems/ovirt-engine-sdk" rel="noreferrer" target="_blank">http://www.rubydoc.info/gems/<wbr>ovirt-engine-sdk</a><br>
<br>
Java:<br>
<a href="https://github.com/oVirt/ovirt-engine-sdk-java/tree/master/sdk" rel="noreferrer" target="_blank">https://github.com/oVirt/ovirt<wbr>-engine-sdk-java/tree/master/<wbr>sdk</a><br>
<br>
<a href="https://github.com/oVirt/ovirt-engine-sdk-java/tree/master/sdk/src/test/java/org/ovirt/engine/sdk4/examples" rel="noreferrer" target="_blank">https://github.com/oVirt/ovirt<wbr>-engine-sdk-java/tree/master/<wbr>sdk/src/test/java/org/ovirt/<wbr>engine/sdk4/examples</a> <br>
<br>
<br>
<a href="http://www.javadoc.io/doc/org.ovirt.engine.api/sdk" rel="noreferrer" target="_blank">http://www.javadoc.io/doc/<wbr>org.ovirt.engine.api/sdk</a><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
--<br>
Nicolas ECARNOT<br>
<br>
_____________________________<wbr>__________________<br>
Users mailing list<br>
<a href="mailto:Users@ovirt.org" target="_blank">Users@ovirt.org</a> <mailto:<a href="mailto:Users@ovirt.org" target="_blank">Users@ovirt.org</a>><br>
<a href="http://lists.ovirt.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailma<wbr>n/listinfo/users</a><br>
<<a href="http://lists.ovirt.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailma<wbr>n/listinfo/users</a>><br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
Users mailing list<br>
<a href="mailto:Users@ovirt.org" target="_blank">Users@ovirt.org</a><br>
<a href="http://lists.ovirt.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman<wbr>/listinfo/users</a><br>
<br>
</blockquote>
______________________________<wbr>_________________<br>
Users mailing list<br>
<a href="mailto:Users@ovirt.org" target="_blank">Users@ovirt.org</a><br>
<a href="http://lists.ovirt.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman<wbr>/listinfo/users</a><br>
</blockquote></blockquote></blockquote></blockquote></blockquote>
<br>
</blockquote>
<br>
-- <br>
Nathanaël Blanchet<br>
<br>
Supervision réseau<br>
Pôle Infrastrutures Informatiques<br>
227 avenue Professeur-Jean-Louis-Viala<br>
34193 MONTPELLIER CEDEX 5 <br>
Tél. 33 (0)4 67 54 84 55<br>
Fax 33 (0)4 67 54 84 14<br>
<a href="mailto:blanchet@abes.fr" target="_blank">blanchet@abes.fr</a><br>
<br>
______________________________<wbr>_________________<br>
Users mailing list<br>
<a href="mailto:Users@ovirt.org" target="_blank">Users@ovirt.org</a><br>
<a href="http://lists.ovirt.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman<wbr>/listinfo/users</a><br>
</div></div></blockquote></div><br></div></div>