Beispiel #1
0
def remove_peer_conf(user, data_age):
    peerq = """
        MATCH (peer_group:Node:Peering_Group)
        MATCH (peer_group)<-[r:Uses]-(peering_partner:Peering_Partner)
        WHERE (peer_group.noclook_auto_manage = true) OR (r.noclook_auto_manage = true)
        RETURN collect(distinct peer_group.handle_id) as peer_groups, collect(id(r)) as uses_relationships
        """
    peer_result = nc.query_to_dict(nc.graphdb.manager, peerq)

    for relationship_id in peer_result.get('uses_relationships', []):
        relationship = nc.get_relationship_model(nc.graphdb.manager,
                                                 relationship_id)
        if relationship:
            last_seen, expired = helpers.neo4j_data_age(
                relationship.data, data_age)
            if expired:
                rel_info = helpers.relationship_to_str(relationship)
                helpers.delete_relationship(user, relationship.id)
                logger.warning('Deleted relationship {rel_info}'.format(
                    rel_info=rel_info))
    for handle_id in peer_result.get('peer_groups', []):
        peer_group = nc.get_node_model(nc.graphdb.manager, handle_id)
        if peer_group:
            last_seen, expired = helpers.neo4j_data_age(
                peer_group.data, data_age)
            if expired:
                helpers.delete_node(user, peer_group.handle_id)
                logger.warning('Deleted node {name} ({handle_id}).'.format(
                    name=peer_group.data.get('name'), handle_id=handle_id))
Beispiel #2
0
def cleanup_hardware_v1(router_node, user):
    p = r"^\d+/\d+/\d+$"
    bad_interfaces = re.compile(p)

    # Cleanup ni hardware info v1...
    # Get all ports that are not directly on router
    q = """
        MATCH (n:Router {handle_id: {handle_id}})-[:Has*1..3]->(:Node)-[r:Has]->(port:Port)
        RETURN port.handle_id as handle_id, port.name as name, id(r) as rel_id
        """
    ports = nc.query_to_list(nc.graphdb.manager,
                             q,
                             handle_id=router_node.handle_id)
    for port in ports:
        if bad_interfaces.match(port['name']):
            # delete it!
            helpers.delete_node(user, port['handle_id'])
        else:
            # move it to router
            helpers.set_has(user, router_node, port['handle_id'])
            # Remove from hardware info (pic)
            helpers.delete_relationship(user, port['rel_id'])
            # Scrub interface properties..?
    # Remove hardware info
    q = """
        MATCH (n:Router {handle_id: {handle_id}})-[:Has*]->(hw:Node)
        WHERE NOT hw:Port
        return hw.handle_id as handle_id, hw.name as name
        """
    old_hardware = nc.query_to_list(nc.graphdb.manager,
                                    q,
                                    handle_id=router_node.handle_id)
    for hw in old_hardware:
        helpers.delete_node(user, hw['handle_id'])
Beispiel #3
0
 def obj_update(self, bundle, **kwargs):
     bundle = super(CableResource, self).obj_update(bundle, **kwargs)
     end_point_nodes = self.get_end_point_nodes(bundle)
     node = bundle.obj.get_node()
     if end_point_nodes:
         for result in node.relationships.get('Connected_to', []):
             helpers.delete_relationship(bundle.request.user,
                                         result['relationship_id'])
         for end_point in end_point_nodes:
             helpers.set_connected_to(bundle.request.user, node,
                                      end_point.handle_id)
     return bundle
Beispiel #4
0
 def obj_update(self, bundle, **kwargs):
     bundle = super(ServiceL2VPNResource, self).obj_update(bundle, **kwargs)
     end_point_nodes = self.get_end_point_nodes(bundle)
     node = bundle.obj.get_node()
     if end_point_nodes:
         for item in node.get_dependencies().get('Depends_on', []):
             helpers.delete_relationship(bundle.request.user,
                                         item['relationship_id'])
         for end_point in end_point_nodes:
             helpers.set_depends_on(bundle.request.user, node,
                                    end_point.handle_id)
     return bundle
Beispiel #5
0
 def obj_delete(self, request=None, **kwargs):
     helpers.delete_relationship(request.user, kwargs['pk'])