metalsmith package


Module contents

class metalsmith.Instance(connection, node, allocation=None)

Bases: object

Instance status in metalsmith.

property allocation

Allocation object associated with the node (if any).

property hostname

Node’s hostname.


Returns IP addresses for this instance.


dict mapping network name or ID to a list of IP addresses.

property is_deployed

Whether the node is deployed.

property is_healthy

Whether the instance is not at fault or maintenance.

network_cache = {}

List NICs for this instance.


List of Port objects with additional network fields with full representations of their networks.

property node

Underlying Node object.

property state

Instance state, one of InstanceState.


Convert instance to a dict.

property uuid

Instance UUID (the same as Node UUID for metalsmith).

class metalsmith.InstanceState(value)

Bases: Enum

A state of an instance.

ACTIVE = 'active'

The instance is provisioned.

DEPLOYING = 'deploying'

Provisioning is in progress.

This includes the case when a node is still in the available state, but already has an instance associated with it.

ERROR = 'error'

The instance has a failure.

MAINTENANCE = 'maintenance'

The instance is provisioned but is in the maintenance mode.

UNKNOWN = 'unknown'

The node is in an unexpected state.

It can be unprovisioned or modified by a third party.

property is_deployed

Whether the state designates a finished deployment.

property is_healthy

Whether the state is considered healthy.

class metalsmith.Provisioner(session=None, cloud_region=None, dry_run=False)

Bases: object

API to deploy/undeploy nodes with OpenStack.

  • sessionSession object (from keystoneauth) to use when making API requests. Mutually exclusive with cloud_region.

  • cloud_region – cloud configuration object (from openstacksdk) to use when making API requests. Mutually exclusive with session.

  • dry_run – boolean value, set to True to prevent any API calls from being actually made.


connectionopenstacksdk Connection object used for accessing OpenStack API during provisioning.

allocations_cache = {}

List instances deployed by metalsmith.


list of metalsmith.Instance objects.

provision_node(node, image, nics=None, root_size_gb=None, swap_size_mb=None, config=None, hostname=None, netboot=False, capabilities=None, traits=None, wait=None, clean_up_on_failure=True)

Provision the node with the given image.


provisioner.provision_node("compute-1", "centos",
                           nics=[{"network": "private"},
                                 {"network": "external"}],
  • node – Node object, UUID or name. Will be reserved first, if not reserved already. Must be in the “available” state with maintenance mode off.

  • image – Image source - one of sources, Image name or UUID.

  • nics

    List of virtual NICs to attach to physical ports. Each item is a dict with a key describing the type of the NIC:

    • {"port": "<port name or ID>"} to use the provided pre-created port.

    • {"network": "<network name or ID>"} to create a port on the provided network. Optionally, a fixed_ip argument can be used to specify an IP address.

    • {"subnet": "<subnet name or ID>"} to create a port with an IP address from the provided subnet. The network is determined from the subnet.

  • root_size_gb – The size of the root partition. By default the value of the local_gb property is used.

  • swap_size_mb – The size of the swap partition. It’s an error to specify it for a whole disk image.

  • config – configuration to pass to the instance, one of objects from metalsmith.instance_config.

  • hostname – Hostname to assign to the instance. If provided, overrides the hostname passed to reserve_node.

  • netboot – Whether to use networking boot for final instances. Deprecated and does not work in Ironic Zed.

  • capabilities – Requested capabilities of the node. If present, overwrites the capabilities set by reserve_node(). Note that the capabilities are not checked against the ones provided by the node - use reserve_node() for that.

  • traits – Requested traits of the node. If present, overwrites the traits set by reserve_node(). Note that the traits are not checked against the ones provided by the node - use reserve_node() for that.

  • wait – How many seconds to wait for the deployment to finish, None to return immediately.

  • clean_up_on_failure – If True, then on failure the node is cleared of instance information, VIFs are detached, created ports and allocations are deleted.


metalsmith.Instance object with the current status of provisioning. If wait is not None, provisioning is already finished.



reserve_node(resource_class, conductor_group=None, capabilities=None, traits=None, candidates=None, predicate=None, hostname=None)

Find and reserve a suitable node.


node = provisioner.reserve_node("compute",
                                capabilities={"boot_mode": "uefi"})
  • resource_class – Requested resource class.

  • conductor_group – Conductor group to pick the nodes from. Value None means any group, use empty string “” for nodes from the default group.

  • capabilities – Requested capabilities as a dict.

  • traits – Requested traits as a list of strings.

  • candidates – List of nodes (UUIDs, names or Node objects) to pick from. The filters (for resource class and capabilities) are still applied to the provided list. The order in which the nodes are considered is retained.

  • predicate – Custom predicate to run on nodes. A callable that accepts a node and returns True if it should be included, False otherwise. Any exceptions are propagated to the caller.

  • hostname – Hostname to assign to the instance. Defaults to the node’s name or UUID.


reserved Node object.




Show information about instance.


instance_id – hostname, UUID or node name.


metalsmith.Instance object.


metalsmith.exceptions.InstanceNotFound if the instance is not a valid instance.


Show information about instance.

More efficient than calling show_instance() in a loop, because it caches the node list.


instances – list of hostnames, UUIDs or node names.


list of metalsmith.Instance objects in the same order as instances.


metalsmith.exceptions.InstanceNotFound if one of the instances cannot be found or the found node is not a valid instance.

unprovision_node(node, wait=None)

Unprovision a previously provisioned node.

  • nodeNode object, metalsmith.Instance, hostname, UUID or node name.

  • wait – How many seconds to wait for the process to finish, None to return immediately.


the latest Node object.


metalsmith.exceptions.DeploymentFailed if undeployment fails.


metalsmith.exceptions.DeploymentTimeout if undeployment times out.


metalsmith.exceptions.InstanceNotFound if requested node cannot be found.

wait_for_provisioning(nodes, timeout=None)

Wait for nodes to be provisioned.

Loops until all nodes finish provisioning.

  • nodes – List of nodes (UUID, name, Node object or metalsmith.Instance).

  • timeout – How much time (in seconds) to wait for all nodes to finish provisioning. If None (the default), wait forever (more precisely, until the operation times out on server side).


List of updated metalsmith.Instance objects if all succeeded.


metalsmith.exceptions.DeploymentFailed if deployment fails or times out.


metalsmith.exceptions.InstanceNotFound if requested nodes cannot be found.