metalsmith package

Module contents

class metalsmith.Instance(api, node)

Bases: object

Instance status in metalsmith.


Node’s hostname.


Returns IP addresses for this instance.

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

Whether the node is deployed.


Whether the node is not at fault or maintenance.


List NICs for this instance.

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

Underlying Node object.


Instance state.

deployment is in progress
node is provisioned
node is provisioned but is in maintenance mode
node has a failure
node in unexpected state (maybe unprovisioned or modified by a third party)

Convert instance to a dict.


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

class metalsmith.InstanceConfig(ssh_keys=None)

Bases: object

Configuration of the target instance.

The information attached to this object will be passed via a configdrive to the instance’s first boot script (e.g. cloud-init).

  • ssh_keys – List of SSH public keys.
  • users – Users to add on first boot.
add_user(name, admin=True, password_hash=None, sudo=False, **kwargs)

Add a user to be created on first boot.

  • name – user name.
  • admin – whether to add the user to the admin group (wheel).
  • password_hash – user password hash, if password authentication is expected.
  • sudo – whether to allow the user sudo without password.
  • kwargs – other arguments to pass.

Build a configdrive from the provided information.

  • nodeNode object.
  • hostname – instance hostname.

a context manager yielding a directory with files

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.


List instances deployed by metalsmith.

Returns: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, root_disk_size=None)

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: either a port ({"port": "<port name or ID>"}) or a network to create a port on ({"network": "<network name or ID>"}). A network record can optionally feature a fixed_ip argument to use this specific fixed IP from a suitable 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.
  • configmetalsmith.InstanceConfig object with the configuration to pass to the instance.
  • hostname – Hostname to assign to the instance. Defaults to the node’s name or UUID.
  • netboot – Whether to use networking boot for final instances.
  • 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.
  • root_disk_size – DEPRECATED, use root_size_gb.

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



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

Find and reserve a suitable node.


node = provisioner.reserve_node("compute",
                                capabilities={"boot_mode": "uefi"})
  • resource_class – Requested resource class. If None, a node with any resource class can be chosen.
  • 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.

reserved Node object.




Show information about instance.

Parameters:instance_id – hostname, UUID or node name.
Returns:metalsmith.Instance object.

Show information about instance.

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

Parameters:instances – list of hostnames, UUIDs or node names.
Returns:list of metalsmith.Instance objects in the same order as instances.
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.

wait_for_provisioning(nodes, timeout=None, delay=15)

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).
  • delay – Delay (in seconds) between two provision state checks.

List of updated metalsmith.Instance objects if all succeeded.


metalsmith.exceptions.DeploymentFailure if the deployment failed or timed out for any nodes.