Dropped in fixes for juju ssh.
[osm/N2VC.git] / examples / add_model.py
1 """
2 This example:
3
4 1. Creates a model on the current controller
5 2. Deploys a charm to it.
6 3. Attempts to ssh into the charm
7
8 """
9 from juju import loop
10 from juju import utils
11 from juju.controller import Controller
12 import asyncio
13 from logging import getLogger
14
15 LOG = getLogger(__name__)
16
17
18 async def main():
19 controller = Controller()
20 print("Connecting to controller")
21 await controller.connect_current()
22
23 try:
24 model = await controller.add_model("quux")
25
26 print('Deploying ubuntu')
27 application = await model.deploy(
28 'ubuntu-10',
29 application_name='ubuntu',
30 series='trusty',
31 channel='stable',
32 )
33
34 print('Waiting for active')
35 await asyncio.sleep(10)
36 await model.block_until(
37 lambda: all(unit.workload_status == 'active'
38 for unit in application.units))
39
40 print("Verifying that we can ssh into the created model")
41 ret = utils.execute_process('juju', 'ssh', 'ls /', log=LOG)
42 assert ret
43
44 print('Removing ubuntu')
45 await application.remove()
46
47 print("Destroying model")
48 await controller.destroy_model(model.info.uuid)
49
50 finally:
51 print('Disconnecting from controller')
52 await model.disconnect()
53 await controller.disconnect()
54
55
56 loop.run(main())