Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
b10f9dfa
Commit
b10f9dfa
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
no changes if new netconf timestamp is same
parent
6c8ae704
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/juniper.py
+15
-0
15 additions, 0 deletions
inventory_provider/juniper.py
inventory_provider/tasks/worker.py
+45
-21
45 additions, 21 deletions
inventory_provider/tasks/worker.py
with
60 additions
and
21 deletions
inventory_provider/juniper.py
+
15
−
0
View file @
b10f9dfa
...
...
@@ -399,3 +399,18 @@ def snmp_community_string(netconf_config):
if
me
in
allowed_network
:
return
community
.
xpath
(
'
./name/text()
'
)[
0
]
return
None
def
netconf_changed_timestamp
(
netconf_config
):
'''
<configuration changed-seconds=
"
1549049195
"
changed-localtime=
"
2019-02-01 19:26:35 UTC
"
>
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
This diff is collapsed.
Click to expand it.
inventory_provider/tasks/worker.py
+
45
−
21
View file @
b10f9dfa
...
...
@@ -311,39 +311,63 @@ def reload_router_config(self, hostname):
'
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_doc
=
load_netconf_data
(
hostname
)
if
netconf_doc
is
None
:
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
:
self
.
update_state
(
state
=
states
.
STARTED
,
meta
=
{
'
task
'
:
'
reload_router_config
'
,
'
hostname
'
:
hostname
,
'
message
'
:
'
refreshing
peer
s
'
'
message
'
:
'
refreshing
snmp interface indexe
s
'
})
refresh_ix_public_peers
(
hostname
,
netconf_doc
)
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
)
snmp_refresh_interfaces
.
apply
(
args
=
[
hostname
,
community
])
logger
.
debug
(
'
<<< reload_router_config
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment