ironic_inspector.node_cache module

Cache for nodes currently under introspection.

class ironic_inspector.node_cache.NodeInfo(uuid, version_id=None, state=None, started_at=None, finished_at=None, error=None, node=None, ports=None, ironic=None, manage_boot=True)[source]

Bases: object

Record about a node in the cache.

This class optionally allows to acquire a lock on a node. Note that the class instance itself is NOT thread-safe, you need to create a new instance for every thread.

acquire_lock(blocking=True)[source]

Acquire a lock on the associated node.

Exits with success if a lock is already acquired using this NodeInfo object.

Parameters:

blocking – if True, wait for lock to be acquired, otherwise return immediately.

Returns:

boolean value, whether lock was acquired successfully

add_attribute(name, value)[source]

Store look up attribute for a node in the database.

Parameters:
  • name – attribute name

  • value – attribute value or list of possible values

add_trait(trait, ironic=None)[source]

Add a trait to the node.

Parameters:
  • trait – trait to add

  • ironic – Ironic client to use instead of self.ironic

property attributes

Node look up attributes as a dict.

commit()[source]

Commit current node status into the database.

create_ports(ports, ironic=None)[source]

Create one or several ports for this node.

Parameters:
  • ports – List of ports with all their attributes e.g [{‘mac’: xx, ‘ip’: xx, ‘client_id’: None}, {‘mac’: xx, ‘ip’: None, ‘client_id’: None}] It also support the old style of list of macs. A warning is issued if port already exists on a node.

  • ironic – Ironic client to use instead of self.ironic

delete_port(port, ironic=None)[source]

Delete port.

Parameters:
  • port – port object or its MAC

  • ironic – Ironic client to use instead of self.ironic

finished(event, error=None)[source]

Record status for this node and process a terminal transition.

Also deletes look up attributes from the cache.

Parameters:
  • event – the event to process

  • error – error message

classmethod from_row(row, ironic=None, node=None)[source]

Construct NodeInfo from a database row.

fsm_event(event, strict=False)[source]

Update node_info.state based on a fsm.process_event(event) call.

An AutomatonException triggers an error event. If strict, node_info.finished(istate.Events.error, error=str(exc)) is called with the AutomatonException instance and a EventError raised.

Parameters:

event – an event to process by the fsm

Strict:

whether to fail the introspection upon an invalid event

Raises:

NodeStateInvalidEvent

get_by_path(path)[source]

Get field value by ironic-style path (e.g. /extra/foo).

Parameters:

path – path to a field

Returns:

field value

Raises:

KeyError if field was not found

invalidate_cache()[source]

Clear all cached info, so that it’s reloaded next time.

property ironic

Ironic client instance.

property manage_boot

Whether to manage boot for this node.

node(ironic=None)[source]

Get Ironic node object associated with the cached node record.

property options

Node introspection options as a dict.

patch(patches, ironic=None, **kwargs)[source]

Apply JSON patches to a node.

Refreshes cached node instance.

Parameters:
  • patches – JSON patches to apply

  • ironic – Ironic client to use instead of self.ironic

  • kwargs – Arguments to pass to ironicclient.

Raises:

openstacksdk exceptions

patch_port(port, patches, ironic=None)[source]

Apply JSON patches to a port.

Parameters:
  • port – port object or its MAC

  • patches – JSON patches to apply

  • ironic – Ironic client to use instead of self.ironic

ports(ironic=None)[source]

Get Ironic port objects associated with the cached node record.

This value is cached as well, use invalidate_cache() to clean.

Returns:

dict MAC -> port object

release_lock()[source]

Release a lock on a node.

Does nothing if lock was not acquired using this NodeInfo object.

remove_trait(trait, ironic=None)[source]

Remove a trait from the node.

Parameters:
  • trait – trait to add

  • ironic – Ironic client to use instead of self.ironic

replace_field(path, func, **kwargs)[source]

Replace a field on ironic node.

Parameters:
  • path – path to a field as used by the ironic client

  • func – function accepting an old value and returning a new one

  • kwargs – if ‘default’ value is passed here, it will be used when no existing value is found.

Raises:

KeyError if value is not found and default is not set

Raises:

everything that patch() may raise

set_option(name, value)[source]

Set an option for a node.

property state

State of the node_info object.

update_capabilities(ironic=None, **caps)[source]

Update capabilities on a node.

Parameters:
  • caps – capabilities to update

  • ironic – Ironic client to use instead of self.ironic

update_properties(ironic=None, **props)[source]

Update properties on a node.

Parameters:
  • props – properties to update

  • ironic – Ironic client to use instead of self.ironic

property version_id

Deprecated - Get the version id

ironic_inspector.node_cache.active_macs()[source]

List all MAC’s that are on introspection right now.

ironic_inspector.node_cache.add_node(uuid, state, manage_boot=True, **attributes)[source]

Store information about a node under introspection.

All existing information about this node is dropped. Empty values are skipped.

Parameters:
  • uuid – Ironic node UUID

  • state – The initial state of the node

  • manage_boot – whether to manage boot for this node

  • attributes – attributes known about this node (like macs, BMC etc); also ironic client instance may be passed under ‘ironic’

Returns:

NodeInfo

ironic_inspector.node_cache.clean_up()[source]

Clean up the cache.

Finish introspection for timed out nodes.

Returns:

list of timed out node UUID’s

ironic_inspector.node_cache.create_node(driver, ironic=None, **attributes)[source]

Create ironic node and cache it.

  • Create new node in ironic.

  • Cache it in inspector.

  • Sets node_info state to enrolling.

Parameters:
  • driver – driver for Ironic node.

  • ironic – ironic client instance.

  • attributes – dict, additional keyword arguments to pass to the ironic client on node creation.

Returns:

NodeInfo, or None in case error happened.

ironic_inspector.node_cache.delete_nodes_not_in_list(uuids)[source]

Delete nodes which don’t exist in Ironic node UUIDs.

Parameters:

uuids – Ironic node UUIDs

ironic_inspector.node_cache.find_node(**attributes)[source]

Find node in cache.

Looks up a node based on attributes in a best-match fashion. This function acquires a lock on a node.

Parameters:

attributes – attributes known about this node (like macs, BMC etc) also ironic client instance may be passed under ‘ironic’

Returns:

structure NodeInfo with attributes uuid and created_at

Raises:

Error if node is not found or multiple nodes match the attributes

ironic_inspector.node_cache.fsm_event_after(event, strict=False)[source]

Trigger an fsm event after the function execution.

It is assumed the first function arg of the decorated function is always a NodeInfo instance.

Parameters:
  • event – the event to process after the function call

  • strict – make an invalid fsm event trigger an error event

ironic_inspector.node_cache.fsm_event_before(event, strict=False)[source]

Trigger an fsm event before the function execution.

It is assumed the first function arg of the decorated function is always a NodeInfo instance.

Parameters:
  • event – the event to process before the function call

  • strict – make an invalid fsm event trigger an error event

ironic_inspector.node_cache.fsm_transition(event, reentrant=True, **exc_kwargs)[source]

Decorate a function to perform a (non-)reentrant transition.

If True, reentrant transition will be performed at the end of a function call. If False, the transition will be performed before the function call. The function is decorated with the triggers_fsm_error_transition decorator as well.

Parameters:
  • event – the event to bind the transition to.

  • reentrant – whether the transition is reentrant.

  • exc_kwargs – passed on to the triggers_fsm_error_transition decorator

ironic_inspector.node_cache.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.node_cache.get_node(node_id, ironic=None)[source]

Get node from cache.

Parameters:
  • node_id – node UUID or name.

  • ironic – optional ironic client instance

Returns:

structure NodeInfo.

ironic_inspector.node_cache.get_node_list(ironic=None, marker=None, limit=None, state=None)[source]

Get node list from the cache.

The list of the nodes is ordered based on the (started_at, uuid) attribute pair, newer items first.

Parameters:
  • ironic – optional ironic client instance

  • marker – pagination marker (an UUID or None)

  • limit – pagination limit; None for default CONF.api_max_limit

  • state – list of states for the filter; None for no state filter

Returns:

a list of NodeInfo instances.

ironic_inspector.node_cache.introspection_active()[source]

Check if introspection is active for at least one node.

ironic_inspector.node_cache.record_node(ironic=None, bmc_addresses=None, macs=None)[source]

Create a cache record for a known active node.

Parameters:
  • ironic – ironic client instance.

  • bmc_addresses – list of BMC addresses.

  • macs – list of MAC addresses.

Returns:

NodeInfo

ironic_inspector.node_cache.release_lock(func)[source]

Decorate a node_info-function to release the node_info lock.

Assumes the first parameter of the function func is always a NodeInfo instance.

ironic_inspector.node_cache.start_introspection(uuid, **kwargs)[source]

Start the introspection of a node.

If a node_info record exists in the DB, a start transition is used rather than dropping the record in order to check for the start transition validity in particular node state.

Parameters:
  • uuid – Ironic node UUID

  • kwargs – passed on to add_node()

Raises:

NodeStateInvalidEvent in case the start transition is invalid in the current node state

Raises:

NodeStateRaceCondition if a mismatch was detected between the node_info cache and the DB

Returns:

NodeInfo

ironic_inspector.node_cache.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.node_cache.triggers_fsm_error_transition(errors=(<class 'Exception'>, ), no_errors=(<class 'ironic_inspector.utils.NodeStateInvalidEvent'>, <class 'ironic_inspector.utils.NodeStateRaceCondition'>))[source]

Trigger an fsm error transition upon certain errors.

It is assumed the first function arg of the decorated function is always a NodeInfo instance.

Parameters:
  • errors – a tuple of exceptions upon which an error event is triggered. Re-raised.

  • no_errors – a tuple of exceptions that won’t trigger the error event.