示例#1
0
    def check_ha_controller(self, timeout=30):
        ha = action.HALinstorController()
        node_list = [node['hostname'] for node in self.conn.cluster['node']]
        t_beginning = time.time()

        while True:
            if ha.check_linstor_controller(node_list):
                break
            seconds_passed = time.time() - t_beginning
            if timeout and seconds_passed > timeout:
                print("Linstor controller status error")
                return False
            time.sleep(1)

        for ssh in self.conn.list_ssh:
            ha = action.HALinstorController(ssh)
            service = action.ServiceSet(ssh)
            if service.check_linstor_satellite() != 'enable':
                print('LINSTOR Satellite Service is not "enable".')
                return False
            if not ha.check_satellite_settings():
                print("File linstor-satellite.service modification failed")
                return False

        return True
示例#2
0
    def build_ha_controller(self, sp):
        backup_path = self.conn.cluster['backup_path']
        ha = action.HALinstorController()
        if not ha.linstor_is_conn():
            print('LINSTOR connection refused')
            sys.exit()

        node_list = [node['hostname'] for node in self.conn.cluster['node']]
        if not ha.pool_is_exist(node_list, sp):
            print(f'storage-pool:{sp} does not exist')
            sys.exit()

        ha.create_rd('linstordb')
        ha.create_vd('linstordb', '250M')

        for node in self.conn.cluster['node']:
            ha.create_res('linstordb', node['hostname'], sp)

        for ssh in self.conn.list_ssh:
            ha = action.HALinstorController(ssh)
            if ha.is_active_controller():
                ha.stop_controller()
                ha.backup_linstor(backup_path)  # 要放置备份文件的路径(文件夹)
                ha.move_database(backup_path)
                ha.add_linstordb_to_pacemaker(len(self.conn.cluster['node']))
            ha.modify_satellite_service()  # linstor satellite systemd 配置
示例#3
0
    def destroy_linstordb(self):
        ha = action.HALinstorController()
        if not ha.linstor_is_conn():
            print('LINSTOR connection refused')
            sys.exit()

        for ssh in self.conn.list_ssh:
            ha = action.HALinstorController(ssh)
            list_lv = ha.get_linstordb_lv()
            ha.umount_lv(list_lv)
            ha.secondary_drbd('linstordb')
            ha.delete_rd('linstordb')  # 一般只需在一个节点上执行一次
            ha.remove_lv(list_lv)
示例#4
0
    def backup_linstordb(self, timeout=30):
        linstordb_path = 'ls -l /var/lib/linstor'
        if self.conn.cluster['backup_path'].endswith('/'):
            backup_path = f"{self.conn.cluster['backup_path']}backup_{time.strftime('%Y%m%d%H%M')}"
        else:
            backup_path = f"{self.conn.cluster['backup_path']}/backup_{time.strftime('%Y%m%d%H%M')}"

        t_beginning = time.time()
        while True:
            for ssh in self.conn.list_ssh:
                ha = action.HALinstorController(ssh)
                if ha.is_active_controller():
                    if ha.check_linstor_file(linstordb_path):
                        ha.backup_linstor(backup_path)
                if ha.check_linstor_file(f'{backup_path}/linstor'):
                    return True
            seconds_passed = time.time() - t_beginning
            if timeout and seconds_passed > timeout:
                return False
            time.sleep(1)