juju.unit

Summary

Unit

Methods:

Reference

class juju.unit.Unit(entity_id, model, history_index=-1, connected=True)[source]

Bases: juju.model.ModelEntity

add_storage(name, constraints=None)[source]

Add unit storage dynamically.

Parameters:
  • name (str) – Storage name, as specified by the charm
  • constraints (str) – Comma-separated list of constraints in the form ‘POOL,COUNT,SIZE’
agent_status

Returns the current agent status string.

agent_status_message

Get the agent status message.

agent_status_since

Get the time when the agent_status was last updated.

collect_metrics()[source]

Collect metrics on this unit.

coroutine destroy()[source]

Destroy this unit.

coroutine get_annotations()[source]

Get annotations on this unit.

Return dict:The annotations for this unit
coroutine get_metrics()[source]

Get metrics for the unit.

Returns:Dictionary of metrics for this unit.
get_resources(details=False)[source]

Return resources for this unit.

Parameters:details (bool) – Include detailed info about resources used by each unit
coroutine is_leader_from_status()[source]

Check to see if this unit is the leader. Returns True if so, and False if it is not, or if leadership does not make sense (e.g., there is no leader in this application.)

This method is a kluge that calls FullStatus in the ClientFacade to get its information. Once https://bugs.launchpad.net/juju/+bug/1643691 is resolved, we should add a simple .is_leader property, and deprecate this method.

machine

Get the machine object for this unit.

public_address

Get the public address.

coroutine remove()

Destroy this unit.

coroutine resolved(retry=False)[source]

Mark unit errors resolved.

Parameters:retry (bool) – Re-execute failed hooks
Returns:A juju.client._definitions.ErrorResults instance.
coroutine run(command, timeout=None)[source]

Run command on this unit.

Parameters:
  • command (str) – The command to run
  • timeout (int) – Time, in seconds, to wait before command is

considered failed :returns: A juju.action.Action instance.

coroutine run_action(action_name, **params)[source]

Run an action on this unit.

Parameters:
  • action_name (str) – Name of action to run
  • **params

    Action parameters

Returns:

A juju.action.Action instance.

Note that this only enqueues the action. You will need to call action.wait() on the resulting Action instance if you wish to block until the action is complete.

coroutine scp_from(source, destination, user='ubuntu', proxy=False, scp_opts='')[source]

Transfer files from this unit.

Parameters:
  • source (str) – Remote path of file(s) to transfer
  • destination (str) – Local destination of transferred files
  • user (str) – Remote username
  • proxy (bool) – Proxy through the Juju API server
  • scp_opts (str or list) – Additional options to the scp command
coroutine scp_to(source, destination, user='ubuntu', proxy=False, scp_opts='')[source]

Transfer files to this unit.

Parameters:
  • source (str) – Local path of file(s) to transfer
  • destination (str) – Remote destination of transferred files
  • user (str) – Remote username
  • proxy (bool) – Proxy through the Juju API server
  • scp_opts (str or list) – Additional options to the scp command
coroutine set_annotations(annotations)[source]

Set annotations on this unit.

Parameters:map[string]string (annotations) – the annotations as key/value pairs.
set_meter_status()[source]

Set the meter status on this unit.

ssh(command, user=None, proxy=False, ssh_opts=None)[source]

Execute a command over SSH on this unit.

Parameters:
  • command (str) – Command to execute
  • user (str) – Remote username
  • proxy (bool) – Proxy through the Juju API server
  • ssh_opts (str) – Additional options to the ssh command
status_history(num=20, utc=False)[source]

Get status history for this unit.

Parameters:
  • num (int) – Size of history backlog
  • utc (bool) – Display time as UTC in RFC3339 format
tag
workload_status

Returns the current workload status string.

workload_status_message

Get the workload status message.

workload_status_since

Get the time when the workload_status was last updated.