The ironic_inspector.node_cache Module

Cache for nodes currently under introspection.

class ironic_inspector.node_cache.NodeInfo(uuid, started_at=None, finished_at=None, error=None, node=None, ports=None, ironic=None, lock=None)[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, session=None)[source]

Store look up attribute for a node in the database.

Parameters:
  • name – attribute name
  • value – attribute value or list of possible values
  • session – optional existing database session
Raises:

Error if attributes values are already in database

attributes[source]

Node look up attributes as a dict.

create_ports(macs)[source]

Create one or several ports for this node.

A warning is issued if port already exists on a node.

delete_port(port)[source]

Delete port.

Parameters:port – port object or its MAC
finished(error=None)[source]

Record status for this node.

Also deletes look up attributes from the cache.

Parameters:error – error message
classmethod from_row(row, ironic=None, lock=None)[source]

Construct NodeInfo from a database row.

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.

ironic[source]

Ironic client instance.

node()[source]

Get Ironic node object associated with the cached node record.

options[source]

Node introspection options as a dict.

patch(patches)[source]

Apply JSON patches to a node.

Refreshes cached node instance.

Parameters:patches – JSON patches to apply
Raises:ironicclient exceptions
patch_port(port, patches)[source]

Apply JSON patches to a port.

Parameters:
  • port – port object or its MAC
  • patches – JSON patches to apply
ports()[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.

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.

update_capabilities(**caps)[source]

Update capabilities on a node.

Parameters:props – capabilities to update
update_properties(**props)[source]

Update properties on a node.

Parameters:props – properties to update
ironic_inspector.node_cache.active_macs()[source]

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

ironic_inspector.node_cache.add_node(uuid, **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
  • 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.
  • Drop outdated node status information.
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.
Parameters:
  • driver – driver for Ironic node.
  • ironic – ronic 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.

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

Get node from cache by it’s UUID.

Parameters:
  • uuid – node UUID.
  • ironic – optional ironic client instance
  • locked – if True, get a lock on node before fetching its data
Returns:

structure NodeInfo.

ironic_inspector.node_cache.introspection_active()[source]

Check if introspection is active for at least one node.

Previous topic

The ironic_inspector.main Module

Next topic

The ironic_inspector.plugins.base Module

Project Source

This Page