Esempio n. 1
0
def format_history(histories):
    history_list = []
    trans = MigrateDal.get_isp_trans()
    for history in histories:
        history_list.append({
            'id':
            history.id,
            'migrate_rooms':
            sorted(json.loads(history.migrate_rooms)),
            'dst_rooms':
            sorted(json.loads(history.dst_rooms)),
            'migrate_isps':
            sorted([trans[isp] for isp in json.loads(history.migrate_isps)]),
            'cur':
            history.cur,
            'all':
            history.all,
            'state':
            history.state,
            'rtx_id':
            history.rtx_id,
            'update_at':
            history.updated_time.strftime('%Y-%m-%d %H:%M:%S')
        })
    return history_list
Esempio n. 2
0
def get_previewinfo():
    trans = MigrateDal.get_isp_trans()
    domain_count = ViewRecordDal.zone_domain_count()
    migrate_list = []
    histories = MigrateDal.get_migrated_history()
    for history in histories:
        migrate_list.append({
            'migrate_rooms': sorted(json.loads(history.migrate_rooms)),
            'dst_rooms': sorted(json.loads(history.dst_rooms)),
            'migrate_isps': sorted([trans[isp] for isp in json.loads(history.migrate_isps)])
        })

    migrate_acl_subnet = ViewIspAclDal.get_migrate_subnet()

    return {'domain_count': domain_count,
            'migrate': migrate_list,
            'acl_migrate': migrate_acl_subnet}
Esempio n. 3
0
def format_history(histories):
    history_list = []
    trans = MigrateDal.get_isp_trans()
    for history in histories:
        history_list.append({
            'id': history.id,
            'migrate_rooms': sorted(json.loads(history.migrate_rooms)),
            'dst_rooms': sorted(json.loads(history.dst_rooms)),
            'migrate_isps': sorted([trans[isp] for isp in json.loads(history.migrate_isps)]),
            'cur': history.cur,
            'all': history.all,
            'state': history.state,
            'rtx_id': history.rtx_id,
            'update_at': history.updated_time.strftime('%Y-%m-%d %H:%M:%S')
        })
    return history_list
Esempio n. 4
0
 def run(self):
     with self.app.app_context():
         for i in range(0, len(self.migrate_domain_list), self.step):
             try:
                 MigrateDal.migrate_domains(self.migrate_domain_list[i: i + self.step], self.migrate_history_id)
             except Exception as e:
                 log.error('migrate rooms failed:%s' % e)
                 MigrateDal.update_history_by_id(self.migrate_history_id, state='error')
                 return
         # 更新serial
         MigrateDal.increase_serial_num(NORMAL_TO_CNAME.values())
Esempio n. 5
0
 def run(self):
     with self.app.app_context():
         for i in range(0, len(self.migrate_domain_list), self.step):
             try:
                 MigrateDal.migrate_domains(
                     self.migrate_domain_list[i:i + self.step],
                     self.migrate_history_id)
             except Exception as e:
                 log.error('migrate rooms failed:%s' % e)
                 MigrateDal.update_history_by_id(self.migrate_history_id,
                                                 state='error')
                 return
         # 更新serial
         MigrateDal.increase_serial_num(NORMAL_TO_CNAME.values())
Esempio n. 6
0
def list_migrate_domain():
    json_data = request.get_json(force=True)
    src_rooms = json_data.get('src_rooms', [])
    dst_rooms = json_data.get("dst_rooms", [])
    isps = json_data.get("isps", [])
    return MigrateDal.list_migrate_domain(src_rooms, dst_rooms, isps)
Esempio n. 7
0
def list_migrate_history():
    return format_history(MigrateDal.get_last_few_history(limit=15))
Esempio n. 8
0
def migrate_rooms(src_rooms, dst_rooms, to_migrate_isps, username):
    history_id = MigrateDal.create_migrage_history(username)

    migrated_isp_rooms = MigrateDal.get_all_abnormal_isps(key='isp', value='room')
    to_migrate_dict = {isp: set(src_rooms) | migrated_isp_rooms.get(isp, set())
                       for isp in to_migrate_isps}

    migrate_isp_domains = MigrateDal.list_migrate_domain_by_isp(to_migrate_dict, dst_rooms)

    has_migrate_domains = False
    for isp, migrate_domains_list in migrate_isp_domains.items():
        migrate_domains_list = [domain for domain in migrate_domains_list if domain['after_enabled_rooms']]
        if len(migrate_domains_list) == 0:
            continue
        has_migrate_domains = True
        MigrateDal.update_history_total(history_id, len(migrate_domains_list))
        m_thread = MigrateThread(username, history_id, migrate_domains_list)
        m_thread.start()

    if has_migrate_domains:
        MigrateDal.add_batch_abnormal_isp(username, to_migrate_dict)
        # send_alert_email("[FROM DNSDB]: 机房{}上运营商{}迁移到{}啦.".format(src_rooms, to_migrate_isps, dst_rooms))
        MigrateDal.update_history_by_id(history_id,
                                        migrate_rooms=json.dumps(src_rooms),
                                        migrate_isps=json.dumps(to_migrate_isps),
                                        dst_rooms=json.dumps(dst_rooms),
                                        migrate_info=json.dumps({}))
    else:
        MigrateDal.delete_history_by_id(history_id)
        raise BadParam("no domain can migrate, isp_rooms: %s"
                       % to_migrate_dict, msg_ch=u'没有可迁移的机房')

    history_info = get_migrate_info(history_id)
    return history_info
Esempio n. 9
0
def get_migrate_info(history_id):
    try:
        history_id = int(history_id)
    except Exception:
        raise BadParam('id should be int')
    return format_history([MigrateDal.get_history_info(history_id)])
Esempio n. 10
0
def get_view_migrate_detail(migrate_id, domain, page, page_size):
    return MigrateDal.get_view_migrate_detail(migrate_id, domain, page, page_size)
Esempio n. 11
0
def get_view_migrate_detail(migrate_id, domain, page, page_size):
    return MigrateDal.get_view_migrate_detail(migrate_id, domain, page,
                                              page_size)
Esempio n. 12
0
def onekey_recover_rooms():
    return MigrateDal.onekey_recover_rooms()
Esempio n. 13
0
def list_migrate_domain():
    json_data = request.get_json(force=True)
    src_rooms = json_data.get('src_rooms', [])
    dst_rooms = json_data.get("dst_rooms", [])
    isps = json_data.get("isps", [])
    return MigrateDal.list_migrate_domain(src_rooms, dst_rooms, isps)
Esempio n. 14
0
def onekey_recover_rooms():
    return MigrateDal.onekey_recover_rooms()
Esempio n. 15
0
def list_migrate_history():
    return format_history(MigrateDal.get_last_few_history(limit=15))
Esempio n. 16
0
def migrate_rooms(src_rooms, dst_rooms, to_migrate_isps, username):
    history_id = MigrateDal.create_migrage_history(username)

    migrated_isp_rooms = MigrateDal.get_all_abnormal_isps(key='isp',
                                                          value='room')
    to_migrate_dict = {
        isp: set(src_rooms) | migrated_isp_rooms.get(isp, set())
        for isp in to_migrate_isps
    }

    migrate_isp_domains = MigrateDal.list_migrate_domain_by_isp(
        to_migrate_dict, dst_rooms)

    has_migrate_domains = False
    for isp, migrate_domains_list in migrate_isp_domains.iteritems():
        migrate_domains_list = [
            domain for domain in migrate_domains_list
            if domain['after_enabled_rooms']
        ]
        if len(migrate_domains_list) == 0:
            continue
        has_migrate_domains = True
        MigrateDal.update_history_total(history_id, len(migrate_domains_list))
        m_thread = MigrateThread(username, history_id, migrate_domains_list)
        m_thread.start()

    if has_migrate_domains:
        MigrateDal.add_batch_abnormal_isp(username, to_migrate_dict)
        # send_alert_email("[FROM DNSDB]: 机房{}上运营商{}迁移到{}啦.".format(src_rooms, to_migrate_isps, dst_rooms))
        MigrateDal.update_history_by_id(
            history_id,
            migrate_rooms=json.dumps(src_rooms),
            migrate_isps=json.dumps(to_migrate_isps),
            dst_rooms=json.dumps(dst_rooms),
            migrate_info=json.dumps({}))
    else:
        MigrateDal.delete_history_by_id(history_id)
        raise BadParam("no domain can migrate, isp_rooms: %s" %
                       to_migrate_dict,
                       msg_ch=u'没有可迁移的机房')

    history_info = get_migrate_info(history_id)
    return history_info
Esempio n. 17
0
def get_migrate_info(history_id):
    try:
        history_id = int(history_id)
    except Exception:
        raise BadParam('id should be int')
    return format_history([MigrateDal.get_history_info(history_id)])