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
04b3a824
Commit
04b3a824
authored
4 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
changed _load_interfaces to use cached interface service info
parent
f71fe002
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/routes/poller.py
+24
-31
24 additions, 31 deletions
inventory_provider/routes/poller.py
with
24 additions
and
31 deletions
inventory_provider/routes/poller.py
+
24
−
31
View file @
04b3a824
...
...
@@ -6,7 +6,8 @@ from distutils.util import strtobool
from
flask
import
Blueprint
,
Response
,
current_app
,
request
from
inventory_provider
import
juniper
from
inventory_provider.routes
import
common
from
inventory_provider.routes.classifier
import
get_ims_equipment_name
from
inventory_provider.routes.classifier
import
get_ims_equipment_name
,
\
get_ims_interface
logger
=
logging
.
getLogger
(
__name__
)
routes
=
Blueprint
(
'
poller-support-routes
'
,
__name__
)
...
...
@@ -109,19 +110,9 @@ def _load_services(hostname=None):
if
hostname
:
hostname
=
get_ims_equipment_name
(
hostname
)
key_pattern
=
f
'
ims:interface_port_ids:
{
hostname
}
:*
'
\
if
hostname
else
'
ims:interface_port_ids:*
'
port_id_interfaces
=
{}
interface_services
=
{}
def
_get_port_id_services
(
s
):
nonlocal
port_id_interfaces
for
d
in
s
:
k
=
d
[
'
key
'
]
v
=
d
[
'
value
'
]
port_id_interfaces
[
v
[
'
port_id
'
]]
=
k
.
split
(
'
:
'
)[
-
2
:]
yield
f
'
ims:port_id_services:
{
v
[
"
port_id
"
]
}
'
result
=
dict
()
key_pattern
=
f
'
ims:interface_services:
{
hostname
}
:*
'
\
if
hostname
else
'
ims:interface_services:*
'
def
_filter_and_format_services
(
_services
):
included_service_ids
=
set
()
...
...
@@ -137,25 +128,24 @@ def _load_services(hostname=None):
'
status
'
:
s
[
'
status
'
]
}
if_ports
=
common
.
load_json_docs
(
for
doc
in
common
.
load_json_docs
(
config_params
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
],
key_pattern
=
key_pattern
,
num_threads
=
20
)
for
r
in
common
.
load_json_docs
(
config_params
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
],
key_pattern
=
_get_port_id_services
(
if_ports
),
num_threads
=
20
):
services
=
r
[
'
value
'
]
if
services
:
h
,
i
=
port_id_interfaces
[
services
[
0
][
'
port_a_id
'
]]
ifs_h
=
interface_services
.
get
(
h
,
{})
interface_services
[
h
]
=
ifs_h
ifs_h_i
=
ifs_h
.
get
(
i
,
[])
ifs_h_i
.
extend
(
list
(
_filter_and_format_services
(
services
)))
ifs_h
[
i
]
=
ifs_h_i
return
interface_services
m
=
re
.
match
(
r
'
^ims:interface_services:([^:]+):(.+)
'
,
doc
[
'
key
'
])
if
not
m
:
logger
.
warning
(
f
'
can
\'
t parse redis service key
{
doc
[
"
key
"
]
}
'
)
# there are some weird records (dtn*, dp1*)
continue
router
=
m
.
group
(
1
)
interface
=
m
.
group
(
2
)
result
.
setdefault
(
router
,
dict
())
result
[
router
][
interface
]
=
\
list
(
_filter_and_format_services
(
doc
[
'
value
'
]))
return
result
def
_load_interfaces
(
hostname
):
...
...
@@ -199,9 +189,12 @@ def _load_poller_interfaces(hostname=None):
base_ifc
=
ifc
[
'
name
'
].
split
(
'
.
'
)[
0
]
ifc
[
'
bundle-parents
'
]
=
router_bundle
.
get
(
base_ifc
,
[])
router_services
=
services
.
get
(
ifc
[
'
router
'
],
None
)
router_services
=
services
.
get
(
get_ims_equipment_name
(
ifc
[
'
router
'
]),
None
)
if
router_services
:
ifc
[
'
circuits
'
]
=
router_services
.
get
(
ifc
[
'
name
'
],
[])
ifc
[
'
circuits
'
]
=
router_services
.
get
(
get_ims_interface
(
ifc
[
'
name
'
]),
[]
)
yield
ifc
...
...
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