579308b55b929f601b868b54415684184c0a6936
[osm/N2VC.git] / examples / config.py
1 """
2 This example:
3
4 1. Connects to the current model
5 2. Resets it
6 3. Deploys a charm and prints its config and constraints
7
8 """
9 import asyncio
10 import logging
11
12 from juju.model import Model
13
14 log = logging.getLogger(__name__)
15
16 MB = 1024 * 1024
17
18 async def run():
19 model = Model()
20 await model.connect_current()
21 await model.reset(force=True)
22
23 ubuntu_app = await model.deploy(
24 'mysql',
25 application_name='mysql',
26 series='trusty',
27 channel='stable',
28 config={
29 'tuning-level': 'safest',
30 },
31 constraints={
32 'mem': 256 * MB,
33 },
34 )
35
36 # update and check app config
37 await ubuntu_app.set_config({'tuning-level': 'fast'})
38 config = await ubuntu_app.get_config()
39 assert(config['tuning-level']['value'] == 'fast')
40
41 # update and check app constraints
42 await ubuntu_app.set_constraints({'mem': 512 * MB})
43 constraints = await ubuntu_app.get_constraints()
44 assert(constraints['mem'] == 512 * MB)
45
46 await model.disconnect()
47 model.loop.stop()
48
49 logging.basicConfig(level=logging.DEBUG)
50 ws_logger = logging.getLogger('websockets.protocol')
51 ws_logger.setLevel(logging.INFO)
52 loop = asyncio.get_event_loop()
53 loop.set_debug(False)
54 loop.create_task(run())
55 loop.run_forever()