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

added circuit hierarchy information and testing route to refresh it

parent e5c47709
No related branches found
No related tags found
No related merge requests found
......@@ -9,21 +9,24 @@ from enum import Enum
from requests import HTTPError
CIRCUIT_PROPERTIES = {
'Customer': 32,
'Product': 128,
'Ports': 512,
'InternalPorts': 1024,
'CarrierCircuits': 65536,
'SubCircuits': 131072,
'PortsFullDetails': 262144,
'PortA': 34359738368,
'PortB': 68719476736
}
# http://149.210.162.190:81/ImsVersions/4.19.9/html/dbc969d0-e735-132e-6281-f724c6d7da64.htm # NOQA
# http://149.210.162.190:81/ImsVersions/4.19.9/html/dbc969d0-e735-132e-6281-f724c6d7da64.htm # noqa
CONTACT_PROPERTIES = {
'SiteRelatedContacts': 8,
'CustomerRelatedContacts': 16,
'GroupRelatedContacts': 32,
'VendorRelatedContacts': 64
}
# http://149.210.162.190:81/ImsVersions/4.19.9/html/5a40472e-48ee-c120-0a36-52a85d52127c.htm # NOQA
# http://149.210.162.190:81/ImsVersions/4.19.9/html/5a40472e-48ee-c120-0a36-52a85d52127c.htm # noqa
CUSTOMER_PROPERTIES = {
'CustomerRelatedContacts': 32768,
'CustomerType': 262144
......
......@@ -20,6 +20,27 @@ IMS_OPSDB_STATUS_MAP = {
}
def get_circuit_hierarchy(ds):
circuit_nav_props = [
ims.CIRCUIT_PROPERTIES['Customer'],
ims.CIRCUIT_PROPERTIES['Product'],
ims.CIRCUIT_PROPERTIES['SubCircuits'],
ims.CIRCUIT_PROPERTIES['CarrierCircuits']
]
circuits = ds.get_all_entities(
'Circuit', circuit_nav_props, step_count=1000)
for circuit in circuits:
sub_circuits = [c['subcircuitid'] for c in circuit['subcircuits']]
carrier_circuits = [c['carriercircuitid'] for c in circuit['carriercircuits']]
yield {
'id': circuit['id'],
'product': circuit['product']['name'],
'project': circuit['customer']['name'],
'sub-circuits': sub_circuits,
'carrier-circuits': carrier_circuits
}
def get_node_locations(ds):
site_nav_props = [
ims.SITE_PROPERTIES['City'],
......
......@@ -21,6 +21,12 @@ def flushdb():
# IMS routes
@routes.route("update-circuit-hierarchy-ims", methods=['GET', 'POST'])
def update_circuit_hierarchy_ims():
ims_worker.update_circuit_hierarchy_ims.delay(use_current=True)
return Response('OK')
@routes.route("update-equipment-locations-ims", methods=['GET', 'POST'])
def update_equipment_locations_ims():
ims_worker.update_equipment_locations_ims.delay(use_current=True)
......
......@@ -21,6 +21,29 @@ environment.setup_logging()
logger = logging.getLogger(__name__)
@app.task(base=InventoryTask, bind=True, name='update_circuit_hierarchy_ims')
@log_task_entry_and_exit
def update_circuit_hierarchy_ims(self, use_current=False):
if use_current:
r = get_current_redis(InventoryTask.config)
# scan with bigger batches, to mitigate network latency effects
else:
r = get_next_redis(InventoryTask.config)
rp = r.pipeline()
for k in r.scan_iter('ims:circuit_hierarchy:*', count=1000):
rp.delete(k)
rp.execute()
c = InventoryTask.config["ims"]
ds = IMS(c['api'], c['username'], c['password'])
rp = r.pipeline()
for d in ims_data.get_circuit_hierarchy(ds):
rp.set(f'ims:circuit_hierarchy:{d["id"]}', json.dumps([d]))
rp.execute()
@app.task(base=InventoryTask, bind=True, name='update_equipment_locations_ims')
@log_task_entry_and_exit
def update_equipment_locations_ims(self, use_current=False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment