Skip to content
Snippets Groups Projects
Commit b12fd2f2 authored by Robert Latta's avatar Robert Latta
Browse files

added Nokia peer refresh. RE DBOARD3-1086

parent 2923edff
No related branches found
No related tags found
No related merge requests found
...@@ -400,7 +400,7 @@ def _build_snmp_peering_db(update_callback=lambda s: None): ...@@ -400,7 +400,7 @@ def _build_snmp_peering_db(update_callback=lambda s: None):
key_prefix = 'snmp-peerings:hosts:' key_prefix = 'snmp-peerings:hosts:'
for k in r.scan_iter(f'{key_prefix}*', count=1000): for k in r.scan_iter(f'{key_prefix}*', count=1000):
key_name = k.decode('utf-8') key_name = k.decode('utf-8')
hostname = key_name[len(key_prefix):] hostname = key_name.split(':')[-1]
host_peerings = r.get(key_name).decode('utf-8') host_peerings = r.get(key_name).decode('utf-8')
host_peerings = json.loads(host_peerings) host_peerings = json.loads(host_peerings)
for p in host_peerings: for p in host_peerings:
...@@ -621,6 +621,43 @@ def _reload_router_config_nokia( ...@@ -621,6 +621,43 @@ def _reload_router_config_nokia(
communities = _nokia_community_strings(InventoryTask.config) communities = _nokia_community_strings(InventoryTask.config)
snmp_refresh_interfaces_nokia(hostname, state_doc, communities, r, info_callback) snmp_refresh_interfaces_nokia(hostname, state_doc, communities, r, info_callback)
refresh_nokia_bgp_peers(hostname, netconf_doc) refresh_nokia_bgp_peers(hostname, netconf_doc)
snmp_refresh_peerings_nokia(hostname, communities)
def snmp_refresh_peerings_nokia(hostname, communities, update_callback=lambda S: None):
get_peerings_func = functools.partial(
snmp.get_peer_state_info_nokia,
community=communities['inventory-provider'],
)
snmp_refresh_peerings(
get_peerings_func, hostname, 'nokia', update_callback=update_callback
)
def snmp_refresh_peerings(
get_peerings_func,
hostname,
redis_key_group,
update_callback=lambda s: None):
try:
peerings = get_peerings_func(hostname)
except ConnectionError:
msg = f'error loading snmp peering data from {hostname}'
logger.exception(msg)
update_callback(msg)
r = get_current_redis(InventoryTask.config)
peerings = r.get(f'snmp-peerings:hosts:{redis_key_group}:{hostname}')
if peerings is None:
raise InventoryTaskError(
f'snmp error with {hostname} and no cached peering data found')
# unnecessary json encode/decode here ... could be optimized
peerings = json.loads(peerings.decode('utf-8'))
update_callback(f'using cached snmp peering data for {hostname}')
r = get_next_redis(InventoryTask.config)
r.set(f'snmp-peerings:hosts:{redis_key_group}:{hostname}', json.dumps(peerings))
update_callback(f'snmp peering info loaded from {hostname}')
def retrieve_and_persist_config_nokia( def retrieve_and_persist_config_nokia(
...@@ -1027,27 +1064,15 @@ def snmp_refresh_interfaces_juniper( ...@@ -1027,27 +1064,15 @@ def snmp_refresh_interfaces_juniper(
@log_task_entry_and_exit @log_task_entry_and_exit
def snmp_refresh_peerings_juniper( def snmp_refresh_peerings_juniper(
hostname, community, logical_systems, update_callback=lambda S: None): hostname, community, logical_systems, update_callback=lambda S: None):
try:
peerings = list(
snmp.get_peer_state_info_juniper(hostname, community, logical_systems))
except ConnectionError:
msg = f'error loading snmp peering data from {hostname}'
logger.exception(msg)
update_callback(msg)
r = get_current_redis(InventoryTask.config)
peerings = r.get(f'snmp-peerings:hosts:{hostname}')
if peerings is None:
raise InventoryTaskError(
f'snmp error with {peerings}'
f' and no cached peering data found')
# unnecessary json encode/decode here ... could be optimized
peerings = json.loads(peerings.decode('utf-8'))
update_callback(f'using cached snmp peering data for {hostname}')
r = get_next_redis(InventoryTask.config) get_peerings_func = functools.partial(
r.set(f'snmp-peerings:hosts:{hostname}', json.dumps(peerings)) snmp.get_peer_state_info_juniper,
community=community,
update_callback(f'snmp peering info loaded from {hostname}') logical_systems=logical_systems
)
snmp_refresh_peerings(
get_peerings_func, hostname, 'juniper', update_callback=update_callback
)
def cache_extracted_ims_data(extracted_data, use_current=False): def cache_extracted_ims_data(extracted_data, use_current=False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment