blob: c7580f6300f53e5c6f1f3f88465800637bacb20f [file] [log] [blame]
Adam Israeldcdf82b2017-08-15 15:26:43 -04001"""
2This example:
3
41. Connects to the current model
52. Resets it
63. Deploys a charm and prints its config and constraints
7
8"""
Adam Israeldcdf82b2017-08-15 15:26:43 -04009import logging
10
11from juju.model import Model
12from juju import loop
13
14log = logging.getLogger(__name__)
15
16MB = 1
17
18
19async def main():
20 model = Model()
Adam Israelb0943662018-08-02 15:32:00 -040021 # connect to current model with current user, per Juju CLI
Adam Israelc3e6c2e2018-03-01 09:31:50 -050022 await model.connect()
Adam Israeldcdf82b2017-08-15 15:26:43 -040023
24 ubuntu_app = await model.deploy(
25 'mysql',
26 application_name='mysql',
27 series='trusty',
28 channel='stable',
29 config={
30 'tuning-level': 'safest',
31 },
32 constraints={
33 'mem': 256 * MB,
34 },
35 )
36
37 # update and check app config
38 await ubuntu_app.set_config({'tuning-level': 'fast'})
39 config = await ubuntu_app.get_config()
40 assert(config['tuning-level']['value'] == 'fast')
41
42 # update and check app constraints
43 await ubuntu_app.set_constraints({'mem': 512 * MB})
44 constraints = await ubuntu_app.get_constraints()
45 assert(constraints['mem'] == 512 * MB)
46
47 await model.disconnect()
48
Adam Israelb0943662018-08-02 15:32:00 -040049
Adam Israeldcdf82b2017-08-15 15:26:43 -040050if __name__ == '__main__':
51 logging.basicConfig(level=logging.DEBUG)
52 ws_logger = logging.getLogger('websockets.protocol')
53 ws_logger.setLevel(logging.INFO)
54 loop.run(main())