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

coroutine remove()

Destroy this unit.

resolved(retry=False)[source]

Mark unit errors resolved.

Parameters:retry (bool) – Re-execute failed hooks
coroutine run(command, timeout=None)[source]

Run command on this unit.

Parameters:
  • command (str) – The command to run
  • timeout (int) – Time 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.

scp(source_path, user=None, destination_path=None, proxy=False, scp_opts=None)[source]

Transfer files to this unit.

Parameters:
  • source_path (str) – Path of file(s) to transfer
  • user (str) – Remote username
  • destination_path (str) – Destination of transferred files on remote machine
  • proxy (bool) – Proxy through the Juju API server
  • scp_opts (str) – Additional options to the scp command
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.