2023年7月10日发(作者:)
vcenterapi接⼝获取开发通过连接vcenter 管理服务器,获取其下所有的:存储,⽹络,ESXI实体机,虚拟机相关信息的脚步:#!/opt/python3/bin/python3#Author: zhaoyong"""只⽤于模拟开发功能测试"""from pyVmomi import vimfrom t import SmartConnect, Disconnect, SmartConnectNoSSLimport atexitimport argparsedef get_args(): parser = ntParser( description='Arguments for talking to vCenter') _argument('-s', '--host', required=True, action='store', help='vSpehre service to connect to') _argument('-o', '--port', type=int, default=443, action='store', help='Port to connect on') _argument('-u', '--user', required=True, action='store', help='User name to use') _argument('-p', '--password', required=True, action='store', help='Password to use') args = _args() return argsdef get_obj(content, vimtype, name=None): ''' 列表返回,name 可以指定匹配的对象 ''' container = ContainerView(lder, vimtype, True) obj = [ view for view in ] return objdef main(): esxi_host = {} args = get_args() # connect this thing si = SmartConnectNoSSL( host=, user=, pwd=rd, port=) # disconnect this thing er(Disconnect, si) content = veContent() esxi_obj = get_obj(content, [stem]) for esxi in esxi_obj: esxi_host[] = {'esxi_info':{},'datastore':{}, 'network': {}, 'vm': {}} esxi_host[]['esxi_info']['⼚商'] = esxi_host[]['esxi_info']['型号'] = for i in dentifyingInfo: if isinstance(i, IdentificationInfo): esxi_host[]['esxi_info']['SN'] = fierValue esxi_host[]['esxi_info']['处理器'] = '数量:%s 核数:%s 线程数:%s 频率:%s(%s) ' % (Pkgs, Cores, Threads, , el) esxi_host[]['esxi_info']['处理器使⽤率'] = '%.1f%%' % (lCpuUsage / (Pkgs * Cores * ) * 100) esxi_host[]['esxi_info']['内存(MB)'] = Size/1024/1024 esxi_host[]['esxi_info']['可⽤内存(MB)'] = '%.1f MB' % ((Size/1024/1024) - lMemoryUsage) esxi_host[]['esxi_info']['内存使⽤率'] = '%.1f%%' % ((lMemoryUsage / (Size/1024/1024)) * 100) esxi_host[]['esxi_info']['系统'] = me for ds in ore: esxi_host[]['datastore'][] = {} esxi_host[]['datastore'][]['总容量(G)'] = int((ty)/1024/1024/1024) esxi_host[]['datastore'][]['空闲容量(G)'] = int((ace)/1024/1024/1024) esxi_host[]['datastore'][]['类型'] = () for nt in k: esxi_host[]['network'][] = {} esxi_host[]['network'][]['标签ID'] = for vm in : esxi_host[]['vm'][] = {} esxi_host[]['vm'][]['电源状态'] = tate esxi_host[]['vm'][]['CPU(内核总数)'] = esxi_host[]['vm'][]['内存(总数MB)'] = MB esxi_host[]['vm'][]['系统信息'] = ullName if ess: esxi_host[]['vm'][]['IP'] = ess else: esxi_host[]['vm'][]['IP'] = '服务器需要开机后才可以获取' for d in : if isinstance(d, lDisk): esxi_host[]['vm'][][] = str((tyInKB)/1024/1024) + ' GB' f = open( + '.txt', 'w') for host in esxi_host: print('ESXI IP:', host) ('ESXI IP: %s n' % host) for hd in esxi_host[host]['esxi_info']: print(' %s: %s' % (hd, esxi_host[host]['esxi_info'][hd])) (' %s: %s' % (hd, esxi_host[host]['esxi_info'][hd])) for ds in esxi_host[host]['datastore']: print(' 存储名称:', ds) (' 存储名称: %s n' % ds) for k in esxi_host[host]['datastore'][ds]: print(' %s: %s' % (k, esxi_host[host]['datastore'][ds][k])) (' %s: %s n' % (k, esxi_host[host]['datastore'][ds][k])) for nt in esxi_host[host]['network']: print(' ⽹络名称:', nt) (' ⽹络名称:%s n' % nt) for k in esxi_host[host]['network'][nt]: print(' %s: %s' % (k, esxi_host[host]['network'][nt][k])) (' %s: %s n' % (k, esxi_host[host]['network'][nt][k])) for vmachine in esxi_host[host]['vm']: print(' 虚拟机名称:', vmachine) (' 虚拟机名称:%s n' % vmachine) for k in esxi_host[host]['vm'][vmachine]: print(' %s: %s' % (k, esxi_host[host]['vm'][vmachine][k])) (' %s: %s n' % (k, esxi_host[host]['vm'][vmachine][k])) ()if __name__ == '__main__': main()
发布者:admin,转转请注明出处:http://www.yc00.com/news/1688932706a184986.html
评论列表(0条)