congress.api.webservice module

congress.api.webservice module

class congress.api.webservice.AbstractApiHandler(path_regex)

Bases: object

Abstract handler for API requests.

Attributes:
path_regex: The regular expression matching paths supported by this
handler.
handle_request(request)

Handle a REST request.

Param:request: A webob request object.
Returns:A webob response object.
handles_request(request)

Return true iff handler supports the request.

class congress.api.webservice.CollectionHandler(path_regex, model, allow_named_create=True, allow_list=True, allow_create=True, allow_replace=False)

Bases: congress.api.webservice.AbstractApiHandler

API handler for REST collection resources.

REST collections represent collections of entities in the data model, and often support the following operations: - List elements in the collection - Create new element in the collection

The following less-common collection operations are NOT SUPPORTED: - Replace all elements in the collection - Delete all elements in the collection

create_member(request, id_=None)
handle_request(request)

Handle a REST request.

Param:request: A webob request object.
Returns:A webob response object.
list_members(request)
replace_members(request)
exception congress.api.webservice.DataModelException(error_code, description, data=None, http_status_code=<HTTPStatus.BAD_REQUEST: 400>)

Bases: Exception

Congress API Data Model Exception

Custom exception raised by API Data Model methods to communicate errors to the API framework.

classmethod create(error)

Generate a DataModelException from an existing CongressException.

Param:error: has a ‘name’ field corresponding to an error_codes error-name. It may also have a ‘data’ field.
Returns:a DataModelException properly populated.
rest_response()
class congress.api.webservice.ElementHandler(path_regex, model, collection_handler=None, allow_read=True, allow_actions=True, allow_replace=True, allow_update=True, allow_delete=True)

Bases: congress.api.webservice.AbstractApiHandler

API handler for REST element resources.

REST elements represent individual entities in the data model, and often support the following operations: - Read a representation of the element - Update (replace) the entire element with a new version - Update (patch) parts of the element with new values - Delete the element

Elements may also exhibit ‘controller’ semantics for RPC-style method invocation, however this is not currently supported.

action(request)
delete(request)
handle_request(request)

Handle a REST request.

Param:request: A webob request object.
Returns:A webob response object.
read(request)
replace(request)
update(request)
class congress.api.webservice.SimpleDataModel(model_name)

Bases: object

A container providing access to a single type of data.

add_item(item, params, id_=None, context=None)

Add item to model.

Param:

item: The item to add to the model

Param:

params: A dict-like object containing parameters from the request query string and body.

Param:

The ID of the item, or None if an ID should be generated

Param:

context: Key-values providing frame of reference of request

Returns:

Tuple of (ID, newly_created_item)

Raises:
delete_item(id_, params, context=None)

Remove item from model.

Param:id_: The ID of the item to be removed
Param:params: A dict-like object containing parameters from the request query string and body.
Param:context: Key-values providing frame of reference of request
Returns:The removed item.
Raises:KeyError – Item with specified id_ not present.
get_item(id_, params, context=None)

Retrieve item with id id_ from model.

Param:id_: The ID of the item to retrieve
Param:params: A dict-like object containing parameters from the request query string and body.
Param:context: Key-values providing frame of reference of request
Returns:The matching item or None if item with id_ does not exist.
get_items(params, context=None)

Get items in model.

Param:params: A dict-like object containing parameters from the request query string and body.
Param:context: Key-values providing frame of reference of request
Returns:A dict containing at least a ‘results’ key whose value is a list of items in the model. Additional keys set in the dict will also be rendered for the user.
replace_item(id_, item, params, context=None)

Replace item with id_ with new data.

Param:

id_: The ID of the item to be replaced item: The new item

Param:

params: A dict-like object containing parameters from the request query string and body.

Param:

context: Key-values providing frame of reference of request

Returns:

The new item after replacement.

Raises:
  • KeyError – Item with specified id_ not present.
  • DataModelException – Replacement cannot be performed.
replace_items(items, params, context=None)

Replace items in the model.

Param:items: A dict-like object containing new data
Param:params: A dict-like object containing parameters
Param:context: Key-values providing frame of reference of request
Returns:None
update_item(id_, item, params, context=None)

Update item with id_ with new data.

Param:

id_: The ID of the item to be updated item: The new item

Param:

params: A dict-like object containing parameters from the request query string and body.

Param:

context: Key-values providing frame of reference of request

Returns:

The updated item.

Raises:
  • KeyError – Item with specified id_ not present.
  • DataModelException – Update cannot be performed.
congress.api.webservice.error_response(status, error_code, description, data=None)

Construct and return an error response.

Args:
status: The HTTP status code of the response. error_code: The application-specific error code. description: Friendly G11N-enabled string corresponding to error_code. data: Additional data (not G11N-enabled) for the API consumer.
congress.api.webservice.original_msg(e)

Undo oslo-messaging added traceback to return original exception msg

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.