On 04/22/2015 11:44 AM, Ernest Beinrohr wrote:
Dňa 21.04.2015 o 17:33 Dan Yasny napísal(a):
> Why not just script them to migrate one after the other? The CLI is
> nice and simple, and the SDK is even nicer
Well I gave it a try, but I'm quite new to python and this does not work
as expected:
for vm in vms:
print vm.name
for disk in vm.disks.list( ):
print " disk: " + disk.name
sd = api.storagedomains.get('newstorage')
disk.move(params.Disk(storage_domains=params.StorageDomains(storage_domain=[sd])))
status: 500
reason: Internal Server Error
detail: HTTP Status 500 - Bad arguments passed to public abstract
javax.ws.rs.core.Response
org.ovirt.engine.api.resource.MovableResource.move(org.ovirt.engine.api.model.Action)
( org.ovirt.engine.api.model.Disk org.ovirt.engine.api.model.Disk@6a0db58b )
The parameter to the "move" method should be an "Action", containing
a
reference to the target storage domain. You need something like this:
---8<---
#!/usr/bin/python
import time
from ovirtsdk import api
from ovirtsdk.xml import params
# Connect to the server:
api = api.API(
url="https://ovirt.example.com/ovirt-engine/api",
username="admin@internal",
password="***",
insecure=True,
debug=False
)
# Find the VM whose disks we want to move:
vm = api.vms.get(name="myvm")
# Create the information of the storage domain where we will
# move the disks to. Note that we only need to know the name
# (or id) of the storage domain, the server will locate it so
# we don't need to look it up here:
sd = params.StorageDomain(name="newstorage")
# Iterate the disks of the VM and for each of them move it
# to the target storage domain:
for disk in vm.disks.list():
# Start moving the disk. Note that this is an asynchronous
# operation, so once the "move" method returns you will
# have to wait for the actual movement to finish.
print("Moving disk \"%s\" ..." % disk.get_alias())
disk.move(
params.Action(
storage_domain=sd
)
)
# Wait till the state of the disk is "ok", which means it
# has been moved completely. Note that it is important to
# wait a few seconds before doing the first check, as
# otherwise you will get the status of the disk before
# the movement started, thus you would get "ok" but
# because the movement didn't start yet.
disk_id = disk.get_id()
while True:
print("Waiting for movement to complete ...")
time.sleep(5)
disk = vm.disks.get(id=disk_id)
if disk.get_status().get_state() == "ok":
break
# Bye:
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.