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
7936f4a3
Commit
7936f4a3
authored
2 years ago
by
Sam Roberts
Browse files
Options
Downloads
Patches
Plain Diff
rewritten to provide NREN, and to use caching
parent
05d8b71d
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!3
Feature/reporting 311 add msr asn peers
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/routes/msr.py
+62
-12
62 additions, 12 deletions
inventory_provider/routes/msr.py
test/test_msr_routes.py
+3
-3
3 additions, 3 deletions
test/test_msr_routes.py
with
65 additions
and
15 deletions
inventory_provider/routes/msr.py
+
62
−
12
View file @
7936f4a3
...
...
@@ -362,6 +362,40 @@ DOMAIN_TO_POP_MAPPING = {
"
ams.nl
"
:
"
Amsterdam
"
}
# very similar to PEERING_LIST_SCHEMA but
# with a field for NREN, which is required
ASN_PEER_LIST_SCHEMA
=
{
'
$schema
'
:
'
http://json-schema.org/draft-07/schema#
'
,
'
definitions
'
:
{
'
peering-instance
'
:
{
'
type
'
:
'
object
'
,
'
properties
'
:
{
'
address
'
:
{
'
type
'
:
'
string
'
},
'
description
'
:
{
'
type
'
:
'
string
'
},
'
logical-system
'
:
{
'
type
'
:
'
string
'
},
'
group
'
:
{
'
type
'
:
'
string
'
},
'
hostname
'
:
{
'
type
'
:
'
string
'
},
'
remote-asn
'
:
{
'
type
'
:
'
integer
'
},
'
local-asn
'
:
{
'
type
'
:
'
integer
'
},
'
instance
'
:
{
'
type
'
:
'
string
'
},
'
nren
'
:
{
'
type
'
:
'
string
'
}
},
# only vrr peerings have remote-asn
# only group peerings have local-asn or instance
# not all group peerings have 'description'
# and only vrr or vpn-proxy peerings are within a logical system
'
required
'
:
[
'
address
'
,
'
group
'
,
'
hostname
'
,
'
nren
'
],
'
additionalProperties
'
:
False
}
},
'
type
'
:
'
array
'
,
'
items
'
:
{
'
$ref
'
:
'
#/definitions/peering-instance
'
}
}
@routes.after_request
def
after_request
(
resp
):
...
...
@@ -1203,14 +1237,14 @@ def asn_peers(asn):
The response will be formatted according to the following schema:
.. asjson::
inventory_provider.routes.msr.PEER
ING
_LIST_SCHEMA
inventory_provider.routes.msr.
ASN_
PEER_LIST_SCHEMA
:param asn: specific ASN to get peers for
:return:
"""
r
=
common
.
get_current_redis
()
def
_get_filtered_peers_for_asn
(
asn
,
group
,
instance
):
def
_get_filtered_peers_for_asn
(
asn
,
nren
,
group
,
instance
):
peers
=
json
.
loads
(
r
.
get
(
f
'
juniper-peerings:peer-asn:
{
asn
}
'
))
def
_attribute_filter
(
peer
,
name
,
value
):
...
...
@@ -1223,12 +1257,12 @@ def asn_peers(asn):
for
peer
in
peers
:
if
_attribute_filter
(
peer
,
"
group
"
,
group
)
and
\
_attribute_filter
(
peer
,
"
instance
"
,
instance
):
peer
[
'
nren
'
]
=
nren
yield
peer
def
_get_filtered_peers
(
nren_asn_map
,
group
,
instance
):
for
pair
in
nren_asn_map
:
asn
=
pair
[
'
asn
'
]
asn_peers
=
_get_filtered_peers_for_asn
(
asn
,
group
,
instance
)
def
_get_filtered_peers
(
asn_nren_map
,
group
,
instance
):
for
asn
,
nren
in
asn_nren_map
.
items
():
asn_peers
=
_get_filtered_peers_for_asn
(
asn
,
nren
,
group
,
instance
)
for
peer
in
asn_peers
:
yield
peer
...
...
@@ -1241,10 +1275,26 @@ def asn_peers(asn):
group
=
params
.
get
(
'
group
'
,
None
)
instance
=
params
.
get
(
'
instance
'
,
None
)
if
asn
is
not
None
:
peers
=
list
(
_get_filtered_peers_for_asn
(
asn
,
group
,
instance
))
else
:
cache_key
=
f
'
classifier-cache:msr:asn-peers:
{
asn
}
:
{
group
}
:
{
instance
}
'
response
=
_ignore_cache_or_retrieve
(
request
,
cache_key
,
r
)
if
not
response
:
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
nren_asn_map
=
config
[
'
nren-asn-map
'
]
peers
=
list
(
_get_filtered_peers
(
nren_asn_map
,
group
,
instance
))
return
jsonify
(
peers
)
# set up quick lookup based on ASN
asn_nren_map
=
{
item
[
'
asn
'
]:
item
[
'
nren
'
]
for
item
in
config
[
'
nren-asn-map
'
]
}
if
asn
is
not
None
:
nren
=
asn_nren_map
.
get
(
asn
,
None
)
peers
=
list
(
_get_filtered_peers_for_asn
(
asn
,
nren
,
group
,
instance
)
)
else
:
peers
=
list
(
_get_filtered_peers
(
asn_nren_map
,
group
,
instance
)
)
response
=
json
.
dumps
(
peers
)
r
.
set
(
cache_key
,
response
.
encode
(
'
utf-8
'
))
return
Response
(
response
,
mimetype
=
'
application/json
'
)
This diff is collapsed.
Click to expand it.
test/test_msr_routes.py
+
3
−
3
View file @
7936f4a3
...
...
@@ -6,7 +6,7 @@ import pytest
from
inventory_provider.routes.msr
import
PEERING_LIST_SCHEMA
,
\
PEERING_GROUP_LIST_SCHEMA
,
PEERING_ADDRESS_SERVICES_LIST
,
\
SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA
,
_get_services_for_address
,
\
MDVPN_LIST_SCHEMA
,
VPN_PROXY_LIST_SCHEMA
MDVPN_LIST_SCHEMA
,
VPN_PROXY_LIST_SCHEMA
,
ASN_PEER_LIST_SCHEMA
from
inventory_provider.routes.poller
import
SERVICES_LIST_SCHEMA
from
inventory_provider.tasks.common
import
_get_redis
...
...
@@ -366,7 +366,7 @@ def test_get_asn_peers_get(endpoint_variant, client, mocked_redis):
assert
rv
.
status_code
==
200
assert
rv
.
is_json
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
response_data
,
PEER
ING
_LIST_SCHEMA
)
jsonschema
.
validate
(
response_data
,
ASN_
PEER_LIST_SCHEMA
)
assert
response_data
# test data is non-empty
...
...
@@ -389,5 +389,5 @@ def test_get_asn_peers_post(endpoint_variant, post_body, client, mocked_redis):
assert
rv
.
status_code
==
200
assert
rv
.
is_json
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
response_data
,
PEER
ING
_LIST_SCHEMA
)
jsonschema
.
validate
(
response_data
,
ASN_
PEER_LIST_SCHEMA
)
assert
response_data
# test data is non-empty
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