blob: 5d6b48d2c128dbf37d0d94854a88fa9e54db4fbf [file] [log] [blame]
Adam Israeldcdf82b2017-08-15 15:26:43 -04001Units
2=====
3For api docs, see :class:`juju.unit.Unit`.
4
5
6Running Commands
7----------------
8Run arbitrary commands on a unit with the
9:meth:`juju.unit.Unit.run` method. This method blocks
10the current coroutine until a result is available, and
11returns a :class:`juju.action.Action` instance.
12
13
14.. code:: python
15
16 from juju.model import Model
17
18 model = Model()
19 await model.connect_current()
20
21 app = await model.deploy(
22 'ubuntu',
23 application_name='ubuntu',
24 series='trusty',
25 channel='stable',
26 )
27
28 for unit in app.units:
29 action = await unit.run('unit-get public-address')
30 print(action.results)
31
32 action = await unit.run('uname -a')
33 print(action.results)
34
35
36Running Actions
37---------------
38Run actions on a unit with the
39:meth:`juju.unit.Unit.run_action` method. This method
40returns a :class:`juju.action.Action` instance immediately. To block until
41the action completes, use the :meth:`juju.action.Action.wait` method, as
42in the example below.
43
44
45.. code:: python
46
47 from juju.model import Model
48
49 model = Model()
50 await model.connect_current()
51
52 app = await model.deploy(
53 'git',
54 application_name='git',
55 series='trusty',
56 channel='stable',
57 )
58
59 for unit in app.units:
60 # run the 'add-repo' action, passing a 'repo' param
61 action = await unit.run_action('add-repo', repo='myrepo')
62 # wait for the action to complete
63 action = await action.wait()
64
65 print(action.results)