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
d3f24620
Commit
d3f24620
authored
2 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Refactor mapping of ports to SIDs a bit
parent
5786f6f6
No related branches found
No related tags found
1 merge request
!4
Add feature to raise SIDs defined on ports to services on those ports
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/db/ims_data.py
+38
-21
38 additions, 21 deletions
inventory_provider/db/ims_data.py
with
38 additions
and
21 deletions
inventory_provider/db/ims_data.py
+
38
−
21
View file @
d3f24620
...
@@ -129,9 +129,9 @@ def get_circuit_related_customers(ds: IMS):
...
@@ -129,9 +129,9 @@ def get_circuit_related_customers(ds: IMS):
return_value
=
defaultdict
(
list
)
return_value
=
defaultdict
(
list
)
for
ccr
in
ds
.
get_filtered_entities
(
for
ccr
in
ds
.
get_filtered_entities
(
'
CircuitCustomerRelation
'
,
'
CircuitCustomerRelation
'
,
'
circuit.inventoryStatusId== 3
'
,
'
circuit.inventoryStatusId== 3
'
,
ims
.
CIRCUIT_CUSTOMER_RELATION
[
'
Customer
'
]):
ims
.
CIRCUIT_CUSTOMER_RELATION
[
'
Customer
'
]):
return_value
[
ccr
[
'
circuitid
'
]].
append
(
return_value
[
ccr
[
'
circuitid
'
]].
append
(
{
{
'
id
'
:
ccr
[
'
customer
'
][
'
id
'
],
'
id
'
:
ccr
[
'
customer
'
][
'
id
'
],
...
@@ -273,6 +273,32 @@ def get_port_id_services(ds: IMS):
...
@@ -273,6 +273,32 @@ def get_port_id_services(ds: IMS):
}
}
def
get_port_sids
(
ds
:
IMS
):
"""
This function fetches SIDs for external ports that have them defined,
:param ds: IMS datasource object
:returns: Dict mapping external port IDs to the SID assigned to the port
"""
return
{
p
[
'
objectid
'
]:
p
[
'
value
'
]
for
p
in
ds
.
get_filtered_entities
(
'
ExtraFieldValue
'
,
'
extrafieldid == 3249 | value <>
""'
,
step_count
=
10000
)}
def
get_internal_port_sids
(
ds
:
IMS
):
"""
This function fetches SIDs for external ports that have them defined,
:param ds: IMS datasource object
:returns: Dict mapping internal port IDs to the SID assigned to the port
"""
return
{
p
[
'
objectid
'
]:
p
[
'
value
'
]
for
p
in
ds
.
get_filtered_entities
(
'
ExtraFieldValue
'
,
'
extrafieldid == 3250 | value <>
""'
,
step_count
=
10000
)}
def
get_port_details
(
ds
:
IMS
):
def
get_port_details
(
ds
:
IMS
):
port_nav_props
=
[
port_nav_props
=
[
ims
.
PORT_PROPERTIES
[
'
Node
'
],
ims
.
PORT_PROPERTIES
[
'
Node
'
],
...
@@ -283,18 +309,15 @@ def get_port_details(ds: IMS):
...
@@ -283,18 +309,15 @@ def get_port_details(ds: IMS):
ims
.
PORT_PROPERTIES
[
'
Shelf
'
]
ims
.
PORT_PROPERTIES
[
'
Shelf
'
]
}
}
_port_sids
=
{
p
[
'
objectid
'
]:
p
[
'
value
'
]
for
p
in
ds
.
get_filtered_entities
(
'
ExtraFieldValue
'
,
'
extrafieldid == 3249 | value <>
""'
,
step_count
=
10000
)}
_internal_port_sids
=
{
p
[
'
objectid
'
]:
p
[
'
value
'
]
for
p
in
ds
.
get_filtered_entities
(
'
ExtraFieldValue
'
,
'
extrafieldid == 3250 | value <>
""'
,
step_count
=
10000
)}
# this is here instead of chaining to make debugging easier
# this is here instead of chaining to make debugging easier
def
_process_ports
(
ports
,
p_type
):
def
_process_ports
(
ports
,
p_type
):
_port_sids
=
{}
if
p_type
==
'
external
'
:
_port_sids
=
get_port_sids
(
ds
)
else
:
_port_sids
=
get_internal_port_sids
(
ds
)
for
p
in
ports
:
for
p
in
ports
:
vendor
=
None
vendor
=
None
interface_name
=
None
interface_name
=
None
...
@@ -320,14 +343,8 @@ def get_port_details(ds: IMS):
...
@@ -320,14 +343,8 @@ def get_port_details(ds: IMS):
'
interface_name
'
:
interface_name
'
interface_name
'
:
interface_name
}
}
_port_sid
=
None
if
p
[
'
id
'
]
in
_port_sids
:
if
p_type
==
'
internal
'
and
p
[
'
id
'
]
in
_internal_port_sids
:
data
[
'
sid
'
]
=
_port_sids
[
p
[
'
id
'
]]
_port_sid
=
_internal_port_sids
[
p
[
'
id
'
]]
elif
p_type
==
'
external
'
and
p
[
'
id
'
]
in
_port_sids
:
_port_sid
=
_port_sids
.
get
(
p
[
'
id
'
])
if
_port_sid
is
not
None
:
data
[
'
sid
'
]
=
_port_sid
yield
data
yield
data
...
...
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