def check_corosync(self): nodes = [node['hostname'] for node in self.conn.cluster['node']] lst_ring_status = [] lst_cluster_status = [] lst = [] times = 3 for ssh, node in zip(self.conn.list_ssh, self.conn.cluster['node']): corosync = action.Corosync(ssh) lst_ring_status.append(corosync.check_ring_status(node)) lst_cluster_status.append(corosync.check_corosync_status(nodes)) while not all(lst_cluster_status) and times > 0: time.sleep(5) lst_cluster_status = [] for ssh, node in zip(self.conn.list_ssh, self.conn.cluster['node']): corosync = action.Corosync(ssh) lst_cluster_status.append( corosync.check_corosync_status(nodes)) times -= 1 for x, y in zip(lst_ring_status, lst_cluster_status): if x and y: lst.append(True) else: lst.append(False) return lst
def restart_corosync(self): try: for ssh in self.conn.list_ssh: action.Corosync(ssh).restart_corosync() except timeout_decorator.timeout_decorator.TimeoutError: print('Restarting corosync service timed out') sys.exit()
def get_version(self, *args): """ 参数输入要获取版本信息的软件,支持sysos,syskernel,drbd,linstor,targetcli,pacemaker,corosync 返回数据的顺序与参数顺序一致 :param args: :return: """ result = [] for ssh in self.conn.list_ssh: host = action.Host(ssh) result.append(host.get_hostname()) for soft in args: if soft == 'sysos': result.append(host.get_sys_version()) elif soft == 'syskernel': result.append(host.get_kernel_version()) elif soft == 'drbd': drbd = action.DRBD(ssh) result.append(drbd.get_version()) elif soft == 'linstor': linstor = action.Linstor(ssh) result.append(linstor.get_version()) elif soft == 'targetcli': targetcli = action.TargetCLI(ssh) result.append(targetcli.get_version()) elif soft == 'pacemaker': pacemaker = action.Pacemaker(ssh) result.append(pacemaker.get_version()) elif soft == 'corosync': corosync = action.Corosync(ssh) result.append(corosync.get_version()) for i in range(0, len(result), len(args) + 1): yield result[i:i + len(args) + 1]
def corosync_conf_change(self): cluster_name = self.conn.conf_file.get_cluster_name() bindnetaddr_list = self.conn.conf_file.get_bindnetaddr() interface = self.conn.conf_file.get_inferface() nodelist = self.conn.conf_file.get_nodelist() for ssh in self.conn.list_ssh: action.Corosync(ssh).change_corosync_conf(cluster_name, bindnetaddr_list, interface, nodelist)
def restart_corosync(self): lst = [] timeout.start() for ssh in self.list_ssh: lst.append(gevent.spawn(action.Corosync(ssh).restart_corosync)) try: gevent.joinall(lst) except gevent.Timeout: print('Restarting corosync service timed out') else: timeout.close()
def corosync_conf_change(self): lst = [] cluster_name = self.conf_file.get_cluster_name() bindnetaddr = self.conf_file.get_bindnetaddr()[0] interface = self.conf_file.get_inferface() nodelist = self.conf_file.get_nodelist() for ssh in self.list_ssh: lst.append( gevent.spawn( action.Corosync(ssh).change_corosync_conf, cluster_name, bindnetaddr, interface, nodelist)) gevent.joinall(lst)
def check_corosync(self): nodes = [node['hostname'] for node in self.cluster['node']] lst_ring_status = [] lst_cluster_status = [] for ssh, node in zip(self.list_ssh, self.cluster['node']): corosync = action.Corosync(ssh) lst_ring_status.append( gevent.spawn(corosync.check_ring_status, node)) lst_cluster_status.append( gevent.spawn(corosync.check_corosync_status, nodes)) gevent.joinall(lst_ring_status) gevent.joinall(lst_cluster_status) lst = [] for x, y in zip([i.value for i in lst_ring_status], [i.value for i in lst_cluster_status]): if x and y: lst.append(True) else: lst.append(False) return lst
def sync_time(self): for ssh in self.conn.list_ssh: action.Corosync(ssh).sync_time()
def recover_corosync_conf(self): for ssh in self.conn.list_ssh: corosync = action.Corosync(ssh) corosync.recover_conf() corosync.restart_corosync()
def recover_corosync_conf(self): self.modify_cluster_name("debian") for ssh in self.conn.list_ssh: corosync = action.Corosync(ssh) corosync.recover_conf() corosync.restart_corosync()
def sync_time(self): lst = [] for ssh in self.list_ssh: lst.append(gevent.spawn(action.Corosync(ssh).sync_time)) gevent.joinall(lst)