4 from .client
import client
6 log
= logging
.getLogger(__name__
)
9 class Unit(model
.ModelEntity
):
10 def add_storage(self
, name
, constraints
=None):
11 """Add unit storage dynamically.
13 :param str name: Storage name, as specified by the charm
14 :param str constraints: Comma-separated list of constraints in the
15 form 'POOL,COUNT,SIZE'
20 def collect_metrics(self
):
21 """Collect metrics on this unit.
26 async def destroy(self
):
30 app_facade
= client
.ApplicationFacade()
31 app_facade
.connect(self
.connection
)
34 'Destroying %s', self
.name
)
36 return await app_facade
.DestroyUnits([self
.name
])
39 def get_resources(self
, details
=False):
40 """Return resources for this unit.
42 :param bool details: Include detailed info about resources used by each
48 def resolved(self
, retry
=False):
49 """Mark unit errors resolved.
51 :param bool retry: Re-execute failed hooks
56 async def run(self
, command
, timeout
=None):
57 """Run command on this unit.
59 :param str command: The command to run
60 :param int timeout: Time to wait before command is considered failed
63 action
= client
.ActionFacade()
64 action
.connect(self
.connection
)
67 'Running `%s` on %s', command
, self
.name
)
69 return await action
.Run(
77 def run_action(self
, action_name
, **params
):
78 """Run action on this unit.
80 :param str action_name: Name of action to run
81 :param \*\*params: Action parameters
87 self
, source_path
, user
=None, destination_path
=None, proxy
=False,
89 """Transfer files to this unit.
91 :param str source_path: Path of file(s) to transfer
92 :param str user: Remote username
93 :param str destination_path: Destination of transferred files on
95 :param bool proxy: Proxy through the Juju API server
96 :param str scp_opts: Additional options to the `scp` command
101 def set_meter_status(self
):
102 """Set the meter status on this unit.
108 self
, command
, user
=None, proxy
=False, ssh_opts
=None):
109 """Execute a command over SSH on this unit.
111 :param str command: Command to execute
112 :param str user: Remote username
113 :param bool proxy: Proxy through the Juju API server
114 :param str ssh_opts: Additional options to the `ssh` command
119 def status_history(self
, num
=20, utc
=False):
120 """Get status history for this unit.
122 :param int num: Size of history backlog
123 :param bool utc: Display time as UTC in RFC3339 format