Exemplo n.º 1
0
    def db_initiation(cls):
        LOG.info("--- Initiating SONA DB ---")
        init_sql = [
            'CREATE TABLE ' + cls.NODE_INFO_TBL +
            '(nodename text primary key, ip_addr, username)',
            'CREATE TABLE ' + cls.STATUS_TBL +
            '(nodename text primary key, ping, app, cpu, memory, disk, time)',
            'CREATE TABLE ' + cls.RESOURCE_TBL +
            '(nodename text primary key, cpu real, memory real, disk real)',
            'CREATE TABLE ' + cls.REGI_SYS_TBL +
            '(url text primary key, auth)', 'CREATE TABLE ' + cls.EVENT_TBL +
            '(nodename, item, grade, desc, time, PRIMARY KEY (nodename, item))'
        ]

        for sql in init_sql:
            sql_rt = cls.sql_execute(sql)

            if "already exist" in sql_rt:
                table_name = sql_rt.split()[1]
                LOG.info(
                    "\'%s\' table already exist. Delete all tuple of this table...",
                    table_name)
                sql = 'DELETE FROM ' + table_name
                sql_rt = cls.sql_execute(sql)
                if sql_rt != 'SUCCESS':
                    LOG.info("DB %s table initiation fail\n%s", table_name,
                             sql_rt)
                    sys.exit(1)
            elif sql_rt != 'SUCCESS':
                LOG.info("DB initiation fail\n%s", sql_rt)
                sys.exit(1)

        LOG.info('Insert nodes information ...')
        for node in CONF.watchdog()['check_system']:
            if str(node).lower() == 'onos':
                cls.sql_insert_nodes(CONF.onos()['list'],
                                     str(CONF.onos()['account']).split(':')[0])
            elif str(node).lower() == 'xos':
                cls.sql_insert_nodes(CONF.xos()['list'],
                                     str(CONF.xos()['account']).split(':')[0])
            elif str(node).lower() == 'swarm':
                cls.sql_insert_nodes(
                    CONF.swarm()['list'],
                    str(CONF.swarm()['account']).split(':')[0])
            elif str(node).lower() == 'openstack':
                cls.sql_insert_nodes(
                    CONF.openstack()['list'],
                    str(CONF.openstack()['account']).split(':')[0])
Exemplo n.º 2
0
    def db_initiation(cls, db_log):
        try:
            db_path = CONF.base()['db_file']
            if os.path.isfile(db_path):
                os.remove(db_path)

            db_log.write_log("--- Initiating SONA DB ---")
            init_sql = [
                'CREATE TABLE ' + cls.NODE_INFO_TBL +
                '(nodename text primary key, ip_addr, username, type, sub_type)',
                'CREATE TABLE ' + cls.STATUS_TBL +
                '(nodename text primary key, ' + cls.item_list + ', time)',
                'CREATE TABLE ' + cls.REGI_SYS_TBL +
                '(url text primary key, auth)',
                'CREATE TABLE ' + cls.EVENT_TBL +
                '(nodename, item, grade, pre_grade, reason, time, PRIMARY KEY (nodename, item))',
                'CREATE TABLE ' + cls.ONOS_TBL +
                '(nodename text primary key, cluster, device, link, app)'
            ]

            for sql in init_sql:
                sql_rt = cls.sql_execute(sql)

                if sql_rt != 'SUCCESS':
                    db_log.write_log("DB initiation fail\n%s", sql_rt)
                    sys.exit(1)

            db_log.write_log('Insert nodes information ...')
            for node_type in CONF.watchdog()['check_system']:
                cls.sql_insert_nodes(
                    db_log, (CONF_MAP[node_type.upper()]())['list'],
                    str((CONF_MAP[node_type.upper()]()
                         )['account']).split(':')[0], node_type)

        except:
            LOG.exception()
Exemplo n.º 3
0
    def db_initiation(cls, db_log):
        try:
            db_path = CONF.base()['db_file']
            if os.path.isfile(db_path):
                os.remove(db_path)

            db_log.write_log("--- Initiating SONA DB ---")
            init_sql = [
                'CREATE TABLE ' + cls.NODE_INFO_TBL +
                '(nodename text primary key, ip_addr, username, type, sub_type)',
                'CREATE TABLE ' + cls.STATUS_TBL +
                '(nodename text primary key, ' + cls.item_list + ', time)',
                'CREATE TABLE ' + cls.RESOURCE_TBL +
                '(nodename text primary key, cpu real, memory real, disk real)',
                'CREATE TABLE ' + cls.REGI_SYS_TBL +
                '(url text primary key, auth)',
                'CREATE TABLE ' + cls.ONOS_TBL +
                '(nodename text primary key, applist, weblist, nodelist, port, openflow, cluster, traffic_stat)',
                'CREATE TABLE ' + cls.SWARM_TBL +
                '(nodename text primary key, node, service, ps)',
                'CREATE TABLE ' + cls.XOS_TBL +
                '(nodename text primary key, xos_status, synchronizer)',
                'CREATE TABLE ' + cls.OPENSTACK_TBL +
                '(nodename text primary key, sub_type, data_ip, of_id, hostname, docker, onosApp, routingTable, gw_ratio, vxlan_traffic, internal_traffic)',
                'CREATE TABLE ' + cls.HA_TBL +
                '(ha_key text primary key, stats)',
                'CREATE TABLE ' + cls.EVENT_TBL +
                '(nodename, item, grade, pre_grade, reason, time, PRIMARY KEY (nodename, item))'
            ]

            for sql in init_sql:
                sql_rt = cls.sql_execute(sql)

                if sql_rt != 'SUCCESS':
                    db_log.write_log("DB initiation fail\n%s", sql_rt)
                    sys.exit(1)

            db_log.write_log('Insert nodes information ...')
            for node_type in CONF.watchdog()['check_system']:
                if node_type == 'OPENSTACK':
                    cls.sql_insert_nodes(
                        db_log, CONF_MAP[node_type.upper()]()['compute_list'],
                        str((CONF_MAP[node_type.upper()]()
                             )['account']).split(':')[0], node_type, 'COMPUTE')
                    cls.sql_insert_nodes(
                        db_log, CONF_MAP[node_type.upper()]()['gateway_list'],
                        str((CONF_MAP[node_type.upper()]()
                             )['account']).split(':')[0], node_type, 'GATEWAY')
                else:
                    cls.sql_insert_nodes(
                        db_log, CONF_MAP[node_type.upper()]()['list'],
                        str((CONF_MAP[node_type.upper()]()
                             )['account']).split(':')[0], node_type)

            # set ha proxy tbl
            sql = 'INSERT INTO ' + cls.HA_TBL + ' VALUES (\'' + 'HA' + '\', \'none\')'
            sql_rt = cls.sql_execute(sql)
            if sql_rt != 'SUCCESS':
                db_log.write_log(
                    " [HA PROXY TABLE] Node data insert fail \n%s", sql_rt)
                sys.exit(1)
        except:
            LOG.exception()