하드웨어 ID, CPU ID, UUID, Mac 주소 등 가상 머신에 고유 한 모든 고유 ID를보고 싶습니다. 수 있습니다 아무도 날이 ID를 찾을 수 있도록 도와 주시겠습니까 ??VM웨어 가상 머신과 관련된 모든 고유 ID보기
답변
이 중 일부를 찾는 데 도움이 될 수 있습니다. 나머지는 문서를 검색해야합니다.
pyVmomi을 설치하고 다음 코드를 실행하십시오.
편집 : esx 호스트에서 실행되도록 코드가 변경되었습니다. 간단히 파이썬으로 실행하십시오 .py
이 코드가 어떻게 작동하는지 알 수 있습니다. Manged Objects를 배워야합니다. 예를 들어 여기에서는 망된 객체 vm
을 사용하고 있으며이 객체는 doc에 나열된 많은 속성을 가지고 있습니다. 따라서 VM의 uuid를 검색하기 위해 vm.config.uuid
을 호출합니다. 다른 세부 사항에 대해서는 VirtualMachine 객체를 살펴 봐야합니다.
import sys
import atexit
import time
from pyVmomi import vim, vmodl
from pyVim.connect import Disconnect
from pyVim import connect
inputs = {'esx_ip': '15.22.10.10',
'esx_password': 'Password123',
'esx_user': 'root',
'vm_name': 'ubuntu',
}
def wait_for_task(task, actionName='job', hideResult=False):
"""
Waits and provides updates on a vSphere task
"""
while task.info.state == vim.TaskInfo.State.running:
time.sleep(2)
if task.info.state == vim.TaskInfo.State.success:
if task.info.result is not None and not hideResult:
out = '%s completed successfully, result: %s' % (actionName, task.info.result)
print out
else:
out = '%s completed successfully.' % actionName
print out
else:
out = '%s did not complete successfully: %s' % (actionName, task.info.error)
raise task.info.error
print out
return task.info.result
def get_obj(content, vimtype, name):
"""
Get the vsphere object associated with a given text name
"""
obj = None
container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
for c in container.view:
if c.name == name:
obj = c
break
return obj
def main():
si = None
try:
print "Trying to connect ..."
si = connect.Connect(inputs['vcenter_ip'], 443, inputs['vcenter_user'], inputs['vcenter_password'])
except IOError, e:
pass
if not si:
print "Cannot connect to specified host using specified username and password"
sys.exit()
print "Connected to vcenter!"
atexit.register(Disconnect, si)
content = si.RetrieveContent()
# Get the VirtualMachine Object
vm = get_obj(content, [vim.VirtualMachine], inputs['vm_name'])
print "GuestID: ", vm.config.guestId
print "UUID: ", vm.config.uuid
print "Version: ", vm.config.version
for device in vm.config.hardware.device:
if isinstance(device, vim.vm.device.VirtualEthernetCard):
print "MAC Address: ", device.macAddress
#Example of changing UUID:
new_uuid = '423ffff0-5d62-d040-248c-4538ae2c734f'
vmconf = vim.vm.ConfigSpec()
vmconf.uuid = new_uuid
task = vm.ReconfigVM_Task(vmconf)
wait_for_task(task, si)
print "Successfully changed UUID"
print "New UUID: ", vm.config.uuid
if __name__ == "__main__":
main()
정말 Reuben,이 스크립트에 대해 조금 설명해 주시겠습니까? 그리고 내가 나머지를 찾는 데 무엇을 검색해야하는지 당신에게 물어볼 수 있습니까? –
ESXi 호스트가 vCenter가 아닌데이 스크립트의 일부 명령을 변경해야합니까 ?? –
마찬가지로 cpus의 수를 얻으려면 다음을 할 수 있습니다 :'print "CPU 번호 :", vm.config.hardware.numCPU'. 그리고 여기에서 찾을 수있는 부동산 http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.VirtualHardware.html – Reuben
어떻게할까요? 수동 또는 프로그래밍 방식으로? – Reuben
은 중요하지 않습니다. ESXi 호스트 5.1에서 가상 시스템 또는 가상 어플라이언스와 관련된 모든 특정 ID를 볼 수있는 방법을 찾고 싶습니다. 어떻게 내가 그들을 바꿀 수 있는지 알고 싶습니까? 네가 나를 도울 수 있으면 정말 고마워. –