Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mapping 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
Next Generation Map
Mapping Provider
Commits
879ee4fb
"lib/AccessCheck/Data/Token.pm" did not exist on "c9d1fe06edaa75b26066455c23a8d1613ec87230"
Commit
879ee4fb
authored
3 weeks ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added availability from correlator to /map/service response
parent
e23c01c6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mapping_provider/api/map.py
+1
-1
1 addition, 1 deletion
mapping_provider/api/map.py
mapping_provider/backends/services.py
+50
-24
50 additions, 24 deletions
mapping_provider/backends/services.py
test/conftest.py
+2
-1
2 additions, 1 deletion
test/conftest.py
with
53 additions
and
26 deletions
mapping_provider/api/map.py
+
1
−
1
View file @
879ee4fb
...
...
@@ -162,4 +162,4 @@ def get_trunks() -> services.ServiceList:
"""
handler for /trunks
"""
return
services
.
build_service_info_list
()
return
services
.
build_service_info_list
(
service_type
=
'
IP TRUNK
'
)
This diff is collapsed.
Click to expand it.
mapping_provider/backends/services.py
+
50
−
24
View file @
879ee4fb
...
...
@@ -7,24 +7,14 @@ logger = logging.getLogger(__name__)
class
Endpoint
(
BaseModel
):
hostname
:
str
equipment
:
str
interface
:
str
@classmethod
def
from_inprov_endpoint
(
cls
,
endpoint
:
dict
[
str
,
Any
])
->
'
Endpoint
'
:
return
cls
(
hostname
=
endpoint
[
'
hostname
'
],
interface
=
endpoint
[
'
interface
'
],
)
class
Overlays
(
BaseModel
):
speed
:
int
up
:
bool
@classmethod
def
from_inprov_overlays
(
cls
,
overlays
:
dict
[
str
,
Any
])
->
'
Overlays
'
:
return
cls
(
speed
=
overlays
[
'
speed
'
],
)
class
Service
(
BaseModel
):
sid
:
str
...
...
@@ -38,28 +28,64 @@ class ServiceList(BaseModel):
services
:
list
[
Service
]
def
_services
()
->
Generator
[
Service
,
None
,
None
]:
def
_services
(
service_type
:
str
|
None
=
None
)
->
Generator
[
Service
,
None
,
None
]:
"""
load the cached backend data and yield map service records
only return operational services that match the service type, if provided
"""
# TOOD: maybe remove loading of inventory/poller/interfaces & /map/services
try
:
inprov_map_services
=
cache
.
get
(
inventory
.
INPROV_MAP_SERVICES_CACHE_FILENAME
)
#
inprov_map_services = cache.get(inventory.INPROV_MAP_SERVICES_CACHE_FILENAME)
scid_current
=
cache
.
get
(
inventory
.
REPORTING_SCID_CURRENT_CACHE_FILENAME
)
poller_interfaces
=
cache
.
get
(
inventory
.
INPROV_POLLER_INTERFACES_CACHE_FILENAME
)
#
poller_interfaces = cache.get(inventory.INPROV_POLLER_INTERFACES_CACHE_FILENAME)
correlator_state
=
cache
.
get
(
correlator
.
CACHED_CORRELATOR_STATE_FILENAME
)
except
FileNotFoundError
:
logger
.
exception
(
'
not enough data available to build the service list
'
)
return
for
service
in
inprov_map_services
:
overlays
=
Overlays
(
speed
=
service
[
'
overlays
'
][
'
speed
'
])
endpoints
=
list
(
map
(
Endpoint
.
from_inprov_endpoint
,
service
[
'
endpoints
'
]))
def
_get_down_correlator_services
():
for
_e
in
correlator_state
[
'
endpoints
'
]:
if
_e
[
'
up
'
]:
continue
for
_s
in
_e
[
'
services
'
]:
if
'
sid
'
in
_s
:
yield
_s
[
'
sid
'
]
down_service_sids
=
set
(
_get_down_correlator_services
())
for
_s
in
scid_current
:
if
_s
[
'
status
'
]
!=
'
operational
'
:
continue
if
service_type
and
_s
[
'
service_type
'
]
!=
service_type
:
continue
overlays
=
Overlays
(
speed
=
_s
[
'
speed
'
],
up
=
_s
[
'
sid
'
]
not
in
down_service_sids
,
)
endpoints
=
[]
for
_e
in
_s
[
'
endpoints
'
]:
equipment
=
_e
[
'
hostname
'
]
if
'
hostname
'
in
_e
else
_e
[
'
equipment
'
]
interface
=
_e
[
'
interface
'
]
if
'
interface
'
in
_e
else
_e
[
'
port
'
]
endpoints
.
append
(
Endpoint
(
equipment
=
equipment
,
interface
=
interface
))
yield
Service
(
sid
=
service
[
'
sid
'
],
name
=
service
[
'
name
'
],
type
=
service
[
'
type
'
],
sid
=
_s
[
'
sid
'
],
scid
=
_s
[
'
scid
'
],
name
=
_s
[
'
name
'
],
type
=
_s
[
'
service_type
'
],
endpoints
=
endpoints
,
overlays
=
overlays
,
)
def
build_service_info_list
()
->
ServiceList
:
return
ServiceList
(
services
=
_services
())
def
build_service_info_list
(
service_type
:
str
|
None
=
None
)
->
ServiceList
:
"""
return a list of mappable info about all operational services
"""
return
ServiceList
(
services
=
_services
(
service_type
))
This diff is collapsed.
Click to expand it.
test/conftest.py
+
2
−
1
View file @
879ee4fb
...
...
@@ -47,8 +47,9 @@ def client(dummy_config_filename):
os
.
environ
[
'
SETTINGS_FILENAME
'
]
=
dummy_config_filename
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
cache
.
init
(
tmp_dir
)
# there's no rmq in config, so workers won't start
# there's no rmq in the test config data, so cache won't be initialized
cache
.
init
(
tmp_dir
)
cache
.
set
(
inventory
.
INPROV_MAP_SERVICES_CACHE_FILENAME
,
load_test_data
(
'
inprov-services.json
'
))
cache
.
set
(
inventory
.
REPORTING_SCID_CURRENT_CACHE_FILENAME
,
load_test_data
(
'
scid-current.json
'
))
cache
.
set
(
inventory
.
INPROV_POLLER_INTERFACES_CACHE_FILENAME
,
load_test_data
(
'
poller-interfaces.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