blob: 43764d7f690db735c9a09c35237bd14ce5037f8a [file] [log] [blame]
Adam Israeldcdf82b2017-08-15 15:26:43 -04001"""
2This example:
3
41. Connects to the current model
52. Deploy a charm and waits until it reports itself active
63. Destroys the unit and application
7
8"""
9from juju import loop
10from juju.model import Model
11
12
13async def main():
14 model = Model()
15 print('Connecting to model')
Adam Israelb0943662018-08-02 15:32:00 -040016 # connect to current model with current user, per Juju CLI
Adam Israelc3e6c2e2018-03-01 09:31:50 -050017 await model.connect()
Adam Israeldcdf82b2017-08-15 15:26:43 -040018
19 try:
20 print('Deploying ubuntu')
21 application = await model.deploy(
22 'ubuntu-10',
23 application_name='ubuntu',
24 series='trusty',
25 channel='stable',
26 )
27
28 print('Waiting for active')
29 await model.block_until(
30 lambda: all(unit.workload_status == 'active'
31 for unit in application.units))
32
33 print('Removing ubuntu')
34 await application.remove()
35 finally:
36 print('Disconnecting from model')
37 await model.disconnect()
38
39
40if __name__ == '__main__':
41 loop.run(main())