<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Hi, this is my first question, so:</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">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.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">############################ CURRENT SCRIPT</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><div id="bloop_customfont" style="margin: 0px;">def create_virtual_machine(cnn, vm_name, cluster_name, create_from='Blank'):</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; MB = 1024*1024</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; GB = 1024*MB</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; try:</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; vm_created = cnn.vms.add(params.VM(</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name=vm_name,</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memory=1*GB,</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cluster=cnn.clusters.get(cluster_name),</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; template=cnn.templates.get(create_from),</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; disks=params.Disks(clone=True))</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; )</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; print 'Waiting for VM to reach Down status'</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; while cnn.vms.get(id=vm_created.id).status.state != 'down':</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.stdout.write( dot )</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.stdout.flush()</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time.sleep(1)</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; print ""</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; response = (True, vm_created.id)</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; except Exception as e:</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; print 'Failed to create VM\n%s' % str(e)</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; response = (False, str(e))</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; return response</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;"><div id="bloop_customfont" style="margin: 0px;"><div id="bloop_customfont" style="margin: 0px;">def migrate_disks(cnn, vm_name, sd_name, vm_guid=None):</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; storage = cnn.storagedomains.get(name=sd_name)</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; for index, disco in enumerate(get_vm(cnn, vm_name, vm_guid=vm_guid).disks.list()):</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; disco.set_alias("{0}_Disk{1}".format(vm_name, (index+1)))</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; disco = disco.update()</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; if storage.disks.get(disco.alias) is None:</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; disco.move(params.Action(storage_domain=storage))</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print 'Waiting for migrate Disk {0}'.format(disco.alias)</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time.sleep(2)</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while get_vm(cnn, vm_name, vm_guid=vm_guid).disks.get(name=disco.name).status.state != 'ok':</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.stdout.write( dot )</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.stdout.flush()</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time.sleep(1)</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time.sleep(4)</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print ""</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print "Disk '{0}' From '{1}' was moved to {2}".format(disco.alias,</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vm_name, sd_name)</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; else:</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print "Disk '{0}' From '{1}' is already in {2}".format(disco.alias,</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vm_name, sd_name)</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">############################ WHAT I WANT IS SOMETHING LIKE THIS</div><div id="bloop_customfont" style="margin: 0px;"><div id="bloop_customfont" style="margin: 0px;">discos = params.Disks()</div><div id="bloop_customfont" style="margin: 0px;">for index, tmp_disk in enumerate(template.disks.list()):</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; disk = params.Disk(</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; name = "{0}_{1}".format(vm_name, (index+1)),</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; storage_domains=params.StorageDomains(</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; storage_domain = [api.storagedomains.get(sd.name)]</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; ),</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; )</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; discos.add_disk(disk)</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">vm_created_dos = cnn.vms.add(params.VM(</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; name=vm_name,</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; memory=1*GB,</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; cluster=cnn.clusters.get(cluster_name),</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; template=cnn.templates.get(create_from),</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; disks=discos</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; )</div><div id="bloop_customfont" style="margin: 0px;">)</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">Thank you all from Perú!!</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;"><br></div></div></div></div></div></body></html>