Пример #1
0
    def render_POST(self, request):
        config_content = requestargs.get_string(request, 'config')
        name = requestargs.get_string(request, 'name')
        config_hash = requestargs.get_string(request, 'hash')
        check = requestargs.get_bool(request, 'check')

        if not name:
            return respond(
                request=request,
                response={'error': "'name' for config is required."},
                code=http.BAD_REQUEST,
            )

        response = {'status': "Active"}

        if check:
            fn = self.controller.check_config
            req = "configure check"
        elif config_content == "":
            fn = self.controller.delete_config
            req = "configuration delete"
        else:
            fn = self.controller.update_config
            req = "reconfigure"

        log.info("Handling %s request: %s, %s" % (req, name, config_hash))
        error = fn(name, config_content, config_hash)

        if error:
            response['error'] = error
        return respond(request=request, response=response)
Пример #2
0
    def render_POST(self, request):
        config_content = requestargs.get_string(request, 'config')
        name = requestargs.get_string(request, 'name')
        config_hash = requestargs.get_string(request, 'hash')
        check = requestargs.get_bool(request, 'check')

        if not name:
            return respond(
                request=request,
                response={'error': "'name' for config is required."},
                code=http.BAD_REQUEST,
            )

        response = {'status': "Active"}

        if check:
            fn = self.controller.check_config
            req = "configure check"
        elif config_content == "":
            fn = self.controller.delete_config
            req = "configuration delete"
        else:
            fn = self.controller.update_config
            req = "reconfigure"

        log.info("Handling %s request: %s, %s" % (req, name, config_hash))
        error = fn(name, config_content, config_hash)

        if error:
            response['error'] = error
        return respond(request=request, response=response)
Пример #3
0
 def render_POST(self, request):
     old_name = requestargs.get_string(request, 'old_name')
     new_name = requestargs.get_string(request, 'new_name')
     return handle_command(
         request=request,
         api_controller=self.controller,
         obj=self.job_collection,
         old_name=old_name,
         new_name=new_name,
     )
Пример #4
0
 def render_POST(self, request):
     old_name = requestargs.get_string(request, 'old_name')
     new_name = requestargs.get_string(request, 'new_name')
     return handle_command(
         request=request,
         api_controller=self.controller,
         obj=self.job_collection,
         old_name=old_name,
         new_name=new_name,
     )
Пример #5
0
 def render_POST(self, request):
     command = requestargs.get_string(request, 'command')
     if command not in self.controller.COMMANDS:
         return respond(
             request=request,
             response=dict(error=f'Unknown command: {command}'),
             code=http.BAD_REQUEST,
         )
     event = requestargs.get_string(request, 'event')
     fn = getattr(self.controller, command)
     response = fn(event)
     return respond(request=request, response=response)
Пример #6
0
 def render_POST(self, request):
     command = requestargs.get_string(request, 'command')
     if command not in self.controller.COMMANDS:
         return respond(
             request=request,
             response=dict(error=f'Unknown command: {command}'),
             code=http.BAD_REQUEST,
         )
     event = requestargs.get_string(request, 'event')
     fn = getattr(self.controller, command)
     response = fn(event)
     return respond(request=request, response=response)
Пример #7
0
    def render_POST(self, request):
        config_content = requestargs.get_string(request, "config")
        name = requestargs.get_string(request, "name")
        config_hash = requestargs.get_string(request, "hash")
        log.info("Handling reconfigure request: %s, %s" % (name, config_hash))
        if not name:
            return respond(request, {"error": "'name' for config is required."})

        response = {"status": "Active"}
        error = self.controller.update_config(name, config_content, config_hash)
        if error:
            response["error"] = error
        return respond(request, response)
Пример #8
0
    def render_POST(self, request):
        config_content = requestargs.get_string(request, 'config')
        name = requestargs.get_string(request, 'name')
        config_hash = requestargs.get_string(request, 'hash')
        log.info("Handling reconfigure request: %s, %s" % (name, config_hash))
        if not name:
            return respond(request, {'error': "'name' for config is required."})

        response = {'status': "Active"}
        error = self.controller.update_config(name, config_content, config_hash)
        if error:
            response['error'] = error
        return respond(request, response)
Пример #9
0
    def render_POST(self, request):
        config_content = requestargs.get_string(request, 'config')
        name = requestargs.get_string(request, 'name')
        config_hash = requestargs.get_string(request, 'hash')
        log.info("Handling reconfigure request: %s, %s" % (name, config_hash))
        if not name:
            return respond(request,
                           {'error': "'name' for config is required."})

        response = {'status': "Active"}
        error = self.controller.update_config(name, config_content,
                                              config_hash)
        if error:
            response['error'] = error
        return respond(request, response)
Пример #10
0
 def render_GET(self, request):
     include_job_runs = requestargs.get_bool(request, 'include_job_runs')
     include_action_runs = requestargs.get_bool(request, 'include_action_runs')
     namespace = requestargs.get_string(request, 'namespace')
     output = dict(jobs=self.get_data(include_job_runs, include_action_runs,
         namespace))
     return respond(request, output)
Пример #11
0
 def render_GET(self, request):
     config_name = requestargs.get_string(request, "name")
     no_header = requestargs.get_bool(request, "no_header")
     if not config_name:
         return respond(request, {"error": "'name' for config is required."})
     response = self.controller.read_config(config_name, add_header=not no_header)
     return respond(request, response)
Пример #12
0
 def render_GET(self, request):
     config_name = requestargs.get_string(request, 'name')
     no_header = requestargs.get_bool(request, 'no_header')
     if not config_name:
         return respond(request,
                        {'error': "'name' for config is required."})
     response = self.controller.read_config(config_name,
                                            add_header=not no_header)
     return respond(request, response)
Пример #13
0
def handle_command(request, api_controller, obj, **kwargs):
    """Handle a request to perform a command."""
    command = requestargs.get_string(request, 'command')
    log.info("Handling '%s' request on %s", command, obj)
    try:
        response = api_controller.handle_command(command, **kwargs)
        return respond(request, {'result': response})
    except controller.UnknownCommandError, e:
        log.warning("Unknown command %s for %s", command, obj)
        return respond(request, {'error': str(e)}, code=http.NOT_IMPLEMENTED)
Пример #14
0
 def render_GET(self, request):
     config_name = requestargs.get_string(request, 'name')
     if not config_name:
         return respond(
             request=request,
             response={'error': "'name' for config is required."},
             code=http.BAD_REQUEST,
         )
     response = self.controller.read_config(config_name)
     return respond(request=request, response=response)
Пример #15
0
 def render_GET(self, request):
     config_name = requestargs.get_string(request, 'name')
     if not config_name:
         return respond(
             request=request,
             response={'error': "'name' for config is required."},
             code=http.BAD_REQUEST,
         )
     response = self.controller.read_config(config_name)
     return respond(request=request, response=response)
Пример #16
0
Файл: www.py Проект: Bklyn/Tron
    def render_POST(self, request):
        cmd = requestargs.get_string(request, "command")
        log.info("Handling '%s' request for job run %s", cmd, self._run.id)

        if cmd not in ["start", "restart", "success", "fail", "cancel"]:
            log.warning("Unknown request command %s", cmd)
            return respond(request, None, code=http.NOT_IMPLEMENTED)

        getattr(self, "_%s" % cmd)()
        return respond(request, {"result": "Job run now in state %s" % self._run.state.short_name})
Пример #17
0
def handle_command(request, api_controller, obj, **kwargs):
    """Handle a request to perform a command."""
    command = requestargs.get_string(request, "command")
    log.info("Handling '%s' request on %s", command, obj)
    try:
        response = api_controller.handle_command(command, **kwargs)
        return respond(request, {"result": response})
    except controller.UnknownCommandError, e:
        log.warning("Unknown command %s for %s", command, obj)
        return respond(request, {"error": str(e)}, code=http.NOT_IMPLEMENTED)
Пример #18
0
def handle_command(request, api_controller, obj, **kwargs):
    """Handle a request to perform a command."""
    command = requestargs.get_string(request, 'command')
    log.info("Handling '%s' request on %s", command, obj)
    try:
        response = api_controller.handle_command(command, **kwargs)
        return respond(request, {'result': response})
    except controller.UnknownCommandError as e:
        log.warning("Unknown command %s for %s", command, obj)
        return respond(request, {'error': str(e)}, code=http.NOT_IMPLEMENTED)
    except Exception as e:
        log.exception('%r while executing command %s for %s', e, command, obj)
        trace = traceback.format_exc()
        return respond(request, {'error': trace},
                       code=http.INTERNAL_SERVER_ERROR)
Пример #19
0
def handle_command(request, api_controller, obj, **kwargs):
    """Handle a request to perform a command."""
    command = requestargs.get_string(request, 'command')
    log.info("Handling '%s' request on %s", command, obj)
    try:
        response = api_controller.handle_command(command, **kwargs)
        return respond(request=request, response={'result': response})
    except controller.UnknownCommandError:
        error_msg = f"Unknown command '{command}' for '{obj}'"
        log.warning(error_msg)
        return respond(
            request=request, response={'error': error_msg}, code=http.NOT_IMPLEMENTED
        )
    except Exception as e:
        log.exception('%r while executing command %s for %s', e, command, obj)
        trace = traceback.format_exc()
        return respond(request=request, response={'error': trace})
Пример #20
0
 def test_get_string_missing(self):
     assert not get_string(self.request, 'missing')
Пример #21
0
 def test_get_string(self):
     self._add_arg('string', 'bogus')
     assert_equal(get_string(self.request, 'string'), 'astring')