def switch_detail(request, handle_id): nh = get_object_or_404(NodeHandle, pk=handle_id) # Get node from neo4j-database switch = nh.get_node() last_seen, expired = helpers.neo4j_data_age(switch.data) location_path = switch.get_location_path() # Get ports in switch connections = switch.get_connections() host_services = switch.get_host_services() dependent = switch.get_dependent_as_types() dependencies = switch.get_dependencies_as_types() relations = switch.get_relations() urls = helpers.get_node_urls(switch, host_services, connections, dependent, dependencies, relations, location_path) scan_enabled = helpers.app_enabled("apps.scan") hw_name = "{}-hardware.json".format(switch.data.get('name', 'switch')) hw_attachment = helpers.find_attachments(handle_id, hw_name).first() if hw_attachment: try: hardware_modules = [ json.loads(helpers.attachment_content(hw_attachment)) ] except IOError as e: logger.warning( 'Missing hardware modules json for router %s(%s). Error was: %s', nh.node_name, nh.handle_id, e) hardware_modules = [] else: hardware_modules = [] return render( request, 'noclook/detail/switch_detail.html', { 'node_handle': nh, 'node': switch, 'last_seen': last_seen, 'expired': expired, 'host_services': host_services, 'connections': connections, 'dependent': dependent, 'dependencies': dependencies, 'relations': relations, 'location_path': location_path, 'history': True, 'urls': urls, 'scan_enabled': scan_enabled, 'hardware_modules': hardware_modules })
def router_detail(request, handle_id): nh = get_object_or_404(NodeHandle, pk=handle_id) # Get node from neo4j-database router = nh.get_node() last_seen, expired = helpers.neo4j_data_age(router.data) location_path = router.get_location_path() # Get all the Ports and what depends on the port. connections = router.get_connections() dependent = router.get_dependent_as_types() hw_name = "{}-hardware.json".format(router.data.get('name', 'router')) hw_attachment = helpers.find_attachments(handle_id, hw_name).first() if hw_attachment: try: hardware_modules = [ json.loads(helpers.attachment_content(hw_attachment)) ] except IOError as e: logger.warning( 'Missing hardware modules json for router %s(%s). Error was: %s', nh.node_name, nh.handle_id, e) hardware_modules = [] else: hardware_modules = [] # TODO: generally very inefficient lookups in view... urls = helpers.get_node_urls(router, location_path, dependent, connections, hardware_modules) return render( request, 'noclook/detail/router_detail.html', { 'node_handle': nh, 'node': router, 'last_seen': last_seen, 'expired': expired, 'location_path': location_path, 'dependent': dependent, 'connections': connections, 'hardware_modules': hardware_modules, 'history': True, 'urls': urls })