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
8dc0ce4e
Commit
8dc0ce4e
authored
2 years ago
by
Sam Roberts
Browse files
Options
Downloads
Patches
Plain Diff
present VRR peerings in endpoint
parent
a862f23f
No related branches found
No related tags found
1 merge request
!1
Feature/reporting 297 msr mdvpn endpoint
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/routes/msr.py
+58
-11
58 additions, 11 deletions
inventory_provider/routes/msr.py
with
58 additions
and
11 deletions
inventory_provider/routes/msr.py
+
58
−
11
View file @
8dc0ce4e
...
@@ -880,15 +880,37 @@ def bgp_all_peerings():
...
@@ -880,15 +880,37 @@ def bgp_all_peerings():
@routes.route
(
'
/mdvpn
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@routes.route
(
'
/mdvpn
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@common.require_accepts_json
@common.require_accepts_json
def
mdvpn
():
def
mdvpn
():
def
_make_bgplu_index
(
bgplu
):
def
_get_consistent_description
(
description
):
"""
The same interface in VRR peerings can have multiple names.
These names are (currently) the same but with a different local prefix,
with no ordering guaranteed by the redis cache.
As only one description is returned by this endpoint for each
IPv4 address, this serves as a quick and dirty way of merging these
multiple descriptions into one an external user can use to identify
the peering reliably.
:param description: The raw description for a VRR peering
:return: The same description with location prefix removed
"""
# it is incredibly likely this will need revision later down the line
expected_prefixes
=
[
"
MD-VPN-VRR-PARIS-
"
,
"
MD-VPN-VRR-LJUBLJANA-
"
]
for
prefix
in
expected_prefixes
:
if
description
.
startswith
(
prefix
):
return
description
.
replace
(
prefix
,
''
)
return
description
def
_make_group_index
(
group
,
index_key
):
index
=
{}
index
=
{}
for
peering
in
bgplu
:
for
peering
in
group
:
asn
=
peering
[
'
remote-asn
'
]
key
=
peering
.
get
(
index_key
)
if
asn
in
index
:
if
key
in
index
:
peering_list
=
index
[
asn
]
peering_list
=
index
[
key
]
peering_list
.
append
(
peering
)
peering_list
.
append
(
peering
)
else
:
else
:
index
[
asn
]
=
[
peering
]
index
[
key
]
=
[
peering
]
return
index
return
index
def
_bgplu_peerings
(
asn
,
bgplu_index
):
def
_bgplu_peerings
(
asn
,
bgplu_index
):
...
@@ -904,19 +926,44 @@ def mdvpn():
...
@@ -904,19 +926,44 @@ def mdvpn():
peerings
.
append
(
formatted_peering
)
peerings
.
append
(
formatted_peering
)
return
peerings
return
peerings
def
_peerings_for_nren
(
asn
,
bgplu_index
):
def
_vpnrr_peerings
(
asn
,
vpnrr_index
):
peerings
=
[]
if
asn
in
vpnrr_index
:
vrr_peering_group
=
vpnrr_index
[
asn
]
# rearrange into index using ipv4 as key
# this will collect related entries under the same ipv4
ip_index
=
_make_group_index
(
vrr_peering_group
,
'
address
'
)
for
ip
in
ip_index
:
ip_details
=
ip_index
[
ip
]
# a list of all info for given ipv4
hostnames
=
[
item
[
'
hostname
'
]
for
item
in
ip_details
]
description
=
ip_details
[
0
][
'
description
'
]
formatted_peering
=
{
"
description
"
:
_get_consistent_description
(
description
),
"
v4
"
:
ip
,
"
hostname
"
:
hostnames
}
peerings
.
append
(
formatted_peering
)
return
peerings
def
_peerings_for_nren
(
asn
,
bgplu_index
,
vpnrr_index
):
return
{
return
{
"
asn
"
:
asn
,
"
asn
"
:
asn
,
"
AP
"
:
_bgplu_peerings
(
asn
,
bgplu_index
),
"
AP
"
:
_bgplu_peerings
(
asn
,
bgplu_index
),
"
VRR
"
:
[]
"
VRR
"
:
_vpnrr_peerings
(
asn
,
vpnrr_index
)
}
}
r
=
common
.
get_current_redis
()
r
=
common
.
get_current_redis
()
bgplu
=
json
.
loads
(
r
.
get
(
'
juniper-peerings:group:BGPLU
'
).
decode
(
'
utf-8
'
))
bgplu
=
json
.
loads
(
r
.
get
(
'
juniper-peerings:group:BGPLU
'
).
decode
(
'
utf-8
'
))
bgplu_index
=
_make_bgplu_index
(
bgplu
)
vpnrr
=
json
.
loads
(
r
.
get
(
'
juniper-peerings:group:VPN-RR
'
).
decode
(
'
utf-8
'
))
bgplu_index
=
_make_group_index
(
bgplu
,
'
remote-asn
'
)
vpnrr_index
=
_make_group_index
(
vpnrr
,
'
remote-asn
'
)
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
nren_asn_map
=
config
[
'
nren-asn-map
'
]
nren_asn_map
=
config
[
'
nren-asn-map
'
]
nren_details
=
[
_peerings_for_nren
(
int
(
asn
),
bgplu_index
)
for
asn
in
nren_details
=
[
nren_asn_map
]
_peerings_for_nren
(
int
(
asn
),
bgplu_index
,
vpnrr_index
)
for
asn
in
nren_asn_map
]
response
=
json
.
dumps
(
nren_details
)
response
=
json
.
dumps
(
nren_details
)
return
Response
(
response
,
mimetype
=
'
application/json
'
)
return
Response
(
response
,
mimetype
=
'
application/json
'
)
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