Hi,
we are migrating a huge number of VM from a cluster to another cluster. This cluster has a different type of CPU so ordinary inter-cluster vmotion is not possible.
I'm so building up a pysphere script for making automatically this steps:
- shut down the guest OS
- relocate to an NFS datastore that is shared between clusters
- unregister the VM on the old cluster
- register the VM on the new cluster
- start
At the moment i'm testing on a vm doing this:
(removed the part about the connection and so on and the code is quite messy)
from pysphere.resources import VimService_services as VI
vm = server.get_vm_by_name('luca-sviluppo-to-sviluppo2-001')
vm.relocate(sync_run=True,datastore=next(mor for mor,name in server.get_datastores().items() if name=='nfssata_align'))
vmx = vm.get_property('path')
vm.shutdown_guest()
mor = vm._mor
request = VI.UnregisterVMRequestMsg()
_this = request.new__this(mor)
_this.set_attribute_type(mor.get_attribute_type())
request.set_element__this(_this)
server._proxy.UnregisterVM(request)
class VIMor(str):
def __new__(self, value, mor_type):
return str.__new__(self, value)
def __init__(self, value, mor_type):
self._mor_type = mor_type
def get_attribute_type(self):
return self._mor_type
def set_attribute_type(self, mor_type):
self._mor_type = mor_type
folder = VIMor("group-v1736", "Folder")
rpool = VIMor('resgroup-36','ResourcePool')
request = VI.RegisterVM_TaskRequestMsg()
_this = request.new__this(folder)
_this.set_attribute_type(folder.get_attribute_type())
request.set_element__this(_this)
request.set_element_path(vmx)
request.set_element_asTemplate(False)
pool = request.new_pool(rpool)
pool.set_attribute_type(rpool.get_attribute_type())
request.set_element_pool(pool)
request.set_element_host(('host-362117',MORTypes.HostSystem))
server._proxy.RegisterVM_Task(request)
With this last request i suppose to have the VM registered but i get on vmware an error saying: "The object has already been deleted or has not been completely created"
Where i'm mistaking?
Do you have any snippet of code for registering a vm from a datastore to the default resource pool?
thank you
Luca