Skip to content
Snippets Groups Projects
Commit 2a78a62b authored by Erik Reid's avatar Erik Reid
Browse files

Finished feature optimize-juniper-config-change-updates.

parents 6c8ae704 78610873
Branches
Tags
No related merge requests found
...@@ -399,3 +399,17 @@ def snmp_community_string(netconf_config): ...@@ -399,3 +399,17 @@ def snmp_community_string(netconf_config):
if me in allowed_network: if me in allowed_network:
return community.xpath('./name/text()')[0] return community.xpath('./name/text()')[0]
return None return None
def netconf_changed_timestamp(netconf_config):
'''
return the last change timestamp published by the config document
:param netconf_config: netconf lxml etree document
:return: an epoch timestamp (integer number of seconds) or None
'''
for ts in netconf_config.xpath('/configuration/@changed-seconds'):
if re.match(r'^\d+$', ts):
return int(ts)
logger = logging.getLogger(__name__)
logger.warning('no valid timestamp found in netconf configuration')
return None
...@@ -311,39 +311,63 @@ def reload_router_config(self, hostname): ...@@ -311,39 +311,63 @@ def reload_router_config(self, hostname):
'message': 'loading router netconf data' 'message': 'loading router netconf data'
}) })
# get the timestamp for the current netconf data
current_netconf_timestamp = None
netconf_doc = load_netconf_data(hostname)
if netconf_doc:
current_netconf_timestamp \
= juniper.netconf_changed_timestamp(netconf_doc)
logger.debug(
'current netconf timestamp: %r' % current_netconf_timestamp)
# load new netconf data
netconf_refresh_config.apply(args=[hostname]) netconf_refresh_config.apply(args=[hostname])
netconf_doc = load_netconf_data(hostname) netconf_doc = load_netconf_data(hostname)
if netconf_doc is None: if netconf_doc is None:
raise InventoryTaskError( raise InventoryTaskError(
'no netconf data available for %r' % hostname) 'failure loading netconf data for %r' % hostname)
# return if new timestamp is the same as the original timestamp
new_netconf_timestamp = juniper.netconf_changed_timestamp(netconf_doc)
assert new_netconf_timestamp, \
'no timestamp available for new netconf data'
if new_netconf_timestamp == current_netconf_timestamp:
logger.debug('no netconf change timestamp change, aborting')
logger.debug('<<< reload_router_config')
return {
'task': 'reload_router_config',
'hostname': hostname,
'message': 'OK (no change)'
}
# clear cached classifier responses for this router, and
# refresh peering data
self.update_state(
state=states.STARTED,
meta={
'task': 'reload_router_config',
'hostname': hostname,
'message': 'refreshing peers & clearing cache'
})
refresh_ix_public_peers(hostname, netconf_doc)
refresh_vpn_rr_peers(hostname, netconf_doc)
clear_cached_classifier_responses(hostname)
# load snmp indexes
community = juniper.snmp_community_string(netconf_doc)
if not community:
raise InventoryTaskError(
'error extracting community string for %r' % hostname)
else: else:
self.update_state( self.update_state(
state=states.STARTED, state=states.STARTED,
meta={ meta={
'task': 'reload_router_config', 'task': 'reload_router_config',
'hostname': hostname, 'hostname': hostname,
'message': 'refreshing peers' 'message': 'refreshing snmp interface indexes'
}) })
refresh_ix_public_peers(hostname, netconf_doc) snmp_refresh_interfaces.apply(args=[hostname, community])
refresh_vpn_rr_peers(hostname, netconf_doc)
community = juniper.snmp_community_string(netconf_doc)
if not community:
raise InventoryTaskError(
'error extracting community string for %r' % hostname)
else:
self.update_state(
state=states.STARTED,
meta={
'task': 'reload_router_config',
'hostname': hostname,
'message': 'refreshing snmp interface indexes'
})
snmp_refresh_interfaces.apply(args=[hostname, community])
# TODO: move this out of else? (i.e. clear even if netconf fails?)
clear_cached_classifier_responses(hostname)
logger.debug('<<< reload_router_config') logger.debug('<<< reload_router_config')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment