Python多线程批处理管理服务器脚本 - 汇站网

Python多线程批处理管理服务器脚本

2023-11-24 0 863

正文:

今天写了两个python多线程批处理管理服务器的脚本。

IPMI(Intelligent Platform Management Interface,智能平台管理接口)是应用于服务器管理系统设计的标准,由 Intel、HP、Dell 和 NEC 于 1998 年联合提出。IPMI 的主要特点是它可以独立于处理器、BIOS 和操作系统。使用该标准,有助于在不同类型的服务器系统硬件上实现系统管理,并使不同平台的集中管理成为可能。

在 IPMI 管理平台中,BMC(基板管理控制器)是核心控制器,通过与 BMC 的通信实现系统管理软件对各个设备的管理。BMC 与主处理器和板上的组件连接,并监控或管理物理组件。

由于 BMC 系统的独立性,IPMI 为高可用性(HA)系统提供了企业级管理工具,即使在系统断电状态下也可以使用平台管理功能。当系统管理软件和正常的带内管理机制不可用时,可以获取平台状态信息并开始恢复操作。通过 IPMI 独立的监控、日志记录等功能,它为服务器硬件提供了一个内置的可管理平台。

首先看下运行界面

Python多线程批处理管理服务器脚本

版本 BMC 管理脚本一

// https://www.huizhanii.com
import os
import subprocess
import time
from queue import Queue
from threading import Thread

class IPMI_Manaeger:
   # 任务队列

   def __init__(self):
       # ip 列表
       self.ipaddress_queue=Queue()
       self.IPMI_tool_queue = Queue()
   def IP_list(self):
       with open("ip_list.txt", "r", encoding="utf-8") as f:
           ip_address = f.readlines()
           self.ipaddress_queue.put(ip_address)
   def IPMI(self, choose_id, user, pwd):
       ipaddress_list=self.ipaddress_queue.get()
       if choose_id == 1:
           for ipaddress in ipaddress_list:

               #self.IPMI_tool_queue.put(subprocess.run('dir',shell=True))
              # self.IPMI_tool_queue.put(os.system( "<a target="_blank" href="https://www.huizhanii.com/tag/ipmi" title="View all posts in ipmi" rel="noopener">ipmi</a>tool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " power status"))
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " power status",shell=True))

       elif choose_id == 2:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " power on",shell=True))

       elif choose_id == 3:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " power off",shell=True))
           self.ipaddress_queue.task_done()
       elif choose_id == 4:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " power reset",shell=True))

       elif choose_id == 5:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " chassis bootdev pxe",shell=True))

       elif choose_id == 6:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " chassis bootdev bios",shell=True))

       elif choose_id == 7:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " chassis bootdev cdrom",shell=True))

       elif choose_id == 8:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " chassis bootdev disk",shell=True))

       elif choose_id == 9:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " mc reset cold",shell=True))

       elif choose_id == 10:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " mc reset warm",shell=True))

       elif choose_id == 11:
           for ipaddress in ipaddress_list:
               self.IPMI_tool_queue.put(subprocess.Popen("ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " power off"& time.sleep(
                   5) & "ipmitool -I lanplus -H " + ipaddress + " -U " + user + " -P " + pwd + " power on",shell=True))

       self.ipaddress_queue.task_done()
   def IPMI_run(self):
       print("***************************************")
       print("1.查看电源状态")
       print("2.开机")
       print("3.关机")
       print("4.重启")
       print("5.PXE 启动")
       print("6.BIOS 启动")
       print("7.从 CD/DVD 启动")
       print("8.从硬盘启动")
       print("9.冷重启 BMC")
       print("10.热重启 BMC")
       print("11.冷重启系统")
       print("***************************************")
       choose_id = int(input("请选择需要执行指令 ID:"))
       username = input("请输入 BMC 用户名:")
       password = input("请输入 BMC 密码:")
       IMPI_list = []
       IPMI_ip = Thread(target=self.IP_list())
       IMPI_list.append(IPMI_ip)
       #print(IMPI_list)
       for i in range(5):
           IPMI_tools = Thread(target=self.IPMI, args=(choose_id, username, password))
           IMPI_list.append(IPMI_tools)

       for t in IMPI_list:
           t.setDaemon(True)
           t.start()
           time.sleep(5)
       print(IMPI_list)
       for q in [self.IPMI_tool_queue,self.ipaddress_queue]:
           q.join()
if __name__ == '__main__':
   # 消费线程
   IPMI=IPMI_Manaeger()
   IPMI.IPMI_run()

版本 BMC 管理脚本二

// https://www.huizhanii.com
import os
import time
import subprocess
from queue import Queue
from threading import Thread


class IPMI_Manager:
   def __init__(self):
       self.ipaddress_queue = Queue()
       self.IPMI_tool_queue = Queue()

   def IP_list(self):
       with open("ip_list.txt", "r", encoding="utf-8") as f:
           ip_address = f.readlines()
           self.ipaddress_queue.put(ip_address)

   def IPMI(self, choose_id, user, pwd):
       ipaddress_list = self.ipaddress_queue.get()
       for ipaddress in ipaddress_list:
           command = f"ipmitool -I lanplus -H {ipaddress.strip()} -U {user} -P {pwd}"
           if choose_id == 1:
               command += " power status"
           elif choose_id == 2:
               command += " power on"
           elif choose_id == 3:
               command += " power off"
           elif choose_id == 4:
               command += " power reset"
           elif choose_id == 5:
               command += " chassis bootdev pxe"
           elif choose_id == 6:
               command += " chassis bootdev bios"
           elif choose_id == 7:
               command += " chassis bootdev cdrom"
           elif choose_id == 8:
               command += " chassis bootdev disk"
           elif choose_id == 9:
               command += " mc reset cold"
           elif choose_id == 10:
               command += " mc reset warm"
           elif choose_id == 11:
               command += " power off && sleep 5 && ipmitool -I lanplus -H {ipaddress.strip()} -U {user} -P {pwd} power on"

           process = subprocess.run(command, shell=True)
           self.IPMI_tool_queue.put(process)

       self.ipaddress_queue.task_done()

   def IPMI_run(self):
       print("***************************************")
       print("1. 查看电源状态")
       print("2. 开机")
       print("3. 关机")
       print("4. 重启")
       print("5. PXE 启动")
       print("6. BIOS 启动")
       print("7. 从 CD/DVD 启动")
       print("8. 从硬盘启动")
       print("9. 冷重启 BMC")
       print("10. 热重启 BMC")
       print("11. 冷重启系统")
       print("***************************************")
       choose_id = int(input("请选择需要执行指令 ID: "))
       username = input("请输入 BMC 用户名: ")
       password = input("请输入 BMC 密码: ")

       IMPI_list = []
       IPMI_ip = Thread(target=self.IP_list)
       IMPI_list.append(IPMI_ip)

       for _ in range(4):
           IPMI_tools = Thread(target=self.IPMI, args=(choose_id, username, password))
           IMPI_list.append(IPMI_tools)

       for t in IMPI_list:
           print(t)
           t.setDaemon(True)
           t.start()

       for q in [self.IPMI_tool_queue, self.ipaddress_queue]:
           q.join()


if __name__ == '__main__':
   IPMI = IPMI_Manager()
   IPMI.IPMI_run()

转载请注明:汇站网 » Python 多线程批处理管理服务器脚本

收藏 (0)

微信支付 微信扫一扫

支付宝支付 支付宝扫一扫

支付二维码
点赞 (0)

免责 声明

本资源仅用于个人 学习和研究使用,禁止用于任何商业环境!

 1.  本网站名称:汇站网
 2.  本站永久网址:https://www.huizhanii.com/
 3.  本站所有资源来源于网友投稿和高价 购买,所有资源仅对编程人员及源代码爱好者开放下载做参考和研究及学习,本站不提供任何技术服务 !
 4.  本站所有资源的展示图片和信息不代表本站的立场 !本站只是储蓄平台及搬运
 5.  下载者禁止在服务器和虚拟机下进行搭建运营,本站 所有资源不支持联网运行!只允许调试,参考和研究!!!!
 6.  未经原版权作者许可,禁止用于任何 商业环境,任何人不得擅作它用,下载者不得用于违反国家法律,否则发生的一切法律后果自行承担!
 7.  为尊重作者版权,请在下载24小时 内删除!请购买原版授权作品,支持你喜欢的作者,谢谢!
 8.  若资源侵犯了您的合法权益, 请持 您的版权证书和相关原作品信息来信通知我们请来信     通知我们 我们会及时删除,给您带来的不便,我们深表歉意!
 9.  如下载链接失效、广告或者压缩包 问题请联系站长处理!
 10.  如果你也有好源码或者教程,可以 发布到网站,分享有金币奖励和额外收入!
 11.  本站资源售价只是赞助,收取费用 仅维持本站的日常运营所需!
 12.  因源码具有可复制性,一经赞助 ,不得以任何形式退款。
 13.  更多详情请点击查看

汇站网 Python Python多线程批处理管理服务器脚本 https://www.huizhanii.com/33935.html

站长资源下载中心-找源码上汇站

常见问题
  • 如果付款后没有弹出下载页面,多刷新几下,有问题联系客服!
查看详情
  • 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
查看详情

相关文章

发表评论
暂无评论
  随机评论   表情   下载本站到电脑桌面


表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情表情
登录后评论
联系官方客服

为您解决烦忧 - 24小时在线 专业服务

(汇站网)一个专注站长资源的平台网站,提供最新的网站模板和整站源码,内容包含各类精品网页模板,企业网站模板,网站模板,DIV+CSS模板,织梦模板,帝国cms模板,discuz模板,wordpress模板,个人博客论坛模板,上千种免费网页模板下载尽在汇站网.找源码上汇站.huizhanii.com