Hi, this is my first question, so:

I’m playing with python sdk and i can manage the CRUD and some other options, but im stuck in this one, when I create a VM from template this new machine is created in the same storage than template is. If i want to move the machine I create it, wait to reach down status and then, move their disks to a new storage. What I want is create a new machine from scratch on a new storage.



############################ CURRENT SCRIPT
def create_virtual_machine(cnn, vm_name, cluster_name, create_from='Blank'):
    MB = 1024*1024
    GB = 1024*MB
    try:
        vm_created = cnn.vms.add(params.VM(
            name=vm_name,
            memory=1*GB,
            cluster=cnn.clusters.get(cluster_name),
            template=cnn.templates.get(create_from),
            disks=params.Disks(clone=True))
        )
        print 'Waiting for VM to reach Down status'
        while cnn.vms.get(id=vm_created.id).status.state != 'down':
            sys.stdout.write( dot )
            sys.stdout.flush()
            time.sleep(1)
        print ""
        response = (True, vm_created.id)
    except Exception as e:
        print 'Failed to create VM\n%s' % str(e)
        response = (False, str(e))
    return response


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ú!!