示例#1
0
class AnsibleController():

    __ansible_configure = ProductionConfig()
    __loader = DataLoader()
    __variable_manager = VariableManager()
    __options = OptionAnsible(
        become=__ansible_configure.ANSIBLE_CONFIG["become"],
        become_method=__ansible_configure.ANSIBLE_CONFIG["become_method"],
        become_user=__ansible_configure.ANSIBLE_CONFIG["become_user"],
        remote_user=__ansible_configure.ANSIBLE_CONFIG["remote_user"],
        private_key_file=__ansible_configure.
        ANSIBLE_CONFIG["private_key_file"],
        host_key_checking=False)

    def __init__(self, host, task, **kwargs):
        self.__tqm = None
        self.__tasks = task
        self.__host = host
        self.__inventory = Inventory(host_list=self.__host,
                                     loader=self.__loader,
                                     variable_manager=self.__variable_manager)

    def play_task(self):

        play_source = {
            "name": "app cfm",
            "hosts": "all",
            "gather_facts": "no",
            "tasks": self.__tasks
        }
        play = Play().load(play_source,
                           variable_manager=self.__variable_manager,
                           loader=self.__loader)
        data = self.__run(play)
        return data

    def __run(self, play):
        callback = ResultsCollector()

        try:
            self.__tqm = TaskQueueManager(
                inventory=self.__inventory,
                variable_manager=self.__variable_manager,
                loader=self.__loader,
                options=self.__options,
                stdout_callback=callback,
                passwords=None,
                run_tree=False,
            )

            self.__tqm.run(play)
            return callback
        finally:
            if self.__tqm is not None:
                self.__tqm.cleanup()

    def __getitem__(self):
        list_hosts = self.__host
        list_tasks = self.__tasks
        return {"hosts": list_hosts, "tasks": list_tasks}
示例#2
0
 def __init__(self, filename):
     self.filename = filename
     self.conf = ProductionConfig()
示例#3
0
 def __init__(self, command):
     self.conf = ProductionConfig()
     self.command = command
示例#4
0
from configure import ProductionConfig

__conf = ProductionConfig()

log_config = {
    'loggers': {
        'app': {
            'level': 'INFO',
            'propagate': False,
            'handlers': ['handler_error', 'handler_debug', 'handler_info']
        }
    },
    'version': 1,
    'disable_existing_loggers': True,
    'handlers': {
        'handler_error': {
            'formatter': 'simple',
            'backupCount': 7,
            'level': 'ERROR',
            'interval': 1,
            'when': 'midnight',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': __conf.BASE_DIR + '/logs/error.log'
        },
        'handler_debug': {
            'formatter': 'simple',
            'backupCount': 7,
            'level': 'DEBUG',
            'interval': 1,
            'when': 'midnight',
            'class': 'logging.handlers.TimedRotatingFileHandler',
示例#5
0
def copy_api():
    __logging = LogManager("app").get_logger()
    __conf = ProductionConfig()

    # {'method': 'check', 'filename': 'cfm.ssff.tar.gz'}
    data = json.loads(request.data)
    if 'method' in [x for x in dict(data).iterkeys()
                    ] and 'filename' in [x for x in dict(data).iterkeys()]:
        if data["method"] == "check":
            try:
                data_result = copy_check(filname=data["filename"],
                                         host=__conf.HOST_GAME)
                msg_result = FormatLog(remote_addr=request.remote_addr,
                                       base_url=request.base_url,
                                       name="check copy file " +
                                       data["filename"],
                                       code=str(200),
                                       description=None,
                                       message=data_result).formatter()
                __logging.info(msg_result)
                return jsonify(
                    ResponeEntity.return_ok(msg=None, data=data_result))
            except Exception as e:
                msg_result = FormatLog(remote_addr=request.remote_addr,
                                       base_url=request.base_url,
                                       name="exception copy file " +
                                       data["filename"],
                                       description=None,
                                       code=str(5000),
                                       message=e.message).formatter()
                __logging.error(msg_result)
                return jsonify(
                    ResponeEntity.return_exception(
                        msg=e.message,
                        data="exception copy file " + data["filename"]))

        elif data["method"] == "run":
            try:
                data_result = copy_run(filname=data["filename"],
                                       host=__conf.HOST_GAME)
                msg_result = FormatLog(remote_addr=request.remote_addr,
                                       base_url=request.base_url,
                                       name="copy file " + data["filename"],
                                       code=str(200),
                                       description=None,
                                       message=data_result).formatter()
                __logging.info(msg_result)
                return jsonify(
                    ResponeEntity.return_ok(msg=None, data=data_result))
            except Exception as e:
                msg_result = FormatLog(remote_addr=request.remote_addr,
                                       base_url=request.base_url,
                                       name="exception copy file " +
                                       data["filename"],
                                       description=None,
                                       code=str(5000),
                                       message=e.message).formatter()
                __logging.error(msg_result)
                return jsonify(
                    ResponeEntity.return_exception(msg=e.message,
                                                   data="exception filename" +
                                                   data["filename"]))
        else:
            msg_result = FormatLog(remote_addr=request.remote_addr,
                                   base_url=request.base_url,
                                   code=str(5000),
                                   name="Method Wrong ",
                                   description=None,
                                   message="dkmm ngu vai noi").formatter()
            __logging.error(msg_result)
            return jsonify(
                ResponeEntity.return_error(msg=msg_result,
                                           data="Method Wrong Format"))
    else:

        msg_result = FormatLog(remote_addr=request.remote_addr, base_url=request.base_url, code=str(5000), name="Data "
                                                                                                                "Wrong " \
                                                                                                                "Format",
                               description=None, message="dkmm ngu vai noi").formatter()
        __logging.error(msg_result)
        return jsonify(
            ResponeEntity.return_error(msg=msg_result,
                                       data="Data Wrong Format"))