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
8c799a73
Commit
8c799a73
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
handle new redis schema format
parent
97e44547
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/data.py
+20
-22
20 additions, 22 deletions
inventory_provider/routes/data.py
with
20 additions
and
22 deletions
inventory_provider/routes/data.py
+
20
−
22
View file @
8c799a73
import
json
import
pkg_resources
import
re
from
flask
import
Blueprint
,
jsonify
,
Response
,
current_app
from
lxml
import
etree
...
...
@@ -11,7 +11,6 @@ from inventory_provider.routes import common
routes
=
Blueprint
(
"
inventory-data-query-routes
"
,
__name__
)
@routes.route
(
"
/routers
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@common.require_accepts_json
def
routers
():
...
...
@@ -19,9 +18,12 @@ def routers():
r
=
redis
.
StrictRedis
(
host
=
redis_config
[
"
hostname
"
],
port
=
redis_config
[
"
port
"
])
return
Response
(
json
.
dumps
(
list
([
k
.
decode
(
"
utf-8
"
)
for
k
in
r
.
keys
(
"
*
"
)])),
mimetype
=
"
application/json
"
)
result
=
[]
for
k
in
r
.
keys
(
'
netconf:*
'
):
m
=
re
.
match
(
'
^netconf:(.+)$
'
,
k
.
decode
(
'
utf-8
'
))
assert
m
result
.
append
(
m
.
group
(
1
))
return
jsonify
(
result
)
@routes.route
(
"
/interfaces/<hostname>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
...
...
@@ -47,9 +49,7 @@ def router_interfaces(hostname):
status
=
404
,
mimetype
=
"
text/html
"
)
return
Response
(
json
.
dumps
(
interfaces
),
mimetype
=
"
application/json
"
)
return
jsonify
(
interfaces
)
@routes.route
(
"
/snmp/<hostname>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
...
...
@@ -77,9 +77,7 @@ def snmp_ids(hostname):
result
=
[
{
'
index
'
:
i
[
'
index
'
],
'
name
'
:
_ifc_name
(
i
)}
for
i
in
ifc_data
]
return
Response
(
json
.
dumps
(
result
),
mimetype
=
"
application/json
"
)
return
jsonify
(
result
)
@routes.route
(
"
/bgp/<hostname>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
...
...
@@ -105,9 +103,7 @@ def bgp_configs(hostname):
status
=
404
,
mimetype
=
"
text/html
"
)
return
Response
(
json
.
dumps
(
routes
),
mimetype
=
"
application/json
"
)
return
jsonify
(
routes
)
@routes.route
(
"
/interfaces/status/<hostname>/<path:interface>
"
,
...
...
@@ -115,14 +111,15 @@ def bgp_configs(hostname):
@common.require_accepts_json
def
interface_statuses
(
hostname
,
interface
):
r
=
common
.
get_redis
()
result
=
r
.
hget
(
"
interface_statuses
"
,
"
{}::{}
"
.
format
(
hostname
,
interface
))
if
not
result
:
status
=
r
.
get
(
'
alarmsdb:interface_status:%s:%s
'
%
(
hostname
,
interface
))
if
not
status
:
return
Response
(
response
=
"
no available info for {} {}
"
.
format
(
hostname
,
interface
),
status
=
404
,
mimetype
=
"
text/html
"
)
return
jsonify
({
"
status
"
:
result
.
decode
(
'
utf-8
'
)})
return
jsonify
({
"
status
"
:
status
.
decode
(
'
utf-8
'
)})
@routes.route
(
"
/services/<hostname>/<path:interface>
"
,
...
...
@@ -130,11 +127,12 @@ def interface_statuses(hostname, interface):
@common.require_accepts_json
def
services_for_interface
(
hostname
,
interface
):
r
=
common
.
get_redis
()
result
=
r
.
hget
(
"
interface_services
"
,
"
{}::{}
"
.
format
(
hostname
,
interface
))
if
not
result
:
services
=
r
.
get
(
'
opsdb:interface_services:%s:%s
'
%
(
hostname
,
interface
))
if
not
services
:
return
Response
(
response
=
"
no available info for {} {}
"
.
format
(
hostname
,
interface
),
status
=
404
,
mimetype
=
"
text/html
"
)
return
jsonify
(
json
.
loads
(
result
.
decode
(
'
utf-8
'
)))
return
jsonify
(
json
.
loads
(
services
.
decode
(
'
utf-8
'
)))
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