2018-05-31 18:18:33 +08:00
|
|
|
import logging
|
2017-09-20 20:55:02 +08:00
|
|
|
from flask import request, jsonify
|
|
|
|
import flask_restful
|
|
|
|
|
|
|
|
from cc.services.node import NodeService
|
|
|
|
|
|
|
|
__author__ = 'itay.mizeretz'
|
|
|
|
|
2018-05-31 18:18:33 +08:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2017-09-20 20:55:02 +08:00
|
|
|
|
|
|
|
class ClientRun(flask_restful.Resource):
|
|
|
|
def get(self):
|
|
|
|
client_ip = request.remote_addr
|
|
|
|
if client_ip == "127.0.0.1":
|
|
|
|
monkey = NodeService.get_monkey_island_monkey()
|
|
|
|
else:
|
|
|
|
monkey = NodeService.get_monkey_by_ip(client_ip)
|
|
|
|
NodeService.update_dead_monkeys()
|
|
|
|
if monkey is not None:
|
|
|
|
is_monkey_running = not monkey["dead"]
|
|
|
|
else:
|
2018-06-01 00:27:26 +08:00
|
|
|
logger.info("Monkey is not running")
|
2017-09-20 20:55:02 +08:00
|
|
|
is_monkey_running = False
|
|
|
|
|
|
|
|
return jsonify(is_running=is_monkey_running)
|