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
df07258c
Commit
df07258c
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
add snmp id/ifcname map route
parent
cf64eb60
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/routes/data.py
+31
-0
31 additions, 0 deletions
inventory_provider/routes/data.py
test/test_data_routes.py
+27
-0
27 additions, 0 deletions
test/test_data_routes.py
with
58 additions
and
0 deletions
inventory_provider/routes/data.py
+
31
−
0
View file @
df07258c
...
...
@@ -66,6 +66,7 @@ def router_interfaces(hostname):
status
=
404
,
mimetype
=
"
text/html
"
)
def
_interfaces
(
s
):
for
ifc
in
json
.
loads
(
s
):
if
'
v4InterfaceName
'
in
ifc
:
...
...
@@ -85,6 +86,36 @@ def router_interfaces(hostname):
mimetype
=
"
application/json
"
)
@routes.route
(
"
/snmp/<hostname>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@require_accepts_json
def
snmp_ids
(
hostname
):
redis_config
=
current_app
.
config
[
"
INVENTORY_PROVIDER_CONFIG
"
][
"
redis
"
]
r
=
redis
.
StrictRedis
(
host
=
redis_config
[
"
hostname
"
],
port
=
redis_config
[
"
port
"
])
ifc_data_string
=
r
.
hget
(
hostname
,
'
snmp-interfaces
'
)
if
not
ifc_data_string
:
return
Response
(
response
=
"
no available info for
'
%s
'"
%
hostname
,
status
=
404
,
mimetype
=
"
text/html
"
)
def
_ifc_name
(
ifc
):
if
'
v4InterfaceName
'
in
ifc
:
return
ifc
[
'
v4InterfaceName
'
]
if
'
v6InterfaceName
'
in
ifc
:
return
ifc
[
'
v6InterfaceName
'
]
assert
False
,
"
sanity failure: no interface name found
"
ifc_data
=
json
.
loads
(
ifc_data_string
.
decode
(
'
utf-8
'
))
result
=
[
{
'
index
'
:
i
[
'
index
'
],
'
name
'
:
_ifc_name
(
i
)}
for
i
in
ifc_data
]
return
Response
(
json
.
dumps
(
result
),
mimetype
=
"
application/json
"
)
@routes.route
(
"
/debug-dump/<hostname>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@require_accepts_json
def
debug_dump_router_info
(
hostname
):
...
...
This diff is collapsed.
Click to expand it.
test/test_data_routes.py
+
27
−
0
View file @
df07258c
...
...
@@ -254,6 +254,33 @@ def test_router_interfaces(client_with_mocked_data):
assert
response
# at least shouldn't be empty
def
test_snmp_ids
(
client_with_mocked_data
):
snmp_id_list_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
array
"
,
"
items
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
index
"
:
{
"
type
"
:
"
string
"
},
"
name
"
:
{
"
type
"
:
"
string
"
}
},
"
required
"
:
[
"
index
"
,
"
name
"
],
"
additionalProperties
"
:
False
}
}
for
hostname
in
_routers
(
client_with_mocked_data
):
rv
=
client_with_mocked_data
.
post
(
"
/data/snmp/
"
+
hostname
,
headers
=
DEFAULT_REQUEST_HEADERS
)
response
=
json
.
loads
(
rv
.
data
.
decode
(
"
utf-8
"
))
jsonschema
.
validate
(
response
,
snmp_id_list_schema
)
assert
response
# at least shouldn't be empty
def
test_router_bgp_route
(
client_with_mocked_data
):
bgp_list_schema
=
{
...
...
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