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
e0b9f45f
Commit
e0b9f45f
authored
1 year ago
by
Sam Roberts
Browse files
Options
Downloads
Patches
Plain Diff
rewrote _load_interfaces to not parse the entire netconf docs
parent
e059a01c
No related branches found
No related tags found
1 merge request
!30
Feature/pol1 775 poller interfaces cache built from preparsed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/routes/poller.py
+68
-16
68 additions, 16 deletions
inventory_provider/routes/poller.py
with
68 additions
and
16 deletions
inventory_provider/routes/poller.py
+
68
−
16
View file @
e0b9f45f
...
@@ -670,6 +670,54 @@ def _load_netconf_docs(
...
@@ -670,6 +670,54 @@ def _load_netconf_docs(
}
}
def
_get_filter_pattern
(
base_pattern
,
hostname
=
None
,
is_lab
=
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_hosts(config, hostname=None, is_lab=False, use_next_redis=False):
# filter_pattern = _get_filter_pattern('netconf-interfaces-hosts', 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-hosts:(.+)$', doc['key'])
# if m:
# router = m.group(1)
# for host in doc['value']:
# interface = host['interface name']
# key = f'{router}:{interface}'
# yield key, host
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
)
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
'
])
if
m
:
key
=
m
.
group
(
1
)
yield
key
,
doc
[
'
value
'
]
def
_load_interfaces
(
def
_load_interfaces
(
config
,
hostname
=
None
,
no_lab
=
False
,
use_next_redis
=
False
):
config
,
hostname
=
None
,
no_lab
=
False
,
use_next_redis
=
False
):
"""
"""
...
@@ -681,28 +729,31 @@ def _load_interfaces(
...
@@ -681,28 +729,31 @@ def _load_interfaces(
:return:
:return:
"""
"""
def
_load_
docs
(
key_pattern
):
def
_load_
netconf_caches
(
is_lab
=
False
):
for
doc
in
_load_netconf_docs
(
config
,
key_pattern
,
use_next_redis
):
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
))
# interface_hosts = dict(_load_netconf_interface_hosts(config, hostname, is_lab, use_next_redis))
for
ifc
in
juniper
.
list_interfaces
(
doc
[
'
netconf
'
]):
for
key
,
ifc
in
interfaces
.
items
():
if
not
ifc
[
'
description
'
]:
router
,
interface_name
=
key
.
split
(
'
:
'
)
continue
bundle
=
interface_bundles
[
key
]
if
not
ifc
[
'
description
'
]:
continue
yield
{
yield
{
'
router
'
:
doc
[
'
router
'
]
,
'
router
'
:
router
,
'
name
'
:
i
fc
[
'
name
'
]
,
'
name
'
:
i
nterface_
name
,
'
bundle
'
:
ifc
[
'
bundle
'
]
,
'
bundle
'
:
bundle
,
'
bundle-parents
'
:
[],
'
bundle-parents
'
:
[],
'
description
'
:
ifc
[
'
description
'
],
'
description
'
:
ifc
[
'
description
'
],
'
circuits
'
:
[]
'
circuits
'
:
[]
}
}
base_key_pattern
=
f
'
netconf:
{
hostname
}
*
'
if
hostname
else
'
netconf:*
'
yield
from
_load_netconf_caches
()
yield
from
_load_docs
(
base_key_pattern
)
if
not
no_lab
:
if
not
no_lab
:
logger
.
debug
(
'
lab
'
)
logger
.
debug
(
'
lab
'
)
yield
from
_load_
docs
(
f
'
lab:
{
base_key_pattern
}
'
)
yield
from
_load_
netconf_caches
(
is_lab
=
True
)
def
_add_speeds
(
interfaces
):
def
_add_speeds
(
interfaces
):
...
@@ -729,6 +780,7 @@ def _add_bundle_parents(interfaces, hostname=None):
...
@@ -729,6 +780,7 @@ def _add_bundle_parents(interfaces, hostname=None):
:param hostname: hostname or None for all
:param hostname: hostname or None for all
:return: generator with bundle-parents populated in each element
:return: generator with bundle-parents populated in each element
"""
"""
def
_get_base_name
(
name
):
def
_get_base_name
(
name
):
return
name
.
split
(
'
.
'
)[
0
]
return
name
.
split
(
'
.
'
)[
0
]
...
...
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