from ansible.parsing.dataloader import DataLoader from ansible.vars.manager import VariableManager from ansible.inventory.manager import InventoryManager from ansible.playbook.play import Play from ansible.executor.task_queue_manager import TaskQueueManager from ansible.executor.playbook_executor import PlaybookExecutor from ansible.plugins.callback import CallbackBase from collections import namedtuple from itmsp.settings import BASE_DIR, LOG_DIR from iuser.models import ExUser from itmsp.utils.base import set_log, LOG_LEVEL ansible_logger = set_log(LOG_LEVEL, filename='ansible.log', logger_name='ansible') class ResultCallback(CallbackBase): """ 自定义log输出 """ def v2_runner_on_ok(self, result, **kwargs): ansible_logger.info("RUN_OK") host = result._host print json.dumps({host.name: result._result}, indent=4) def v2_runner_on_unreachable(self, result, **kwargs): host = result._host print "Unreachable"
from django.forms.models import model_to_dict from rest_framework.decorators import api_view from rest_framework.views import APIView from datetime import datetime from itmsp.utils.base import logger from iconfig.models import BlueEngineTask from iconfig.blue_instance_api.blue_instance_api import BlueInstanceAPI from itmsp.utils.base import set_log, smart_get, LOG_LEVEL from itmsp.utils.decorators import post_data_to_dict from iconfig.blue_engine.utils import set_log from iconfig.blue_engine.blue_logger import blue_engine_task_logger, tail from iconfig.tasks import blue_engine_control_center import json # from celery.utils.in list1 = [] blue_engine_logger = set_log(LOG_LEVEL) class BLueEngine(APIView): """ 此类属于蓝图引擎类,用于提供蓝图实例化接口调用和任务的执行 """ globals_note_list = [] @staticmethod @api_view(["POST"]) # @auto_log def blue_engine_query(request): """ 此静态方法用于 蓝图引擎的查询接口, :param request: 接受查询参数