DELL IDRAC API接口开发文档翻译

Posted 十年如一..bj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DELL IDRAC API接口开发文档翻译相关的知识,希望对你有一定的参考价值。

今天和DELL官网要了一份关于服务器IDRAC 版本7/8 的API开发文档,花了一天的时间,进行了翻译,不一定全部准确,但对于英语不好的人会有所帮助。也不用重复造轮子了。
下载链接:

IDRAC API开发文档翻译版本

DELL IDRAC7/8  硬件监控client模块

  1 #!/opt/python3/bin/python3
  2 #Author: zhaoyong
  3 \'\'\'
  4 本模块用于DELL 服务器IDARC API接口,只用于检测硬件状态,检测硬件包括如下:
  5     < CPU, 内存, 磁盘, 电源, 风扇, raid卡>
  6 注意:只支持IDRAC版本7和版本8
  7 注意:只提取URL:/redfish/v1/Systems/System.Embedded.1 下的信息
  8 \'\'\'
  9 import requests, json
 10 
 11 
 12 class idrac_api(object):
 13     \'\'\'
 14     DELL powerEdge服务器IDRAC 7/8 API 硬件监控客户端接口
 15     \'\'\'
 16 
 17     def __init__(self, ip, username, passwd):
 18         self.__ip = ip
 19         self.__username = username
 20         self.__passwd = passwd
 21         # 服务器连接tokin对象
 22         self.__s_tokin = \'\'
 23         # 第一次访问提取的元数据,字典格式
 24         self.__meta_data_dict = \'\'
 25 
 26     def conn(self):
 27         \'\'\'
 28         连接服务器
 29         :return:
 30         \'\'\'
 31         # SSL验证会提示警告,这里进行关闭警告信息的提示
 32         requests.packages.urllib3.disable_warnings()
 33         # 初始化一个session连接
 34         c = requests.Session()
 35         c.timeout = 60
 36         # 设置验证信息
 37         c.auth = (self.__username, self.__passwd)
 38         # 关闭SSL验证
 39         c.verify = False
 40         # 连接IDRAC并进行身份验证和原始数据的提取
 41         auth_url = \'https://%s/redfish/v1/Systems/System.Embedded.1\' % (self.__ip)
 42         try:
 43             conn_status = c.get(auth_url)
 44             # 如果连接成功,将session对象赋予self.__s_tokin,获取的元数据赋予self.__meta_data_dict,否则报错
 45             if conn_status.ok:
 46                 self.__s_tokin = c
 47                 self.__meta_data_dict = conn_status.json()
 48             else:
 49                 err_info = conn_status.raise_for_status()
 50                 # print(\'----->\',err_info)
 51                 return \'服务器: %s IDRAC连接失败,错误信息:%s\' % (self.__ip, err_info)
 52         except Exception as e:
 53             return \'服务器: %s IDRAC连接失败,错误信息:%s\' % (self.__ip, e)
 54 
 55     def memory_status(self):
 56         \'\'\'
 57         检测内存
 58         输出格式:MemorySummary {\'Status\': {\'Health\': \'OK\', \'HealthRollUp\': \'OK\', \'State\': \'Enabled\'}, \'TotalSystemMemoryGiB\': 64.0}
 59         :return: 返回内存状态
 60         \'\'\'
 61         mem_status = self.__meta_data_dict[\'MemorySummary\'][\'Status\'][\'Health\']
 62         return mem_status
 63 
 64     def cpu_status(self):
 65         \'\'\'
 66         检测CPU
 67         输出格式:ProcessorSummary {\'Count\': 2, \'Model\': \'Intel(R) Xeon(R) CPU E5-2660 v3 @ 2.60GHz\', \'Status\': {\'Health\': \'OK\', \'HealthRollUp\': \'OK\', \'State\': \'Enabled\'}}
 68         :return:返回CPU状态
 69         \'\'\'
 70         cpu_status = self.__meta_data_dict[\'ProcessorSummary\'][\'Status\'][\'Health\']
 71         return cpu_status
 72 
 73     def sn(self):
 74         \'\'\'
 75         提取服务的SN,暂时不需要
 76         :return: 返回SN码
 77         \'\'\'
 78         sn_str = self.__meta_data_dict[\'SKU\']
 79         return sn_str
 80 
 81     def disk_status(self):
 82         \'\'\'
 83         硬盘检测输出:
 84         SimpleStorage {\'@odata.id\': \'/redfish/v1/Systems/System.Embedded.1/Storage/Controllers\'}
 85         Status {\'Health\': \'OK\', \'HealthRollUp\': \'OK\', \'State\': \'Enabled\'}
 86         如果总体检测结果为OK,直接返回默认字典
 87         否则将详细检查每一个磁盘和raid卡,将有故障的设备名称写入返回的字典
 88         :return: 返回硬盘和raid卡状态
 89         \'\'\'
 90         disk_result= {\'raid_card\':\'OK\',\'pre_disk\':\'OK\'}
 91         disk_check = self.__meta_data_dict[\'Status\'][\'Health\']
 92         if disk_check != \'OK\':
 93             d_url_str = \'https://%s%s\' % (self.__ip, self.__meta_data_dict[\'SimpleStorage\'][\'@odata.id\'])
 94             member_out = self.__s_tokin.get(d_url_str).json()
 95             member_url_str = \'https://%s%s\' % (self.__ip, member_out[\'Members\'][0][\'@odata.id\'])
 96             pre_disk_out = self.__s_tokin.get(member_url_str).json()
 97             if pre_disk_out[\'Status\'][\'Health\'] != \'OK\':
 98                 disk_result[\'raid_card\'] = pre_disk_out[\'Name\']
 99             for pd in pre_disk_out[\'Devices\']:
100                 if pd[\'Status\'][\'Health\'] != \'OK\':
101                     disk_result[\'pre_disk\'] = pd[\'Name\']
102 
103         return disk_result
104 
105     def power_status(self):
106         \'\'\'
107         电源检测
108         :return: 返回电源状态
109         \'\'\'
110         pow_status = {}
111         power_url_list = self.__meta_data_dict[\'Links\'][\'PoweredBy\']
112         for p in power_url_list:
113             p_url = \'https://%s%s\' % (self.__ip, p[\'@odata.id\'])
114             p_dict = self.__s_tokin.get(p_url).json()
115             pow_status[p_dict[\'Name\']] = p_dict[\'Status\'][\'Health\']
116         return pow_status
117 
118     def fan_status(self):
119         \'\'\'
120         风扇检测
121         :return:统一返回风扇整体状态
122         \'\'\'
123         fan_status={\'fan\':\'OK\'}
124         fan_all_list = self.__meta_data_dict[\'Links\'][\'CooledBy\']
125         for f in fan_all_list:
126             f_url_str = \'https://%s%s\' % (self.__ip, f[\'@odata.id\'])
127             fan_out = self.__s_tokin.get(f_url_str).json()
128             if fan_out[\'Status\'][\'Health\'] != \'OK\':
129                 fan_status[\'fan\'] = fan_out[\'FanName\']
130                 return fan_status
131         return fan_status
132 
133     def hardware_status(self):
134         \'\'\'
135         收集所有硬件信息
136         :return: 返回json格式数据
137         \'\'\'
138         out = []
139         ck_result = {}
140         ck_result[\'cpu\'] = self.cpu_status()
141         ck_result[\'memory\'] = self.memory_status()
142         ck_result[\'disk\'] = self.disk_status()[\'pre_disk\']
143         ck_result[\'raid_card\'] = self.disk_status()[\'raid_card\']
144         ck_result[\'power1\'] = self.power_status()[\'PS1 Status\']
145         ck_result[\'power2\'] = self.power_status()[\'PS2 Status\']
146         ck_result[\'fan\'] = self.fan_status()[\'fan\']
147         # 提取故障设备
148         for s in ck_result:
149             if ck_result[s] != \'OK\':
150                 out.append(ck_result[s])
151         if len(out) == 0:
152             out.append(\'OK\')
153         # 以字符串返回故障设备,否则返回OK,表示无故障
154         return \',\'.join(out)
155 
156 if __name__ == \'__main__\':
157     \'\'\'
158     运行主程序,测试使用
159     \'\'\'
160     out = idrac_api(\'IDRAC IP\', \'账号\', \'密码\')
161     # 连接服务器
162     mess = out.conn()
163     # 有错误就打印报错信息并exit
164     if mess:
165         exit(mess)
166     # 以字符串打印检测结果
167     result = out.hardware_status()
168     print(result)

 

以上是关于DELL IDRAC API接口开发文档翻译的主要内容,如果未能解决你的问题,请参考以下文章

DELL服务器使用idrac虚拟控制台进行系统安装

ansible+redfish+idrac管理DELL服务器

dell服务器idrac初始化错误

ubuntu 访问dell Idrac卡方法实践

安装并使用 iDRAC 服务模块

Dell服务器iDRAC卡重置密码,忘记密码