def list_all(data): conn = libvirt.open('qemu:///system') if isinstance(data,dict): for x in range(len(data)): temp_key = data.keys()[x] a = data[temp_key] #print a.get('state') if (a.get('state') == 'NULL') or (a.get('state') == 'fluent') or (a.get('state') == 'inactive'): b = a.get('id') name = a.get('hostname') print "The virtual machine [%s] state for id [%s] do not need to do anying..." %(name,b) logging.info("The virtual machine [%s] state for id [%s] do not need to do anying..." %(name,b)) elif (a.get('state') == 'active'): c = a.get('id') name2 = a.get('hostname') stop = action.shutdownDomaction(conn,int(c)) if not stop: print "The virtual machine [%s] state for id [%s] shutown successfully..." %(name2,c) logging.info("The virtual machine [%s] state for id [%s] shutdown successfully..." %(name2,c)) cmd = 'sh /root/script/monitoring_kvm/tools/send_mail.sh Successfully %s' % name2 shell.shell_cmd(cmd) else: print "The virtual machine [%s] state for id [%s] shutown faild..." %(name2,c) logging.info("The virtual machine [%s] state for id [%s] shutdown faild..." %(name2,c)) cmd = 'sh /root/script/monitoring_kvm/tools/send_mail.sh Faild %s' % name2 shell.shell_cmd(cmd) conn.close()
def check_ip(ip): cmd = 'fping %s' % ip ping_result = shell.shell_cmd(cmd)[0] if 'alive' in ping_result: return 'active' else: return 'inactive'
def check_ip(ip): cmd = 'fping %s' %ip ping_result = shell.shell_cmd(cmd)[0] if 'alive' in ping_result: return 'active' else: return 'inactive'
def host_id_associated(): associated = [] associated_cmd = "virsh list |grep -v -e Id -e - -e ^$|awk '{print $2,$1}'" result = shell.shell_cmd(associated_cmd) for i in xrange(len(result)): rs = result[i].split() associated.append(rs) return associated
def exist_hostname(): exist_host = [] exist_cmd = "virsh list --all |grep -v -e Id -e '---' -e '^$'|awk '{print $2}'" result = shell.shell_cmd(exist_cmd) if not result: exist_host = ['NULL'] return exist_host else: for i in xrange(len(result)): ap = result[i].split()[0] exist_host.append(ap) return exist_host
def send_faild(self,host): title = self.title mail_cmd = '/bin/mail -s %s %s < %s' % (title,self,mailbox,mail_content(times,host,'Faild.')) shell.shell_cmd(mail_cmd) return 1
def send_success(self,host): title = self.title mail_cmd = '/bin/mail -s %s %s < %s' % (title,self.mailbox,mail_content(times,host,'successfully')) shell.shell_cmd(mail_cmd) return 0
def send_faild(self, host): title = self.title mail_cmd = '/bin/mail -s %s %s < %s' % ( title, self, mailbox, mail_content(times, host, 'Faild.')) shell.shell_cmd(mail_cmd) return 1
def send_success(self, host): title = self.title mail_cmd = '/bin/mail -s %s %s < %s' % ( title, self.mailbox, mail_content(times, host, 'successfully')) shell.shell_cmd(mail_cmd) return 0