oslo_versionedobjects.fields

class oslo_versionedobjects.fields.AbstractFieldType
abstract coerce(obj: base.VersionedObject | None, attr: str, value: Any) T

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

abstract describe() str

Returns a string describing the type of the field.

abstract from_primitive(obj: base.VersionedObject, attr: str, value: object) T

This is called to deserialize a value.

This method should deserialize a value from the form given by to_primitive() to the designated type.

Param:obj:

The VersionedObject on which the value is to be set

Param:attr:

The name of the attribute which will hold the value

Param:value:

The serialized form of the value

Returns:

The natural form of the value

abstract stringify(value: T) str

Returns a short stringified version of a value.

abstract to_primitive(obj: base.VersionedObject, attr: str, value: T) object

This is called to serialize a value.

This method should serialize a value to the form expected by from_primitive().

Param:obj:

The VersionedObject on which the value is set

Param:attr:

The name of the attribute holding the value

Param:value:

The natural form of the value

Returns:

The serialized form of the value

class oslo_versionedobjects.fields.AutoTypedField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)

Base class for fields with automatic type detection.

class oslo_versionedobjects.fields.BaseEnumField(nullable: bool = False, default: str | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)

Base class for all enum field types

This class should not be directly instantiated. Instead subclass it and set AUTO_TYPE to be a SomeEnum() where SomeEnum is a subclass of Enum.

property valid_values: Collection[str]

Return the valid values for the field.

class oslo_versionedobjects.fields.Boolean
coerce(obj: base.VersionedObject | None, attr: str, value: Any) bool

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.BooleanField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.CoercedCollectionMixin(*args: Any, **kwargs: Any)
class oslo_versionedobjects.fields.CoercedDict(*args: Any, **kwargs: Any)

Dict which coerces its values

Dict implementation which overrides all element-adding methods and coercing the element(s) being added to the required element type

setdefault(key: str, default: Any = None) Any

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

class oslo_versionedobjects.fields.CoercedList(*args: Any, **kwargs: Any)

List which coerces its elements

List implementation which overrides all element-adding methods and coercing the element(s) being added to the required element type

append(x: Any) None

Append object to the end of the list.

extend(t: Any) None

Extend list by appending elements from the iterable.

insert(i: SupportsIndex, x: Any) None

Insert object before index.

class oslo_versionedobjects.fields.CoercedSet(*args: Any, **kwargs: Any)

Set which coerces its values

Set implementation which overrides all element-adding methods and coercing the element(s) being added to the required element type

add(value: Any) None

Add an element to a set.

This has no effect if the element is already present.

symmetric_difference_update(values: Iterable[Any]) None

Update a set with the symmetric difference of itself and another.

update(values: Iterable[Any]) None

Update a set with the union of itself and others.

class oslo_versionedobjects.fields.CompoundFieldType(element_type: FieldType[E], **field_args: Any)

Base class for compound field types like List, Dict, Set.

E is the element type stored in the container.

class oslo_versionedobjects.fields.DateTime(tzinfo_aware: bool = True, *args: Any, **kwargs: Any)
coerce(obj: base.VersionedObject | None, attr: str, value: Any) datetime.datetime

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

from_primitive(obj: base.VersionedObject, attr: str, value: Any) datetime.datetime

This is called to deserialize a value.

This method should deserialize a value from the form given by to_primitive() to the designated type.

Param:obj:

The VersionedObject on which the value is to be set

Param:attr:

The name of the attribute which will hold the value

Param:value:

The serialized form of the value

Returns:

The natural form of the value

stringify(value: datetime) str

Returns a short stringified version of a value.

to_primitive(obj: base.VersionedObject, attr: str, value: datetime.datetime) object

This is called to serialize a value.

This method should serialize a value to the form expected by from_primitive().

Param:obj:

The VersionedObject on which the value is set

Param:attr:

The name of the attribute holding the value

Param:value:

The natural form of the value

Returns:

The serialized form of the value

class oslo_versionedobjects.fields.DateTimeField(tzinfo_aware: bool = True, **kwargs: Any)
class oslo_versionedobjects.fields.Dict(element_type: FieldType[E], **field_args: Any)

A field type for dicts with string keys and values of type E.

coerce(obj: base.VersionedObject | None, attr: str, value: Any) dict[str, E]

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

from_primitive(obj: base.VersionedObject, attr: str, value: Any) dict[str, E]

This is called to deserialize a value.

This method should deserialize a value from the form given by to_primitive() to the designated type.

Param:obj:

The VersionedObject on which the value is to be set

Param:attr:

The name of the attribute which will hold the value

Param:value:

The serialized form of the value

Returns:

The natural form of the value

stringify(value: dict[str, E]) str

Returns a short stringified version of a value.

to_primitive(obj: base.VersionedObject, attr: str, value: dict[str, E]) dict[str, object]

This is called to serialize a value.

This method should serialize a value to the form expected by from_primitive().

Param:obj:

The VersionedObject on which the value is set

Param:attr:

The name of the attribute holding the value

Param:value:

The natural form of the value

Returns:

The serialized form of the value

class oslo_versionedobjects.fields.DictOfIntegersField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.DictOfListOfStringsField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.DictOfNullableStringsField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.DictOfStringsField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.DictProxyField(dict_field_name: str, key_type: type = <class 'int'>)

Descriptor allowing us to assign pinning data as a dict of key_types

This allows us to have an object field that will be a dict of key_type keys, allowing that will convert back to string-keyed dict.

This will take care of the conversion while the dict field will make sure that we store the raw json-serializable data on the object.

key_type should return a type that unambiguously responds to str so that calling key_type on it yields the same thing.

exception oslo_versionedobjects.fields.ElementTypeError(expected: str, key: Any, value: Any)
class oslo_versionedobjects.fields.Enum(valid_values: Collection[str])
coerce(obj: base.VersionedObject | None, attr: str, value: Any) str

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

stringify(value: str) str

Returns a short stringified version of a value.

class oslo_versionedobjects.fields.EnumField(valid_values: Collection[Any], **kwargs: Any)

Anonymous enum field type

This class allows for anonymous enum types to be declared, simply by passing in a list of valid values to its constructor. It is generally preferable though, to create an explicit named enum type by sub-classing the BaseEnumField type directly.

class oslo_versionedobjects.fields.Field(field_type: ~oslo_versionedobjects.fields.FieldType[~oslo_versionedobjects.fields.T], nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
coerce(obj: base.VersionedObject | None, attr: str, value: Any) T | None

Coerce a value to a suitable type.

This is called any time you set a value on an object, like:

foo.myint = 1

and is responsible for making sure that the value (1 here) is of the proper type, or can be sanely converted.

This also handles the potentially nullable or defaultable nature of the field and calls the coerce() method on a FieldType to actually do the coercion.

Param:obj:

The object being acted upon

Param:attr:

The name of the attribute/field being set

Param:value:

The value being set

Returns:

The properly-typed value

describe() str

Return a short string describing the type of this field.

from_primitive(obj: base.VersionedObject, attr: str, value: None) None
from_primitive(obj: base.VersionedObject, attr: str, value: object) T

Deserialize a value from primitive form.

This is responsible for deserializing a value from primitive into regular form. It calls the from_primitive() method on a FieldType to do the actual deserialization.

Param:obj:

The object being acted upon

Param:attr:

The name of the attribute/field being deserialized

Param:value:

The value to be deserialized

Returns:

The deserialized value

to_primitive(obj: base.VersionedObject, attr: str, value: T) object

Serialize a value to primitive form.

This is responsible for serializing a value to primitive form. It calls to_primitive() on a FieldType to do the actual serialization.

Param:obj:

The object being acted upon

Param:attr:

The name of the attribute/field being serialized

Param:value:

The value to be serialized

Returns:

The serialized value

class oslo_versionedobjects.fields.FieldType
coerce(obj: base.VersionedObject | None, attr: str, value: Any) T

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

describe() str

Returns a string describing the type of the field.

from_primitive(obj: base.VersionedObject, attr: str, value: object) T

This is called to deserialize a value.

This method should deserialize a value from the form given by to_primitive() to the designated type.

Param:obj:

The VersionedObject on which the value is to be set

Param:attr:

The name of the attribute which will hold the value

Param:value:

The serialized form of the value

Returns:

The natural form of the value

stringify(value: T) str

Returns a short stringified version of a value.

to_primitive(obj: base.VersionedObject, attr: str, value: T) object

This is called to serialize a value.

This method should serialize a value to the form expected by from_primitive().

Param:obj:

The VersionedObject on which the value is set

Param:attr:

The name of the attribute holding the value

Param:value:

The natural form of the value

Returns:

The serialized form of the value

class oslo_versionedobjects.fields.FlexibleBoolean
coerce(obj: base.VersionedObject | None, attr: str, value: Any) bool

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.FlexibleBooleanField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.Float
coerce(obj: base.VersionedObject | None, attr: str, value: Any) float

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.FloatField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.IPAddress
coerce(obj: base.VersionedObject | None, attr: str, value: Any) netaddr.IPAddress

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

from_primitive(obj: base.VersionedObject, attr: str, value: object) netaddr.IPAddress

This is called to deserialize a value.

This method should deserialize a value from the form given by to_primitive() to the designated type.

Param:obj:

The VersionedObject on which the value is to be set

Param:attr:

The name of the attribute which will hold the value

Param:value:

The serialized form of the value

Returns:

The natural form of the value

to_primitive(obj: base.VersionedObject, attr: str, value: T) object

This is called to serialize a value.

This method should serialize a value to the form expected by from_primitive().

Param:obj:

The VersionedObject on which the value is set

Param:attr:

The name of the attribute holding the value

Param:value:

The natural form of the value

Returns:

The serialized form of the value

class oslo_versionedobjects.fields.IPAddressField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.IPNetwork
coerce(obj: base.VersionedObject | None, attr: str, value: Any) netaddr.IPNetwork

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

from_primitive(obj: base.VersionedObject, attr: str, value: object) netaddr.IPNetwork

This is called to deserialize a value.

This method should deserialize a value from the form given by to_primitive() to the designated type.

Param:obj:

The VersionedObject on which the value is to be set

Param:attr:

The name of the attribute which will hold the value

Param:value:

The serialized form of the value

Returns:

The natural form of the value

to_primitive(obj: base.VersionedObject, attr: str, value: T) object

This is called to serialize a value.

This method should serialize a value to the form expected by from_primitive().

Param:obj:

The VersionedObject on which the value is set

Param:attr:

The name of the attribute holding the value

Param:value:

The natural form of the value

Returns:

The serialized form of the value

class oslo_versionedobjects.fields.IPNetworkField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.IPV4Address
coerce(obj: base.VersionedObject | None, attr: str, value: Any) netaddr.IPAddress

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.IPV4AddressField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.IPV4AndV6Address
coerce(obj: base.VersionedObject | None, attr: str, value: Any) netaddr.IPAddress

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.IPV4AndV6AddressField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.IPV4Network
coerce(obj: base.VersionedObject | None, attr: str, value: Any) netaddr.IPNetwork

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.IPV4NetworkField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.IPV6Address
coerce(obj: base.VersionedObject | None, attr: str, value: Any) netaddr.IPAddress

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.IPV6AddressField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.IPV6Network(*args: Any, **kwargs: Any)
coerce(obj: base.VersionedObject | None, attr: str, value: Any) netaddr.IPNetwork

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.IPV6NetworkField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.Integer
coerce(obj: base.VersionedObject | None, attr: str, value: Any) int

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.IntegerField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
exception oslo_versionedobjects.fields.KeyTypeError(expected: type, value: Any)
class oslo_versionedobjects.fields.List(element_type: FieldType[E], **field_args: Any)

A field type for lists of elements of type E.

coerce(obj: base.VersionedObject | None, attr: str, value: Any) list[E]

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

from_primitive(obj: base.VersionedObject, attr: str, value: Any) list[E]

This is called to deserialize a value.

This method should deserialize a value from the form given by to_primitive() to the designated type.

Param:obj:

The VersionedObject on which the value is to be set

Param:attr:

The name of the attribute which will hold the value

Param:value:

The serialized form of the value

Returns:

The natural form of the value

stringify(value: list[E]) str

Returns a short stringified version of a value.

to_primitive(obj: base.VersionedObject, attr: str, value: list[E]) list[object]

This is called to serialize a value.

This method should serialize a value to the form expected by from_primitive().

Param:obj:

The VersionedObject on which the value is set

Param:attr:

The name of the attribute holding the value

Param:value:

The natural form of the value

Returns:

The serialized form of the value

class oslo_versionedobjects.fields.ListOfDictOfNullableStringsField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.ListOfEnumField(valid_values: list[str], **kwargs: Any)
class oslo_versionedobjects.fields.ListOfIntegersField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.ListOfObjectsField(objtype: str, subclasses: bool = False, **kwargs: Any)
class oslo_versionedobjects.fields.ListOfSetsOfIntegersField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.ListOfStringsField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.ListOfUUIDField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.MACAddress
coerce(obj: base.VersionedObject | None, attr: str, value: Any) str

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.MACAddressField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.NonNegativeFloat
coerce(obj: base.VersionedObject | None, attr: str, value: Any) float

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.NonNegativeFloatField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.NonNegativeInteger
coerce(obj: base.VersionedObject | None, attr: str, value: Any) int

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.NonNegativeIntegerField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.Object(obj_name: str, subclasses: bool = False, **kwargs: Any)
coerce(obj: base.VersionedObject | None, attr: str, value: Any) base.VersionedObject

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

describe() str

Returns a string describing the type of the field.

from_primitive(obj: base.VersionedObject, attr: str, value: Any) base.VersionedObject

This is called to deserialize a value.

This method should deserialize a value from the form given by to_primitive() to the designated type.

Param:obj:

The VersionedObject on which the value is to be set

Param:attr:

The name of the attribute which will hold the value

Param:value:

The serialized form of the value

Returns:

The natural form of the value

stringify(value: base.VersionedObject) str

Returns a short stringified version of a value.

to_primitive(obj: base.VersionedObject, attr: str, value: base.VersionedObject) object

This is called to serialize a value.

This method should serialize a value to the form expected by from_primitive().

Param:obj:

The VersionedObject on which the value is set

Param:attr:

The name of the attribute holding the value

Param:value:

The natural form of the value

Returns:

The serialized form of the value

class oslo_versionedobjects.fields.ObjectField(objtype: str, subclasses: bool = False, **kwargs: Any)
class oslo_versionedobjects.fields.PCIAddress
coerce(obj: base.VersionedObject | None, attr: str, value: Any) str

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.PCIAddressField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.SensitiveString

A string field type that may contain sensitive (password) information.

Passwords in the string value are masked when stringified.

stringify(value: str) str

Returns a short stringified version of a value.

class oslo_versionedobjects.fields.SensitiveStringField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)

Field type that masks passwords when the field is stringified.

class oslo_versionedobjects.fields.Set(element_type: FieldType[E], **field_args: Any)

A field type for sets of elements of type E.

coerce(obj: base.VersionedObject | None, attr: str, value: Any) set[E]

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

from_primitive(obj: base.VersionedObject, attr: str, value: Any) set[E]

This is called to deserialize a value.

This method should deserialize a value from the form given by to_primitive() to the designated type.

Param:obj:

The VersionedObject on which the value is to be set

Param:attr:

The name of the attribute which will hold the value

Param:value:

The serialized form of the value

Returns:

The natural form of the value

stringify(value: set[E]) str

Returns a short stringified version of a value.

to_primitive(obj: base.VersionedObject, attr: str, value: set[E]) tuple[object, ...]

This is called to serialize a value.

This method should serialize a value to the form expected by from_primitive().

Param:obj:

The VersionedObject on which the value is set

Param:attr:

The name of the attribute holding the value

Param:value:

The natural form of the value

Returns:

The serialized form of the value

class oslo_versionedobjects.fields.SetOfIntegersField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.StateMachine(valid_values: Collection[Any], **kwargs: Any)

A mixin that can be applied to an EnumField to enforce a state machine

e.g: Setting the code below on a field will ensure an object cannot transition from ERROR to ACTIVE

Example:
class FakeStateMachineField(fields.EnumField, fields.StateMachine):
    ACTIVE = 'ACTIVE'
    PENDING = 'PENDING'
    ERROR = 'ERROR'
    DELETED = 'DELETED'

    ALLOWED_TRANSITIONS = {
        ACTIVE: {
            PENDING,
            ERROR,
            DELETED,
        },
        PENDING: {ACTIVE, ERROR},
        ERROR: {
            PENDING,
        },
        DELETED: {},  # This is a terminal state
    }

    _TYPES = (ACTIVE, PENDING, ERROR, DELETED)

    def __init__(self, **kwargs):
        super(FakeStateMachineField, self).__init__(
            self._TYPES, **kwargs
        )
coerce(obj: base.VersionedObject | None, attr: str, value: Any) str

Coerce a value to a suitable type.

This is called any time you set a value on an object, like:

foo.myint = 1

and is responsible for making sure that the value (1 here) is of the proper type, or can be sanely converted.

This also handles the potentially nullable or defaultable nature of the field and calls the coerce() method on a FieldType to actually do the coercion.

Param:obj:

The object being acted upon

Param:attr:

The name of the attribute/field being set

Param:value:

The value being set

Returns:

The properly-typed value

class oslo_versionedobjects.fields.String
coerce(obj: base.VersionedObject | None, attr: str, value: Any) str

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

stringify(value: str) str

Returns a short stringified version of a value.

class oslo_versionedobjects.fields.StringField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)
class oslo_versionedobjects.fields.StringPattern
class oslo_versionedobjects.fields.UUID
coerce(obj: base.VersionedObject | None, attr: str, value: Any) str

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.UUIDField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)

UUID Field Type

Warning

This class does not actually validate UUIDs. This will happen in a future major version of oslo.versionedobjects

To validate that you have valid UUIDs you need to do the following in your own objects/fields.py

Example:
import oslo_versionedobjects.fields as ovo_fields


class UUID(ovo_fields.UUID):
    def coerce(self, obj, attr, value):
        uuid.UUID(value)
        return str(value)


class UUIDField(ovo_fields.AutoTypedField):
    AUTO_TYPE = UUID()

and then in your objects use <your_projects>.object.fields.UUIDField.

This will become default behaviour in the future.

class oslo_versionedobjects.fields.VersionPredicate
coerce(obj: base.VersionedObject | None, attr: str, value: Any) str

This is called to coerce (if possible) a value on assignment.

This method should convert the value given into the designated type, or throw an exception if this is not possible.

Param:obj:

The VersionedObject on which an attribute is being set

Param:attr:

The name of the attribute being set

Param:value:

The value being set

Returns:

A properly-typed value

class oslo_versionedobjects.fields.VersionPredicateField(nullable: bool = False, default: ~oslo_versionedobjects.fields.T | type[~oslo_versionedobjects.fields.UnspecifiedDefault] = <class 'oslo_versionedobjects.fields.UnspecifiedDefault'>, read_only: bool = False)