ironic_inspector.db.api module

DB models API for inspection data and shared database code.

ironic_inspector.db.api.add_node(uuid, state, started_at=None, finished_at=None, error=None, manage_boot=None)[source]

Add new node

Before creating new node with certain uuid clean ups all existing node info.

Parameters:
  • uuid – node uuid

  • state – initial node state

  • started_at – node caching datetime

  • finished_at – introspection finished datetime

  • error – introspection error

  • manage_boot – whether to manage boot for this node

Returns:

created node object

ironic_inspector.db.api.create_node(uuid, state, started_at=None, finished_at=None, error=None, manage_boot=None)[source]

Create new node

Parameters:
  • uuid – node uuid

  • state – initial node state

  • started_at – node caching datetime

  • finished_at – introspection finished datetime

  • error – introspection error

Returns:

created node object

ironic_inspector.db.api.create_rule(uuid, conditions, actions, description=None, scope=None)[source]

Create new rule

Parameters:
  • uuid – rule uuid

  • conditions – list of (field, op, multiple, invert, params) tuple, which represents condition object

  • actions – list of (action, params) pair, which represents action object

  • description – rule description

  • scope – rule scope

Returns:

created rule

ironic_inspector.db.api.delete_all_rules()[source]

Delete all rules

Returns:

None

ironic_inspector.db.api.delete_attributes(uuid)[source]

Delete all attributes

Parameters:

uuid – the UUID of the node whose attributes you wish tod elete

Returns:

None

ironic_inspector.db.api.delete_node(uuid)[source]

Delete node and its attributes

Parameters:

uuid – node uuid

Returns:

None

ironic_inspector.db.api.delete_nodes(finished_until=None)[source]

Delete all nodes

Parameters:

finished_until – datetime object, delete nodes are introspected before finished_until time

Returns:

None

ironic_inspector.db.api.delete_options(**filters)[source]

Delete all options

Parameters:

filters – deletion filter criteria

Returns:

None

ironic_inspector.db.api.delete_rule(uuid)[source]

Delete the rule by uuid

Parameters:

uuid – rule uuid

Raises:

RuleNotFoundError in case rule not found

Returns:

None

ironic_inspector.db.api.get_active_nodes(started_before=None)[source]

Get list of nodes on introspection

Parameters:

started_before – datetime object, returns nodes, started before provided time

Returns:

list of nodes, could be empty

ironic_inspector.db.api.get_attributes(order_by=None, **fields)[source]

Get all attributes

Parameters:
  • order_by – ordering criterion

  • fields – filter criteria fields

Returns:

list of attributes

ironic_inspector.db.api.get_introspection_data(node_id, processed=True)[source]

Get introspection data for this node.

Parameters:
  • node_id – node UUID.

  • processed – Specify the type of introspected data, set to False indicates retrieving the unprocessed data.

Returns:

A dictionary representation of intropsected data

ironic_inspector.db.api.get_node(uuid, **fields)[source]

Get all cached nodes

Parameters:
  • uuid – node uuid

  • fields – fields are used as filtering criterion

Returns:

get node object

Raises:

NodeNotFoundInDBError in case node not found or node version differ from passed in fields.

ironic_inspector.db.api.get_nodes()[source]

Get list of cached nodes

Returns:

list of nodes, could be empty

ironic_inspector.db.api.get_options(**fields)[source]

Get all options

Parameters:

fields – filter criteria fields

Returns:

list of options

ironic_inspector.db.api.get_rule(uuid)[source]

Get rule by uuid

Parameters:

uuid – rule uuid

Returns:

rule object

ironic_inspector.db.api.get_rules(**fields)[source]

List all rules.

ironic_inspector.db.api.get_rules_actions(**fields)[source]

Get all rule actions

Parameters:

fields – field filter criteria

Returns:

list of actions

ironic_inspector.db.api.get_rules_conditions(**fields)[source]

Get all rule conditions

Parameters:

fields – field filter criteria

Returns:

list of conditions

ironic_inspector.db.api.get_writer_session()[source]

Help method to get writer session.

Returns:

The writer session.

ironic_inspector.db.api.init()[source]

Initialize the database.

Method called on service start up, initialize transaction context manager and try to create db session.

ironic_inspector.db.api.list_nodes_by_attributes(attributes)[source]

Get list of nodes with certain attributes

Parameters:

attributes – list of attributes as (name, value) pair

Returns:

list of nodes, could be empty

ironic_inspector.db.api.list_nodes_options_by_uuid(uuid)[source]

Get list of node options

Parameters:

uuid – node uuid

Returns:

list of node options, could be empty

ironic_inspector.db.api.model_query(model, *args, **kwargs)[source]

Query helper for simpler session usage.

Parameters:

session – if present, the session to use

ironic_inspector.db.api.session_for_read()[source]

Create read session within context manager

ironic_inspector.db.api.session_for_write()[source]

Create write session within context manager

ironic_inspector.db.api.set_attribute(node_uuid, name, values)[source]

Set lookup attributes for node

Parameters:
  • node_uuid – node uuid

  • name – option name

  • values – list of attribute values

Returns:

None

ironic_inspector.db.api.set_option(node_uuid, name, value)[source]

Set option for node

Parameters:
  • node_uuid – node uuid

  • name – option name

  • value – option value

Returns:

None

ironic_inspector.db.api.store_introspection_data(node_id, introspection_data, processed=True)[source]

Store introspection data for this node.

Parameters:
  • node_id – node UUID.

  • introspection_data – A dictionary of introspection data

  • processed – Specify the type of introspected data, set to False indicates the data is unprocessed.

ironic_inspector.db.api.update_node(uuid, **values)[source]

Update node by uuid

Updates node fields with provided values, also bump node version.

Parameters:
  • uuid – node uuid

  • values – node fields with values to be updated

Raises:

NodeNotFoundInDBError in case node not found or node version differ from passed in values.