国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

PYTHON獲取機器硬件信息及狀態(tài)

2019-11-14 17:37:30
字體:
供稿:網(wǎng)友
#!/usr/bin/env python# encoding: utf-8from optparse import OptionParserimport osimport reimport jsondef main():    try:        parser = OptionParser(usage="%PRog [options]")        reg_result=re.compile('/[(.*)/]')        #add option        parser.add_option("-m","--machine",action="store",type="string",dest="machine",help="the machine to be check")        parser.add_option("-f","--file",action="store",type="string",dest="file",help="the file with machine list")        parser.add_option("-n","--noah_path",action="store",type="string",dest="noah",help="the bns path or group")        (options,args)=parser.parse_args()        result=""        if options.machine:            options.machine=options.machine.replace(".baidu.com","")            result=os.popen("meta-query entity host "+options.machine+" -f sysSuit,memTotal,diskTotal,cpuFrequency,cpuPhysicalCores,netIdc,status -j").read()        elif options.file:            result=os.popen("meta-query entity host  -f sysSuit,memTotal,diskTotal,cpuFrequency,cpuPhysicalCores,netIdc,status -F "+options.file+" -j").read()        elif options.noah:            result=os.popen("get_instance_by_service "+options.noah+" |meta-query entity host  -f sysSuit,memTotal,diskTotal,cpuFrequency,cpuPhysicalCores,netIdc,status -F  -j").read()        else:            return        result=json.loads(result)        print "%-*s%-*s%-*s%-*s%-*s%-*s"%(40,"Name",10,"CPU",10,"memery",10,"disk",10,"IDC",10,"status")        for item in result:            if item['Values']['cpuFrequency']!="null":                item['Values']['cpuFrequency']=str(float(item['Values']['cpuFrequency'])/1000.0)[0:3]            else:                item['Values']['cpuFrequency']="0"            item['Values']['diskTotal']=str(float(item['Values']['diskTotal'])/1000000000.0)[0:5]            item['Values']['memTotal']=str(float(item['Values']['memTotal'])/1024/1000.0)[0:5]                        print "%-*s%-*s%-*s%-*s%-*s%-*s" % (40,item['Name'],10,item['Values']['cpuFrequency']+" x"+item['Values']['cpuPhysicalCores'],10,item['Values']['memTotal']+"G",10,item['Values']['diskTotal']+"T",10,item['Values']['netIdc'],10,item['Values']['status'])    except Exception,e:        returnif __name__ =="__main__":    main()

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 遂昌县| 临漳县| 平南县| 霍林郭勒市| 清河县| 高阳县| 塘沽区| 南川市| 鹿泉市| 中宁县| 灌阳县| 沙河市| 康乐县| 镇巴县| 威信县| 日喀则市| 凉城县| 黄浦区| 曲阳县| 黑龙江省| 随州市| 获嘉县| 托克托县| 漯河市| 垣曲县| 包头市| 芦山县| 彭阳县| 彭泽县| 含山县| 宜宾市| 富川| 锦屏县| 云浮市| 台南县| 交口县| 宿州市| 黑龙江省| 本溪市| 盐津县| 桐庐县|