7e7f0dae3a5fdddb3392a3f72755aed1f17a1f35
[osm/N2VC.git] / examples / controller.py
1 """
2 This example:
3
4 1. Connects to current controller.
5 2. Creates a new model.
6 3. Deploys an application on the new model.
7 4. Disconnects from the model
8 5. Destroys the model
9
10 """
11 import asyncio
12 import logging
13
14 from juju.controller import Controller
15
16
17 async def run():
18 controller = Controller()
19 await controller.connect_current()
20 model = await controller.add_model(
21 'my-test-model',
22 'aws',
23 'aws-tim',
24 )
25 await model.deploy(
26 'ubuntu-0',
27 application_name='ubuntu',
28 series='trusty',
29 channel='stable',
30 )
31 await model.disconnect()
32 await controller.destroy_model(model.info.uuid)
33 await controller.disconnect()
34 model.loop.stop()
35
36
37 logging.basicConfig(level=logging.DEBUG)
38 ws_logger = logging.getLogger('websockets.protocol')
39 ws_logger.setLevel(logging.INFO)
40 loop = asyncio.get_event_loop()
41 loop.set_debug(False)
42 loop.create_task(run())
43 loop.run_forever()