Пример #1
0
def _watcher_parser_v2(conf, logname, prom_client):
    logger = config_parser_util.get_logger(logname)
    result = []

    dps = {}
    for faucet_file in conf['faucet_configs']:
        _, dp_list = dp_parser(faucet_file, logname)
        if dp_list:
            for dp in dp_list:
                dps[dp.name] = dp

    dbs = conf.pop('dbs')

    for watcher_name, watcher_conf in list(conf['watchers'].items()):
        if watcher_conf.get('all_dps', False):
            watcher_dps = list(dps.keys())
        else:
            watcher_dps = watcher_conf['dps']
        # Watcher config has a list of DPs, but actually a WatcherConf is
        # created for each DP.
        # TODO: refactor watcher_conf as a container.
        for dp_name in watcher_dps:
            if dp_name not in dps:
                logger.error('DP %s in Gauge but not configured in FAUCET', dp_name)
                continue
            dp = dps[dp_name]
            watcher = WatcherConf(watcher_name, dp.dp_id, watcher_conf, prom_client)
            watcher.add_db(dbs[watcher.db])
            watcher.add_dp(dp)
            result.append(watcher)

    return result
Пример #2
0
def _watcher_parser_v2(conf, logname, prom_client):
    logger = config_parser_util.get_logger(logname)
    result = []

    if conf is None:
        conf = {}

    dps = {}
    if 'faucet_configs' in conf:
        for faucet_file in conf['faucet_configs']:
            _, dp_list = dp_parser(faucet_file, logname)
            if dp_list:
                for dp in dp_list:
                    dps[dp.name] = dp

    if 'faucet' in conf:
        faucet_conf = conf['faucet']
        acls = faucet_conf.get('acls', {})
        fct_dps = faucet_conf.get('dps', {})
        meters = faucet_conf.get('meters', {})
        routers = faucet_conf.get('routers', {})
        vlans = faucet_conf.get('vlans', {})
        for dp in _dp_parser_v2(acls, fct_dps, meters, routers, vlans):
            dps[dp.name] = dp

    if not dps:
        raise InvalidConfigError(
            'Gauge configured without any FAUCET configuration')

    dbs = conf.pop('dbs')

    # pylint: disable=fixme
    for watcher_name, watcher_conf in list(conf['watchers'].items()):
        if watcher_conf.get('all_dps', False):
            watcher_dps = list(dps.keys())
        else:
            watcher_dps = watcher_conf['dps']
        # Watcher config has a list of DPs, but actually a WatcherConf is
        # created for each DP.
        # TODO: refactor watcher_conf as a container.
        for dp_name in watcher_dps:
            if dp_name not in dps:
                logger.error('DP %s in Gauge but not configured in FAUCET',
                             dp_name)
                continue
            dp = dps[dp_name]
            if 'dbs' in watcher_conf:
                watcher_dbs = watcher_conf['dbs']
            elif 'db' in watcher_conf:
                watcher_dbs = [watcher_conf['db']]
            else:
                raise InvalidConfigError('Watcher configured without DB')
            for db in watcher_dbs:
                watcher = WatcherConf(watcher_name, dp.dp_id, watcher_conf,
                                      prom_client)
                watcher.add_db(dbs[db])
                watcher.add_dp(dp)
                result.append(watcher)

    return result
Пример #3
0
def _watcher_parser_v2(conf, logname, prom_client):
    logger = config_parser_util.get_logger(logname)
    result = []

    dps = {}
    for faucet_file in conf['faucet_configs']:
        _, dp_list = dp_parser(faucet_file, logname)
        if dp_list:
            for dp in dp_list:
                dps[dp.name] = dp

    dbs = conf.pop('dbs')

    for name, dictionary in list(conf['watchers'].items()):
        for dp_name in dictionary['dps']:
            if dp_name not in dps:
                logger.error('dp %s metered but not configured', dp_name)
                continue
            dp = dps[dp_name]
            watcher = WatcherConf(name, dictionary, prom_client)
            watcher.add_db(dbs[watcher.db])
            watcher.add_dp(dp)
            result.append(watcher)

    return result
Пример #4
0
def dp_parser(config_file, logname):
    logger = config_parser_util.get_logger(logname)
    conf = config_parser_util.read_config(config_file, logname)
    config_hashes = None
    dps = None

    if conf is not None:
        version = conf.pop('version', 2)
        if version != 2:
            logger.fatal('Only config version 2 is supported')

        config_hashes, dps = _config_parser_v2(config_file, logname)
    return config_hashes, dps
Пример #5
0
def dp_parser(config_file, logname):
    logger = config_parser_util.get_logger(logname)
    conf = config_parser_util.read_config(config_file, logname)
    if conf is None:
        return None
    version = conf.pop('version', 2)
    if version != 2:
        logger.fatal('Only config version 2 is supported')

    config_hashes, dps = _config_parser_v2(config_file, logname)
    if dps is not None:
        for dp in dps:
            try:
                dp.finalize_config(dps)
            except AssertionError as err:
                logger.exception('Error finalizing datapath configs: %s', err)
        for dp in dps:
            dp.resolve_stack_topology(dps)
    return config_hashes, dps
Пример #6
0
def _config_parser_v2(config_file, logname):
    logger = config_parser_util.get_logger(logname)
    config_path = config_parser_util.dp_config_path(config_file)
    top_confs = {}
    config_hashes = {}
    dps = None
    for top_conf in V2_TOP_CONFS:
        top_confs[top_conf] = {}

    if not config_parser_util.dp_include(config_hashes, config_path, logname,
                                         top_confs):
        logger.critical('error found while loading config file: %s',
                        config_path)
    elif not top_confs['dps']:
        logger.critical('DPs not configured in file: %s', config_path)
    else:
        dps = _dp_parser_v2(logger, top_confs['acls'], top_confs['dps'],
                            top_confs['meters'], top_confs['routers'],
                            top_confs['vlans'])
    return (config_hashes, dps)
Пример #7
0
def _watcher_parser_v2(conf, logname, prom_client):
    logger = config_parser_util.get_logger(logname)

    if conf is None:
        conf = {}
    faucet_config_files, faucet_conf_hashes, dps = _parse_dps_for_watchers(
        conf, logname)
    dbs = conf.pop('dbs')

    result = []
    # pylint: disable=fixme
    for watcher_name, watcher_conf in conf['watchers'].items():
        if watcher_conf.get('all_dps', False):
            watcher_dps = dps.keys()
        else:
            watcher_dps = watcher_conf['dps']
        # Watcher config has a list of DPs, but actually a WatcherConf is
        # created for each DP.
        # TODO: refactor watcher_conf as a container.
        for dp_name in watcher_dps:
            if dp_name not in dps:
                logger.error('DP %s in Gauge but not configured in FAUCET',
                             dp_name)
                continue
            dp = dps[dp_name]
            if 'dbs' in watcher_conf:
                watcher_dbs = watcher_conf['dbs']
            elif 'db' in watcher_conf:
                watcher_dbs = [watcher_conf['db']]
            else:
                raise InvalidConfigError('Watcher configured without DB')
            for db in watcher_dbs:
                watcher = WatcherConf(watcher_name, dp.dp_id, watcher_conf,
                                      prom_client)
                watcher.add_db(dbs[db])
                watcher.add_dp(dp)
                result.append(watcher)

    return faucet_config_files, faucet_conf_hashes, result
Пример #8
0
def _watcher_parser_v2(conf, logname, prom_client):
    logger = config_parser_util.get_logger(logname)

    if conf is None:
        conf = {}
    dps = _parse_dps_for_watchers(conf, logname)
    dbs = conf.pop('dbs')

    result = []
    # pylint: disable=fixme
    for watcher_name, watcher_conf in list(conf['watchers'].items()):
        if watcher_conf.get('all_dps', False):
            watcher_dps = list(dps.keys())
        else:
            watcher_dps = watcher_conf['dps']
        # Watcher config has a list of DPs, but actually a WatcherConf is
        # created for each DP.
        # TODO: refactor watcher_conf as a container.
        for dp_name in watcher_dps:
            if dp_name not in dps:
                logger.error('DP %s in Gauge but not configured in FAUCET', dp_name)
                continue
            dp = dps[dp_name]
            if 'dbs' in watcher_conf:
                watcher_dbs = watcher_conf['dbs']
            elif 'db' in watcher_conf:
                watcher_dbs = [watcher_conf['db']]
            else:
                raise InvalidConfigError('Watcher configured without DB')
            for db in watcher_dbs:
                watcher = WatcherConf(watcher_name, dp.dp_id, watcher_conf, prom_client)
                watcher.add_db(dbs[db])
                watcher.add_dp(dp)
                result.append(watcher)

    return result
Пример #9
0
def _config_parser_v2(config_file, logname):
    logger = config_parser_util.get_logger(logname)
    config_path = config_parser_util.dp_config_path(config_file)
    config_hashes = {}
    top_confs = {
        'acls': {},
        'dps': {},
        'routers': {},
        'vlans': {},
    }

    if not config_parser_util.dp_include(config_hashes, config_path, logname,
                                         top_confs):
        logger.critical('error found while loading config file: %s',
                        config_path)
        return None

    if not top_confs['dps']:
        logger.critical('DPs not configured in file: %s', config_path)
        return None

    dps = _dp_parser_v2(logger, top_confs['acls'], top_confs['dps'],
                        top_confs['routers'], top_confs['vlans'])
    return (config_hashes, dps)