Fix single app deploy not using config_yaml
[osm/N2VC.git] / docs / readme.rst
1 A Python library for Juju
2 =========================
3
4 Source code: https://github.com/juju/python-libjuju
5
6 Bug reports: https://github.com/juju/python-libjuju/issues
7
8 Documentation: https://pythonhosted.org/juju/
9
10
11 Requirements
12 ------------
13
14 * Python 3.5+
15 * Juju 2.0+
16
17
18 Design Notes
19 ------------
20
21 * Asynchronous - uses asyncio and async/await features of python 3.5
22 * Websocket-level bindings are programmatically generated (indirectly) from the
23   Juju golang code, ensuring full api coverage
24 * Provides an OO layer which encapsulates much of the websocket api and
25   provides familiar nouns and verbs (e.g. Model.deploy(), Application.add_unit(),
26   etc.)
27
28
29 Installation
30 ------------
31
32 .. code:: bash
33
34   pip install juju
35
36
37 Quickstart
38 ----------
39 Here's a simple example that shows basic usage of the library. The example
40 connects to the currently active Juju model, deploys a single unit of the
41 ubuntu charm, then exits.
42
43 More examples can be found in the `examples/` directory of the source tree,
44 and in the documentation.
45
46
47 .. code:: python
48
49   #!/usr/bin/python3.5
50
51   import asyncio
52   import logging
53
54   from juju.model import Model
55
56
57   async def run():
58       # Create a Model instance. We need to connect our Model to a Juju api
59       # server before we can use it.
60       model = Model()
61
62       # Connect to the currently active Juju model
63       await model.connect_current()
64
65       # Deploy a single unit of the ubuntu charm, using revision 0 from the
66       # stable channel of the Charm Store.
67       ubuntu_app = await model.deploy(
68           'ubuntu-0',
69           application_name='ubuntu',
70           series='xenial',
71           channel='stable',
72       )
73
74       # Disconnect from the api server and cleanup.
75       model.disconnect()
76
77       # Stop the asyncio event loop.
78       model.loop.stop()
79
80
81   def main():
82       # Set logging level to debug so we can see verbose output from the
83       # juju library.
84       logging.basicConfig(level=logging.DEBUG)
85
86       # Quiet logging from the websocket library. If you want to see
87       # everything sent over the wire, set this to DEBUG.
88       ws_logger = logging.getLogger('websockets.protocol')
89       ws_logger.setLevel(logging.INFO)
90
91       # Create the asyncio event loop
92       loop = asyncio.get_event_loop()
93
94       # Queue up our `run()` coroutine for execution
95       loop.create_task(run())
96
97       # Start the event loop
98       loop.run_forever()
99
100
101   if __name__ == '__main__':
102       main()