Exemplo n.º 1
0
def querydatabase(testbed, layer2mode, tag):
    """
     #     Column     Type     Collation     Attributes     Null     Default     Extra     Action
1     TBNAME     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
2     dslamname     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
3     PORT     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
4     MODE     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
5     TAG     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
6     PVC     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
7     ETHNo     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
8     VLAN     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
9     LineProfile     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
10     LineTemplate     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
11     BondGroupIndex     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
12     BondGroupMainPort     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
13     BondGrouplinkPort     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
14     DiscoverCode     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
(1L, (('at_sh1', 'HuaWei', 'NA', 'VDSL_B_8B', '101', 'NA', '300', '405', '112', '120', '5', '0/1/17', '0/1/18', '0000-0000-0001'),))
    """
    mytuple = []
    mytuple = db_helper.queryTBDSLAM({'TBNAME': testbed, 'MODE': layer2mode, 'TAG': tag})
    print mytuple
    num = str(mytuple[0])
    if num == '1':
        print 'AT_INFO : Find 1 data!'
    elif num == '0':
        print 'AT_ERROR : Can\'t find data!'
        return False
    else:
        print 'AT_ERROR : Find ' + num + ' data!'
        return False
    return mytuple
Exemplo n.º 2
0
    def get_info_from_database(self):
        """
         #     Column     Type     Collation     Attributes     Null     Default     Extra     Action
    1     TBNAME     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    2     DSLAMTYPE     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    3     PORT     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    4     MODE     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    5     TAG     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    6     PVC     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    7     ETHNo     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    8     VLAN     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    9     LineProfile     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    10     LineTemplate     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    11     BondGroupIndex     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    12     BondGroupMainPort     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    13     BondGrouplinkPort     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    14     DiscoverCode     varchar(255)     utf8_general_ci         No     None         Change Change     Drop Drop     More Show more actions
    (1L, (('at_sh1', 'Adtran', 'NA', 'VDSL_B_8B', '101', 'NA', '300', '405', '112', '120', '5', '0/1/17', '0/1/18', '0000-0000-0001'),))
        """
        print '\n' + '#' * 50 + 'Enter function get_info_from_database'
        profile_name = '';
        fsp = [];
        fs = '';
        mfsp = '';
        sfsp = '';
        port = [];
        mport = '';
        vlan = '';
        bond_group = '';
        pvc = '';
        eth = '';
        tag = '';
        query_dict = {'TBNAME': self._testbed, 'DSLAMTYPE': self._dslam_type, 'MODE': self._layer2mode,
                      'TAG': self._tag}
        if self._linemode == 'ADSL':
            query_dict = {'TBNAME': self._testbed, 'DSLAMTYPE': self._dslam_type, 'MODE': self._layer2mode}
        mytuple = db_helper.queryTBDSLAM(query_dict)
        print mytuple
        num = str(mytuple[0])
        if num == '1':
            print 'AT_INFO : Find 1 data!'
        elif num == '0':
            print 'AT_ERROR : Can\'t find data!'
            exit(1)
        else:
            print 'AT_ERROR : Find ' + num + ' data!'
            exit(1)
        profilename = mytuple[1][0][8]
        tag = mytuple[1][0][4]
        pvc = mytuple[1][0][5]
        eth = mytuple[1][0][6]
        vlan = mytuple[1][0][7]
        #        profile_index = mytuple[1][0][8]
        #        template_index = mytuple[1][0][9]
        bond_group = mytuple[1][0][10]
        #        discovercode = mytuple[1][0][13]

        #        template_name = profile_index + '_' + profilename
        #        refsp = '[0-9]/[0-9]+/[0-9]+'

        #if self._bonding:
        mfsp = mytuple[1][0][11]
        rc = re.findall(refsp, mfsp)
        if not rc:
            print 'AT_ERROR : frameid/slotid/portid ' + mfsp + ' format Error!'
            exit(1)
        sfsp = mytuple[1][0][12]
        rc = re.findall(refsp, sfsp)
        if not rc:
            print 'AT_ERROR : frameid/slotid/portid ' + sfsp + ' format Error!'
            exit(1)
        fsp = [mfsp, sfsp]
        mport = mfsp.split('/')[2]
        sport = sfsp.split('/')[2]
        port = [mport, sport]
        #        else:
        #            mfsp = mytuple[1][0][2]
        #            rc = re.findall(refsp, mfsp)
        #            if not rc:
        #                print 'AT_ERROR : frameid/slotid/portid ' + mfsp + ' format Error!'
        #                exit(1)
        #            fsp = [mfsp]
        #            mport = mfsp.split('/')[2]
        #            port = [mport]
        fs = mfsp.split('/')[0] + '/' + mfsp.split('/')[1]
        return profilename, fsp, fs, mfsp, sfsp, port, mport, sport, vlan, bond_group, eth, tag