bad5b6d8c4494fb47bb14e743f643a93be9f05da
[osm/N2VC.git] / modules / libjuju / 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 from juju import loop
14
15 log = logging.getLogger(__name__)
16
17 MB = 1
18
19
20 async def main():
21 model = Model()
22 await model.connect()
23 await model.reset(force=True)
24
25 ubuntu_app = await model.deploy(
26 'mysql',
27 application_name='mysql',
28 series='trusty',
29 channel='stable',
30 config={
31 'tuning-level': 'safest',
32 },
33 constraints={
34 'mem': 256 * MB,
35 },
36 )
37
38 # update and check app config
39 await ubuntu_app.set_config({'tuning-level': 'fast'})
40 config = await ubuntu_app.get_config()
41 assert(config['tuning-level']['value'] == 'fast')
42
43 # update and check app constraints
44 await ubuntu_app.set_constraints({'mem': 512 * MB})
45 constraints = await ubuntu_app.get_constraints()
46 assert(constraints['mem'] == 512 * MB)
47
48 await model.disconnect()
49
50
51 if __name__ == '__main__':
52 logging.basicConfig(level=logging.DEBUG)
53 ws_logger = logging.getLogger('websockets.protocol')
54 ws_logger.setLevel(logging.INFO)
55 loop.run(main())