Exemple #1
0
class OperatorApi(object):
    default_log_format = '%(asctime)s %(levelname)s %(message)s'

    def __init__(self):
        self._init_log_handler()
        self.internal_api = InternalApi(self.log_handler)

    def _init_log_handler(self):
        self.log_handler = RpcLogHandler()
        self.log_handler.setLevel(logging.ERROR)
        self.log_handler.formatter = logging.Formatter(self.default_log_format)

    @register_method(name="operator.show")
    def show(self, **kwargs):
        return self._run('show', kw=kwargs)

    @register_method(name="operator.set")
    def set(self, **kwargs):
        return self._run('set', kw=kwargs)

    @register_method(name="operator.clear")
    def clear(self, **kwargs):
        return self._run('clear', kw=kwargs)

    def _run(self, cmd, kw={}):
        params = kw.get('params', [])
        fmt = kw.get('format', 'json')
        root = RootCmd(api=self.internal_api, resp_formatter_name=fmt)
        ret, _ = root([cmd] + params)
        if ret.status == STATUS_ERROR:
            raise ApiException(str(ret.value))
        return ret.value
Exemple #2
0
class OperatorApi(object):
    default_log_format = '%(asctime)s %(levelname)s %(message)s'

    def __init__(self):
        self._init_log_handler()
        self.internal_api = InternalApi(self.log_handler)

    def _init_log_handler(self):
        self.log_handler = RpcLogHandler()
        self.log_handler.setLevel(logging.ERROR)
        self.log_handler.formatter = logging.Formatter(self.default_log_format)

    @register_method(name="operator.show")
    def show(self, **kwargs):
        return self._run('show', kw=kwargs)

    @register_method(name="operator.set")
    def set(self, **kwargs):
        return self._run('set', kw=kwargs)

    @register_method(name="operator.clear")
    def clear(self, **kwargs):
        return self._run('clear', kw=kwargs)

    def _run(self, cmd, kw={}):
        params = kw.get('params', [])
        fmt = kw.get('format', 'json')
        root = RootCmd(api=self.internal_api, resp_formatter_name=fmt)
        ret, _ = root([cmd] + params)
        if ret.status == STATUS_ERROR:
            raise ApiException(str(ret.value))
        return ret.value
Exemple #3
0
def _init_log_handler():
    log_handler = RpcLogHandler()
    log_handler.setLevel(logging.ERROR)
    log_handler.formatter = logging.Formatter(DEFAULT_LOG_FORMAT)
    return log_handler
Exemple #4
0
def _init_log_handler():
    log_handler = RpcLogHandler()
    log_handler.setLevel(logging.ERROR)
    log_handler.formatter = logging.Formatter(DEFAULT_LOG_FORMAT)
    return log_handler
Exemple #5
0
 def _init_log_handler(self):
     self.log_handler = RpcLogHandler()
     self.log_handler.setLevel(logging.ERROR)
     self.log_handler.formatter = logging.Formatter(self.default_log_format)
Exemple #6
0
 def _init_log_handler(self):
     self.log_handler = RpcLogHandler()
     self.log_handler.setLevel(logging.ERROR)
     self.log_handler.formatter = logging.Formatter(self.default_log_format)