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
0136eb04
Commit
0136eb04
authored
4 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
switched poller route to use IMS data
parent
1aa3e9ee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/routes/poller.py
+58
-28
58 additions, 28 deletions
inventory_provider/routes/poller.py
with
58 additions
and
28 deletions
inventory_provider/routes/poller.py
+
58
−
28
View file @
0136eb04
import
json
import
logging
import
re
from
distutils.util
import
strtobool
from
flask
import
Blueprint
,
Response
,
current_app
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
logger
=
logging
.
getLogger
(
__name__
)
routes
=
Blueprint
(
'
poller-support-routes
'
,
__name__
)
...
...
@@ -104,35 +106,56 @@ def _load_interface_bundles(hostname=None):
def
_load_services
(
hostname
=
None
):
result
=
dict
()
key_pattern
=
f
'
opsdb:interface_services:
{
hostname
}
:*
'
\
if
hostname
else
'
opsdb:interface_services:*
'
def
_service_params
(
full_service_info
):
return
{
'
id
'
:
full_service_info
[
'
id
'
],
'
name
'
:
full_service_info
[
'
name
'
],
'
type
'
:
full_service_info
[
'
service_type
'
],
'
status
'
:
full_service_info
[
'
status
'
]
}
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
"
]
}
'
def
_filter_and_format_services
(
_services
):
included_service_ids
=
set
()
for
s
in
_services
:
if
s
[
'
id
'
]
in
included_service_ids
:
continue
if
s
[
'
circuit_type
'
]
==
'
service
'
:
included_service_ids
.
add
(
s
[
'
id
'
])
yield
{
'
id
'
:
s
[
'
id
'
],
'
name
'
:
s
[
'
name
'
],
'
type
'
:
s
[
'
service_type
'
],
'
status
'
:
s
[
'
status
'
]
}
for
doc
in
common
.
load_json_docs
(
if_ports
=
common
.
load_json_docs
(
config_params
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
],
key_pattern
=
key_pattern
,
num_threads
=
20
):
m
=
re
.
match
(
r
'
^opsdb: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
num_threads
=
20
)
router
=
m
.
group
(
1
)
interface
=
m
.
group
(
2
)
result
.
setdefault
(
router
,
dict
())
result
[
router
][
interface
]
=
[
_service_params
(
s
)
for
s
in
doc
[
'
value
'
]]
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
result
return
interface_services
def
_load_interfaces
(
hostname
):
...
...
@@ -159,7 +182,6 @@ def _load_interfaces(hostname):
def
_load_poller_interfaces
(
hostname
=
None
):
snmp_indexes
=
_load_snmp_indexes
(
hostname
)
bundles
=
_load_interface_bundles
(
hostname
)
services
=
_load_services
(
hostname
)
...
...
@@ -207,10 +229,18 @@ def interfaces(hostname=None):
cache_key
=
f
'
classifier-cache:poller-interfaces:
{
hostname
}
'
\
if
hostname
else
'
classifier-cache:poller-interfaces:all
'
r
=
common
.
get_current_redis
()
result
=
r
.
get
(
cache_key
)
ignore_cache
=
request
.
args
.
get
(
'
ignore-cache
'
,
default
=
'
false
'
,
type
=
str
)
try
:
ignore_cache
=
strtobool
(
ignore_cache
)
except
ValueError
:
ignore_cache
=
False
if
ignore_cache
:
result
=
False
else
:
result
=
r
.
get
(
cache_key
)
if
result
:
result
=
result
.
decode
(
'
utf-8
'
)
else
:
...
...
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