Python falcon.HTTP_500 Examples

The following are 30 code examples of falcon.HTTP_500(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module falcon , or try the search function .
Example #1
Source File: rollback.py    From armada with Apache License 2.0 6 votes vote down vote up
def on_post(self, req, resp, release):
        try:
            with self.get_tiller(req, resp) as tiller:
                msg = self.handle(req, release, tiller)
                resp.body = json.dumps({
                    'message': msg,
                })
                resp.content_type = 'application/json'
                resp.status = falcon.HTTP_200
        except LockException as e:
            self.return_error(resp, falcon.HTTP_409, message=str(e))
        except Exception as e:
            self.logger.exception('Caught unexpected exception')
            err_message = 'Failed to rollback release: {}'.format(e)
            self.error(req.context, err_message)
            self.return_error(resp, falcon.HTTP_500, message=err_message) 
Example #2
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_relabel_nodes(self, req, resp, json_data):
        """Create async task for relabel nodes."""
        action = json_data.get('action', None)

        if action != 'relabel_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_relabel_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #3
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_deploy_nodes(self, req, resp, json_data):
        """Create async task for deploy node."""
        action = json_data.get('action', None)

        if action != 'deploy_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_deploy_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #4
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_destroy_nodes(self, req, resp, json_data):
        """Create async task for destroy node."""
        action = json_data.get('action', None)

        if action != 'destroy_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_destroy_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #5
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def get_task(self, req, resp, task_id, builddata):
        try:
            task = self.state_manager.get_task(uuid.UUID(task_id))
            if task is None:
                return None

            task_dict = task.to_dict()

            if builddata:
                task_bd = self.state_manager.get_build_data(
                    task_id=task.get_id())
                task_dict['build_data'] = [bd.to_dict() for bd in task_bd]

            return task_dict
        except Exception as ex:
            self.error(req.context, "Unknown error: %s" % (str(ex)))
            self.return_error(
                resp, falcon.HTTP_500, message="Unknown error", retry=False) 
Example #6
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_prepare_nodes(self, req, resp, json_data):
        """Create async task for prepare node."""
        action = json_data.get('action', None)

        if action != 'prepare_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_prepare_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #7
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_verify_nodes(self, req, resp, json_data):
        """Create async task for verify node."""
        action = json_data.get('action', None)

        if action != 'verify_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_verify_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #8
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_verify_site(self, req, resp, json_data):
        """Create async task for verify site."""
        action = json_data.get('action', None)

        if action != 'verify_site':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_verify_site"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #9
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_validate_design(self, req, resp, json_data):
        """Create async task for validate design."""
        action = json_data.get('action', None)

        if action != 'validate_design':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_validate_design"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #10
Source File: service_endpoints.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def _get_ks_session():
    # Establishes a keystone session
    try:
        auth = loading.load_auth_from_conf_options(CONF, "keystone_authtoken")
        return session.Session(auth=auth)
    except exc.AuthorizationFailure as aferr:
        LOG.error('Could not authorize against keystone: %s',
                  str(aferr))
        raise AppError(
            title='Could not authorize Shipyard against Keystone',
            description=(
                'Keystone has rejected the authorization request by Shipyard'
            ),
            status=falcon.HTTP_500,
            retry=False
        ) 
Example #11
Source File: notedetails_api.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def get_note_with_access_check(self, context, note_id):
        """Retrieve the note and checks user access to the note

        :param context: the request context
        :param note_id: the id of the note to retrieve.
        :returns: the note
        """
        try:
            note = notes_helper.get_note(note_id)
            note_type = notes_helper.get_note_assoc_id_type(note)
            if note_type not in NOTE_TYPE_RBAC:
                raise ApiError(
                    title="Unable to check permission for note type",
                    description=(
                        "Shipyard is not correctly identifying note type "
                        "for note {}".format(note_id)),
                    status=falcon.HTTP_500,
                    retry=False)
            policy.check_auth(context, NOTE_TYPE_RBAC[note_type])
            return note
        except NoteNotFoundError:
            raise ApiError(
                title="No note found",
                description=("Note {} is not found".format(note_id)),
                status=falcon.HTTP_404) 
Example #12
Source File: nodes.py    From drydock with Apache License 2.0 6 votes vote down vote up
def on_post(self, req, resp):
        try:
            json_data = self.req_json(req)
            node_filter = json_data.get('node_filter', None)
            design_ref = json_data.get('design_ref', None)
            if design_ref is None:
                self.info(req.context,
                          'Missing required input value: design_ref')
                self.return_error(
                    resp,
                    falcon.HTTP_400,
                    message='Missing input required value: design_ref',
                    retry=False)
                return
            _, site_design = self.orchestrator.get_effective_site(design_ref)
            nodes = self.orchestrator.process_node_filter(
                node_filter=node_filter, site_design=site_design)
            resp_list = [n.name for n in nodes if nodes]

            resp.body = json.dumps(resp_list)
            resp.status = falcon.HTTP_200
        except Exception as ex:
            self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex)
            self.return_error(
                resp, falcon.HTTP_500, message="Unknown error", retry=False) 
Example #13
Source File: errors.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def default_exception_handler(ex, req, resp, params):
    """
    Catch-all exception handler for standardized output.
    If this is a standard falcon HTTPError, rethrow it for handling
    """
    if isinstance(ex, falcon.HTTPError):
        # allow the falcon http errors to bubble up and get handled
        raise ex
    else:
        # take care of the uncaught stuff
        exc_string = traceback.format_exc()
        logging.error('Unhandled Exception being handled: \n%s', exc_string)
        format_error_resp(
            req,
            resp,
            falcon.HTTP_500,
            error_type=ex.__class__.__name__,
            message="Unhandled Exception raised: %s" % str(ex),
            retry=True
        ) 
Example #14
Source File: service_endpoints.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def get_endpoint(endpoint):
    """
    Wraps calls to keystone for lookup of an endpoint by service type
    :param Endpoints endpoint: The endpoint to look up
    :returns: The url string of the endpoint
    :rtype: str
    :raises AppError: if the endpoint cannot be resolved
    """
    service_type = _get_service_type(endpoint)
    try:
        return _get_ks_session().get_endpoint(
            interface='internal',
            service_type=service_type)
    except exc.EndpointNotFound:
        LOG.error('Could not find an internal interface for %s',
                  endpoint.name)
        raise AppError(
            title='Can not access service endpoint',
            description=(
                'Keystone catalog has no internal endpoint for service type: '
                '{}'.format(service_type)
            ),
            status=falcon.HTTP_500,
            retry=False) 
Example #15
Source File: status_helper.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def get_nodes_provision_status(drydock):
    # Calls Drydock client to fetch node provision status
    try:
        nodes = drydock.get_nodes()

        nodes_status = []
        for node in nodes:
            nodes_status.append(
                {
                    'hostname': node.get('hostname'),
                    'status': node.get('status_name')
                })
    except dderrors.ClientError as ddex:
        raise AppError(
            title='Unable to retrieve nodes status',
            description=(
                'Drydock has responded unexpectedly: '
                '{}'.format(ddex.response_message)),
            status=falcon.HTTP_500,
            retry=False, )

    machine_status = {'nodes_provision_status': nodes_status}

    return machine_status 
Example #16
Source File: designs.py    From drydock with Apache License 2.0 6 votes vote down vote up
def on_get(self, req, resp):
        """Method handler for GET requests.

        :param req: Falcon request object
        :param resp: Falcon response object
        """
        state = self.state_manager

        try:
            designs = list(state.designs.keys())

            resp.body = json.dumps(designs)
            resp.status = falcon.HTTP_200
        except Exception as ex:
            self.error(req.context, "Exception raised: %s" % str(ex))
            self.return_error(
                resp,
                falcon.HTTP_500,
                message="Error accessing design list",
                retry=True) 
Example #17
Source File: tiller.py    From armada with Apache License 2.0 6 votes vote down vote up
def on_get(self, req, resp):
        '''Controller for listing Tiller releases.
        '''
        try:
            with self.get_tiller(req, resp) as tiller:
                releases = self.handle(tiller)
                resp.body = json.dumps({
                    'releases': releases,
                })
                resp.content_type = 'application/json'
                resp.status = falcon.HTTP_200

        except Exception as e:
            err_message = 'Unable to find Tiller Releases: {}'.format(e)
            self.error(req.context, err_message)
            self.return_error(resp, falcon.HTTP_500, message=err_message) 
Example #18
Source File: configdocs_helper.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def is_collection_in_buffer(self, collection_id):
        """Returns if the collection is represented in the buffer"""
        if self.is_buffer_empty():
            return False

        # If there is no committed revision, then it's 0.
        # new revision is ok because we just checked for buffer emptiness
        old_revision_id = self.get_revision_id(COMMITTED) or 0

        try:
            diff = self.deckhand.get_diff(
                old_revision_id=old_revision_id,
                new_revision_id=self.get_revision_id(BUFFER))
            # the collection is in the buffer if it's not unmodified
            return diff.get(collection_id, 'unmodified') != 'unmodified'

        except DeckhandResponseError as drex:
            raise AppError(
                title='Unable to retrieve revisions',
                description=(
                    'Deckhand has responded unexpectedly: {}:{}'.format(
                        drex.status_code, drex.response_message)),
                status=falcon.HTTP_500,
                retry=False, ) 
Example #19
Source File: logs.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
def process_on_post_request(self, req, res):
        try:
            request_body = helpers.from_json(req)
            log_list = self._get_logs(request_body)
            global_dimensions = self._get_global_dimensions(request_body)

        except Exception as ex:
            LOG.error('Entire bulk package has been rejected')
            LOG.exception(ex)

            raise ex
        tenant_id = (req.cross_project_id if req.cross_project_id
                     else req.project_id)

        try:
            self._processor.send_message(
                logs=log_list,
                global_dimensions=global_dimensions,
                log_tenant_id=tenant_id
            )
        except Exception as ex:
            res.status = getattr(ex, 'status', falcon.HTTP_500)
            return

        res.status = falcon.HTTP_204 
Example #20
Source File: errors.py    From armada with Apache License 2.0 6 votes vote down vote up
def default_exception_handler(ex, req, resp, params):
    """
    Catch-all exception handler for standardized output.
    If this is a standard falcon HTTPError, rethrow it for handling
    """
    if isinstance(ex, falcon.HTTPError):
        # allow the falcon http errors to bubble up and get handled
        raise ex
    else:
        # take care of the uncaught stuff
        exc_string = traceback.format_exc()
        logging.error('Unhanded Exception being handled: \n%s', exc_string)
        format_error_resp(
            req,
            resp,
            falcon.HTTP_500,
            error_type=ex.__class__.__name__,
            message="Unhandled Exception raised: %s" % str(ex),
            retry=True
        ) 
Example #21
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_destroy_nodes(self, req, resp, json_data):
        """Create async task for destroy node."""
        action = json_data.get('action', None)

        if action != 'destroy_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_destroy_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #22
Source File: swagger_server.py    From falsy with MIT License 6 votes vote down vote up
def default_error_handler(req, resp, e):
    resp.body = json.dumps({'title': str(type(e)), 'description': str(e)}, indent=2, ensure_ascii=False)
    resp.status = falcon.HTTP_500
    resp.content_type = 'application/json'


# def http_not_found_handler(req, resp, e):
#     resp.body = e.title
#     resp.status = e.status
#     resp.content_type = 'application/json'
#
#
# def http_missing_param_handler(req, resp, e):
#     resp.body = json.dumps({'error': e.title + ':' + ' '.join([p for p in e.args])})
#     resp.status = e.status
#     resp.content_type = 'application/json'
#
#
# def http_invalid_param_handler(req, resp, e):
#     resp.body = json.dumps({'error': e.title + ':' + ' '.join([p for p in e.args])})
#     resp.status = e.status
#     resp.content_type = 'application/json' 
Example #23
Source File: exceptions.py    From promenade with Apache License 2.0 6 votes vote down vote up
def default_exception_handler(ex, req, resp, params):
    """
    Catch-all exception handler for standardized output.
    If this is a standard falcon HTTPError, rethrow it for handling
    """
    if isinstance(ex, falcon.HTTPError):
        # allow the falcon http errors to bubble up and get handled
        raise ex
    else:
        # take care of the uncaught stuff
        exc_string = traceback.format_exc()
        LOG.error('Unhanded Exception being handled: \n%s', exc_string)
        format_error_resp(
            req,
            resp,
            falcon.HTTP_500,
            error_type=ex.__class__.__name__,
            message="Unhandled Exception raised: %s" % str(ex),
            retry=True) 
Example #24
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_deploy_nodes(self, req, resp, json_data):
        """Create async task for deploy node."""
        action = json_data.get('action', None)

        if action != 'deploy_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_deploy_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #25
Source File: designs.py    From drydock with Apache License 2.0 6 votes vote down vote up
def on_get(self, req, resp):
        """Method handler for GET requests.

        :param req: Falcon request object
        :param resp: Falcon response object
        """
        state = self.state_manager

        try:
            designs = list(state.designs.keys())

            resp.body = json.dumps(designs)
            resp.status = falcon.HTTP_200
        except Exception as ex:
            self.error(req.context, "Exception raised: %s" % str(ex))
            self.return_error(
                resp,
                falcon.HTTP_500,
                message="Error accessing design list",
                retry=True) 
Example #26
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_prepare_nodes(self, req, resp, json_data):
        """Create async task for prepare node."""
        action = json_data.get('action', None)

        if action != 'prepare_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_prepare_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #27
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_verify_nodes(self, req, resp, json_data):
        """Create async task for verify node."""
        action = json_data.get('action', None)

        if action != 'verify_nodes':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_verify_nodes"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #28
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_verify_site(self, req, resp, json_data):
        """Create async task for verify site."""
        action = json_data.get('action', None)

        if action != 'verify_site':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_verify_site"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #29
Source File: tasks.py    From drydock with Apache License 2.0 6 votes vote down vote up
def task_validate_design(self, req, resp, json_data):
        """Create async task for validate design."""
        action = json_data.get('action', None)

        if action != 'validate_design':
            self.error(
                req.context,
                "Task body ended up in wrong handler: action %s in task_validate_design"
                % action)
            self.return_error(
                resp, falcon.HTTP_500, message="Error", retry=False)

        try:
            task = self.create_task(json_data, req.context)
            resp.body = json.dumps(task.to_dict())
            resp.append_header('Location',
                               "/api/v1.0/tasks/%s" % str(task.task_id))
            resp.status = falcon.HTTP_201
        except errors.InvalidFormat as ex:
            self.error(req.context, ex.msg)
            self.return_error(
                resp, falcon.HTTP_400, message=ex.msg, retry=False) 
Example #30
Source File: nodes.py    From drydock with Apache License 2.0 6 votes vote down vote up
def on_post(self, req, resp):
        try:
            json_data = self.req_json(req)
            node_filter = json_data.get('node_filter', None)
            design_ref = json_data.get('design_ref', None)
            if design_ref is None:
                self.info(req.context, 'Missing required input value: design_ref')
                self.return_error(
                    resp,
                    falcon.HTTP_400,
                    message='Missing input required value: design_ref',
                    retry=False)
                return
            _, site_design = self.orchestrator.get_effective_site(design_ref)
            nodes = self.orchestrator.process_node_filter(node_filter=node_filter,
                                                          site_design=site_design)
            resp_list = [n.name for n in nodes if nodes]

            resp.body = json.dumps(resp_list)
            resp.status = falcon.HTTP_200
        except Exception as ex:
            self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex)
            self.return_error(
                resp, falcon.HTTP_500, message="Unknown error", retry=False)