Skip to content
Snippets Groups Projects
Commit f31d156b authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Added an API endpoint for deleting the network topology graph

parent b11d50e5
No related branches found
No related tags found
No related merge requests found
......@@ -428,6 +428,16 @@ class TestGraphAPI(object):
assert response == {"forward_latencies": forward_latencies, "reverse_latencies": reverse_latencies, "total_forward_latency": sum(forward_latencies), "total_reverse_latency": sum(reverse_latencies),
"bandwidth": 104857600, "response_time": response_time, "global_tags": global_tags}, "Incorrect RTT response"
def test_delete_network_graph(self):
"""
Tests the delete network graph functionality.
"""
request = testing.DummyRequest()
response = GraphAPI(request).delete_network_topology()
assert response == {"deleted_switches_count": 6, "deleted_clusters_count": 6}
@staticmethod
def check_exist_relationship(relationships_tuple, graph, uuid):
"""
......
......@@ -366,3 +366,34 @@ def build_network_graph(graph, switches, links, clusters):
find_or_create_edge(graph, "linkedTo", cluster_node, to_node, latency=0)
return new_switches_count, new_clusters_count
def delete_network_graph(graph):
"""
A function used to delete all nodes of type Switch and Cluster in the neo4j graph.
:param graph: the neo4j graph
:return: the number of deleted switches and clusters
"""
log.info("Deleting Switch nodes.".format())
subgraph = graph.nodes.match("Switch")
deleted_switches = 0
for node in subgraph:
graph.delete(node)
deleted_switches += 1
log.info("Deleted {0} Switch nodes.".format(deleted_switches))
log.info("Deleting Cluster nodes.")
subgraph = graph.nodes.match("Cluster")
deleted_clusters = 0
for node in subgraph:
graph.delete(node)
deleted_clusters += 1
log.info("Deleted {0} Cluster nodes.".format(deleted_clusters))
return deleted_switches, deleted_clusters
......@@ -24,7 +24,7 @@
from clmcservice.graphapi.utilities import validate_json_queries_body, validate_graph_url_params, \
build_network_graph, build_temporal_subgraph, delete_temporal_subgraph, validate_graph_rtt_params, RTT_CYPHER_QUERY_TEMPLATE
build_network_graph, delete_network_graph, build_temporal_subgraph, delete_temporal_subgraph, validate_graph_rtt_params, RTT_CYPHER_QUERY_TEMPLATE
from uuid import uuid4
from influxdb import InfluxDBClient
from py2neo import Graph
......@@ -276,3 +276,17 @@ class GraphAPI(object):
switch_count, clusters_count = build_network_graph(graph, switches, links, clusters)
return {"new_switches_count": switch_count, "new_clusters_count": clusters_count}
@view_config(route_name='graph_network_topology', request_method='DELETE')
def delete_network_topology(self):
"""
An API endpoint to delete the network topology in the neo4j graph.
:return: A JSON response with the number of switches and clusters that were deleted.
"""
graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password']) # connect to the neo4j graph db
deleted_switches, deleted_clusters = delete_network_graph(graph)
return {"deleted_switches_count": deleted_switches, "deleted_clusters_count": deleted_clusters}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment