2016-10-26 5 views
0

안녕하세요, 저는 DRS가 수동 모드로 설정되어있을 때 클러스터에 대해 vmotions를 수행하기 위해 pyvmomi API를 사용하고 있습니다. 나는 vcenter를 거치고 클러스터를 쿼리하고 권장 사항을 얻고이를 사용하여 Vmotions를 수행합니다. 코드는 다음과 같습니다.pyvmomi : RelocateVM을 호출 할 때 오류가 발생했습니다.

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 documentaion https://github.com/vmware/pyvmomi/blob/master/docs/vim/VirtualMachine.rst 상세한 방법 RelocateVM에 대한 설명 (사양, 우선 순위)가 있습니다

누구든지 이유 무엇인지를 방법이 없습니까? 나는 또한 대신 (있는 내가 문서를 찾을 수 없습니다) 나는 내가 정력에 대한 설명서를 확인

TypeError: For "spec" expected type vim.vm.RelocateSpec, but got str 

이 오류가 있음을 사용할 경우 RelocateVM의, RelocateVM_Task가있는 객체의 가능한 방법을 확인했습니다. 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) 

도움을 주시면 감사하겠습니다. 감사합니다.

답변

0

문서의 실수처럼 보입니다. 이 방법은 Relocate (RelocateVM이 아님)입니다.

참고, 처음 샘플에서는 Relocate에 대한 호출에 대상 호스트를 전달하지 않으므로 여기에 뭔가가 분명히 없습니다.

https://gist.github.com/rgerganov/12fdd2ded8d80f36230f 또는 https://github.com/sijis/pyvmomi-examples/blob/master/migrate-vm.py에서 일부 샘플을 볼 수 있습니다.

마지막으로 틀린 이름을 사용하고 있다는 것을 깨닫는 한 가지 방법은 VirtualMachine 객체에서 Python의 dir 메서드를 호출하는 것입니다. 당신이 가지고있는 방법을 볼 수 있도록이 개체의 모든 속성을 나열합니다 :

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

(약식 출력) 나는 이주/RelocateVM_Task를 호출 할 때

+0

내가, 어떤 아이디어 오류는 무엇입니까? 나는 호스트와 사양을 설정합니다. 하지만이 오류가 발생합니다. pyVmomi.VmomiSupport.ManagedObjectNotFound (vmodl.fault.ManagedObjectNotFound) { dynamicType = , DynamicProperty를 = (vmodl.DynamicProperty)] MSG = '' faultCause = , faultMessage = (vmodl.LocalizableMessage) [], obj = 'vim.VirtualMachine : xxxx' } – jramacha

+0

@jramacha 질문에 업데이트 된 코드를 게시 할 수 있습니까? 새로운'vim.vm.RelocateSpec' 객체를 생성해야합니다 (당신은'spec = host'를 전달할 수 없습니다). https://github.com/sijis/pyvmomi-examples/blob/master/migrate-vm.py의 예를 참조하십시오. – YSK

+0

사실 지금은 작동하지만 오타가있었습니다. 나는 spec.host = host obj를했다. 고마워. – jramacha

관련 문제