2017-08-25 22:47:08 +08:00
|
|
|
from datetime import datetime
|
|
|
|
|
2017-08-29 19:12:07 +08:00
|
|
|
from flask import request, make_response, jsonify
|
2017-08-25 22:47:08 +08:00
|
|
|
import flask_restful
|
|
|
|
|
|
|
|
from cc.database import mongo
|
|
|
|
|
2017-09-13 18:30:28 +08:00
|
|
|
from cc.utils import local_ip_addresses
|
2017-08-25 22:47:08 +08:00
|
|
|
|
|
|
|
__author__ = 'Barak'
|
|
|
|
|
|
|
|
|
|
|
|
class Root(flask_restful.Resource):
|
|
|
|
def get(self, action=None):
|
|
|
|
if not action:
|
|
|
|
action = request.args.get('action')
|
2017-08-29 19:12:07 +08:00
|
|
|
|
2017-08-25 22:47:08 +08:00
|
|
|
if not action:
|
2017-09-03 05:40:43 +08:00
|
|
|
return jsonify(ip_addresses=local_ip_addresses(), mongo=str(mongo.db))
|
2017-08-29 19:12:07 +08:00
|
|
|
|
2017-08-25 22:47:08 +08:00
|
|
|
elif action == "reset":
|
|
|
|
mongo.db.config.drop()
|
|
|
|
mongo.db.monkey.drop()
|
|
|
|
mongo.db.telemetry.drop()
|
|
|
|
mongo.db.node.drop()
|
|
|
|
mongo.db.edge.drop()
|
2017-08-29 19:12:07 +08:00
|
|
|
return jsonify(status='OK')
|
2017-08-25 22:47:08 +08:00
|
|
|
elif action == "killall":
|
|
|
|
mongo.db.monkey.update({}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}}, upsert=False,
|
|
|
|
multi=True)
|
2017-08-29 19:12:07 +08:00
|
|
|
return 200
|
2017-08-25 22:47:08 +08:00
|
|
|
else:
|
2017-08-29 19:12:07 +08:00
|
|
|
return make_response(400, {'error': 'unknown action'})
|