Skip to content
Snippets Groups Projects
Commit eab9a044 authored by Robert Latta's avatar Robert Latta
Browse files

added customer email addresses to circuit hierarchy

parent 982c04f1
Branches
Tags
No related merge requests found
......@@ -41,6 +41,11 @@ CUSTOMER_PROPERTIES = {
'CustomerRelatedContacts': 32768,
'CustomerType': 262144
}
# http://149.210.162.190:81/ImsVersions/20.1/html/4f3e1d5e-53c3-1beb-cb16-65b5308dcb81.htm
CUSTOMER_RELATED_CONTACT_PROPERTIES = {
'Customer': 8,
'Contact': 16
}
# http://149.210.162.190:81/ImsVersions/4.19.9/html/347cb410-8c05-47bd-ceb0-d1dd05bf98a4.htm # noqa
CITY_PROPERTIES = {
'Country': 8
......
import logging
import re
from collections import OrderedDict
from collections import OrderedDict, defaultdict
from copy import copy
from itertools import chain
from inventory_provider import environment
from inventory_provider.db import ims
from inventory_provider.db.ims import InventoryStatus, IMS
from inventory_provider.db.ims import InventoryStatus, IMS, \
CUSTOMER_RELATED_CONTACT_PROPERTIES
environment.setup_logging()
logger = logging.getLogger(__name__)
......@@ -32,6 +33,25 @@ def get_service_types(ds: IMS):
yield d['selection']
def get_customer_service_emails(ds: IMS):
customer_contacts = defaultdict(set)
for x in ds.get_filtered_entities(
'customerrelatedcontact',
"contact.plannedworkmail != ''",
CUSTOMER_RELATED_CONTACT_PROPERTIES['Contact']
):
customer_contacts[x['customerid']].add(x['contact']['mail'])
for x in ds.get_filtered_entities(
'customerrelatedcontact',
"contact.troubleticketMail != ''",
CUSTOMER_RELATED_CONTACT_PROPERTIES['Contact']
):
customer_contacts[x['customerid']].add(x['contact']['mail'])
for k, v in customer_contacts.items():
yield k, sorted(list(v))
def get_port_id_services(ds: IMS):
circuit_nav_props = [
ims.CIRCUIT_PROPERTIES['Ports'],
......@@ -236,7 +256,8 @@ def get_circuit_hierarchy(ds: IMS):
'project': circuit['customer']['name'],
'circuit-type': circuit_type,
'sub-circuits': sub_circuits,
'carrier-circuits': carrier_circuits
'carrier-circuits': carrier_circuits,
'customerid': circuit['customerid']
}
......
......@@ -472,6 +472,8 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False):
locations = {k: v for k, v in ims_data.get_node_locations(ds1)}
tls_names = list(ims_data.get_service_types(ds1))
customer_contacts = \
{k: v for k, v in ims_data.get_customer_service_emails(ds1)}
hierarchy = None
port_id_details = defaultdict(list)
port_id_services = defaultdict(list)
......@@ -572,7 +574,11 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False):
'name': c['name'],
'status': c['status'],
'circuit_type': 'service',
'project': c['project']
'project': c['project'],
'contacts': customer_contacts.get(
c['customerid'],
[]
)
}
elif c['sub-circuits']:
for sub in c['sub-circuits']:
......@@ -636,6 +642,12 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False):
} for x in set(_get_fibre_routes(circ['id']))]
circ['top-level-services'] = \
get_top_level_services(circ['id'])
contacts = set()
for tlc in circ['top-level-services']:
contacts.update(tlc.pop('contacts'))
circ['contacts'] = sorted(list(contacts))
circ['calculated-speed'] = _get_speed(circ['id'])
_format_service(circ)
......
......@@ -34,7 +34,8 @@ def test_get_circuit_hierarchy(mocker):
'project': 'ORIENTPLUS',
'circuit-type': 'service',
'sub-circuits': [],
'carrier-circuits': [660461]
'carrier-circuits': [660461],
'customerid': 57773
},
{
'id': 660461,
......@@ -45,7 +46,8 @@ def test_get_circuit_hierarchy(mocker):
'project': 'ORIENTPLUS',
'circuit-type': 'circuit',
'sub-circuits': [661591],
'carrier-circuits': [668866]
'carrier-circuits': [668866],
'customerid': 57773
}
]
assert res == predicted
......@@ -266,7 +268,7 @@ def test_get_node_location(mocker):
ds = inventory_provider.db.ims.IMS(
'dummy_base', 'dummy_username', 'dummy_password')
res = list(get_node_locations(ds))
assert len(res) == 35
assert len(res) == 36
assert res[0] == ('LON3_CX_01', {
'equipment-name': 'LON3_CX_01',
'status': IMS_OPSDB_STATUS_MAP[InventoryStatus.IN_SERVICE],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment