# neutron_lib.context module

Context: context for security/db session.

class neutron_lib.context.Context(*args, **kwargs)

  Bases: `ContextBaseWithSession`

  clear_transaction_constraint()
  get_transaction_constraint()
  property session
  set_transaction_constraint(resource, resource_id, rev_number)

    Set a revision constraint to enforce before resource_id is changed.

    Parameters:

      - resource – Collection name of resource (e.g. ports or networks)

      - resource_id – The primary key ID of the individual resource that should have its revision number matched before allowing the transaction to proceed.

      - rev_number – The revision_number that the resource should be at.

class neutron_lib.context.ContextBase(user_id=None, project_id=None, is_admin=None, timestamp=None, project_name=None, user_name=None, is_advsvc=None, is_service_role=None, tenant_id=None, tenant_name=None, has_global_access=False, can_set_project_id=False, **kwargs)

  Bases: `RequestContext`

  Security context and request information.

  Represents the user taking a given action within the system.

  property can_set_project_id
  elevated()

    Return a version of this context with admin flag set.

  classmethod from_dict(values)

    Construct a context object from a provided dictionary.

  property has_global_access
  property is_advsvc
  property is_service_role
  property tenant_id
  property tenant_name
  to_dict()

    Return a dictionary of context attributes.

  to_policy_values()

    A dictionary of context attributes to enforce policy with.

    oslo.policy enforcement requires a dictionary of attributes representing the current logged in user on which it applies policy enforcement. This dictionary defines a standard list of attributes that should be available for enforcement across services.

    It is expected that services will often have to override this method with either deprecated values or additional attributes used by that service specific policy.

class neutron_lib.context.ContextBaseWithSession(user_id=None, project_id=None, is_admin=None, timestamp=None, project_name=None, user_name=None, is_advsvc=None, is_service_role=None, tenant_id=None, tenant_name=None, has_global_access=False, can_set_project_id=False, **kwargs)

  Bases: `ContextBase`

  property connection
  property session
  property transaction
  property transaction_ctx

neutron_lib.context.get_admin_context()

neutron_lib.context.get_admin_context_without_session()

this page last updated: 2026-03-26 12:58:28

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

found an error? report a bug