def migrate_disks(cnn, vm_name, sd_name, vm_guid=None):
storage = cnn.storagedomains.get(name=sd_name)
for index, disco in enumerate(get_vm(cnn, vm_name, vm_guid=vm_guid).disks.list()):
disco.set_alias("{0}_Disk{1}".format(vm_name, (index+1)))
disco = disco.update()
if storage.disks.get(disco.alias) is None:
disco.move(params.Action(storage_domain=storage))
print 'Waiting for migrate Disk {0}'.format(disco.alias)
time.sleep(2)
while get_vm(cnn, vm_name, vm_guid=vm_guid).disks.get(name=disco.name).status.state != 'ok':
sys.stdout.write( dot )
sys.stdout.flush()
time.sleep(1)
time.sleep(4)
print ""
print "Disk '{0}' From '{1}' was moved to {2}".format(disco.alias,
vm_name, sd_name)
else:
print "Disk '{0}' From '{1}' is already in {2}".format(disco.alias,
vm_name, sd_name)
############################ WHAT I WANT IS SOMETHING LIKE THIS
discos = params.Disks()
for index, tmp_disk in enumerate(template.disks.list()):
disk = params.Disk(
name = "{0}_{1}".format(vm_name, (index+1)),
storage_domains=params.StorageDomains(
storage_domain = [api.storagedomains.get(sd.name)]
),
)
discos.add_disk(disk)
vm_created_dos = cnn.vms.add(params.VM(
name=vm_name,
memory=1*GB,
cluster=cnn.clusters.get(cluster_name),
template=cnn.templates.get(create_from),
disks=discos
)
)
Thank you all from Perú!!