ironic.common.args module

ironic.common.args.and_valid(*validators)[source]

Validates that every supplied validator passes

The value returned from each validator is passed as the value to the next one.

Parameters
  • name – Name of the argument

  • value – A value

Returns

The value transformed through every supplied validator

Raises

The error from the first failed validator

ironic.common.args.boolean(name, value)[source]

Validate that the value is a string representing a boolean

Parameters
  • name – Name of the argument

  • value – A string value

Returns

The boolean representation of the value, or None if value is None

Raises

InvalidParameterValue if the value cannot be converted to a boolean

ironic.common.args.dict_valid(**validators)[source]

Return a validator function which validates dict fields

Validators will replace the value with the validation result. Any dict item which has no validator is ignored. When a key is missing in the value then the corresponding validator will not be run.

Param

validators dict where the key is a dict key to validate and the value is a validator function to run on that value

Returns

validator function which takes name and value arguments

ironic.common.args.integer(name, value)[source]

Validate that the value represents an integer

Parameters
  • name – Name of the argument

  • value – A value representing an integer

Returns

The value as an int, or None if value is None

Raises

InvalidParameterValue if the value does not represent an integer

ironic.common.args.mac_address(name, value)[source]

Validate that the value represents a MAC address

Parameters
  • name – Name of the argument

  • value – A string value representing a MAC address

Returns

The value as a normalized MAC address, or None if value is None

Raises

InvalidParameterValue if the value is not a valid MAC address

ironic.common.args.name(name, value)[source]

Validate that the value is a logical name

Parameters
  • name – Name of the argument

  • value – A logical name string value

Returns

The value, or None if value is None

Raises

InvalidParameterValue if the value is not a valid logical name

ironic.common.args.or_valid(*validators)[source]

Validates if at least one supplied validator passes

Parameters
  • name – Name of the argument

  • value – A value

Returns

The value returned from the first successful validator

Raises

The error from the last validator when every validation fails

ironic.common.args.patch(name, value, *, schema={'items': {'additionalProperties': False, 'properties': {'op': {'enum': ['add', 'replace', 'remove'], 'type': 'string'}, 'path': {'pattern': '^(/[\\w-]+)+$', 'type': 'string'}, 'value': {}}, 'required': ['op', 'path'], 'type': 'object'}, 'type': 'array'})

Validate a patch API operation

ironic.common.args.schema(schema)[source]

Return a validator function which validates the value with jsonschema

Param

schema dict representing jsonschema to validate with

Returns

validator function which takes name and value arguments

ironic.common.args.string(name, value)[source]

Validate that the value is a string

Parameters
  • name – Name of the argument

  • value – A string value

Returns

The string value, or None if value is None

Raises

InvalidParameterValue if the value is not a string

ironic.common.args.string_list(name, value)[source]

Validate and convert comma delimited string to a list.

Parameters
  • name – Name of the argument

  • value – A comma separated string of values

Returns

A list of unique values (lower-cased), maintaining the same order, or None if value is None

Raises

InvalidParameterValue if the value is not a string

ironic.common.args.types(*types)[source]

Return a validator function which checks the value is one of the types

Param

types one or more types to use for the isinstance test

Returns

validator function which takes name and value arguments

ironic.common.args.uuid(name, value)[source]

Validate that the value is a UUID

Parameters
  • name – Name of the argument

  • value – A UUID string value

Returns

The value, or None if value is None

Raises

InvalidParameterValue if the value is not a valid UUID

ironic.common.args.uuid_or_name(name, value)[source]

Validate that the value is a UUID or logical name

Parameters
  • name – Name of the argument

  • value – A UUID or logical name string value

Returns

The value, or None if value is None

Raises

InvalidParameterValue if the value is not a valid UUID or logical name

ironic.common.args.validate(*args, **kwargs)[source]

Decorator which validates and transforms function arguments