简介:浪潮集团,是中国本土顶尖的大型IT企业之一,中国领先的云计算、大数据服务商。浪潮集团旗下拥有浪潮信息、浪潮软件、浪潮国际,业务涵盖云计算、大数据、工业互联网等新一代信息技术产业领域,为全球120多个国家和地区提供IT产品和服务,浪潮致力于成为世界一流的新一代信息技术产业龙头企业,经济社会数字化转型的优秀服务商,新型基础设施建设的骨干企业。浪潮服务器面向智慧时代所设计,以“硬件重构+软件定义”技术理念, 为云计算、大数据和人工智能提供高度定制化的承载平台,适合云数据中心部署环境, 赋能各行业的数字化、智慧化转型与重塑。
历史攻略:
Python:requests + BMC 获取和设置服务器风速
Python:requests + bmc开机、关机、优雅重启、强制重启
从入门到精通:IPMITool 的详尽指南
案例源码:仅供参考,实际请按相关BMC信息配置
# -*- coding: utf-8 -*-
# time: 2023/12/06 15:36
# file: fan.py
# 公众号: 玩转测试开发
import re
import requests
import warningswarnings.filterwarnings("ignore")class Fans(object):headers = {"content-type": "application/json","User-Agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/117.0.2045.60",}def __init__(self, host, username, password):self.host = hostself.username = usernameself.password = passworddef get_random(self):url = f"https://{self.host}/api/randomtag"res = requests.get(url, headers=self.headers, verify=False)return res.json()["random"]def get_session(self, random_string):url = f"https://{self.host}/api/session"self.headers["content-type"] = "application/x-www-form-urlencoded; charset=UTF-8"data = {"encrypt_flag": 0,"username": self.username,"password": self.password,"login_tag": str(random_string)}response = requests.post(url, headers=self.headers, data=data, verify=False)token = re.findall("QSESSIONID=(.*?);", response.headers["Set-Cookie"])[0]self.headers["X-Csrftoken"] = response.json()["CSRFToken"]self.headers["Cookie"] = str("lang=zh-cn;QSESSIONID=" + token + "; refresh_disable=1")self.headers["content-type"] = "application/json"def get_fans(self):url = f"https://{self.host}/api/status/fan_info"response = requests.get(url, headers=self.headers, verify=False).json()for k, v in response.items():if k == "fans":for i in v:print(i)def fans_mode(self, mode="manual"):url = f"https://{self.host}/api/settings/fans-mode"# manual - autodata = {"control_mode": mode}response = requests.put(url, headers=self.headers, json=data, verify=False)print("response:", response.text)def change_fans(self, rate=100, fans=24):for i in range(fans):url = f'https://{self.host}/api/settings/fan/{i}'data = {"duty": rate}response = requests.put(url=url, json=data, verify=False, headers=self.headers)response.encoding = "utf-8"print(f"The index {i} fan change to {response.json()['duty']} %", )if __name__ == '__main__':# e.g.bmc_host = "111.1112.113.114"username = "admin"password = "123456789"f = Fans(host=bmc_host, username=username, password=password)random_string = f.get_random()f.get_session(random_string)f.get_fans()f.fans_mode()f.change_fans(rate=100, fans=24)
运行结果:
注意事项:
1、慎重起见,请先进行抓包,解析 http 网络接口数据,调试再使用。
2、设置时,需要先自动挡改成手动档,详见方法 fans_mode()