Modified Jenkinsfile to disable TEST_INSTALL in branch feature7928
[osm/N2VC.git] / modules / libjuju / 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()
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
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
65 if __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())