예제 #1
0
def get_right_business_accord_instance_and_ips(instance, ips, day=None):
    if day is None:
        day = utils.get_yesterday_str()
    ips_str = utils.convert_ips_to_str(ips)
    sql = config_db.GET_BUSINESS_RIGHT_ACCORD_INST_IPS.format(instance, ips_str, day)
    right_businesses = db.cursor.execute(sql).fetchall()
    return right_businesses, sql
예제 #2
0
def get_ip_left_right(ip_address, day=None):
    if day is None:
        day = utils.get_yesterday_str()
    sql_left = config_db.GET_IP_LEFT.format(ip_address, day)
    sql_right = config_db.GET_IP_RIGHT.format(ip_address, day)
    ip_left_set = [dict(zip(IP_FORMATE, item)) for item in db.cursor.execute(sql_left).fetchall()]
    ip_right_set = [dict(zip(IP_FORMATE, item)) for item in db.cursor.execute(sql_right).fetchall()]
    for item in ip_left_set:
        if item['instance'].find('DB') == -1:
            del item['instance']
            del item['machine']
        else:
            pass
    for item in ip_right_set:
        if item['instance'].find('DB') == -1:
            del item['instance']
            del item['machine']
        else:
            pass

    def f(a):
        return socket.inet_aton(a['ip_address'])

    ip_left_set.sort(key=f)
    ip_right_set.sort(key=f)
    for item in ip_left_set:
        item['ip_address' ]= convert_dbip_to_dbinstanceip(item['ip_address'])
    for item in ip_right_set:
        item['ip_address'] = convert_dbip_to_dbinstanceip(item['ip_address'])
    return ip_left_set, ip_right_set
예제 #3
0
def get_left_business_ip_accord_instances_and_ips(instances, ips, day=None):
    if day is None:
        day = utils.get_yesterday_str()
    ips_str = utils.convert_ips_to_str(ips)
    instances_str = utils.convert_ips_to_str(instances)
    sql = config_db.GET_BUSINESS_IP_LEFT_ACCORD_INSTS_IPS.format(instances_str, ips_str)
    left_businesses = db.cursor.execute(sql).fetchall()
    return left_businesses, sql
예제 #4
0
def get_targetip_accord_business_instance(business_center, business=None, instance_center=None, day=None):
    target_ips = []
    result = []
    if day is None:
        day = utils.get_yesterday_str()
    if instance_center is None:
        sql = config_db.GET_IP_RIGHT_ACCORD_BUSI.format(business, business_center, day)
    else:
        sql = config_db.GET_IP_RIGHT_ACCORD_INST_BUSI.format(business, instance_center, day)
    target_ips = db.cursor.execute(sql).fetchall()
    for ip in target_ips:
        if ip != '' and ip is not None:
            result.append(ip)
    result.sort()
    return result, sql
예제 #5
0
def get_ip_accord_business_instance_ips(direction, business, center_business, center_instance, center_ips, day=None):
    sql = ''
    if day is None:
        day = utils.get_yesterday_str()
    ips_str = utils.convert_ips_to_str(center_ips)
    if direction == 'source':
        sql = config_db.GET_IP_LEFT_ACCORD_BUSI_INST_IPS.format(business, center_business, center_instance, ips_str,
                                                                day)
    elif direction == 'target':
        sql = config_db.GET_IP_RIGHT_ACCORD_BUSI_INST_IPS.format(business, center_business, center_instance, ips_str,
                                                                 day)
    print sql

    result = list(db.cursor.execute(sql).fetchall())
    return result, sql
예제 #6
0
def get_oop_accord_business_and_oop_and_direction(business, direction, business_center=None, oop_center=None, day=None):
    sql = ''
    if day is None:
        day = utils.get_yesterday_str()
    if direction == 'right':
        if oop_center is None:
            sql = config_db.GET_INSTANCE_RIGHT_ACCORD_BUSI.format(business, business_center, day)
        elif business_center is None:
            sql = config_db.GET_INSTANCE_RIGHT_ACCORD_INST.format(business, oop_center, day)
    elif direction == 'left':
        if oop_center is None:
            sql = config_db.GET_INSTANCE_LEFT_ACCORD_BUSI.format(business, business_center, day)
        elif business_center is None:
            sql = config_db.GET_INSTANCE_LEFT_ACCORD_INST.format(business, oop_center, day)
    oops = db.cursor.execute(sql).fetchall()

    return oops, sql
예제 #7
0
def get_right_business_accord_instance_busi(instance, busi, day=None):
    if day is None:
        day = utils.get_yesterday_str()
    sql = config_db.GET_BUSINESS_RIGHT_ACCORD_INST_BUSI.format(busi, instance, day)
    right_businesses = db.cursor.execute(sql).fetchall()
    return right_businesses, sql
예제 #8
0
def get_right_business(business, day=None):
    if day is None:
        day = utils.get_yesterday_str()
    sql = config_db.GET_BUSINESS_RIGHT.format(business, day)
    businesses = db.cursor.execute(sql).fetchall()
    return businesses, sql
예제 #9
0
def get_left_business_ip_accord_instance(instance, day=None):
    if day is None:
        day = utils.get_yesterday_str()
    sql = config_db.GET_BUSINESS_IP_LEFT_ACCORD_INST.format(instance, day)
    left_businesses = db.cursor.execute(sql).fetchall()
    return left_businesses, sql