[ovirt-users] VM migration by using the Python SDK
Juan Hernández
jhernand at redhat.com
Tue Mar 8 09:31:56 UTC 2016
On 03/07/2016 07:59 PM, Yaniv Kaul wrote:
>
>
> On Mon, Mar 7, 2016 at 6:17 PM, Jean-Pierre Ribeauville
> <jpribeauville at axway.com <mailto:jpribeauville at axway.com>> wrote:
>
> Hi,____
>
> __ __
>
> __ __
>
> I’m a little bit lost by looking how to migrate a Guest between two
> nodes of a same cluster by using ovirt python API .
>
>
> Copy-paste from oVirt system tests[1], adapt as you need:
>
> def vm_migrate(prefix):
> api = prefix.virt_env.engine_vm().get_api()
> host_names = [h.name <http://h.name>() for h in
> prefix.virt_env.host_vms()]
>
> migrate_params = params.Action(
> host=params.Host(
> name=sorted(host_names)[1]
> ),
> )
> api.vms.get(VM1_NAME).migrate(migrate_params)
> testlib.assert_true_within_short(
> lambda: api.vms.get(VM1_NAME).status.state == 'up',
> )
>
>
> Y.
> [1] https://gerrit.ovirt.org/#/c/48206/4/basic_suite_3.6/test-scenarios/004_basic_sanity.py
>
The above is correct.
If you want a simpler complete example, it should be something like this:
---8<---
#!/usr/bin/python
from ovirtsdk.api import API
from ovirtsdk.xml import params
# Connect to the server:
api = API(
url="https://engine.example.com/ovirt-engine/api",
username="admin at internal",
password="...",
ca_file="/etc/pki/ovirt-engine/ca.pem",
debug=False,
)
# Find the VM:
vm = api.vms.get(name="myvm")
# Migrate the VM to the host:
vm.migrate(
action=params.Action(
host=params.Host(
name="myhost",
)
),
)
# Disconnect:
api.disconnect()
--->8---
--
Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
3ºD, 28016 Madrid, Spain
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
More information about the Users
mailing list