Skip to content
Snippets Groups Projects
Commit d3f24620 authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Refactor mapping of ports to SIDs a bit

parent 5786f6f6
No related branches found
No related tags found
1 merge request!4Add feature to raise SIDs defined on ports to services on those ports
...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment