diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py new file mode 100644 index 0000000000000000000000000000000000000000..696a59350126a060e26275b80ca1d38b03f52e8a --- /dev/null +++ b/inventory_provider/db/ims_data.py @@ -0,0 +1,163 @@ +import re + +from inventory_provider.db import ims +from inventory_provider.db.ims import IMS, InventoryStatus + +INTERNAL_POP_NAMES = { + 'Cambridge OC', + 'DANTE Lab', + 'GÉANT LAB', + 'GEANT LAB', + 'Amsterdam GEANT Office', + 'Amsterdam GÉANT Office' +} + + +def lookup_lg_routers(ds): + pattern = re.compile("vpn-proxy|vrr|taas", re.IGNORECASE) + + def _matching_node(node_): + if InventoryStatus(node_['InventoryStatusId']) not in [ + InventoryStatus.IN_SERVICE, + InventoryStatus.PLANNED # remove once data fully migrated + ]: + return False + + if pattern.match(node_['Name']): + return False + + return True + + site_nav_props = [ + ims.SITE_PROPERTIES['aliases'], + ims.SITE_PROPERTIES['city'], + ims.SITE_PROPERTIES['country'] + ] + + eq_definitions = ds.get_filtered_entities( + 'EquipmentDefinition', + 'Name like mx', + ims.EQUIP_DEF_PROPERTIES['nodes']) + + for eq_def in eq_definitions: + nodes = eq_def['Nodes'] + + for node in nodes: + if not _matching_node(node): + continue + site = ds.get_entity_by_id('Site', node['SiteId'], site_nav_props, + True) + city = site['City'] + + abbreviation = '' + try: + abbreviation = site['SiteAliases'][0]['AliasName'] + except IndexError: + pass # no alias - ignore silently + + eq = { + 'equipment name': node['Name'], + 'type': + 'INTERNAL' + if site['Name'] in INTERNAL_POP_NAMES + else 'CORE', + 'pop': { + 'name': site['Name'], + 'city': city['Name'], + 'country': city['Country']['Name'], + 'country code': city['Country']['Abbreviation'], + 'abbreviation': abbreviation, + 'longitude': site['Longitude'], + 'latitude': site['Latitude'], + } + } + yield(eq) + + +def lookup_pop_info(ds, hostname): + site_nav_props = [ + ims.SITE_PROPERTIES['aliases'], + ims.SITE_PROPERTIES['city'], + ims.SITE_PROPERTIES['country'] + ] + + node = ds.get_entity_by_name('Node', hostname) + if not node: + return None + site = ds.get_entity_by_id('Site', node['SiteId'], site_nav_props, True) + city = site['City'] + abbreviation = '' + try: + abbreviation = site['SiteAliases'][0]['AliasName'] + except IndexError: + pass # no alias - ignore silently + eq = { + 'equipment-name': node['Name'], + 'status': InventoryStatus(node['InventoryStatusId']).name, + 'pop': { + 'name': site['Name'], + 'city': city['Name'], + 'country': city['Country']['Name'], + 'abbreviation': abbreviation, + 'longitude': site['Longitude'], + 'latitude': site['Latitude'], + } + } + return eq + + +if __name__ == '__main__': + import sys + username = sys.argv[1] + password = sys.argv[2] + ds = IMS('http://83.97.94.128:81/api', username, password) + + equipment_names = [ + 'mx1.ams.nl', + 'mx1.ath2.gr', + 'mx1.buc.ro', + 'mx1.bud.hu', + 'mx1.dub.ie', + 'mx1.dub2.ie', + 'mx1.fra.de', + 'mx1.gen.ch', + 'mx1.ham.de', + 'mx1.kau.lt', + 'mx1.lis.pt', + 'mx1.lon.uk', + 'mx1.lon2.uk', + 'mx1.mad.es', + 'mx1.mar.fr', + 'mx1.mil2.it', + 'mx1.par.fr', + 'mx1.poz.pl', + 'mx1.pra.cz', + 'mx1.sof.bg', + 'mx1.tal.ee', + 'mx1.vie.at', + 'mx2.ath.gr', + 'mx2.bra.sk', + 'mx2.bru.be', + 'mx2.kau.lt', + 'mx2.lis.pt', + 'mx2.lju.si', + 'mx2.rig.lv', + 'mx2.tal.ee', + 'mx2.zag.hr', + 'qfx.fra.de', + 'qfx.lon2.uk', + 'qfx.par.fr' + ] + for equipment in equipment_names: + r = lookup_pop_info(ds, equipment) + print('') + print(r) + print('') + print('--------------------') + + print('--------------------') + print('--------------------') + + for r in lookup_lg_routers(ds): + print(r) + print('')