您好我正在使用 pyvmomi API,在 DRS 设置为手动模式时对集群执行 vmotions。我正在通过一个中心并查询一个集群并获得推荐并使用它来执行 Vmotion。代码是这样的。
content=getVCContent(thisHost, {'user':username,'pwd':decoded_password},logger)
allClusterObj = content.viewManager.CreateContainerView(content.rootFolder, [pyVmomi.vim.ClusterComputeResource], True)
allCluster = allClusterObj.view
for thisDrsRecommendation in thisCluster.drsRecommendation:
print thisDrsRecommendation.reason
for thisMigration in thisDrsRecommendation.migrationList:
print ' vm:', thisMigration.vm.name
while True:
relocate_vm_to_host(thisMigration.vm.name,thisMigration.destination.name, allClusterObj.view)
#FUNCTION definition
def relocate_vm_to_host(vm, host , allCluster):
for thisCluster in allCluster:
for thisHost in thisCluster.host:
if thisHost.name == host:
for thisVm in thisHost.vm:
print 'Relocating vm:%s to host:%s on cluster:%s' %(thisVm.name,thisHost.name,thisCluster.name)
task = thisVm.RelocateVM(priority='defaultpriority')
我收到一条错误消息,说该属性不存在。AttributeError: 'vim.VirtualMachine' 对象没有属性 'RelocateVM'
但是这里的 pyvmomi 文档https://github.com/vmware/pyvmomi/blob/master/docs/vim/VirtualMachine.rst 对 RelocateVM(spec, priority) 方法有详细的解释:
任何人都知道该方法丢失的原因是什么?我还尝试检查具有 RelocateVM_Task 的对象的可用方法,而不是 RelocateVM(我找不到文档)当我使用它时,我得到了这个错误
TypeError: For "spec" expected type vim.vm.RelocateSpec, but got str
我检查了 vim.vm.RelocateSpec 的文档,我在函数中调用它,但仍然抛出错误。
def relocate_vm(VmToRelocate,destination_host,content):
allvmObj = content.viewManager.CreateContainerView(content.rootFolder, [pyVmomi.vim.VirtualMachine], True)
allvms = allvmObj.view
for vm in allvms:
if vm.name == VmToRelocate:
print 'vm:%s to relocate %s' %(vm.name , VmToRelocate)
task = vm.RelocateVM_Task(spec = destination_host)
任何帮助表示赞赏。谢谢