base

Common internal object model

class oslo_versionedobjects.base.ComparableVersionedObject

Mix-in to provide comparison methods

When objects are to be compared with each other (in tests for example), this mixin can be used.

class oslo_versionedobjects.base.ObjectListBase(*args, **kwargs)

Mixin class for lists of objects.

This mixin class can be added as a base class for an object that is implementing a list of objects. It adds a single field of ‘objects’, which is the list store, and behaves like a list itself. It supports serialization of the list of objects automatically.

class oslo_versionedobjects.base.VersionedObject(context=None, **kwargs)

Base class and object factory.

This forms the base of all objects that can be remoted or instantiated via RPC. Simply defining a class that inherits from this base class will make it remotely instantiatable. Objects should implement the necessary “get” classmethod routines as well as “save” object methods as appropriate.

obj_attr_is_set(attrname)

Test object to see if attrname is present.

Returns True if the named attribute has a value set, or False if not. Raises AttributeError if attrname is not a valid attribute for this object.

classmethod obj_class_from_name(objname, objver)

Returns a class from the registry based on a name and version.

obj_clone()

Create a copy.

classmethod obj_from_primitive(primitive, context=None)

Object field-by-field hydration.

obj_get_changes()

Returns a dict of changed fields and their new values.

obj_load_attr(attrname)

Load an additional attribute from the real object.

This should load self.$attrname and cache any data that might be useful for future load operations.

obj_make_compatible(primitive, target_version)

Make an object representation compatible with a target version.

This is responsible for taking the primitive representation of an object and making it suitable for the given target_version. This may mean converting the format of object attributes, removing attributes that have been added since the target version, etc. In general:

  • If a new version of an object adds a field, this routine should remove it for older versions.
  • If a new version changed or restricted the format of a field, this should convert it back to something a client knowing only of the older version will tolerate.
  • If an object that this object depends on is bumped, then this object should also take a version bump. Then, this routine should backlevel the dependent object (by calling its obj_make_compatible()) if the requested version of this object is older than the version where the new dependent object was added.
Parameters:
  • primitive – The result of obj_to_primitive()
  • target_version – The version string requested by the recipient of the object
Raises:

oslo_versionedobjects.exception.UnsupportedObjectError if conversion is not possible for some reason

classmethod obj_name()

Return the object’s name

Return a canonical name for this object which will be used over the wire for remote hydration.

obj_reset_changes(fields=None, recursive=False)

Reset the list of fields that have been changed.

Parameters:
  • fields – List of fields to reset, or “all” if None.
  • recursive – Call obj_reset_changes(recursive=True) on any sub-objects within the list of fields being reset.

This is NOT “revert to previous values”.

Specifying fields on recursive resets will only be honored at the top level. Everything below the top will reset all.

obj_to_primitive(target_version=None, version_manifest=None)

Simple base-case dehydration.

This calls to_primitive() for each item in fields.

obj_what_changed()

Returns a set of fields that have been modified.

save(context)

Save the changed fields back to the store.

This is optional for subclasses, but is presented here in the base class for consistency among those that do.

class oslo_versionedobjects.base.VersionedObjectDictCompat

Mix-in to provide dictionary key access compatibility

If an object needs to support attribute access using dictionary items instead of object attributes, inherit from this class. This should only be used as a temporary measure until all callers are converted to use modern attribute access.

class oslo_versionedobjects.base.VersionedObjectSerializer

A VersionedObject-aware Serializer.

This implements the Oslo Serializer interface and provides the ability to serialize and deserialize VersionedObject entities. Any service that needs to accept or return VersionedObjects as arguments or result values should pass this to its RPCClient and RPCServer objects.

OBJ_BASE_CLASS

alias of VersionedObject

oslo_versionedobjects.base.obj_make_list(context, list_obj, item_cls, db_list, **extra_args)

Construct an object list from a list of primitives.

This calls item_cls._from_db_object() on each item of db_list, and adds the resulting object to list_obj.

:param:context: Request context :param:list_obj: An ObjectListBase object :param:item_cls: The VersionedObject class of the objects within the list :param:db_list: The list of primitives to convert to objects :param:extra_args: Extra arguments to pass to _from_db_object() :returns: list_obj

oslo_versionedobjects.base.obj_tree_get_versions(objname, tree=None)

Construct a mapping of dependent object versions.

This method builds a list of dependent object versions given a top- level object with other objects as fields. It walks the tree recursively to determine all the objects (by symbolic name) that could be contained within the top-level object, and the maximum versions of each. The result is a dict like:

{‘MyObject’: ‘1.23’, ... }
Parameters:
  • objname – The top-level object at which to start
  • tree – Used internally, pass None here.
Returns:

A dictionary of object names and versions

oslo_versionedobjects.base.remotable(fn)

Decorator for remotable object methods.

oslo_versionedobjects.base.remotable_classmethod(fn)

Decorator for remotable classmethods.