def list_peering_partners(request): q = """ MATCH (peer:Peering_Partner) OPTIONAL MATCH (peer)-[:Uses]->(peering_group) WITH distinct peer, peering_group RETURN peer, collect(peering_group) as peering_groups ORDER BY peer.name """ partner_list = nc.query_to_list(nc.graphdb.manager, q) partner_list = _filter_expired(partner_list, request, select=lambda n: n.get('peer')) urls = get_node_urls(partner_list) table = Table('Peering Partner', 'AS Number', 'Peering Groups') table.rows = [ _peering_partner_table(item['peer'], item['peering_groups']) for item in partner_list ] _set_filters_expired(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Peering Partners', 'urls': urls })
def list_optical_multiplex_section(request): q = """ MATCH (oms:Optical_Multiplex_Section) OPTIONAL MATCH (oms)-[r:Depends_on]->(dep) RETURN oms, collect(dep) as dependencies """ oms_list = nc.query_to_list(nc.graphdb.manager, q) oms_list = _filter_operational_state(oms_list, request, select=lambda n: n.get('oms')) urls = get_node_urls(oms_list) table = Table("Optical Multiplex Section", "Description", "Depends on") table.rows = [ _oms_table(item['oms'], item['dependencies']) for item in oms_list ] _set_filters_operational_state(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Optical Multiplex Sections', 'urls': urls })
def list_hosts(request): q = """ MATCH (host:Host) OPTIONAL MATCH (host)<-[:Owns|Uses]-(user) RETURN host, collect(user) as users ORDER BY host.name """ host_list = nc.query_to_list(nc.graphdb.manager, q) host_list = _filter_expired(host_list, request, select=lambda n: n.get('host')) host_list = _filter_operational_state(host_list, request, select=lambda n: n.get('host')) urls = get_node_urls(host_list) table = Table('Host', 'Address', 'OS', 'OS version', 'User') table.rows = [ _host_table(item['host'], item['users']) for item in host_list ] _set_filters_expired(table, request) _set_filters_operational_state(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Hosts', 'urls': urls })
def list_switches(request): q = """ MATCH (switch:Switch) OPTIONAL MATCH (switch)<-[:Owns|Uses]-(user) RETURN switch, collect(user) as users ORDER BY switch.name """ switch_list = nc.query_to_list(nc.graphdb.manager, q) switch_list = _filter_expired(switch_list, request, select=lambda n: n.get('switch')) urls = get_node_urls(switch_list) table = Table('Switch', 'Model', 'Address', 'User') table.rows = [ _switch_table(item['switch'], item['users']) for item in switch_list ] _set_filters_expired(table, request) return render(request, 'noclook/list/list_generic.html', { 'name': 'Switches', 'table': table, 'urls': urls })
def list_by_type(request, slug): node_type = get_object_or_404(NodeType, slug=slug) q = """ MATCH (node:%(nodetype)s) RETURN node ORDER BY node.name """ % { 'nodetype': node_type.get_label() } node_list = nc.query_to_list(nc.graphdb.manager, q) node_list = _filter_expired(node_list, request, select=lambda n: n.get('node')) # Since all is the same type... we could use a defaultdict with type/id return urls = get_node_urls(node_list) table = Table('Name', 'Description') table.rows = [_type_table(node) for node in node_list] _set_filters_expired(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': '{}s'.format(node_type), 'urls': urls })
def role_detail(request, handle_id): role = get_object_or_404(Role, pk=handle_id) con_list = nc.models.RoleRelationship.get_contacts_with_role_name( role.name) urls = [] rows = [] for x, y in con_list: con_node = NodeHandle.objects.get(handle_id=x.data['handle_id']) org_node = NodeHandle.objects.get(handle_id=y.data['handle_id']) urls.append((con_node.get_absolute_url(), org_node.get_absolute_url())) rows.append(_contact_with_role_table(con_node, org_node)) table = Table('Name', 'Organization') table.rows = rows table.no_badges = True return render( request, 'noclook/detail/role_detail.html', { 'table': table, 'name': role.name, 'slug': 'role', 'urls': urls, 'node_handle': role })
def list_cables(request): # MK: not 100% sure this gives the correct end+port pairs # Due to the <-[:Has*1..10] q = """ MATCH (cable:Cable) OPTIONAL MATCH (cable)-[r:Connected_to]->(port:Port) OPTIONAL MATCH (port)<-[:Has*1..10]-(end) WHERE NOT((end)<-[:Has]-()) RETURN cable, collect({equipment: {name: end.name, handle_id: end.handle_id}, port: {name: port.name, handle_id: port.handle_id}}) as end order by cable.name """ cable_list = nc.query_to_list(nc.graphdb.manager, q) cable_list = _filter_expired(cable_list, request, select=lambda n: n.get('cable')) urls = get_node_urls(cable_list) table = Table('Name', 'Cable type', 'End equipment', 'Port') table.rows = [_cable_table(item) for item in cable_list] _set_filters_expired(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Cables', 'urls': urls })
def list_rooms(request): q = """ MATCH (room:Room) RETURN room ORDER BY room.name """ room_list = nc.query_to_list(nc.graphdb.manager, q) urls = get_node_urls(room_list) table = Table('Name', 'Location') for item in room_list: room = item.get('room') nh = get_object_or_404(NodeHandle, pk=room.get('handle_id')) node = nh.get_node() location_path = node.get_location_path() table.rows.append( TableRow(item['room'], location_path.get('location_path'))) table.no_badges = True return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Rooms', 'urls': urls })
def list_pdu(request): q = """ MATCH (pdu:PDU) RETURN pdu ORDER BY pdu.name """ pdu_list = nc.query_to_list(nc.graphdb.manager, q) pdu_list = _filter_expired(pdu_list, request, select=lambda n: n.get('pdu')) pdu_list = _filter_operational_state(pdu_list, request, select=lambda n: n.get('pdu')) urls = get_node_urls(pdu_list) table = Table('Name', 'Type', 'Description') table.rows = [_pdu_table(item['pdu']) for item in pdu_list] _set_filters_expired(table, request) _set_filters_operational_state(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'PDUs', 'urls': urls })
def list_racks(request): q = """ MATCH (rack:Rack) OPTIONAL MATCH (rack)<-[:Has]-(loc) OPTIONAL MATCH p=(loc)<-[:Has*0..20]-() WITH COLLECT(nodes(p)) as paths, MAX(length(nodes(p))) AS maxLength, rack AS rack WITH FILTER(path IN paths WHERE length(path)=maxLength) AS longestPaths, rack AS rack UNWIND CASE WHEN longestPaths = [] THEN [null] ELSE longestPaths END as location_path RETURN rack, reverse(location_path) as location_path ORDER BY rack.name """ rack_list = nc.query_to_list(nc.graphdb.manager, q) urls = get_node_urls(rack_list) table = Table('Name', 'Location') table.no_badges = True for item in rack_list: rack = item.get('rack') location_path = item.get('location_path') table.rows.append(TableRow(rack, location_path)) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Racks', 'urls': urls })
def list_patch_panels(request): q = """ MATCH (patch_panel:Patch_Panel) OPTIONAL MATCH (patch_panel)-[:Located_in]->(r) OPTIONAL MATCH p=()-[:Has*0..20]->(r) WITH COLLECT(nodes(p)) as paths, MAX(length(nodes(p))) AS maxLength, patch_panel WITH FILTER(path IN paths WHERE length(path)=maxLength) AS longestPaths, patch_panel AS patch_panel UNWIND CASE WHEN longestPaths = [] THEN [null] ELSE longestPaths END as location_path RETURN patch_panel, location_path ORDER BY patch_panel.name """ patch_panel_list = nc.query_to_list(nc.graphdb.manager, q) patch_panel_list = _filter_operational_state( patch_panel_list, request, select=lambda n: n.get('patch_panel')) urls = get_node_urls(patch_panel_list) table = Table("Name", "Location") table.rows = [_patch_panel_table(item) for item in patch_panel_list] # Filter out _set_filters_operational_state(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Patch Panels', 'urls': urls })
def list_optical_links(request): # TODO: returns [None,None] and [node, None] # tried to use [:Has *0-1] path matching but that gave "duplicate paths" q = """ MATCH (link:Optical_Link) OPTIONAL MATCH (link)-[:Depends_on]->(node) OPTIONAL MATCH p=(node)<-[:Has]-(parent) RETURN link as link, collect([node, parent]) as dependencies """ optical_link_list = nc.query_to_list(nc.graphdb.manager, q) optical_link_list = _filter_operational_state( optical_link_list, request, select=lambda n: n.get('link')) table = Table('Optical Link', 'Type', 'Description', 'Depends on') table.rows = [ _optical_link_table(item['link'], item['dependencies']) for item in optical_link_list ] _set_filters_operational_state(table, request) urls = get_node_urls(optical_link_list) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Optical Links', 'urls': urls })
def list_firewalls(request): q = """ MATCH (firewall:Firewall) OPTIONAL MATCH (firewall)<-[:Owns|Uses]-(user) RETURN firewall, collect(user) as users ORDER BY firewall.name """ firewall_list = nc.query_to_list(nc.graphdb.manager, q) firewall_list = _filter_expired(firewall_list, request, select=lambda n: n.get('firewall')) urls = get_node_urls(firewall_list) table = Table('Firewall', 'Model', 'Address', 'User') table.rows = [ _switch_table(item['firewall'], item['users']) for item in firewall_list ] _set_filters_expired(table, request) return render(request, 'noclook/list/list_generic.html', { 'name': 'Firewalls', 'table': table, 'urls': urls })
def list_roles(request): role_list = Role.objects.all() table = Table('Name', 'Description') table.rows = [_role_table(role) for role in role_list] table.no_badges = True return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Roles', 'urls': role_list })
def list_customers(request): q = """ MATCH (customer:Customer) RETURN customer ORDER BY customer.name """ customer_list = nc.query_to_list(nc.graphdb.manager, q) urls = get_node_urls(customer_list) table = Table('Name', 'Description') table.rows = [_customer_table(customer) for customer in customer_list] table.no_badges = True return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Customers', 'urls': urls })
def room_detail(request, handle_id): nh = get_object_or_404(NodeHandle, pk=handle_id) # Get node from neo4j-database room = nh.get_node() last_seen, expired = helpers.neo4j_data_age(room.data) relations = room.get_relations() # Direct equipment (aka not racked) equipment_relationships = _nodes_without( room.get_located_in().get('Located_in', []), 'operational_state', ['decommissioned']) # Racked equipment q = """ MATCH (room:Room {handle_id: {handle_id}})-[:Has]->(rack:Node) OPTIONAL MATCH (rack)<-[:Located_in]-(item:Node) WHERE NOT item.operational_state IN ['Decommissioned'] OR NOT exists(item.operational_state) RETURN rack, item order by toLower(rack.name), toLower(item.name) """ rack_list = nc.query_to_list(nc.graphdb.manager, q, handle_id=nh.handle_id) # Create racked equipment table racks_table = Table('Rack', 'Equipment') racks_table.rows = [ TableRow(r.get('rack'), r.get('item')) for r in rack_list ] location_path = room.get_location_path() urls = helpers.get_node_urls(room, equipment_relationships, relations, rack_list) return render( request, 'noclook/detail/room_detail.html', { 'node_handle': nh, 'node': room, 'last_seen': last_seen, 'expired': expired, 'equipment_relationships': equipment_relationships, 'relations': relations, 'racks_table': racks_table, 'history': True, 'urls': urls, 'location_path': location_path, })
def list_sites(request): q = """ MATCH (site:Site) RETURN site ORDER BY site.country_code, site.name """ site_list = nc.query_to_list(nc.graphdb.manager, q) urls = get_node_urls(site_list) table = Table('Country', 'Site name', 'Area') table.rows = [_site_table(item['site']) for item in site_list] table.no_badges = True return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Sites', 'urls': urls })
def list_contacts(request): q = """ MATCH (con:Contact) OPTIONAL MATCH (con)-[:Works_for]->(org:Organization) RETURN con.handle_id AS con_handle_id, con, count(DISTINCT org), org """ con_list = nc.query_to_list(nc.graphdb.manager, q) contact_list = {} for row in con_list: con_handle_id = row['con_handle_id'] org_list = [] if con_handle_id in contact_list.keys(): org_list = contact_list[con_handle_id]['org_list'] new_org_name = '' if 'org' in row and row['org']: new_org_name = row['org'].get('name', '') org_list.append(new_org_name) contact_list[con_handle_id] = { 'con': row['con'], 'org_list': org_list, 'org': ', '.join(org_list) } con_list = contact_list.values() urls = get_node_urls(con_list) table = Table('Name', 'Organization') table.rows = [ _contact_table(item['con'], item['org']) for item in con_list ] table.no_badges = True return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Contacts', 'urls': urls })
def list_racks(request): q = """ MATCH (rack:Rack) OPTIONAL MATCH (rack)<-[:Has]-(site) RETURN rack, site ORDER BY site.name, rack.name """ rack_list = nc.query_to_list(nc.graphdb.manager, q) urls = get_node_urls(rack_list) table = Table('Site', 'Name') table.rows = [TableRow(item['site'], item['rack']) for item in rack_list] table.no_badges = True return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Racks', 'urls': urls })
def list_ports(request): q = """ MATCH (port:Port) OPTIONAL MATCH (port)<-[:Has]-(parent:Node) RETURN port, collect(parent) as parent order by toLower(port.name) """ port_list = nc.query_to_list(nc.graphdb.manager, q) port_list = _filter_expired(port_list, request, select=lambda n: n.get('port')) urls = get_node_urls(port_list) table = Table('Name', 'Description', 'Equipment') table.rows = [_port_row(item) for item in port_list] _set_filters_expired(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Ports', 'urls': urls })
def list_external_equipment(request): q = """ MATCH (equipment:External_Equipment) OPTIONAL MATCH (equipment)<-[:Owns]-(owner:Node) RETURN equipment, owner ORDER BY equipment.name """ equipment_list = nc.query_to_list(nc.graphdb.manager, q) urls = get_node_urls(equipment_list) table = Table('Name', 'Description', 'Owner') table.rows = [ _external_equipment_table(item['equipment'], item['owner']) for item in equipment_list ] return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'External Equipment', 'urls': urls })
def list_routers(request): q = """ MATCH (router:Router) RETURN router ORDER BY router.name """ router_list = nc.query_to_list(nc.graphdb.manager, q) router_list = _filter_expired(router_list, request, select=lambda n: n.get('router')) urls = get_node_urls(router_list) table = Table('Router', 'Model', 'JUNOS version', 'Operational state') table.rows = [_router_table(item['router']) for item in router_list] _set_filters_expired(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Routers', 'urls': urls })
def list_optical_nodes(request): q = """ MATCH (node:Optical_Node) RETURN node ORDER BY node.name """ optical_node_list = nc.query_to_list(nc.graphdb.manager, q) optical_node_list = _filter_operational_state( optical_node_list, request, select=lambda n: n.get('node')) urls = get_node_urls(optical_node_list) table = Table('Name', 'Type', 'Link', 'OTS') table.rows = [ _optical_nodes_table(item['node']) for item in optical_node_list ] _set_filters_operational_state(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Optical Nodes', 'urls': urls })
def list_organizations(request): q = """ MATCH (org:Organization) OPTIONAL MATCH (parent_org)-[:Parent_of]->(org:Organization) RETURN org, parent_org ORDER BY org.name """ org_list = nc.query_to_list(nc.graphdb.manager, q) urls = get_node_urls(org_list) table = Table('Name', 'Parent Org.') table.rows = [] orgs_dict = {} for item in org_list: org = item['org'] parent_org = item['parent_org'] org_handle_id = org.get('handle_id') if org_handle_id not in orgs_dict: orgs_dict[org_handle_id] = {'org': org, 'parent_orgs': []} if item['parent_org']: orgs_dict[org_handle_id]['parent_orgs'].append(item['parent_org']) for org_dict in orgs_dict.values(): table.rows.append( _organization_table(org_dict['org'], org_dict['parent_orgs'])) table.no_badges = True return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Organizations', 'urls': urls })
def list_services(request, service_class=None): where_statement = '' name = 'Services' if service_class: where_statement = 'WHERE service.service_class = "%s"' % service_class name = '{} Services'.format(service_class) q = """ MATCH (service:Service) %s OPTIONAL MATCH (service)<-[:Uses]-(customer:Customer) WITH service, COLLECT(customer) as customers OPTIONAL MATCH (service)<-[:Uses]-(end_user:End_User) RETURN service, customers, COLLECT(end_user) as end_users ORDER BY service.name """ % where_statement service_list = nc.query_to_list(nc.graphdb.manager, q) service_list = _filter_operational_state(service_list, request, select=lambda n: n.get('service')) urls = get_node_urls(service_list) table = Table('Service', 'Service Class', 'Service Type', 'Description', 'Customers', 'End Users') table.rows = [ _service_table(item['service'], item['customers'], item['end_users']) for item in service_list ] _set_filters_operational_state(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': name, 'urls': urls })
def list_optical_paths(request): q = """ MATCH (path:Optical_Path) RETURN path ORDER BY path.name """ optical_path_list = nc.query_to_list(nc.graphdb.manager, q) optical_path_list = _filter_operational_state( optical_path_list, request, select=lambda n: n.get('path')) urls = get_node_urls(optical_path_list) table = Table('Optical Path', 'Framing', 'Capacity', 'Wavelength', 'Description', 'ENRs') table.rows = [ _optical_path_table(item['path']) for item in optical_path_list ] _set_filters_operational_state(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'Optical Paths', 'urls': urls })
def list_odfs(request): q = """ MATCH (odf:ODF) OPTIONAL MATCH (odf)-[:Located_in]->(location) OPTIONAL MATCH (location)<-[:Has]-(site) RETURN odf, location, site ORDER BY site.name, location.name, odf.name """ odf_list = nc.query_to_list(nc.graphdb.manager, q) odf_list = _filter_operational_state(odf_list, request, select=lambda n: n.get('odf')) urls = get_node_urls(odf_list) table = Table("Location", "Name") table.rows = [_odf_table(item) for item in odf_list] # Filter out _set_filters_operational_state(table, request) return render(request, 'noclook/list/list_generic.html', { 'table': table, 'name': 'ODFs', 'urls': urls })