def inject(): if not request.json or not 'type' in request.json \ or not 'duration' in request.json \ or not 'host' in request.json: abort(400) dto = { 'type': request.json['type'], 'inject_duration': request.json['duration'], 'host': request.json['host'] } if dto['type'] == 'cpu': return jsonify(FaultInjector.inject_cpu(dto)) elif dto['type'] == 'mem': return jsonify(FaultInjector.inject_mem(dto)) else: return jsonify(FaultInjector.inject_io(dto))
def delete_specific_kind_pods(): if not request.json or 'service' not in request.json: abort(400) mq_control = RabbitMq.control() dto = {'service': request.json['service'], 'open': mq_control} print dto return jsonify(FaultInjector.delete_all_pods_for_service(dto))
def view_all_create_success_inject_info(): if not request.json or 'host' not in request.json or 'status' not in request.json: abort(400) status = str(request.json['status']).capitalize() if status not in ['Success', 'Destroyed', 'Error']: abort(400) dto = {'host': request.json['host'], 'status': request.json['status']} return jsonify(FaultInjector.view_inject_on_host_by_status(dto))
def chaos_inject_random(): if not request.json or 'host' not in request.json or 'timeout' not in request.json: abort(400) mq_control = RabbitMq.control() dto = { 'host': request.json['host'], 'timeout': request.json['timeout'], 'open': mq_control } return jsonify(FaultInjector.chaos_inject_random(dto))
def chaos_inject_cpu_with_time(): if not request.json or 'host' not in request.json or 'second' not in request.json: abort(400) mq_control = RabbitMq.control() dto_time = {'time': request.json['second']} dto = {'host': request.json['host'], 'open': mq_control} scheduler = BackgroundScheduler() now = datetime.now() delta = timedelta( seconds=int(dto_time['time'].encode('raw_unicode_escape'))) scheduler.add_job(func=lambda: FaultInjector.chaos_inject_random(dto), trigger='date', next_run_time=(now + delta)) scheduler.start() time.sleep(delta.total_seconds() + 1) return "success"
def test_config(): return jsonify(FaultInjector.test_config())
def view_inject_info(): return jsonify(FaultInjector.view_chaos_inject())
def stop_all_inject_on_all_nodes(): mq_control = RabbitMq.control() mq_control = {'open': mq_control} return jsonify( FaultInjector.stop_all_chaos_inject_on_all_nodes(mq_control))
def stop_all_inject(): if not request.json or 'host' not in request.json: abort(400) mq_control = RabbitMq.control() dto = {'host': request.json['host'], 'open': mq_control} return jsonify(FaultInjector.stop_all_on_specific_node(dto))
def stop_specific_inject(): if not request.json or 'tag' not in request.json: abort(400) mq_control = RabbitMq.control() dto = {'tag': request.json['tag'], 'open': mq_control} return jsonify(FaultInjector.stop_specific_chaos_inject(dto))