안녕하세요, 저는 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)
도움을 주시면 감사하겠습니다. 감사합니다.
내가, 어떤 아이디어 오류는 무엇입니까? 나는 호스트와 사양을 설정합니다. 하지만이 오류가 발생합니다. pyVmomi.VmomiSupport.ManagedObjectNotFound (vmodl.fault.ManagedObjectNotFound) { dynamicType =, DynamicProperty를 = (vmodl.DynamicProperty)] MSG = '' faultCause = , faultMessage = (vmodl.LocalizableMessage) [], obj = 'vim.VirtualMachine : xxxx' } –
jramacha
@jramacha 질문에 업데이트 된 코드를 게시 할 수 있습니까? 새로운'vim.vm.RelocateSpec' 객체를 생성해야합니다 (당신은'spec = host'를 전달할 수 없습니다). https://github.com/sijis/pyvmomi-examples/blob/master/migrate-vm.py의 예를 참조하십시오. – YSK
사실 지금은 작동하지만 오타가있었습니다. 나는 spec.host = host obj를했다. 고마워. – jramacha