metalsmith package

metalsmith package

Module contents

class metalsmith.Instance(connection, node)

Bases: object

Instance status in metalsmith.

hostname

Node’s hostname.

ip_addresses()

Returns IP addresses for this instance.

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

Whether the node is deployed.

is_healthy

Whether the instance is not at fault or maintenance.

nics()

List NICs for this instance.

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

Underlying Node object.

state

Instance state, one of InstanceState.

to_dict()

Convert instance to a dict.

uuid

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

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

Parameters:
  • 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_configdrive(node, hostname)

Make the config drive.

Parameters:
  • nodeNode object.
  • hostname – instance hostname.
Returns:

configdrive contents as a base64-encoded 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.

is_deployed

Whether the state designates a finished deployment.

is_healthy

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.

Parameters:
  • 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.
Variables:

connectionopenstacksdk Connection object used for accessing OpenStack API during provisioning.

list_instances()

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)

Provision the node with the given image.

Example:

provisioner.provision_node("compute-1", "centos",
                           nics=[{"network": "private"},
                                 {"network": "external"}],
                           root_size_gb=50,
                           wait=3600)
Parameters:
  • 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. 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.
Returns:

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

Raises:

metalsmith.exceptions.Error

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

Find and reserve a suitable node.

Example:

node = provisioner.reserve_node("compute",
                                capabilities={"boot_mode": "uefi"})
Parameters:
  • 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.
Returns:

reserved Node object.

Raises:

metalsmith.exceptions.ReservationFailed

show_instance(instance_id)

Show information about instance.

Parameters:instance_id – hostname, UUID or node name.
Returns:metalsmith.Instance object.
Raises:metalsmith.exceptions.InvalidInstance if the instance is not a valid instance.
show_instances(instances)

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.
Raises:metalsmith.exceptions.InvalidInstance if one of the instances are not valid instances.
unprovision_node(node, wait=None)

Unprovision a previously provisioned node.

Parameters:
  • nodeNode object, metalsmith.Instance, hostname, UUID or node name.
  • wait – How many seconds to wait for the process to finish, None to return immediately.
Returns:

the latest Node object.

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

Wait for nodes to be provisioned.

Loops until all nodes finish provisioning.

Parameters:
  • 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.
Returns:

List of updated metalsmith.Instance objects if all succeeded.

Raises:

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.