Correct MB/GB constants
[osm/N2VC.git] / examples / add_machine.py
1 #!/usr/bin/env python3.5
2
3 """
4 This example:
5
6 1. Connects to the current model
7 2. Creates two machines and a lxd container
8 3. Deploys charm to the lxd container
9
10 """
11 import logging
12
13 from juju import loop
14 from juju.model import Model
15
16 MB = 1
17 GB = 1024
18
19
20 async def main():
21 model = Model()
22 await model.connect_current()
23
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 await machine3.destroy()
58 await machine2.destroy()
59 await machine1.destroy()
60 finally:
61 await model.disconnect()
62
63
64 logging.basicConfig(level=logging.DEBUG)
65 ws_logger = logging.getLogger('websockets.protocol')
66 ws_logger.setLevel(logging.INFO)
67
68 loop.run(main())