The cinder.objects.base Module

Cinder common internal object model

class CinderObject(context=None, **kwargs)

Bases: object

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.

VERSION = '1.0'
fields = {}
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.

obj_extra_fields = []
obj_fields
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.

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.

:param:primitive: The result of self.obj_to_primitive() :param:target_version: The version string requested by the recipient of the object :raises: cinder.exception.UnsupportedObjectError if conversion is not possible for some reason

classmethod obj_name()

Return a canonical name for this object.

The canonical name will be used over the wire for remote hydration.

obj_relationships = {}
obj_reset_changes(fields=None)

Reset the list of fields that have been changed.

Note that this is NOT “revert to previous values”

obj_set_defaults(*attrs)
obj_to_primitive(target_version=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 CinderObjectDictCompat

Bases: object

Mix-in to provide dictionary key access compat

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.

NOTE(berrange) This class will eventually be deleted.

get(key, value=<class 'cinder.objects.base.NotSpecifiedSentinel'>)

For backwards-compatibility with dict-based objects.

NOTE(danms): May be removed in the future.

items()
iteritems()

For backwards-compatibility with dict-based objects.

NOTE(danms): May be removed in the future.

update(updates)

For backwards-compatibility with dict-base objects.

NOTE(danms): May be removed in the future.

class CinderObjectMetaclass(names, bases, dict_)

Bases: type

Metaclass that allows tracking of object classes.

indirection_api = None
class CinderObjectSerializer

Bases: oslo_messaging.serializer.NoOpSerializer

A CinderObject-aware Serializer.

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

deserialize_entity(context, entity)
serialize_entity(context, entity)
class CinderPersistentObject

Bases: object

Mixin class for Persistent objects. This adds the fields that we use in common for all persistent objects.

fields = {'deleted': Boolean(default=False,nullable=False), 'created_at': DateTime(default=<class 'cinder.objects.fields.UnspecifiedDefault'>,nullable=True), 'deleted_at': DateTime(default=<class 'cinder.objects.fields.UnspecifiedDefault'>,nullable=True), 'updated_at': DateTime(default=<class 'cinder.objects.fields.UnspecifiedDefault'>,nullable=True)}
obj_as_admin(*args, **kwds)

Context manager to make an object call as an admin.

This temporarily modifies the context embedded in an object to be elevated() and restores it after the call completes. Example usage:

with obj.obj_as_admin():
obj.save()
class NotSpecifiedSentinel

Bases: object

class ObjectListBase(*args, **kwargs)

Bases: object

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.

child_versions = {}
count(value)

List count of value occurrences.

fields = {'objects': List(default=<class 'cinder.objects.fields.UnspecifiedDefault'>,nullable=False)}
index(value)

List index of value.

obj_make_compatible(primitive, target_version)
obj_what_changed()
sort(cmp=None, key=None, reverse=False)
get_attrname(name)

Return the mangled name of the attribute’s underlying storage.

make_class_properties(cls)
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 contextr :param:list_obj: An ObjectListBase object :param:item_cls: The CinderObject 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

obj_to_primitive(obj)

Recursively turn an object into a python primitive.

A CinderObject becomes a dict, and anything that implements ObjectListBase becomes a list.

remotable(fn)

Decorator for remotable object methods.

remotable_classmethod(fn)

Decorator for remotable classmethods.

serialize_args(fn)

Decorator that will do the arguments serialization before remoting.

Previous topic

The cinder.manager Module

Next topic

The cinder.objects.fields Module

This Page