Skip to content
Snippets Groups Projects
Commit 23029270 authored by Sam Roberts's avatar Sam Roberts
Browse files

fix bug where interface has colon in the name

parent 3de32cc1
No related branches found
No related tags found
1 merge request!30Feature/pol1 775 poller interfaces cache built from preparsed
......@@ -670,34 +670,20 @@ def _load_netconf_docs(
}
def _get_filter_pattern(base_pattern, hostname=None, is_lab=False):
def _load_netconf_parsed_cache(config, cache_name, hostname=None, is_lab=False, use_next_redis=False):
hostname_suffix = hostname if hostname else ''
lab_prefix = 'lab:' if is_lab else ''
return f'{lab_prefix}{base_pattern}:{hostname_suffix}*'
def _load_netconf_interfaces(config, hostname=None, is_lab=False, use_next_redis=False):
filter_pattern = _get_filter_pattern('netconf-interfaces', hostname, is_lab)
for doc in common.load_json_docs(
config_params=config,
key_pattern=filter_pattern,
num_threads=20,
use_next_redis=use_next_redis):
m = re.match(r'^netconf-interfaces:(.+:.+)$', doc['key'])
if m:
key = m.group(1)
yield key, doc['value']
def _load_netconf_interface_bundles(config, hostname=None, is_lab=False, use_next_redis=False):
filter_pattern = _get_filter_pattern('netconf-interface-bundles', hostname, is_lab)
filter_pattern = f'{lab_prefix}{cache_name}:{hostname_suffix}*'
for doc in common.load_json_docs(
config_params=config,
key_pattern=filter_pattern,
num_threads=20,
use_next_redis=use_next_redis):
m = re.match(r'^netconf-interface-bundles:(.+:.+)$', doc['key'])
m = re.match(fr'{cache_name}:(.+:.+)$', doc['key'])
if m:
key = m.group(1)
# preparse the key as interfaces can include : in the name
key_parts = m.group(1).split(':')
key = f'{key_parts[0]}-----{":".join(key_parts[1:])}'
yield key, doc['value']
......@@ -714,11 +700,13 @@ def _load_interfaces(
def _load_netconf_caches(is_lab=False):
interfaces = dict(_load_netconf_interfaces(config, hostname, is_lab, use_next_redis))
interface_bundles = dict(_load_netconf_interface_bundles(config, hostname, is_lab, use_next_redis))
interfaces = dict(_load_netconf_parsed_cache(config, 'netconf-interfaces',
hostname, is_lab, use_next_redis))
interface_bundles = dict(_load_netconf_parsed_cache(config, 'netconf-interface-bundles',
hostname, is_lab, use_next_redis))
for key, ifc in interfaces.items():
router, interface_name = key.split(':')
router, interface_name = key.split('-----')
bundle = interface_bundles.get(key, [])
if not ifc['description']:
continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment