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
fd4a3905
Commit
fd4a3905
authored
5 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
moved some unused routes to /testing (intention is to delete these)
parent
ea210e01
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/routes/data.py
+12
-73
12 additions, 73 deletions
inventory_provider/routes/data.py
inventory_provider/routes/testing.py
+85
-0
85 additions, 0 deletions
inventory_provider/routes/testing.py
with
97 additions
and
73 deletions
inventory_provider/routes/data.py
+
12
−
73
View file @
fd4a3905
import
json
import
re
from
flask
import
Blueprint
,
jsonify
,
Response
from
lxml
import
etree
from
flask
import
Blueprint
,
jsonify
,
Response
,
current_app
from
inventory_provider
import
juniper
from
inventory_provider.routes
import
common
from
inventory_provider.db
import
db
from
inventory_provider.db
import
opsdb
routes
=
Blueprint
(
"
inventory-data-query-routes
"
,
__name__
)
...
...
@@ -41,83 +41,22 @@ def router_interfaces(hostname):
return
jsonify
(
interfaces
)
@routes.route
(
"
/
snmp/<host
name>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@routes.route
(
"
/
pop/<equipment_
name>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@common.require_accepts_json
def
snmp_ids
(
hostname
):
r
=
common
.
get_redis
()
ifc_data_string
=
r
.
get
(
'
snmp-interfaces:
'
+
hostname
)
if
not
ifc_data_string
:
def
equipment_location
(
equipment_name
):
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
with
db
.
connection
(
config
[
'
ops-db
'
])
as
cx
:
result
=
opsdb
.
get_equipment_location_data
(
cx
,
equipment_name
)
if
not
result
:
return
Response
(
response
=
"
no available info for
'
%s
'"
%
host
name
,
response
=
"
no available info for
{}
"
.
format
(
equipment_
name
)
,
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
jsonify
(
result
)
@routes.route
(
"
/bgp/<hostname>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@common.require_accepts_json
def
bgp_configs
(
hostname
):
r
=
common
.
get_redis
()
netconf_string
=
r
.
get
(
'
netconf:
'
+
hostname
)
if
not
netconf_string
:
return
Response
(
response
=
"
no available info for
'
%s
'"
%
hostname
,
status
=
404
,
mimetype
=
"
text/html
"
)
routes
=
list
(
juniper
.
list_bgp_routes
(
etree
.
XML
(
netconf_string
.
decode
(
'
utf-8
'
))))
if
not
routes
:
return
Response
(
response
=
"
no interfaces found for
'
%s
'"
%
hostname
,
status
=
404
,
mimetype
=
"
text/html
"
)
return
jsonify
(
routes
)
# TODO: remove all alarmsdb i/o, and then remove the following
# @routes.route("/interfaces/status/<hostname>/<path:interface>",
# methods=['GET', 'POST'])
# @common.require_accepts_json
# def interface_statuses(hostname, interface):
# r = common.get_redis()
# 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": status.decode('utf-8')})
#
#
# @routes.route("/services/<hostname>/<path:interface>",
# methods=['GET', 'POST'])
# @common.require_accepts_json
# def services_for_interface(hostname, interface):
# r = common.get_redis()
# 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(services.decode('utf-8')))
This diff is collapsed.
Click to expand it.
inventory_provider/routes/testing.py
+
85
−
0
View file @
fd4a3905
...
...
@@ -3,6 +3,9 @@ import json
import
re
from
flask
import
Blueprint
,
Response
,
current_app
,
jsonify
from
lxml
import
etree
from
inventory_provider
import
juniper
from
inventory_provider.routes
import
common
from
inventory_provider.tasks
import
worker
...
...
@@ -137,3 +140,85 @@ def get_parents(child_id):
result
=
r
.
get
(
'
opsdb:services:parents:%d
'
%
child_id
)
# TODO: handle None (return 404)
return
jsonify
(
json
.
loads
(
result
.
decode
(
'
utf-8
'
)))
@routes.route
(
"
bgp/<hostname>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@common.require_accepts_json
def
bgp_configs
(
hostname
):
r
=
common
.
get_redis
()
netconf_string
=
r
.
get
(
'
netconf:
'
+
hostname
)
if
not
netconf_string
:
return
Response
(
response
=
"
no available info for
'
%s
'"
%
hostname
,
status
=
404
,
mimetype
=
"
text/html
"
)
routes
=
list
(
juniper
.
list_bgp_routes
(
etree
.
XML
(
netconf_string
.
decode
(
'
utf-8
'
))))
if
not
routes
:
return
Response
(
response
=
"
no interfaces found for
'
%s
'"
%
hostname
,
status
=
404
,
mimetype
=
"
text/html
"
)
return
jsonify
(
routes
)
@routes.route
(
"
snmp/<hostname>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@common.require_accepts_json
def
snmp_ids
(
hostname
):
r
=
common
.
get_redis
()
ifc_data_string
=
r
.
get
(
'
snmp-interfaces:
'
+
hostname
)
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
jsonify
(
result
)
# TODO: remove all alarmsdb i/o, and then remove the following
# @routes.route("/interfaces/status/<hostname>/<path:interface>",
# methods=['GET', 'POST'])
# @common.require_accepts_json
# def interface_statuses(hostname, interface):
# r = common.get_redis()
# 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": status.decode('utf-8')})
#
#
# @routes.route("/services/<hostname>/<path:interface>",
# methods=['GET', 'POST'])
# @common.require_accepts_json
# def services_for_interface(hostname, interface):
# r = common.get_redis()
# 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(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