juju.unit
Summary
Methods: |
Reference
- class juju.unit.Unit(entity_id: str, model: Model, history_index: int = -1, connected: bool = True)[source]
Bases:
ModelEntity
- coroutine add_storage(storage_name, pool=None, count=1, size=1024)[source]
Creates a storage and adds it to this unit.
- Param:
str storage_name: Name of the storage
- Param:
str pool: the storage pool to provision storage instances from. Must
be a name from ‘juju storage-pools’. The default pool is available via executing ‘juju model-config storage-default-block-source’. :param: int count: the number of storage instances to provision from <storage-pool> of <size>. Must be a positive integer. The default count is “1”. May be restricted by the charm, which can specify a maximum number of storage instances per unit. :param: int size: the required size of the storage instance, in MiB.
- Returns:
[]str storage_tags
- property agent_status
Returns the current agent status string.
- property agent_status_message
Get the agent status message.
- property agent_status_since
Get the time when the agent_status was last updated.
- coroutine attach_storage(storage_ids=[])[source]
Attaches existing storage to this unit.
- Parameters:
storage_ids ([str]) – existing storage ids to attach to the unit
- Returns:
- coroutine destroy(destroy_storage=False, dry_run=False, force=False, max_wait=None)[source]
Destroy this unit.
- coroutine detach_storage(*storage_ids, force=False)[source]
Detaches storage from units.
- Parameters:
force (bool) – Forcefully detach storage
storage_ids ([str]) –
- Returns:
- 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.
- coroutine get_public_address()[source]
Return the public address of this unit.
:return int public-address
- get_subordinates()[source]
Returns the unit objects that are subordinates to this unit
:return [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.
- property is_subordinate
True if the unit is subordinate of another unit
- property machine
Get the machine object for this unit.
- property name: str
- property principal_unit
Returns the name of the unit of which this unit is a subordinate to. Returns ‘’ for principal units themselves.
- property public_address
Get the public address.
This property is deprecated, use get_public_address method.
- coroutine remove(destroy_storage=False, dry_run=False, force=False, max_wait=None)
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, block=False)[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 :param bool block: A flag to use this function in synchronized fashion. Useful with older versions of juju, i.e. getting the result without having to call
action.wait()
separately. :returns: Ajuju.action.Action
instance.Note that this is very similarly to unit.run_action 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 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.
- coroutine ssh(command, user='ubuntu', 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
- property tag
- property workload_status
Returns the current workload status string.
- property workload_status_message
Get the workload status message.
- property workload_status_since
Get the time when the workload_status was last updated.