答案 0 :(得分:1)
使用SmartConnect连接到vCentre后,您需要遍历并获取主机
主机硬件信息位于Git (git-credential-winstore
)
一旦有了主机,便可以遍历它们并获取硬件详细信息。它们为原始格式,因此您必须进行转换。我已经粘贴了我使用的convertMemory函数
hosts = content.viewManager.CreateContainerView(content.rootFolder,[vim.HostSystem],True)
for host in hosts.view:
# Print the hosts cpu details
print(host.hardware.cpuInfo)
# convert CPU to total hz to ghz times numCpuCores
print("CPU:", round(((host.hardware.cpuInfo.hz/1e+9)*host.hardware.cpuInfo.numCpuCores),0),"GHz")
#covert the raw bytes to readable size via convertMemory
print("Memory:", convertMemory(host.hardware.memorySize))
convertMemory函数只是将数字转换为可读存储器
def convertMemory(sizeBytes):
name = ("B", "KB", "MB", "GB", "TB", "PB")
base = int(floor(log(sizeBytes, 1024)))
power = pow(1024,base)
size = round(sizeBytes/power,2)
return "{}{}".format(floor(size),name[base])