blob: 33d0c34081f039cd7ea92e50a32927b642afdc96 [file] [log] [blame]
Adam Israeldcdf82b2017-08-15 15:26:43 -04001#!/usr/bin/env python3.5
2
3"""
4This example:
5
61. Connects to the current model
72. Creates two machines and a lxd container
83. Deploys charm to the lxd container
9
10"""
11import logging
12
13from juju import loop
14from juju.model import Model
15
16MB = 1
17GB = 1024
18
19
20async def main():
21 model = Model()
Adam Israelc3e6c2e2018-03-01 09:31:50 -050022 await model.connect()
Adam Israeldcdf82b2017-08-15 15:26:43 -040023
24 try:
25 # add a new default machine
26 machine1 = await model.add_machine()
27 # add a machine with constraints, disks, and series
28 machine2 = await model.add_machine(
29 constraints={
30 'mem': 256 * MB,
31 },
32 disks=[{
33 'pool': 'rootfs',
34 'size': 10 * GB,
35 'count': 1,
36 }],
37 series='xenial',
38 )
39 # add a lxd container to machine2
40 machine3 = await model.add_machine(
41 'lxd:{}'.format(machine2.id))
42
43 # deploy charm to the lxd container
44 application = await model.deploy(
45 'ubuntu-10',
46 application_name='ubuntu',
47 series='xenial',
48 channel='stable',
49 to=machine3.id
50 )
51
52 await model.block_until(
53 lambda: all(unit.workload_status == 'active'
54 for unit in application.units))
55
56 await application.remove()
57
58 await machine3.destroy(force=True)
59 await machine2.destroy(force=True)
60 await machine1.destroy(force=True)
61 finally:
62 await model.disconnect()
63
64
65if __name__ == '__main__':
66 logging.basicConfig(level=logging.DEBUG)
67 ws_logger = logging.getLogger('websockets.protocol')
68 ws_logger.setLevel(logging.INFO)
69
70 loop.run(main())