2017-08-25 22:47:08 +08:00
|
|
|
import flask_restful
|
|
|
|
|
2017-09-06 19:49:58 +08:00
|
|
|
from cc.services.edge import EdgeService
|
2017-08-30 23:14:24 +08:00
|
|
|
from cc.services.node import NodeService
|
2017-08-25 22:47:08 +08:00
|
|
|
from cc.database import mongo
|
|
|
|
|
|
|
|
__author__ = 'Barak'
|
|
|
|
|
|
|
|
|
|
|
|
class NetMap(flask_restful.Resource):
|
|
|
|
def get(self, **kw):
|
2017-08-30 23:14:24 +08:00
|
|
|
monkeys = [NodeService.monkey_to_net_node(x) for x in mongo.db.monkey.find({})]
|
|
|
|
nodes = [NodeService.node_to_net_node(x) for x in mongo.db.node.find({})]
|
2017-09-13 22:20:23 +08:00
|
|
|
edges = [EdgeService.edge_to_net_edge(x) for x in mongo.db.edge.find({})]
|
|
|
|
|
2017-09-06 19:49:58 +08:00
|
|
|
if NodeService.get_monkey_island_monkey() is None:
|
|
|
|
monkey_island = [NodeService.get_monkey_island_pseudo_net_node()]
|
|
|
|
edges += EdgeService.get_monkey_island_pseudo_edges()
|
2017-09-13 22:20:23 +08:00
|
|
|
else:
|
|
|
|
monkey_island = []
|
|
|
|
edges += EdgeService.get_infected_monkey_island_pseudo_edges()
|
2017-08-25 22:47:08 +08:00
|
|
|
|
|
|
|
return \
|
|
|
|
{
|
2017-09-06 19:49:58 +08:00
|
|
|
"nodes": monkeys + nodes + monkey_island,
|
2017-08-25 22:47:08 +08:00
|
|
|
"edges": edges
|
|
|
|
}
|
|
|
|
|
2017-09-13 22:20:23 +08:00
|
|
|
|