blob: 0f25647d78d147c13ef8258d9773bbcd24ec069b [file] [log] [blame]
Adam Israeldcdf82b2017-08-15 15:26:43 -04001"""
2This example:
3
41. Connects to current model and resets it.
52. Deploys a git unit.
63. Runs an action against the unit.
74. Waits for the action results to come back, then exits.
8
9"""
10import asyncio
11import logging
12
13from juju import loop
14from juju.model import Model
15
16
17async def run_action(unit):
18 logging.debug('Running action on unit %s', unit.name)
19
20 # unit.run() returns a juju.action.Action instance
21 action = await unit.run_action('add-repo', repo='myrepo')
22 # wait for the action to complete
23 action = await action.wait()
24
25 logging.debug("Action results: %s", action.results)
26
27
28async def main():
29 model = Model()
30 await model.connect_current()
31 await model.reset(force=True)
32
33 app = await model.deploy(
34 'git',
35 application_name='git',
36 series='trusty',
37 channel='stable',
38 )
39
40 for unit in app.units:
41 await run_action(unit)
42
43 await model.disconnect()
44
45
46if __name__ == '__main__':
47 logging.basicConfig(level=logging.DEBUG)
48 ws_logger = logging.getLogger('websockets.protocol')
49 ws_logger.setLevel(logging.INFO)
50 loop.run(main())