こんにちは、DRS が手動モードに設定されているときにクラスターに対して vmotions を実行するために、pyvmomi API を使用しています。私はvcenterを通過し、クラスターにクエリを実行して推奨事項を取得し、それを使用してVmotionsを実行しています. コードはこのようなものです。
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 の代わりに RelocateVM_Task を持つオブジェクトの使用可能なメソッドを確認しようとしました(ドキュメントが見つかりませんでした)それを使用すると、このエラーが発生します
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)
どんな助けでも大歓迎です。ありがとう