0

こんにちは、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)  

どんな助けでも大歓迎です。ありがとう

4

1 に答える 1

0

ドキュメントの間違いのようです。メソッドが呼び出されますRelocate( ではありませんRelocateVM)。

ところで、最初のサンプルでは、​​宛先ホストを呼び出しに渡していないRelocateため、何かが確実に欠落していることに注意してください。

https://gist.github.com/rgerganov/12fdd2ded8d80f36230fまたはhttps://github.com/sijis/pyvmomi-examples/blob/master/migrate-vm.pyでいくつかのサンプルを確認できます。

最後に、間違った名前を使用していることを認識する 1 つのdir方法は、VirtualMachine オブジェクトで Python のメソッドを呼び出すことです。これにより、オブジェクトのすべてのプロパティが一覧表示されるため、オブジェクトが持つメソッドを確認できます。

>>> vm = vim.VirtualMachine('vm-1234', None)
>>> dir(vm)
['AcquireMksTicket', [...] 'Relocate', 'RelocateVM_Task', [...] ]

(省略出力)

于 2016-10-27T07:37:12.253 に答える