blob: f839f1122dc1a597a3df1e6e4fec14b63c75a63f [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"""
Adam Israeldcdf82b2017-08-15 15:26:43 -040010import logging
11
12from juju import loop
13from juju.model import Model
14
15
16async def run_action(unit):
17 logging.debug('Running action on unit %s', unit.name)
18
19 # unit.run() returns a juju.action.Action instance
20 action = await unit.run_action('add-repo', repo='myrepo')
21 # wait for the action to complete
22 action = await action.wait()
23
24 logging.debug("Action results: %s", action.results)
25
26
27async def main():
28 model = Model()
Adam Israelb0943662018-08-02 15:32:00 -040029 # connect to current model with current user, per Juju CLI
Adam Israelc3e6c2e2018-03-01 09:31:50 -050030 await model.connect()
Adam Israeldcdf82b2017-08-15 15:26:43 -040031
32 app = await model.deploy(
33 'git',
34 application_name='git',
35 series='trusty',
36 channel='stable',
37 )
38
39 for unit in app.units:
40 await run_action(unit)
41
42 await model.disconnect()
43
44
45if __name__ == '__main__':
46 logging.basicConfig(level=logging.DEBUG)
47 ws_logger = logging.getLogger('websockets.protocol')
48 ws_logger.setLevel(logging.INFO)
49 loop.run(main())