Re: [ovirt-users] ovirt-engine-sdk-python-4.1 clone a vm from snapshot

2017-03-08 Thread Niyazi Elvan
Hello Juan !

Thank you very much ! I am quite new to ovirt sdk and I really appreciate
your help.

 ** with 4.0 I actually meant 3.6 , my typo :)





On Wed, Mar 8, 2017 at 9:18 PM, Juan Hernández  wrote:

> On 03/08/2017 06:53 PM, Niyazi Elvan wrote:
> > Hi Folks !
> >
> > I am looking for a documentation for ovirt-engine-sdk-python-4.1 but
> > could not find anything yet. Looks like there are many changes compared
> > to 4.0.
> >
>
> Version 4.1 of the SDK isn't very different for version 4.0. It is very
> different from version 3.6.
>
> Note that version 3 of the API, and version 3 of the SDK are deprecated
> since version 4.0 of the engine, and they will be removed in version 4.2
> of the engine.
>
> There is a general description of version 4 of the SDK here:
>
>   https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/README.adoc
>
> A collection of examples here:
>
>   https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples
>
> And reference documentation here:
>
>   http://ovirt.github.io/ovirt-engine-sdk/4.1
>
> You may also find useful the documentation of the API itself:
>
>   http://ovirt.github.io/ovirt-engine-api-model/4.1
>
> Specially the section that describes how to add virtual machines, as
> there is an example of how to add a virtual machine from a snapshot there:
>
>
> http://ovirt.github.io/ovirt-engine-api-model/4.1/#
> services/vms/methods/add
>
> > Can anyone help me about how to clone a VM from a snapshot using the
> > latest sdk ?
> >
>
> To create a virtual machine from a snapshot with the latest version of
> the SDK you will need something like this:
>
> ---8<---
> import time
>
> import ovirtsdk4 as sdk
> import ovirtsdk4.types as types
>
> # This example shows how to clone a virtual machine from an snapshot.
>
> # Create the connection to the server:
> connection = sdk.Connection(
> url='https://engine.example.com/ovirt-engine/api',
> username='admin@internal',
> password='...',
> ca_file='ca.pem'
> )
>
> # Get the reference to the root of the tree of services:
> 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 service that manages the virtual machine:
> vm_service = vms_service.vm_service(vm.id)
>
> # Find the snapshot. Note that the snapshots collection doesn't support
> # search, so we need to retrieve the complete list and the look for the
> # snapshot that has the description that we are looking for.
> snaps_service = vm_service.snapshots_service()
> snaps = snaps_service.list()
> snap = next(
>   (s for s in snaps if s.description == 'mysnap'),
>   None
> )
>
> # Create a new virtual machine, cloning it from the snapshot:
> cloned_vm = vms_service.add(
> vm=types.Vm(
> name='myclonedvm',
> snapshots=[
> types.Snapshot(
> id=snap.id
> )
> ],
> cluster=types.Cluster(
> name='mycluster'
> )
> )
> )
>
> # Find the service that manages the cloned virtual machine:
> cloned_vm_service = vms_service.vm_service(cloned_vm.id)
>
> # Wait till the virtual machine is down, as that means that the creation
> # of the disks of the virtual machine has been completed:
> while True:
> time.sleep(5)
> cloned_vm = cloned_vm_service.get()
> if cloned_vm.status == types.VmStatus.DOWN:
> break
>
> # Close the connection to the server:
> connection.close()
> --->8---
>



-- 
Niyazi Elvan
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [ovirt-users] ovirt-engine-sdk-python-4.1 clone a vm from snapshot

2017-03-08 Thread Juan Hernández
On 03/08/2017 06:53 PM, Niyazi Elvan wrote:
> Hi Folks !
> 
> I am looking for a documentation for ovirt-engine-sdk-python-4.1 but
> could not find anything yet. Looks like there are many changes compared
> to 4.0.
> 

Version 4.1 of the SDK isn't very different for version 4.0. It is very
different from version 3.6.

Note that version 3 of the API, and version 3 of the SDK are deprecated
since version 4.0 of the engine, and they will be removed in version 4.2
of the engine.

There is a general description of version 4 of the SDK here:

  https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/README.adoc

A collection of examples here:

  https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples

And reference documentation here:

  http://ovirt.github.io/ovirt-engine-sdk/4.1

You may also find useful the documentation of the API itself:

  http://ovirt.github.io/ovirt-engine-api-model/4.1

Specially the section that describes how to add virtual machines, as
there is an example of how to add a virtual machine from a snapshot there:


http://ovirt.github.io/ovirt-engine-api-model/4.1/#services/vms/methods/add

> Can anyone help me about how to clone a VM from a snapshot using the
> latest sdk ?
> 

To create a virtual machine from a snapshot with the latest version of
the SDK you will need something like this:

---8<---
import time

import ovirtsdk4 as sdk
import ovirtsdk4.types as types

# This example shows how to clone a virtual machine from an snapshot.

# Create the connection to the server:
connection = sdk.Connection(
url='https://engine.example.com/ovirt-engine/api',
username='admin@internal',
password='...',
ca_file='ca.pem'
)

# Get the reference to the root of the tree of services:
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 service that manages the virtual machine:
vm_service = vms_service.vm_service(vm.id)

# Find the snapshot. Note that the snapshots collection doesn't support
# search, so we need to retrieve the complete list and the look for the
# snapshot that has the description that we are looking for.
snaps_service = vm_service.snapshots_service()
snaps = snaps_service.list()
snap = next(
  (s for s in snaps if s.description == 'mysnap'),
  None
)

# Create a new virtual machine, cloning it from the snapshot:
cloned_vm = vms_service.add(
vm=types.Vm(
name='myclonedvm',
snapshots=[
types.Snapshot(
id=snap.id
)
],
cluster=types.Cluster(
name='mycluster'
)
)
)

# Find the service that manages the cloned virtual machine:
cloned_vm_service = vms_service.vm_service(cloned_vm.id)

# Wait till the virtual machine is down, as that means that the creation
# of the disks of the virtual machine has been completed:
while True:
time.sleep(5)
cloned_vm = cloned_vm_service.get()
if cloned_vm.status == types.VmStatus.DOWN:
break

# Close the connection to the server:
connection.close()
--->8---
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


[ovirt-users] ovirt-engine-sdk-python-4.1 clone a vm from snapshot

2017-03-08 Thread Niyazi Elvan
Hi Folks !

I am looking for a documentation for ovirt-engine-sdk-python-4.1 but could
not find anything yet. Looks like there are many changes compared to 4.0.

Can anyone help me about how to clone a VM from a snapshot using the latest
sdk ?

Thank you !



-- 
Niyazi Elvan
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


[ovirt-users] ovirt-engine-sdk-python

2016-07-19 Thread qinglong.d...@horebdata.cn
Hi all,
I have an ovirt 4.0 environment. I got an error when I excuted an 
python script which could be normally excuted in 3.6. I have figured out that 
in ovirt 4.0 the version of python sdk is still 3.6.7.0. It seemed that the 
server thought it was an unsecured connection, but HTTPS protocol and the right 
ca file was used.
Anyone can help? Thanks!

[root@test ~]# ./test.py
Traceback (most recent call last):
  File "./test.py", line 30, in 
vms = VirtualMachines()
  File "/root/vm.py", line 31, in __init__
self.api = 
API(url=BASEURL,username=USERNAME,password=PASSWORD,ca_file=CAFILE)
  File "/usr/lib/python2.7/site-packages/ovirtsdk/api.py", line 197, in __init__
raise UnsecuredConnectionAttemptError
ovirtsdk.infrastructure.errors.UnsecuredConnectionAttemptError: [ERROR]::No 
response returned from server. If you're using HTTP protocol
against a SSL secured server, then try using HTTPS instead.

(BASEURL: https://test.example.com/ovirt-engine)
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


[ovirt-users] ovirt-engine-sdk-python too slow

2015-11-23 Thread John Hunter
Hi guys,

I am using the ovirt-engine-sdk-python to communicate with the ovirt-engine,
I am ok to list the vms but the processing time is too long, like 4.5
seconds,
and this line:
from ovirtsdk.api import API
take almost 3 seconds.

This seems a little bit longer than I expected it to be, so I am asking is
there
a quicker way to communicate with the ovirt-engine?

-- 
Best regards
Junwang Zhao
Department of Computer Science 
Peking University
Beijing, 100871, PRC
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users