blob: 805f0ae0d3dc9144eb3f115c230fee813506f449 [file] [log] [blame]
Adam Israeldcdf82b2017-08-15 15:26:43 -04001"""
2This example:
3
41. Connects to current model and resets it.
52. Deploys one ubuntu 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.model import Model
13from juju import loop
14
15
16async def run_command(unit):
17 logging.debug('Running command on unit %s', unit.name)
18
19 # unit.run() returns a juju.action.Action instance
20 action = await unit.run('unit-get public-address')
21 logging.debug("Action results: %s", action.results)
22
23
24async def main():
25 model = Model()
Adam Israelb0943662018-08-02 15:32:00 -040026 # connect to current model with current user, per Juju CLI
Adam Israelc3e6c2e2018-03-01 09:31:50 -050027 await model.connect()
Adam Israeldcdf82b2017-08-15 15:26:43 -040028
29 app = await model.deploy(
30 'ubuntu-0',
31 application_name='ubuntu',
32 series='trusty',
33 channel='stable',
34 )
35
36 for unit in app.units:
37 await run_command(unit)
38
39 await model.disconnect()
40
41
42if __name__ == '__main__':
43 logging.basicConfig(level=logging.DEBUG)
44 ws_logger = logging.getLogger('websockets.protocol')
45 ws_logger.setLevel(logging.INFO)
46 loop.run(main())