<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;"> MB = 1024*1024</div><div id="bloop_customfont" style="margin: 0px;"> GB = 1024*MB</div><div id="bloop_customfont" style="margin: 0px;"> try:</div><div id="bloop_customfont" style="margin: 0px;"> vm_created = cnn.vms.add(params.VM(</div><div id="bloop_customfont" style="margin: 0px;"> name=vm_name,</div><div id="bloop_customfont" style="margin: 0px;"> memory=1*GB,</div><div id="bloop_customfont" style="margin: 0px;"> cluster=cnn.clusters.get(cluster_name),</div><div id="bloop_customfont" style="margin: 0px;"> template=cnn.templates.get(create_from),</div><div id="bloop_customfont" style="margin: 0px;"> disks=params.Disks(clone=True))</div><div id="bloop_customfont" style="margin: 0px;"> )</div><div id="bloop_customfont" style="margin: 0px;"> print 'Waiting for VM to reach Down status'</div><div id="bloop_customfont" style="margin: 0px;"> while cnn.vms.get(id=vm_created.id).status.state != 'down':</div><div id="bloop_customfont" style="margin: 0px;"> sys.stdout.write( dot )</div><div id="bloop_customfont" style="margin: 0px;"> sys.stdout.flush()</div><div id="bloop_customfont" style="margin: 0px;"> time.sleep(1)</div><div id="bloop_customfont" style="margin: 0px;"> print ""</div><div id="bloop_customfont" style="margin: 0px;"> response = (True, vm_created.id)</div><div id="bloop_customfont" style="margin: 0px;"> except Exception as e:</div><div id="bloop_customfont" style="margin: 0px;"> print 'Failed to create VM\n%s' % str(e)</div><div id="bloop_customfont" style="margin: 0px;"> response = (False, str(e))</div><div id="bloop_customfont" style="margin: 0px;"> 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;"> storage = cnn.storagedomains.get(name=sd_name)</div><div id="bloop_customfont" style="margin: 0px;"> for index, disco in enumerate(get_vm(cnn, vm_name, vm_guid=vm_guid).disks.list()):</div><div id="bloop_customfont" style="margin: 0px;"> disco.set_alias("{0}_Disk{1}".format(vm_name, (index+1)))</div><div id="bloop_customfont" style="margin: 0px;"> disco = disco.update()</div><div id="bloop_customfont" style="margin: 0px;"> if storage.disks.get(disco.alias) is None:</div><div id="bloop_customfont" style="margin: 0px;"> disco.move(params.Action(storage_domain=storage))</div><div id="bloop_customfont" style="margin: 0px;"> print 'Waiting for migrate Disk {0}'.format(disco.alias)</div><div id="bloop_customfont" style="margin: 0px;"> time.sleep(2)</div><div id="bloop_customfont" style="margin: 0px;"> 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;"> sys.stdout.write( dot )</div><div id="bloop_customfont" style="margin: 0px;"> sys.stdout.flush()</div><div id="bloop_customfont" style="margin: 0px;"> time.sleep(1)</div><div id="bloop_customfont" style="margin: 0px;"> time.sleep(4)</div><div id="bloop_customfont" style="margin: 0px;"> print ""</div><div id="bloop_customfont" style="margin: 0px;"> print "Disk '{0}' From '{1}' was moved to {2}".format(disco.alias,</div><div id="bloop_customfont" style="margin: 0px;"> vm_name, sd_name)</div><div id="bloop_customfont" style="margin: 0px;"> else:</div><div id="bloop_customfont" style="margin: 0px;"> print "Disk '{0}' From '{1}' is already in {2}".format(disco.alias,</div><div id="bloop_customfont" style="margin: 0px;"> 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;"> disk = params.Disk(</div><div id="bloop_customfont" style="margin: 0px;"> name = "{0}_{1}".format(vm_name, (index+1)),</div><div id="bloop_customfont" style="margin: 0px;"> storage_domains=params.StorageDomains(</div><div id="bloop_customfont" style="margin: 0px;"> storage_domain = [api.storagedomains.get(sd.name)]</div><div id="bloop_customfont" style="margin: 0px;"> ),</div><div id="bloop_customfont" style="margin: 0px;"> )</div><div id="bloop_customfont" style="margin: 0px;"> 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;"> name=vm_name,</div><div id="bloop_customfont" style="margin: 0px;"> memory=1*GB,</div><div id="bloop_customfont" style="margin: 0px;"> cluster=cnn.clusters.get(cluster_name),</div><div id="bloop_customfont" style="margin: 0px;"> template=cnn.templates.get(create_from),</div><div id="bloop_customfont" style="margin: 0px;"> disks=discos</div><div id="bloop_customfont" style="margin: 0px;"> )</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>