Example #1
0
def port_detail(request, handle_id):
    nh = get_object_or_404(NodeHandle, pk=handle_id)
    # Get node from neo4j-database
    port = nh.get_node()
    last_seen, expired = helpers.neo4j_data_age(port.data)
    location_path = port.get_location_path()
    connections = port.get_connections()
    dependent = port.get_dependent_as_types()
    connection_path = port.get_connection_path()
    urls = helpers.get_node_urls(port, connections, dependent, location_path)
    return render(
        request, 'noclook/detail/port_detail.html', {
            'node': port,
            'node_handle': nh,
            'last_seen': last_seen,
            'expired': expired,
            'connections': connections,
            'dependent': dependent,
            'location_path': location_path,
            'connection_path': connection_path,
            'history': True,
            'urls': urls
        })
Example #2
0
def site_owner_detail(request, handle_id):
    nh = get_object_or_404(NodeHandle, pk=handle_id)
    # Get node from neo4j-database
    site_owner = nh.get_node()
    last_seen, expired = helpers.neo4j_data_age(site_owner.data)
    result = site_owner.with_same_name()
    same_name_relations = NodeHandle.objects.in_bulk(
        (result.get('ids'))).values()
    responsible_relations = site_owner.get_responsible_for()

    urls = helpers.get_node_urls(site_owner, same_name_relations,
                                 responsible_relations)
    return render(
        request, 'noclook/detail/site_owner_detail.html', {
            'node_handle': nh,
            'node': site_owner,
            'last_seen': last_seen,
            'expired': expired,
            'same_name_relations': same_name_relations,
            'responsible_relations': responsible_relations,
            'history': True,
            'urls': urls
        })
Example #3
0
def optical_path_detail(request, handle_id):
    nh = get_object_or_404(NodeHandle, pk=handle_id)
    # Get node from neo4j-database
    optical_path = nh.get_node()
    last_seen, expired = helpers.neo4j_data_age(optical_path.data)
    relations = optical_path.get_relations()
    dependent = optical_path.get_dependent_as_types()
    dependencies = optical_path.get_dependencies_as_types()

    urls = helpers.get_node_urls(optical_path, dependent, dependencies,
                                 relations)
    return render(
        request, 'noclook/detail/optical_path_detail.html', {
            'node': optical_path,
            'node_handle': nh,
            'last_seen': last_seen,
            'expired': expired,
            'dependencies': dependencies,
            'dependent': dependent,
            'relations': relations,
            'history': True,
            'urls': urls
        })
Example #4
0
def host_provider_detail(request, handle_id):
    nh = get_object_or_404(NodeHandle, pk=handle_id)
    # Get node from neo4j-database
    host_provider = nh.get_node()
    last_seen, expired = helpers.neo4j_data_age(host_provider.data)
    result = host_provider.with_same_name()
    same_name_relations = NodeHandle.objects.in_bulk(
        (result.get('ids'))).values()
    provides_relationships = host_provider.get_provides()

    urls = helpers.get_node_urls(host_provider, same_name_relations,
                                 provides_relationships)
    return render(
        request, 'noclook/detail/host_provider_detail.html', {
            'node_handle': nh,
            'node': host_provider,
            'last_seen': last_seen,
            'expired': expired,
            'same_name_relations': same_name_relations,
            'provides_relationships': provides_relationships,
            'history': True,
            'urls': urls
        })
Example #5
0
def host_user_detail(request, handle_id):
    nh = get_object_or_404(NodeHandle, pk=handle_id)
    # Get node from neo4j-database
    host_user = nh.get_node()
    last_seen, expired = helpers.neo4j_data_age(host_user.data)
    result = host_user.with_same_name()
    same_name_relations = NodeHandle.objects.in_bulk(
        (result.get('ids'))).values()
    q = """
        MATCH (n:Node {handle_id: {handle_id}})-[r:Uses|:Owns]->(u)
        RETURN
        labels(u) as labels,
        u.handle_id as handle_id,
        u.name as name,
        u.noclook_last_seen as noclook_last_seen,
        u.noclook_auto_manage as noclook_auto_manage
        """
    host_relationships = nc.query_to_list(nc.graphdb.manager,
                                          q,
                                          handle_id=host_user.handle_id)

    urls = helpers.get_node_urls(host_user, same_name_relations,
                                 host_relationships)
    return render(
        request,
        'noclook/detail/host_user_detail.html',
        {
            'node_handle': nh,
            'node': host_user,
            'last_seen': last_seen,
            'expired': expired,
            'same_name_relations': same_name_relations,
            'host_relationships': host_relationships,
            'history': True,
            'urls': urls
        },
    )
Example #6
0
File: list.py Project: SUNET/ni
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
    })
Example #7
0
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
    })
Example #8
0
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
    })
Example #9
0
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
    })
Example #10
0
def cable_detail(request, handle_id):
    nh = get_object_or_404(NodeHandle, pk=handle_id)
    cable = nh.get_node()
    last_seen, expired = helpers.neo4j_data_age(cable.data)
    connections = cable.get_connected_equipment()
    relations = cable.get_relations()
    dependent = cable.get_dependent_as_types()
    connection_path = cable.get_connection_path()
    urls = helpers.get_node_urls(cable, connections, relations, dependent)
    if not any(dependent.values()):
        dependent = None
    return render(
        request, 'noclook/detail/cable_detail.html', {
            'node': cable,
            'node_handle': nh,
            'last_seen': last_seen,
            'expired': expired,
            'connections': connections,
            'dependent': dependent,
            'connection_path': connection_path,
            'history': True,
            'relations': relations,
            'urls': urls
        })