Squashed 'modules/libjuju/' changes from c50c361..c127833
[osm/N2VC.git] / examples / deploy.py
1 """
2 This example:
3
4 1. Connects to the current model
5 2. Deploy a charm and waits until it reports itself active
6 3. Destroys the unit and application
7
8 """
9 from juju import loop
10 from juju.model import Model
11
12
13 async def main():
14 model = Model()
15 print('Connecting to model')
16 # connect to current model with current user, per Juju CLI
17 await model.connect()
18
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
40 if __name__ == '__main__':
41 loop.run(main())