首页 文章 精选 留言 我的

精选列表

搜索[物理引擎],共10012篇文章
优秀的个人博客,低调大师

python 获取VM物理机信息

内存,CPU !/usr/bin/python coding:utf-8 from pyVmomi import vim from pyVim.connect import SmartConnect, Disconnect, SmartConnectNoSSL import atexit import argparse def get_args(): parser = argparse.ArgumentParser( description='Arguments for talking to vCenter') parser.add_argument('-s', '--host', required=True, action='store', help='vSpehre service to connect to') parser.add_argument('-o', '--port', type=int, default=443, action='store', help='Port to connect on') parser.add_argument('-u', '--user', required=True, action='store', help='User name to use') parser.add_argument('-p', '--password', required=True, action='store', help='Password to use') args = parser.parse_args() return args def get_obj(content, vimtype, name=None): container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True) obj = [ view for view in container.view] return obj def main(): esxi_host = {} args = get_args() # connect this thing si = SmartConnectNoSSL( host=args.host, user=args.user, pwd=args.password, port=args.port) # disconnect this thing atexit.register(Disconnect, si) content = si.RetrieveContent() esxi_obj = get_obj(content, [vim.HostSystem]) for esxi in esxi_obj: esxi_host[esxi.name] = {'esxi_info':{},'datastore':{}, 'network': {}, 'vm': {}} esxi_host[esxi.name]['esxi_info']['厂商'] = esxi.summary.hardware.vendor esxi_host[esxi.name]['esxi_info']['型号'] = esxi.summary.hardware.model for i in esxi.summary.hardware.otherIdentifyingInfo: if isinstance(i, vim.host.SystemIdentificationInfo): esxi_host[esxi.name]['esxi_info']['SN'] = i.identifierValue esxi_host[esxi.name]['esxi_info']['处理器'] = '数量:%s 核数:%s 线程数:%s 频率:%s(%s) ' % (esxi.summary.hardware.numCpuPkgs, esxi.summary.hardware.numCpuCores, esxi.summary.hardware.numCpuThreads, esxi.summary.hardware.cpuMhz, esxi.summary.hardware.cpuModel) esxi_host[esxi.name]['esxi_info']['处理器使用率'] = '%.3f%%' % (float(esxi.summary.quickStats.overallCpuUsage) / (float(esxi.summary.hardware.numCpuPkgs * esxi.summary.hardware.numCpuCores * esxi.summary.hardware.cpuMhz)) * 100) esxi_host[esxi.name]['esxi_info']['内存(MB)'] = esxi.summary.hardware.memorySize/1024/1024 esxi_host[esxi.name]['esxi_info']['可用内存(MB)'] = '%.1f MB' % ((esxi.summary.hardware.memorySize/1024/1024) - esxi.summary.quickStats.overallMemoryUsage) esxi_host[esxi.name]['esxi_info']['内存使用率'] = '%.3f%%' % ((float(esxi.summary.quickStats.overallMemoryUsage)/ (float(esxi.summary.hardware.memorySize/1024/1024))) *100) esxi_host[esxi.name]['esxi_info']['系统'] = esxi.summary.config.product.fullName for ds in esxi.datastore: esxi_host[esxi.name]['datastore'][ds.name] = {} esxi_host[esxi.name]['datastore'][ds.name]['总容量(G)'] = int((ds.summary.capacity)/1024/1024/1024) esxi_host[esxi.name]['datastore'][ds.name]['空闲容量(G)'] = int((ds.summary.freeSpace)/1024/1024/1024) esxi_host[esxi.name]['datastore'][ds.name]['类型'] = (ds.summary.type) for nt in esxi.network: esxi_host[esxi.name]['network'][nt.name] = {} esxi_host[esxi.name]['network'][nt.name]['标签ID'] = nt.name for vm in esxi.vm: esxi_host[esxi.name]['vm'][vm.name] = {} esxi_host[esxi.name]['vm'][vm.name]['电源状态'] = vm.runtime.powerState esxi_host[esxi.name]['vm'][vm.name]['CPU(内核总数)'] = vm.config.hardware.numCPU esxi_host[esxi.name]['vm'][vm.name]['内存(总数MB)'] = vm.config.hardware.memoryMB esxi_host[esxi.name]['vm'][vm.name]['系统信息'] = vm.config.guestFullName if vm.guest.ipAddress: esxi_host[esxi.name]['vm'][vm.name]['IP'] = vm.guest.ipAddress else: esxi_host[esxi.name]['vm'][vm.name]['IP'] = '服务器需要开机后才可以获取' for d in vm.config.hardware.device: if isinstance(d, vim.vm.device.VirtualDisk): esxi_host[esxi.name]['vm'][vm.name][d.deviceInfo.label] = str((d.capacityInKB)/1024/1024) + ' GB' f = open(args.host + '.txt', 'w') for host in esxi_host: print('ESXI IP:', host) f.write('ESXI IP: %s \n' % host) for hd in esxi_host[host]['esxi_info']: print(' %s: %s' % (hd, esxi_host[host]['esxi_info'][hd])) f.write(' %s: %s' % (hd, esxi_host[host]['esxi_info'][hd])) for ds in esxi_host[host]['datastore']: print(' 存储名称:', ds) f.write(' 存储名称: %s \n' % ds) for k in esxi_host[host]['datastore'][ds]: print(' %s: %s' % (k, esxi_host[host]['datastore'][ds][k])) f.write(' %s: %s \n' % (k, esxi_host[host]['datastore'][ds][k])) for nt in esxi_host[host]['network']: print(' 网络名称:', nt) f.write(' 网络名称:%s \n' % nt) for k in esxi_host[host]['network'][nt]: print(' %s: %s' % (k, esxi_host[host]['network'][nt][k])) f.write(' %s: %s \n' % (k, esxi_host[host]['network'][nt][k])) for vmachine in esxi_host[host]['vm']: print(' 虚拟机名称:', vmachine) f.write(' 虚拟机名称:%s \n' % vmachine) for k in esxi_host[host]['vm'][vmachine]: print(' %s: %s' % (k, esxi_host[host]['vm'][vmachine][k])) f.write(' %s: %s \n' % (k, esxi_host[host]['vm'][vmachine][k])) f.close() if name == 'main': main()

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册