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

added get_interface_services function

parent 18a0fbb5
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,8 @@ from collections import OrderedDict ...@@ -4,7 +4,8 @@ from collections import OrderedDict
from inventory_provider import environment from inventory_provider import environment
from inventory_provider.db import ims from inventory_provider.db import ims
from inventory_provider.db.ims import InventoryStatus from inventory_provider.db.ims import InventoryStatus, IMS
environment.setup_logging() environment.setup_logging()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -20,7 +21,74 @@ IMS_OPSDB_STATUS_MAP = { ...@@ -20,7 +21,74 @@ IMS_OPSDB_STATUS_MAP = {
} }
def get_circuit_hierarchy(ds): def get_interface_services(ds: IMS):
# get subset of circuits -
# start with just the ams fra lag, then expand to
# include the relevant carrier circuits
service_types = {
'geant lambda',
'geant plus',
'geant ip',
'l3-vpn',
'ip peering - non r&e (public)',
'ip peering - non r&e (private)',
'ip peering - r&e',
'ip trunk',
'geant cloud peering',
'geant open port',
'geant open cross connect',
'pop lan link',
'SERVER LINK'
}
circuit_nav_props = [
ims.CIRCUIT_PROPERTIES['Speed'],
ims.CIRCUIT_PROPERTIES['Product'],
ims.CIRCUIT_PROPERTIES['Ports'],
ims.CIRCUIT_PROPERTIES['InternalPorts'],
]
circuits = ds.get_filtered_entities(
'Circuit', 'name like amsterdam', circuit_nav_props, step_count=1000)
def _populate_end_info(_circuit, _port_info):
port_count = len(_port_info)
if _port_info:
port = _port_info[0]
_circuit['equipment'] = port['node']['name']
_circuit['interface_name'] = port['name']
if port_count > 1:
port = _port_info[1]
_circuit['other_end_equipment'] = port['node']['name']
_circuit['other_end_interface_name'] = port['name']
if port_count > 2:
logger.error(
'More that two (internal)ports found for'
f' {_circuit["name"]} ({_circuit["id"]}')
yield _circuit
if port_count > 1:
_circuit['equipment'], _circuit['other_end_equipment'] = \
_circuit['other_end_equipment'], _circuit['equipment']
_circuit['interface_name'], \
_circuit['other_end_interface_name'] = \
_circuit['other_end_interface_name'], \
_circuit['interface_name']
yield _circuit
for circuit in circuits:
cd = {
'id': circuit['id'],
'name': circuit['name'],
'status': IMS_OPSDB_STATUS_MAP.get(
InventoryStatus(circuit['inventorystatusid']), 'unknown'),
'circuit_type': 'service'
if circuit['product']['name'] in service_types else 'circuit',
'service_type': circuit['product']['name'],
'project': circuit['product']['name']
}
yield from _populate_end_info(cd, circuit['ports'])
yield from _populate_end_info(cd, circuit['internalports'])
def get_circuit_hierarchy(ds: IMS):
circuit_nav_props = [ circuit_nav_props = [
ims.CIRCUIT_PROPERTIES['Customer'], ims.CIRCUIT_PROPERTIES['Customer'],
ims.CIRCUIT_PROPERTIES['Product'], ims.CIRCUIT_PROPERTIES['Product'],
...@@ -42,7 +110,7 @@ def get_circuit_hierarchy(ds): ...@@ -42,7 +110,7 @@ def get_circuit_hierarchy(ds):
} }
def get_node_locations(ds): def get_node_locations(ds: IMS):
site_nav_props = [ site_nav_props = [
ims.SITE_PROPERTIES['City'], ims.SITE_PROPERTIES['City'],
ims.SITE_PROPERTIES['SiteAliases'], ims.SITE_PROPERTIES['SiteAliases'],
...@@ -86,7 +154,7 @@ INTERNAL_POP_NAMES = { ...@@ -86,7 +154,7 @@ INTERNAL_POP_NAMES = {
} }
def lookup_lg_routers(ds): def lookup_lg_routers(ds: IMS):
pattern = re.compile("vpn-proxy|vrr|taas", re.IGNORECASE) pattern = re.compile("vpn-proxy|vrr|taas", re.IGNORECASE)
def _matching_node(node_): def _matching_node(node_):
...@@ -148,7 +216,7 @@ def lookup_lg_routers(ds): ...@@ -148,7 +216,7 @@ def lookup_lg_routers(ds):
yield eq yield eq
def otrs_get_customer_company_rows(ds): def otrs_get_customer_company_rows(ds: IMS):
yield ['customer_id', 'name', 'street', 'zip', 'city', 'country', 'url', yield ['customer_id', 'name', 'street', 'zip', 'city', 'country', 'url',
'comments'] 'comments']
all_cus_comps = set() all_cus_comps = set()
...@@ -170,7 +238,7 @@ def _is_valid_customer(cus): ...@@ -170,7 +238,7 @@ def _is_valid_customer(cus):
return True return True
def otrs_get_customer_contacts(ds): def otrs_get_customer_contacts(ds: IMS):
def _get_customer_id2(t): def _get_customer_id2(t):
if t['id'] == 3 or t['name'] == 'EU NREN': if t['id'] == 3 or t['name'] == 'EU NREN':
...@@ -215,7 +283,7 @@ def otrs_get_customer_contacts(ds): ...@@ -215,7 +283,7 @@ def otrs_get_customer_contacts(ds):
yield t_customer_user yield t_customer_user
def otrs_get_vendor_contacts(ds): def otrs_get_vendor_contacts(ds: IMS):
for vrc in ds.get_all_entities( for vrc in ds.get_all_entities(
'VendorRelatedContact', 'VendorRelatedContact',
...@@ -250,7 +318,7 @@ def otrs_get_vendor_contacts(ds): ...@@ -250,7 +318,7 @@ def otrs_get_vendor_contacts(ds):
yield t_customer_user yield t_customer_user
def otrs_get_customer_users_rows(ds, return_duplicates=False): def otrs_get_customer_users_rows(ds: IMS, return_duplicates: bool = False):
yield ['email', 'username', 'customer_id', 'customer_id_2', 'title', yield ['email', 'username', 'customer_id', 'customer_id_2', 'title',
'firstname', 'lastname', 'phone', 'fax', 'mobile', 'street', 'zip', 'firstname', 'lastname', 'phone', 'fax', 'mobile', 'street', 'zip',
'city', 'country', 'comments'] 'city', 'country', 'comments']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment