Virtual machine 查看与vmware虚拟机相关的所有唯一ID
我想查看特定于虚拟机的所有唯一ID,例如: 硬件ID、CPU ID、UUID、Mac地址等。Virtual machine 查看与vmware虚拟机相关的所有唯一ID,virtual-machine,vmware,Virtual Machine,Vmware,我想查看特定于虚拟机的所有唯一ID,例如: 硬件ID、CPU ID、UUID、Mac地址等。 有谁能帮我找到这些ID吗?我可以帮你找到其中一些。对于其余的事情,你必须搜索文档 安装并运行以下代码 编辑:将代码更改为在esx主机上运行。只需通过python.py运行它 现在我们来了解一下这段代码是如何工作的。你必须学习管理对象。例如,在这里,我们使用的是管理对象vm,该对象在中列出了许多属性。因此,为了检索vm的uuid,我们调用了vm.config.uuid。关于其他细节,您必须仔细查看对象,查
有谁能帮我找到这些ID吗?我可以帮你找到其中一些。对于其余的事情,你必须搜索文档 安装并运行以下代码 编辑:将代码更改为在esx主机上运行。只需通过python.py运行它 现在我们来了解一下这段代码是如何工作的。你必须学习管理对象。例如,在这里,我们使用的是管理对象
vm
,该对象在中列出了许多属性。因此,为了检索vm的uuid,我们调用了vm.config.uuid
。关于其他细节,您必须仔细查看对象,查看您需要的所有属性
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()
你想怎么样?手动还是编程?没关系,我只是想找到一种方法,查看与ESXi主机5.1的虚拟机或虚拟设备关联的所有特定ID。想知道我怎样才能改变它们吗??如果你能帮助我,我会非常感激。我非常感激鲁本,你能解释一下这个剧本吗??我可以请您帮我搜索其他的吗?我有一台ESXi主机而不是vCenter,我是否必须更改此脚本的一些命令?同样,如果您想获得CPU的数量,可以执行:
print“number of CPU:”,vm.config.hardware.numpu
。你可以在这里找到的财产