2b7170ee842fb117b036d4f5ef32ad3c11d94a31
4 from .client
import client
6 log
= logging
.getLogger(__name__
)
9 class Unit(model
.ModelEntity
):
11 return 'unit-{}'.format(self
.data
['Name'].replace('/', '-'))
13 def add_storage(self
, name
, constraints
=None):
14 """Add unit storage dynamically.
16 :param str name: Storage name, as specified by the charm
17 :param str constraints: Comma-separated list of constraints in the
18 form 'POOL,COUNT,SIZE'
23 def collect_metrics(self
):
24 """Collect metrics on this unit.
36 def get_resources(self
, details
=False):
37 """Return resources for this unit.
39 :param bool details: Include detailed info about resources used by each
45 def resolved(self
, retry
=False):
46 """Mark unit errors resolved.
48 :param bool retry: Re-execute failed hooks
53 async def run(self
, command
, timeout
=None):
54 """Run command on this unit.
56 :param str command: The command to run
57 :param int timeout: Time to wait before command is considered failed
60 action
= client
.ActionFacade()
61 conn
= await self
.model
.connection
.clone()
65 'Running `%s` on %s', command
, self
.Name
)
67 return await action
.Run(
75 def run_action(self
, action_name
, **params
):
76 """Run action on this unit.
78 :param str action_name: Name of action to run
79 :param \*\*params: Action parameters
85 self
, source_path
, user
=None, destination_path
=None, proxy
=False,
87 """Transfer files to this unit.
89 :param str source_path: Path of file(s) to transfer
90 :param str user: Remote username
91 :param str destination_path: Destination of transferred files on
93 :param bool proxy: Proxy through the Juju API server
94 :param str scp_opts: Additional options to the `scp` command
99 def set_meter_status(self
):
100 """Set the meter status on this unit.
106 self
, command
, user
=None, proxy
=False, ssh_opts
=None):
107 """Execute a command over SSH on this unit.
109 :param str command: Command to execute
110 :param str user: Remote username
111 :param bool proxy: Proxy through the Juju API server
112 :param str ssh_opts: Additional options to the `ssh` command
117 def status_history(self
, num
=20, utc
=False):
118 """Get status history for this unit.
120 :param int num: Size of history backlog
121 :param bool utc: Display time as UTC in RFC3339 format