metalsmith package¶
Module contents¶
-
class
metalsmith.
Instance
(api, 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 node 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.
deploying
- deployment is in progress
active
- node is provisioned
maintenance
- node is provisioned but is in maintenance mode
error
- node has a failure
unknown
- node in unexpected state (maybe unprovisioned or modified by a third party)
-
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_directory
(*args, **kwds)¶ Build a configdrive from the provided information.
Parameters: - node – Node object.
- hostname – instance hostname.
Returns: 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.
Parameters: - session – Session 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.
-
provision_node
(node, image, nics=None, root_disk_size=None, config=None, hostname=None, netboot=False, capabilities=None, wait=None)¶ Provision the node with the given image.
Example:
provisioner.provision_node("compute-1", "centos", nics=[{"network": "private"}, {"network": "external"}], root_disk_size=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 name or UUID to provision.
- 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>"}
). - root_disk_size – The size of the root partition. By default the value of the local_gb property is used.
- config –
metalsmith.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 - usereserve_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. Ifwait
is notNone
, provisioning is already finished.Raises:
-
reserve_node
(resource_class=None, capabilities=None, candidates=None)¶ Find and reserve a suitable node.
Example:
node = provisioner.reserve_node("compute", capabilities={"boot_mode": "uefi"})
Parameters: - resource_class – Requested resource class. If
None
, a node with any resource class can be chosen. - capabilities – Requested capabilities as a dict.
- 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.
Returns: reserved Node object.
Raises: - resource_class – Requested resource class. If
-
show_instance
(instance_id)¶ Show information about instance.
Parameters: instance_id – hostname, UUID or node name. Returns: metalsmith.Instance
object.
-
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 asinstances
.
-
unprovision_node
(node, wait=None)¶ Unprovision a previously provisioned node.
Parameters: - node – Node 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.
- node – Node object,
-
wait_for_provisioning
(nodes, timeout=None, delay=15)¶ 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 – Delay (in seconds) between two provision state checks.
Returns: List of updated
metalsmith.Instance
objects if all succeeded.Raises: metalsmith.exceptions.DeploymentFailure
if the deployment failed or timed out for any nodes.- nodes – List of nodes (UUID, name, Node object or
- session – Session object (from