metalsmith package

metalsmith package

Module contents

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

Bases: object

Instance status in metalsmith.


Allocation object associated with the node (if any).


Node’s hostname.


Returns IP addresses for this instance.


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


Whether the node is deployed.


Whether the instance is not at fault or maintenance.


List NICs for this instance.


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


Underlying Node object.


Instance state, one of InstanceState.


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.


Make the config drive ISO.

Deprecated, use generate() with openstacksdk’s instead.


nodeNode object.


configdrive contents as a base64-encoded string.


Generate the config drive information.


nodeNode object.


configdrive contents as a dictionary with keys:


meta data dictionary


user data as a string

class metalsmith.InstanceState

Bases: enum.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.


Whether the state designates a finished deployment.


Whether the state is considered healthy.

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

Bases: metalsmith._utils.GetNodeMixin

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.


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.

  • configmetalsmith.InstanceConfig object with the configuration to pass to the instance.

  • 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.

  • 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.InvalidInstance 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.InvalidInstance if one of the instances are not valid 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=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).

  • delay – DEPRECATED, do not use.


List of updated metalsmith.Instance objects if all succeeded.


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

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.