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
226a3077
Commit
226a3077
authored
2 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
initial raft /msr/services updated with redundant asn
parent
98fd8212
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/routes/msr.py
+42
-14
42 additions, 14 deletions
inventory_provider/routes/msr.py
with
42 additions
and
14 deletions
inventory_provider/routes/msr.py
+
42
−
14
View file @
226a3077
...
@@ -260,7 +260,8 @@ SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA = {
...
@@ -260,7 +260,8 @@ SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA = {
'
service_type
'
:
{
'
type
'
:
'
string
'
},
# TODO: enum?
'
service_type
'
:
{
'
type
'
:
'
string
'
},
# TODO: enum?
'
project
'
:
{
'
type
'
:
'
string
'
},
# TODO: remove this?
'
project
'
:
{
'
type
'
:
'
string
'
},
# TODO: remove this?
'
customer
'
:
{
'
type
'
:
'
string
'
},
'
customer
'
:
{
'
type
'
:
'
string
'
},
'
endpoints
'
:
{
'
$ref
'
:
'
#/definitions/endpoints
'
}
'
endpoints
'
:
{
'
$ref
'
:
'
#/definitions/endpoints
'
},
'
redundant_asn
'
:
{
'
type
'
:
'
integer
'
}
},
},
'
required
'
:
[
'
required
'
:
[
'
circuit_id
'
,
'
sid
'
,
'
name
'
,
'
speed
'
,
'
status
'
,
'
monitored
'
,
'
circuit_id
'
,
'
sid
'
,
'
name
'
,
'
speed
'
,
'
status
'
,
'
monitored
'
,
...
@@ -905,39 +906,51 @@ def get_system_correlation_services():
...
@@ -905,39 +906,51 @@ def get_system_correlation_services():
r
=
common
.
get_current_redis
()
r
=
common
.
get_current_redis
()
response
=
_ignore_cache_or_retrieve
(
request
,
cache_key
,
r
)
response
=
_ignore_cache_or_retrieve
(
request
,
cache_key
,
r
)
if
not
response
:
if
not
response
:
peering_info
=
defaultdict
(
defaultdict
)
key_pattern
=
'
netconf-interfaces:*
'
# dict of dicts:
# peering_info[hostname][interface_name] = dict of ifc details
peering_info
=
defaultdict
(
dict
)
host_if_extraction_re
=
re
.
compile
(
host_if_extraction_re
=
re
.
compile
(
r
'
^netconf-interfaces:(.+?):
'
)
r
'
^netconf-interfaces:(.+?):
'
)
for
doc
in
common
.
load_json_docs
(
for
doc
in
common
.
load_json_docs
(
config_params
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
],
config_params
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
],
key_pattern
=
key_pattern
,
key_pattern
=
'
netconf-interfaces:*
'
,
num_threads
=
20
):
num_threads
=
20
):
matches
=
host_if_extraction_re
.
match
(
doc
[
'
key
'
])
matches
=
host_if_extraction_re
.
match
(
doc
[
'
key
'
])
if
matches
:
if
matches
:
peering_info
[
matches
[
1
]][
doc
[
'
value
'
][
'
name
'
]]
=
doc
[
'
value
'
]
peering_info
[
matches
[
1
]][
doc
[
'
value
'
][
'
name
'
]]
=
doc
[
'
value
'
]
def
_load_redundant_peers
():
# REPORTING-312: limited to eGEANT group,
# but this can be expanded here in future
redundant_access_groups
=
[
'
eGEANT
'
]
for
g
in
redundant_access_groups
:
doc
=
r
.
get
(
f
'
juniper-peerings:group:
{
g
}
'
)
for
peer
in
json
.
loads
(
doc
.
decode
(
'
utf-8
'
)):
yield
peer
[
'
address
'
],
peer
[
'
remote-asn
'
]
# dict of peers & asn's: [peer address] -> asn
redundant_access_group_peers
=
dict
(
_load_redundant_peers
())
def
_ip_endpoint_extractor
(
endpoint_details
:
Dict
):
def
_ip_endpoint_extractor
(
endpoint_details
:
Dict
):
hostname
=
ims_equipment_to_hostname
(
hostname
=
ims_equipment_to_hostname
(
endpoint_details
[
'
equipment
'
])
endpoint_details
[
'
equipment
'
])
interface
=
endpoint_details
[
'
port
'
].
lower
()
interface
=
endpoint_details
[
'
port
'
].
lower
()
ip_endpoint
=
{
ip_endpoint
=
{
'
hostname
'
:
hostname
,
'
hostname
'
:
hostname
,
'
interface
'
:
interface
,
'
interface
'
:
interface
,
}
}
addresses
=
{}
host_info
=
peering_info
[
hostname
]
host_info
=
peering_info
.
get
(
hostname
,
{})
interface_info
=
host_info
.
get
(
interface
,
{})
interface_info
=
host_info
.
get
(
interface
,
{})
addresses
=
{}
ipv4
=
interface_info
.
get
(
'
ipv4
'
)
ipv4
=
interface_info
.
get
(
'
ipv4
'
)
ipv6
=
interface_info
.
get
(
'
ipv6
'
)
ipv6
=
interface_info
.
get
(
'
ipv6
'
)
if
ipv4
:
if
ipv4
:
addresses
[
'
v4
'
]
=
ipv4
[
0
]
addresses
[
'
v4
'
]
=
ipv4
[
0
]
if
ipv6
:
if
ipv6
:
addresses
[
'
v6
'
]
=
ipv6
[
0
]
addresses
[
'
v6
'
]
=
ipv6
[
0
]
if
ipv4
or
ipv6
:
if
addresses
:
ip_endpoint
[
'
addresses
'
]
=
addresses
ip_endpoint
[
'
addresses
'
]
=
addresses
return
ip_endpoint
return
ip_endpoint
...
@@ -952,12 +965,23 @@ def get_system_correlation_services():
...
@@ -952,12 +965,23 @@ def get_system_correlation_services():
if
not
endpoint_details
[
'
geant_equipment
'
]:
if
not
endpoint_details
[
'
geant_equipment
'
]:
return
return
potential_hostname
=
ims_equipment_to_hostname
(
potential_hostname
=
ims_equipment_to_hostname
(
endpoint_details
[
'
equipment
'
])
endpoint_details
[
'
equipment
'
])
if
potential_hostname
in
peering_info
.
keys
():
if
potential_hostname
in
peering_info
.
keys
():
return
_ip_endpoint_extractor
(
endpoint_details
)
return
_ip_endpoint_extractor
(
endpoint_details
)
else
:
else
:
return
_optical_endpoint_extractor
(
endpoint_details
)
return
_optical_endpoint_extractor
(
endpoint_details
)
def
_get_redundancy_asn
(
service
):
for
ep
in
service
[
'
endpoints
'
]:
addresses
=
ep
.
get
(
'
addresses
'
,
{})
for
ifc_address
in
addresses
.
values
():
for
p
,
asn
in
redundant_access_group_peers
.
items
():
peer
=
ipaddress
.
ip_address
(
p
)
ifc
=
ipaddress
.
ip_interface
(
ifc_address
)
if
peer
in
ifc
.
network
:
return
asn
return
None
sid_services
=
json
.
loads
(
r
.
get
(
'
ims:sid_services
'
).
decode
(
'
utf-8
'
))
sid_services
=
json
.
loads
(
r
.
get
(
'
ims:sid_services
'
).
decode
(
'
utf-8
'
))
response
=
[]
response
=
[]
...
@@ -977,11 +1001,15 @@ def get_system_correlation_services():
...
@@ -977,11 +1001,15 @@ def get_system_correlation_services():
endpoint
=
_endpoint_extractor
(
d
)
endpoint
=
_endpoint_extractor
(
d
)
if
endpoint
:
if
endpoint
:
service_info
[
'
endpoints
'
].
append
(
endpoint
)
service_info
[
'
endpoints
'
].
append
(
endpoint
)
if
service_info
.
get
(
'
endpoints
'
):
if
service_info
.
get
(
'
endpoints
'
):
asn
=
_get_redundancy_asn
(
service_info
)
if
asn
:
service_info
[
'
redundant_asn
'
]
=
asn
response
.
append
(
service_info
)
response
.
append
(
service_info
)
jsonschema
.
validate
(
response
,
jsonschema
.
validate
(
SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA
)
response
,
SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA
)
if
response
:
if
response
:
response
=
json
.
dumps
(
response
,
indent
=
2
)
response
=
json
.
dumps
(
response
,
indent
=
2
)
...
...
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