IT袋

当前位置:主页 > 经验教程 > 建站编程 >

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

Python多线程批量管理服务器脚本(2)

时间:2023-11-05 17:37:13 来源:IT袋 作者:马勇
导读:Python多线程批量管理服务器脚本,版本BMC管理脚本二 import osimport timeimport subprocessfrom queue import Queuefrom threading import Threadclass IPMI_Manager: def __init__(self): self.ipaddress_queue = Queue() self.IPMI_tool_q

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

版本BMC管理脚本二

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多线程批量管理服务器脚本

以上是IT袋网网关于Python多线程批量管理服务器脚本的具体介绍,供网友们借鉴参考。

相关阅读

  • 建公司网站费用怎么算 制作网站的费用标准

    建公司网站费用怎么算 制作网站的费用标准

    相对于大多数人建公司网站费用怎么算和制作网站的费用标准的电脑小知识,接下来IT袋小编就来介绍。 现在做网站的门槛越来越低,只要你对这个市场有一定的了解,有一台电脑,下载一个

  • Unity正在积极开发 预告 7.7 版

    Unity正在积极开发 预告 7.7 版

    为大家介绍的是Unity正在积极开发的相关介绍,接下来就是全面介绍。 Unity 7.7 版的更新计划为该桌面环境带来一些视觉上的改革。 Unity,经典的桌面环境,从 2010 年到 2017 年都是 Ubuntu 的一部

  • Spring中的Bean创建的⽣命周期有哪些步骤

    Spring中的Bean创建的⽣命周期有哪些步骤

    IT电脑小知识篇,关于Spring中的Bean创建的⽣命周期有哪些步骤的电脑方面的小经验,接下来IT袋网小编就来介绍。 Spring中⼀个Bean的创建⼤概分为以下⼏个步骤: 推断构造⽅法 实例化 填充属性

  • 免费网站怎么做出来的 网页制作正版网站

    免费网站怎么做出来的 网页制作正版网站

    本文摘要:免费网站怎么做出来的和网页制作正版网站的相关知识,请看下面详细的介绍。 在不懂设计知识、也不懂技术的情况下,小白可以做出好看的网站吗?当然也是可以的,而且通过