diff --git a/inventory_provider/db/ims.py b/inventory_provider/db/ims.py index 3f50cc1cb13cecb6c0bd4838f309ab7cc6a292ec..dbf1c5f448ad1a501182a38e94a225e45faf79fa 100644 --- a/inventory_provider/db/ims.py +++ b/inventory_provider/db/ims.py @@ -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 diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py index 83c90fa45576ce3d69a14ff33ed335a8fb04056e..455905eb2ef1ba43c62efd27f2ecbbf9caf7ce0b 100644 --- a/inventory_provider/db/ims_data.py +++ b/inventory_provider/db/ims_data.py @@ -1,12 +1,13 @@ 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'] } diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index ce02225c624c366985ae4c30f046146151d1b0f5..e0d00fff4d81f3f2d9aecef360c6e10f53c59d8d 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -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) diff --git a/test/test_ims_data.py b/test/test_ims_data.py index e581f50da9e019aa6692bb8f7ad7495d8c52d54a..8ec0d174a0c62dec5b856d6bf0cdb25ecf93a320 100644 --- a/test/test_ims_data.py +++ b/test/test_ims_data.py @@ -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],