e6c306a1aeedea0f7bd335d10576b95b18aa39e2
[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 await model.connect_current()
17
18 try:
19 print('Deploying ubuntu')
20 application = await model.deploy(
21 'ubuntu-10',
22 application_name='ubuntu',
23 series='trusty',
24 channel='stable',
25 )
26
27 print('Waiting for active')
28 await model.block_until(
29 lambda: all(unit.workload_status == 'active'
30 for unit in application.units))
31
32 print('Removing ubuntu')
33 await application.remove()
34 finally:
35 print('Disconnecting from model')
36 await model.disconnect()
37
38
39 if __name__ == '__main__':
40 loop.run(main())