编程语言
首页 > 编程语言> > 基于服务器资源监控程序增加一键关机

基于服务器资源监控程序增加一键关机

作者:互联网

增加一键关机按钮

        
        #一键关机
        self.Shutdown_btn = wx.Button(self.panel1, -1, "一键关机", pos=(950,20),size=(70, 70))
        #前景格式
        fontButton = wx.Font(10,wx.SCRIPT,wx.LIGHT,wx.NORMAL,faceName="黑体")
        self.Shutdown_btn.SetFont(fontButton)
        #背景颜色
        self.Shutdown_btn.SetBackgroundColour("#ff9933")
        self.Bind(wx.EVT_BUTTON, self.Shutdown, self.Shutdown_btn)

  增加一键关机方法(会调用之前的SSH登录方式)

    def Shutdown(self,event):
        #实例化Remote_management_WayKind类
        self.Ssh_load = MESRM.Remote_management_WayKind() 
        with open("ServerComputerInfo.json", 'r') as fw:
            injson = json.load(fw)

        LoadInfolist1= []
        LoadInfolist3= []

        for key1,value in injson.items():
            
                    
            if key1 == 'SoftWarePC' :
                self.log_info1.AppendText('\n' +key1 + '虚拟主机正在关机\n')
                for value2 in value :
                           
                    LoadInfolist2=[]
                    for key,value3 in value2.items():             
                   
                        LoadInfolist2.append(value3)
                    LoadInfolist1.append(LoadInfolist2)            
                                
                countlen =  len(LoadInfolist1)    
                for i in range(countlen): 
                    self.log_info1.AppendText(LoadInfolist1[i][0]+'虚拟机正在关机 \n' )   
                
                    td = Thread(target=self.Use_Monitor, args=(self, LoadInfolist1[i]))
                    td.setDaemon(1)
                    td.start()
            else:
                self.log_info1.AppendText('\n' +key1 + '实体机关机等待120秒\n')
                
                def HardWarePC():
                    timecount = 120  
                    for i in range(120):
                        #nowtime = datetime.datetime.now()
                        self.log_info1.AppendText('实体机关机倒计时 ' + str(timecount) +'秒 \n')
                        timecount = timecount - 1
                        time.sleep(1)
                    
                    for value2 in value :
                               
                        LoadInfolist4=[]
                        for key,value3 in value2.items():             
                       
                            LoadInfolist4.append(value3)
                        LoadInfolist3.append(LoadInfolist4)            
                                    
                    countlen =  len(LoadInfolist3)    
                    for i in range(countlen): 
                        self.log_info1.AppendText(LoadInfolist3[i][0]+'实体机开始关机 \n' )   
                    
                        td = Thread(target=self.Use_Monitor, args=(self, LoadInfolist3[i]))
                        td.setDaemon(1)
                        td.start()
                        
                td = Thread(target=HardWarePC)
                td.setDaemon(1)
                td.start()

  调用json文件的格式,注意json细节,比如逗号和括号的使用

{
  "SoftWarePC": 
  [
    {
        "ip": "X.x.x.x",
        "name": "abcde",
        "password": "dadas",
        "command": "sudo shutdown -h now;shutdown -s -t 0"
    }
    
    
  ],

  "HardWarePC": 
  [
    {
        "ip": "1.2.2.3",
        "name": "464564",
        "password": "dadasd",
        "command": "sudo shutdown -h now;shutdown -s -t 0"
    }
    
  ]
}

  

标签:关机,self,服务器资源,一键,Shutdown,info1,td,wx
来源: https://www.cnblogs.com/babashi9527/p/16648666.html