曙光I1620G30获取设备的cpu、内存、存储等参数信息。
admin
2023-02-23 07:00:06
0

曙光I1620G30获取设备的cpu、内存、存储等参数信息。原本打算使用redfish协议获取信息,无奈厂家说暂时不支持,只好使用restfull协议获取信息。

import requests
requests.packages.urllib3.disable_warnings()

class GetHostInfo(object):
    def __init__(self,ipaddr,username,password):
        self.username=username
        self.password=password
        self.URLprefix='http://' + ipaddr.strip()
        global token    ##同时存在4-5个token链接,每个token链接时间为5分钟,可以自己设置。
        global cookie
        token=0
        cookie=0
        tokenurl=self.URLprefix+'/api/session'
        print(tokenurl)
        data={
            "username":self.username,
            "password":self.password
            }
        re1=requests.post(tokenurl,data=data,verify=False)
        print (re1.status_code)
        if re1.status_code == 200:
            #print (re1.json())
            # print(re1.status_code)
            # print(re1.json())
            # print('header:', re1.headers)
            # temp = re1.json()
            # print(temp['CSRFToken'])
            #print(re1.headers)
            #print (re1.json())
            temp_header=re1.headers
            cookie=temp_header['Set-Cookie']
            temp_token=re1.json()
            token=temp_token['CSRFToken']
            print (cookie)
            print (token)
        else:
            pass
    def GetInfo(self,URL_suffix):  #定义总获取函数,传参url的后半部分。如'/api/system1/memory'
        urlset=self.URLprefix + URL_suffix.strip()
        #print(urlset)
        # print ('token:',token)
        # print ('cookie:',cookie)
        if cookie != 0  and token != 0 :
            header = {
                "Content-Type":"application/json,text/javascript",
                'X-Requested-With':'XMLHttpRequest',
                "X-CSRFTOKEN":token,
                "Cookie":cookie
                }
            re1=requests.get(urlset,headers=header,verify=False)
            print(re1.status_code)
            return (re1.json())
        else:
            pass

def Collect_Info(ipaddr,username,password):
    SuGon=GetHostInfo(ipaddr,username,password)
    ####处理CPU
    select_cpu_total = '/api/serverrepo/cpus'
    #print('cpu_total', SuGon.GetInfo(select_cpu_total))
    temp_cpu_result1= SuGon.GetInfo(select_cpu_total)
    if isinstance(temp_cpu_result1,list) :
        cpu_count = len(temp_cpu_result1)
        print('@' * 50)
        print('CPU Count:', cpu_count)
        for cpu_single in temp_cpu_result1:
            if isinstance(cpu_single, dict):
                print('CPU single name:',cpu_single['Location'])
                print('CPU single ID:',cpu_single['id'])
                print('CPU single TotalCores(cpus):', cpu_single['CoreThread'])
                print('CPU single Model(cpus):', cpu_single['BrandName'])
    ####处理内存
    select_mem_total = '/api/serverrepo/mems'
    # print('mem_total', SuGon.GetInfo(select_mem_total))
    temp_mem_result1 = SuGon.GetInfo(select_mem_total)
    memory_count=0
    if isinstance(temp_mem_result1, list):
        mem_count = len(temp_mem_result1)
        print('@' * 50)
        print('Memory Count(exist):', mem_count)
        for mem_single in temp_mem_result1:
            if isinstance(mem_single, dict):
                Memory_Size = mem_single['Size']
                #print ('Memory_Size AAAAA',Memory_Size)
                if Memory_Size:
                    memory_count+=1
                    print('Memory name:', mem_single['Location'])
                    print('Memory ID:', mem_single['id'])
                    print('Memory Size:', Memory_Size)
                    print('Memory Type:', mem_single['DimmType'])
                else:
                    pass
    print('Memory Count(alive):', memory_count)
    ####处理存储,无raid的查询
    select_storage_total = '/api/serverrepo/hdds'
    # print('storage_total', SuGon.GetInfo(select_storage_total))
    temp_storage_result1 = SuGon.GetInfo(select_storage_total)
    if isinstance(temp_storage_result1, list):
        mem_count = len(temp_storage_result1)
        print('@' * 50)
        print('Storage Count:', mem_count)
        for storage_single in temp_storage_result1:
            if isinstance(storage_single, dict):
                print('Storage name:', storage_single['Location'])
                print('Storage ID:', storage_single['id'])
                print('Storage Size:', storage_single['Size'])
                print('Storage Type:', storage_single['Mode'])
    ##处理日志
    selecteventlog = '/api/logs/eventlog'  ##post
    selectselinfo = '/api/logs/selinfo'  ##get
    print('selectselinfo', SuGon.GetInfo(selectselinfo))
    print('selecteventlog', SuGon.GetInfo(selecteventlog))

if __name__ == '__main__':
    Collect_Info('10.249.177.29', username', 'password')

相关内容

热门资讯

瑞士确诊、法国密接、西班牙待命... 综合法媒报道,国际探险邮轮“洪迪厄斯”号上的汉坦病毒事件,正从南美航程延伸至欧洲语境。最新进展显示,...
AMD锐龙X3D快到把游戏跑崩... 快科技5月6日消息,在Apex英雄最新Overclocked补丁中,修复了一个颇为尴尬的问题:AMD...
重磅|第十九届智慧城市大会将于... 2026年7月16日-18日,第十九届智慧城市大会将在天津社会山国际会议中心举办。本届大会由中国服务...
奥巴马暗批特朗普:不应将司法与... 美国前总统奥巴马近日在接受采访时,借列举总统权力被滥用的多个例子,含蓄批评总统特朗普,但全程未直接点...
三星宣布:在中国大陆市场停止销... 【大河财立方消息】5月6日,三星(中国)投资有限公司发布通知称,为应对急剧变化的市场环境,经慎重研究...
郑州商转公“直还”扩容!80家... 【大河财立方消息】5月6日,郑州住房公积金管理中心公告,13家银行已与郑州住房公积金管理中心签订《商...
男子花数十万买回犀牛角、熊胆,... 王绍斌至今想不通,自己是个三十多年的生意人,怎么会在老挝一下子刷出去六位数,买回来两片犀牛角、半块熊...
电动汽车充电量创历史新高!河南... 【大河财立方 记者 张克瑶】5月6日,大河财立方记者从河南省住房和城乡建设厅获悉,2026年“五一”...
为快乐买单,情绪经济如何“点燃... 【大河财立方 记者 王宁宁 文图】从强势出圈的丑萌潮玩LABUBU,到年轻人的解压新宠“网红”拼豆;...
前微软首席技术专家创办,智用开... 瑞财经 李兰 近日,据智用开物微信公众号,智用开物获近亿元天使+轮融资,由老股东瑞枫资本领投,创享投...