d0dd4631b8c6b8fe1ea110d8978a147e40a5d399
[osm/N2VC.git] / examples / future.py
1 """
2 This example doesn't work - it demonstrates features that don't exist yet.
3
4 """
5 import asyncio
6 import logging
7
8 from juju.model import Model
9
10
11 async def run():
12 model = Model()
13 await model.connect_current()
14 await model.reset(force=True)
15
16 goal_state = Model.from_yaml('bundle-like-thing')
17 ubuntu_app = await model.deploy(
18 'ubuntu-0',
19 application_name='ubuntu',
20 series='trusty',
21 channel='stable',
22 )
23 ubuntu_app.on_unit_added(callback=lambda unit: True)
24
25 await model.deploy(
26 'nrpe-11',
27 application_name='nrpe',
28 series='trusty',
29 channel='stable',
30 num_units=0,
31 )
32 await model.add_relation(
33 'ubuntu',
34 'nrpe',
35 )
36
37 result, ok = await model.block_until(
38 lambda: model.matches(goal_state),
39 timeout=600
40 )
41
42
43 logging.basicConfig(level=logging.DEBUG)
44 ws_logger = logging.getLogger('websockets.protocol')
45 ws_logger.setLevel(logging.INFO)
46 loop = asyncio.get_event_loop()
47 loop.create_task(run())
48 loop.run_forever()