blob: b6e2240ab74bf9b15951d1e18502b4fb061b0507 [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"""
10import asyncio
11import logging
12
13from juju.model import Model
14from juju import loop
15
16
17async def run_command(unit):
18 logging.debug('Running command on unit %s', unit.name)
19
20 # unit.run() returns a juju.action.Action instance
21 action = await unit.run('unit-get public-address')
22 logging.debug("Action results: %s", action.results)
23
24
25async def main():
26 model = Model()
Adam Israelc3e6c2e2018-03-01 09:31:50 -050027 await model.connect()
Adam Israeldcdf82b2017-08-15 15:26:43 -040028 await model.reset(force=True)
29
30 app = await model.deploy(
31 'ubuntu-0',
32 application_name='ubuntu',
33 series='trusty',
34 channel='stable',
35 )
36
37 for unit in app.units:
38 await run_command(unit)
39
40 await model.disconnect()
41
42
43if __name__ == '__main__':
44 logging.basicConfig(level=logging.DEBUG)
45 ws_logger = logging.getLogger('websockets.protocol')
46 ws_logger.setLevel(logging.INFO)
47 loop.run(main())