The ironic.objects.base Module

The ironic.objects.base Module

Ironic common internal object model

class ironic.objects.base.IronicObject(context=None, **kwargs)[source]

Bases: oslo_versionedobjects.base.VersionedObject

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.

as_dict()[source]

Return the object represented as a dict.

The returned object is JSON-serialisable.

convert_to_version(target_version, remove_unavailable_fields=True)[source]

Convert this object to the target version.

Convert the object to the target version. The target version may be the same, older, or newer than the version of the object. This is used for DB interactions as well as for serialization/deserialization.

The remove_unavailable_fields flag is used to distinguish these two cases:

  1. For serialization/deserialization, we need to remove the unavailable fields, because the service receiving the object may not know about these fields. remove_unavailable_fields is set to True in this case.
  2. For DB interactions, we need to set the unavailable fields to their appropriate values so that these fields are saved in the DB. (If they are not set, the VersionedObject magic will not know to save/update them to the DB.) remove_unavailable_fields is set to False in this case.

_convert_to_version() does the actual work.

Parameters:
  • target_version – the desired version of the object
  • remove_unavailable_fields – True to remove fields that are unavailable in the target version; set this to True when (de)serializing. False to set the unavailable fields to appropriate values; set this to False for DB interactions.
do_version_changes_for_db()[source]

Change the object to the version needed for the database.

If needed, this changes the object (modifies object fields) to be in the correct version for saving to the database.

The version used to save the object in the DB is determined as follows:

  • If the object is pinned, we save the object in the pinned version. Since it is pinned, we must not save in a newer version, in case a rolling upgrade is happening and some services are still using the older version of ironic, with no knowledge of this newer version.
  • If the object isn’t pinned, we save the object in the latest version.

Because the object may be converted to a different object version, this method must only be called just before saving the object to the DB.

Returns:a dictionary of changed fields and their new values (could be an empty dictionary). These are the fields/values of the object that would be saved to the DB.
classmethod get_target_version()[source]

Returns the target version for this object.

This is the version in which the object should be manipulated, e.g. sent over the wire via RPC or saved in the DB.

Returns:if pinned, returns the version of this object corresponding to the pin. Otherwise, returns the version of the object.
Raises:ovo_exception.IncompatibleObjectVersion
obj_refresh(loaded_object)[source]

Applies updates for objects that inherit from base.IronicObject.

Checks for updated attributes in an object. Updates are applied from the loaded object column by column in comparison with the current object.

classmethod supports_version(version)[source]

Return whether this object supports a particular version.

Check the requested version against the object’s target version. The target version may not be the latest version during an upgrade, when object versions are pinned.

Parameters:version – A tuple representing the version to check
Returns:Whether the version is supported
Raises:ovo_exception.IncompatibleObjectVersion
class ironic.objects.base.IronicObjectListBase(*args, **kwargs)[source]

Bases: oslo_versionedobjects.base.ObjectListBase

as_dict()[source]

Return the object represented as a dict.

The returned object is JSON-serialisable.

class ironic.objects.base.IronicObjectRegistry[source]

Bases: oslo_versionedobjects.base.VersionedObjectRegistry

registration_hook(cls, index)[source]
class ironic.objects.base.IronicObjectSerializer(is_server=False)[source]

Bases: oslo_versionedobjects.base.VersionedObjectSerializer

OBJ_BASE_CLASS

alias of IronicObject

serialize_entity(context, entity)[source]

Serialize the entity.

This serializes the entity so that it can be sent over e.g. RPC. A serialized entity for an IronicObject is a dictionary with keys: ‘ironic_object.namespace’, ‘ironic_object.data’, ‘ironic_object.name’, ‘ironic_object.version’, and ‘ironic_object.changes’.

We assume that the client (ironic-API) is always talking to a server (ironic-conductor) that is running the same or a newer release than the client. The client doesn’t need to downgrade any IronicObjects when sending them over RPC. The server, on the other hand, will need to do so if the server is pinned and the target version of an IronicObject is older than the latest version of that Object.

(Internally, the services deal with the latest versions of objects so we know that these objects are always in the latest versions.)

Parameters:
  • context – security context
  • entity – the entity to be serialized; may be an IronicObject
Returns:

the serialized entity

Raises:

ovo_exception.IncompatibleObjectVersion (via .get_target_version())

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.