The osc_lib.api.api Module

The osc_lib.api.api Module

Base API Library

class osc_lib.api.api.BaseAPI(session=None, service_type=None, endpoint=None, **kwargs)

Bases: object

Base API wrapper for keystoneauth1.session.Session

Encapsulate the translation between keystoneauth1.session.Session and requests.Session in a single layer:

  • Restore some requests.session.Session compatibility; keystoneauth1.session.Session.request() has the method and url arguments swapped from the rest of the requests-using world.
  • Provide basic endpoint handling when a Service Catalog is not available.
HEADER_NAME = 'OpenStack-API-Version'
SERVICE_TYPE = ''
create(url, session=None, method=None, **params)

Create a new resource

Parameters:
  • url (string) – The API-specific portion of the URL path
  • session (Session) – HTTP client session
  • method (string) – HTTP method (default POST)
delete(url, session=None, **params)

Delete a resource

Parameters:
  • url (string) – The API-specific portion of the URL path
  • session (Session) – HTTP client session
find(path, value=None, attr=None, headers=None)

Find a single resource by name or ID

Parameters:
  • path (string) – The API-specific portion of the URL path
  • value (string) – search expression (required, really)
  • attr (string) – name of attribute for secondary search
  • headers (dict) – Headers dictionary to pass to requests
find_attr(path, value=None, attr=None, resource=None)

Find a resource via attribute or ID

Most APIs return a list wrapped by a dict with the resource name as key. Some APIs (Identity) return a dict when a query string is present and there is one return value. Take steps to unwrap these bodies and return a single dict without any resource wrappers.

Parameters:
  • path (string) – The API-specific portion of the URL path
  • value (string) – value to search for
  • attr (string) – attribute to use for resource search
  • resource (string) – plural of the object resource name; defaults to path
For example:
n = find(netclient, ‘network’, ‘networks’, ‘matrix’)
find_bulk(path, headers=None, **kwargs)

Bulk load and filter locally

Parameters:
  • path (string) – The API-specific portion of the URL path
  • kwargs – A dict of AVPs to match - logical AND
  • headers (dict) – Headers dictionary to pass to requests
Returns:

list of resource dicts

find_one(path, **kwargs)

Find a resource by name or ID

Parameters:path (string) – The API-specific portion of the URL path
Returns:resource dict
list(path, session=None, body=None, detailed=False, headers=None, **params)

Return a list of resources

GET ${ENDPOINT}/${PATH}?${PARAMS}

path is often the object’s plural resource type

Parameters:
  • path (string) – The API-specific portion of the URL path
  • session (Session) – HTTP client session
  • body – data that will be encoded as JSON and passed in POST request (GET will be sent by default)
  • detailed (bool) – Adds ‘/details’ to path for some APIs to return extended attributes
  • headers (dict) – Headers dictionary to pass to requests
Returns:

JSON-decoded response, could be a list or a dict-wrapped-list

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.