On Fri, Jan 6, 2017 at 3:51 PM, Nathanaël Blanchet <blanc...@abes.fr> wrote:
> There was a last error in the script : > > snap_service = snaps_service.snapshot_service(snap.id) instead of > snap_service = snaps_service.snap_service(snap.id) > > For those who are interested in using a full remove_vm_snapshot working > script: > Perhaps worth contributing to the examples[1] of the SDK? Y. [1] https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples > > # Create the connection to the server: > connection = sdk.Connection( > url='https://engine/ovirt-engine/api', > username='admin@internal', > password='passwd', > # ca_file='ca.pem', > insecure=True, > debug=True, > log=logging.getLogger(), > ) > > # Locate the virtual machines service and use it to find the virtual > # machine: > vms_service = connection.system_service().vms_service() > vm = vms_service.list(search='name=myvm')[0] > > # Locate the service that manages the snapshots of the virtual machine: > vm_service = vms_service.vm_service(vm.id) > snaps_service = vm_service.snapshots_service() > snaps = snaps_service.list() > snap = [s for s in snaps if s.description == 'My snapshot2'][0] > > # Remove the snapshot: > snap_service = snaps_service.snapshot_service(snap.id) > snap_service.remove() > > # Close the connection to the server: > connection.close() > > > Le 06/01/2017 à 14:44, Nathanaël Blanchet a écrit : > >> >> >> 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 < >>>>>>>> nico...@ecarnot.net >>>>>>>> <mailto:nico...@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 >> 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? >> Will it be possible to use the old sdk3 (manually installed) for old >> scripts in ovirt 4.2 ? >> >> >>> 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@ovirt.org <mailto:Users@ovirt.org> >>>>>>>> http://lists.ovirt.org/mailman/listinfo/users >>>>>>>> <http://lists.ovirt.org/mailman/listinfo/users> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> Users mailing list >>>>>>>> Users@ovirt.org >>>>>>>> http://lists.ovirt.org/mailman/listinfo/users >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>> Users mailing list >>>>>>> Users@ovirt.org >>>>>>> http://lists.ovirt.org/mailman/listinfo/users >>>>>>> >>>>>> >> > -- > Nathanaël Blanchet > > Supervision réseau > Pôle Infrastrutures Informatiques > 227 avenue Professeur-Jean-Louis-Viala > 34193 MONTPELLIER CEDEX 5 > Tél. 33 (0)4 67 54 84 55 > Fax 33 (0)4 67 54 84 14 > blanc...@abes.fr > > _______________________________________________ > Users mailing list > Users@ovirt.org > http://lists.ovirt.org/mailman/listinfo/users >
_______________________________________________ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users