ironic.api.types module

class ironic.api.types.ArrayType(item_type)[source]

Bases: object

property item_type
sample()[source]
validate(value)[source]
class ironic.api.types.Base(**kw)[source]

Bases: object

Base type for complex types

class ironic.api.types.BaseMeta(name, bases, dct)[source]

Bases: type

class ironic.api.types.BinaryType[source]

Bases: ironic.api.types.UserType

A user type that use base64 strings to carry binary data.

basetype

alias of builtins.bytes

frombasetype(value)[source]
name = 'binary'
tobasetype(value)[source]
class ironic.api.types.DictType(key_type, value_type)[source]

Bases: object

sample()[source]
validate(value)[source]
property value_type
class ironic.api.types.Enum(basetype, *values, **kw)[source]

Bases: ironic.api.types.UserType

A simple enumeration type. Can be based on any non-complex type.

Parameters
  • basetype – The actual data type

  • values – A set of possible values

If nullable, ‘None’ should be added the values set.

Example:

Gender = Enum(str, 'male', 'female')
Specie = Enum(str, 'cat', 'dog')
frombasetype(value)[source]
tobasetype(value)[source]
validate(value)[source]
class ironic.api.types.IntegerType(minimum=None, maximum=None)[source]

Bases: ironic.api.types.UserType

A simple integer type. Can validate a value range.

Parameters
  • minimum – Possible minimum value

  • maximum – Possible maximum value

Example:

Price = IntegerType(minimum=1)
basetype

alias of builtins.int

static frombasetype(value)[source]
name = 'integer'
validate(value)[source]
class ironic.api.types.PassthruResponse(obj, status_code=None)[source]

Bases: object

Object to hold the “response” from a passthru call

obj

Store the result object from the view

status_code

Store an optional status_code

class ironic.api.types.Registry[source]

Bases: object

property complex_types
lookup(typename)[source]
register(class_)[source]

Make sure a type is registered.

It is automatically called by expose() and validate(). Unless you want to control when the class inspection is done there is no need to call it.

reregister(class_)[source]

Register a type which may already have been registered.

resolve_type(type_)[source]
class ironic.api.types.StringType(min_length=None, max_length=None, pattern=None)[source]

Bases: ironic.api.types.UserType

A simple string type. Can validate a length and a pattern.

Parameters
  • min_length – Possible minimum length

  • max_length – Possible maximum length

  • pattern – Possible string pattern

Example:

Name = StringType(min_length=1, pattern='^[a-zA-Z ]*$')
basetype

alias of builtins.str

name = 'string'
validate(value)[source]
class ironic.api.types.UnsetType[source]

Bases: object

class ironic.api.types.UserType[source]

Bases: object

basetype = None
frombasetype(value)[source]
name = None
tobasetype(value)[source]
validate(value)[source]
ironic.api.types.binary = <ironic.api.types.BinaryType object>

The binary almost-native type

ironic.api.types.inspect_class(class_)[source]

Extract a list of (name, wsattr|wsproperty) for the given class

ironic.api.types.iscomplex(datatype)[source]
ironic.api.types.isusertype(class_)[source]
ironic.api.types.iswsattr(attr)[source]
ironic.api.types.list_attributes(class_)[source]

Returns a list of a complex type attributes.

ironic.api.types.make_dataholder(class_)[source]
ironic.api.types.register_type(class_)[source]
ironic.api.types.sort_attributes(class_, attributes)[source]

Sort a class attributes list.

3 mechanisms are attempted :

  1. Look for a _wsme_attr_order attribute on the class. This allow to define an arbitrary order of the attributes (useful for generated types).

  2. Access the object source code to find the declaration order.

  3. Sort by alphabetically

ironic.api.types.validate_value(datatype, value)[source]
class ironic.api.types.wsattr(datatype, mandatory=False, name=None, default=Unset, readonly=False)[source]

Bases: object

Complex type attribute definition.

Example:

class MyComplexType(ctypes.Base):
    optionalvalue = int
    mandatoryvalue = wsattr(int, mandatory=True)
    named_value = wsattr(int, name='named.value')

After inspection, the non-wsattr attributes will be replaced, and the above class will be equivalent to:

class MyComplexType(ctypes.Base):
    optionalvalue = wsattr(int)
    mandatoryvalue = wsattr(int, mandatory=True)
property datatype

attribute data type. Can be either an actual type, or a type name, in which case the actual type will be determined when needed (generally just before scanning the api).

default

Default value. The attribute will return this instead of Unset if no value has been set.

key

The attribute name in the parent python class. Set by inspect_class()

mandatory

True if the attribute is mandatory

name

The attribute name on the public of the api. Defaults to key

readonly

If True value cannot be set from json/xml input data

class ironic.api.types.wsproperty(datatype, fget, fset=None, mandatory=False, doc=None, name=None)[source]

Bases: property

A specialised property to define typed-property on complex types.

Example:

class MyComplexType(Base):
    def get_aint(self):
        return self._aint

    def set_aint(self, value):
        assert avalue < 10  # Dummy input validation
        self._aint = value

    aint = wsproperty(int, get_aint, set_aint, mandatory=True)
datatype

property data type

key

The property name in the parent python class

mandatory

True if the property is mandatory

name

The attribute name on the public of the api. Defaults to key