neutron_lib.db.utils module

neutron_lib.db.utils.filter_non_model_columns(data, model)

Return the attributes from data which are model columns.

Parameters:
  • data – The dict containing the data to filter.

  • model – The model who’s column names are used when filtering data.

Returns:

A new dict who’s keys are columns in model or are association proxies of the model.

neutron_lib.db.utils.get_and_validate_sort_keys(sorts, model)

Extract sort keys from sorts and ensure they are valid for the model.

Parameters:
  • sorts – A list of (key, direction) tuples.

  • model – A sqlalchemy ORM model class.

Returns:

A list of the extracted sort keys.

Raises:

BadRequest – If a sort key attribute references another resource and cannot be used in the sort.

neutron_lib.db.utils.get_marker_obj(plugin, context, resource, limit, marker)

Retrieve a resource marker object.

This function is used to invoke plugin._get_<resource>(context, marker) and is used for pagination.

Parameters:
  • plugin – The plugin processing the request.

  • context – The request context.

  • resource – The resource name.

  • limit – Indicates if pagination is in effect.

  • marker – The id of the marker object.

Returns:

The marker object associated with the plugin if limit and marker are given.

neutron_lib.db.utils.get_sort_dirs(sorts, page_reverse=False)

Extract sort directions from sorts, possibly reversed.

Parameters:
  • sorts – A list of (key, direction) tuples.

  • page_reverse – True if sort direction is reversed.

Returns:

The list of extracted sort directions optionally reversed.

neutron_lib.db.utils.is_retriable(exception)

Determine if the said exception is retriable.

Parameters:

exception – The exception to check.

Returns:

True if ‘exception’ is retriable, otherwise False.

neutron_lib.db.utils.model_query(context, model)

Query the context for the said model.

Parameters:
  • context – The context to use for the query.

  • model – The model to query for.

Returns:

A query from the said context for the said model.

neutron_lib.db.utils.model_query_scope_is_project(context, model)

Determine if a model should be scoped to a project.

Parameters:
  • context – The context to check for admin and advsvc rights.

  • model – The model to check the project_id of.

Returns:

True if the context is not admin and not advsvc and the model has a project_id. False otherwise.

neutron_lib.db.utils.reraise_as_retryrequest(function)

Wrap the said function with a RetryRequest upon error.

Parameters:

function – The function to wrap/decorate.

Returns:

The ‘function’ wrapped in a try block that will reraise any Exception’s as a RetryRequest.

Raises:

RetryRequest – If the wrapped function raises retriable exception.

neutron_lib.db.utils.resource_fields(resource, fields)

Return only the resource items that are in fields.

Parameters:
  • resource – A resource dict.

  • fields – A list of fields to select from the resource.

Returns:

A new dict that contains only fields from resource as well as its attribute project info.