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
84c61fa5
Commit
84c61fa5
authored
3 years ago
by
Erik Reid
Browse files
Options
Downloads
Plain Diff
Finished feature feature/gws-direct-config-api.
parents
4f0d0f77
dbeb6b7c
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/poller.py
+81
-1
81 additions, 1 deletion
inventory_provider/routes/poller.py
test/test_general_poller_routes.py
+24
-1
24 additions, 1 deletion
test/test_general_poller_routes.py
with
105 additions
and
2 deletions
inventory_provider/routes/poller.py
+
81
−
1
View file @
84c61fa5
...
...
@@ -30,6 +30,12 @@ These endpoints are intended for use by BRIAN.
.. autofunction:: inventory_provider.routes.poller.gws_direct
/poller/gws/direct-config
---------------------------------
.. autofunction:: inventory_provider.routes.poller.gws_direct_config
/poller/gws/indirect
---------------------------------
...
...
@@ -53,13 +59,14 @@ support method: _get_dashboards
.. autofunction:: inventory_provider.routes.poller._get_dashboards
"""
from
enum
import
Enum
,
auto
import
json
import
logging
import
re
from
flask
import
Blueprint
,
Response
,
current_app
,
request
from
flask
import
Blueprint
,
Response
,
current_app
,
request
,
jsonify
from
lxml
import
etree
from
inventory_provider
import
juniper
...
...
@@ -1269,3 +1276,76 @@ def get_service_types():
redis
.
set
(
cache_key
,
service_types
)
return
Response
(
service_types
,
mimetype
=
'
application/json
'
)
@routes.route
(
'
/gws/direct-config
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
gws_direct_config
():
"""
Handler for `/poller/gws/direct-config` which returns
the basic gws-direct config.
This api is only intended for config validation.
:return:
"""
format
=
request
.
args
.
get
(
'
format
'
,
default
=
'
json
'
,
type
=
str
)
format
=
format
.
lower
()
if
format
not
in
(
'
html
'
,
'
json
'
):
return
Response
(
response
=
'
format must be one of: html, json
'
,
status
=
400
,
mimetype
=
"
text/html
"
)
def
_counters
():
config_params
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
for
nren_isp
in
config_params
[
'
gws-direct
'
]:
for
host
in
nren_isp
[
'
hosts
'
]:
snmp_version
=
'
2
'
if
'
community
'
in
host
.
keys
()
else
'
3
'
for
ifc
in
host
[
'
interfaces
'
]:
for
field
,
oid
in
ifc
[
'
counters
'
].
items
():
yield
{
'
nren
'
:
nren_isp
[
'
nren
'
],
'
isp
'
:
nren_isp
[
'
isp
'
],
'
hostname
'
:
host
[
'
hostname
'
],
'
snmp
'
:
snmp_version
,
'
interface
'
:
ifc
[
'
tag
'
],
'
field
'
:
field
,
'
oid
'
:
oid
}
def
_to_row
(
counter
,
header
=
False
):
_columns
=
(
'
nren
'
,
'
isp
'
,
'
hostname
'
,
'
snmp
'
,
'
interface
'
,
'
field
'
,
'
oid
'
)
elems
=
[
'
<tr>
'
]
for
name
in
_columns
:
if
header
:
elems
.
append
(
f
'
<th>
{
name
}
</th>
'
)
else
:
elems
.
append
(
f
'
<td>
{
counter
[
name
]
}
</td>
'
)
elems
.
append
(
'
</tr>
'
)
return
''
.
join
(
elems
)
if
format
==
'
json
'
:
if
not
request
.
accept_mimetypes
.
accept_json
:
return
Response
(
response
=
"
response will be json
"
,
status
=
406
,
mimetype
=
"
text/html
"
)
else
:
return
jsonify
(
list
(
_counters
()))
if
not
request
.
accept_mimetypes
.
accept_html
:
return
Response
(
response
=
"
response will be html
"
,
status
=
406
,
mimetype
=
"
text/html
"
)
elems
=
[
'
<html>
'
,
'
<body>
'
,
'
<table>
'
]
elems
.
append
(
_to_row
(
None
,
header
=
True
))
elems
+=
map
(
_to_row
,
_counters
())
elems
+=
[
'
</table>
'
,
'
</body>
'
,
'
</html>
'
]
return
Response
(
response
=
''
.
join
(
elems
),
status
=
200
,
mimetype
=
"
text/html
"
)
This diff is collapsed.
Click to expand it.
test/test_general_poller_routes.py
+
24
−
1
View file @
84c61fa5
...
...
@@ -4,7 +4,6 @@ import pytest
from
inventory_provider.routes
import
poller
DEFAULT_REQUEST_HEADERS
=
{
# 'Content-type': 'application/json',
'
Accept
'
:
[
'
application/json
'
]
}
...
...
@@ -315,3 +314,27 @@ def test_description_dashboard_parsing(interface, dashboard_info):
updated
=
poller
.
_get_dashboard_data
(
interface
)
info
=
updated
[
'
dashboard_info
'
]
assert
info
==
dashboard_info
def
test_gws_config_json
(
client
):
rv
=
client
.
get
(
'
/poller/gws/direct-config
'
,
headers
=
{
'
Accept
'
:
[
'
application/json
'
]})
assert
rv
.
status_code
==
200
assert
rv
.
is_json
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
# just a sanity check, no validation
# ... for now, this isn't an important interface
assert
response_data
def
test_gws_config_html
(
client
):
rv
=
client
.
get
(
'
/poller/gws/direct-config?format=html
'
,
headers
=
{
'
Accept
'
:
[
'
text/html
'
]})
assert
rv
.
status_code
==
200
response_data
=
rv
.
data
.
decode
(
'
utf-8
'
)
# just a sanity check, no validation
# ... for now, this isn't an important interface
assert
response_data
.
startswith
(
'
<html>
'
)
assert
response_data
.
endswith
(
'
</html>
'
)
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