X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Fdocs%2Freadme.rst;fp=modules%2Flibjuju%2Fdocs%2Freadme.rst;h=ecfbc5a4b90600949baf988ac55e1da585a7265d;hp=0000000000000000000000000000000000000000;hb=68858c1915122c2dbc8999a5cd3229694abf5f3a;hpb=032a71b2a6692b8b4e30f629a1f906d246f06736 diff --git a/modules/libjuju/docs/readme.rst b/modules/libjuju/docs/readme.rst new file mode 100644 index 0000000..ecfbc5a --- /dev/null +++ b/modules/libjuju/docs/readme.rst @@ -0,0 +1,95 @@ +A Python library for Juju +========================= + +Source code: https://github.com/juju/python-libjuju + +Bug reports: https://github.com/juju/python-libjuju/issues + +Documentation: https://pythonlibjuju.readthedocs.io/en/latest/ + + +Requirements +------------ + +* Python 3.5+ +* Juju 2.0+ + + +Design Notes +------------ + +* Asynchronous - uses asyncio and async/await features of python 3.5 +* Websocket-level bindings are programmatically generated (indirectly) from the + Juju golang code, ensuring full api coverage +* Provides an OO layer which encapsulates much of the websocket api and + provides familiar nouns and verbs (e.g. Model.deploy(), Application.add_unit(), + etc.) + + +Installation +------------ + +.. code:: bash + + pip3 install juju + + +Quickstart +---------- +Here's a simple example that shows basic usage of the library. The example +connects to the currently active Juju model, deploys a single unit of the +ubuntu charm, then exits. + +More examples can be found in the `examples/` directory of the source tree, +and in the documentation. + + +.. code:: python + + #!/usr/bin/python3.5 + + import asyncio + import logging + + from juju import loop + from juju.model import Model + + + async def deploy(): + # Create a Model instance. We need to connect our Model to a Juju api + # server before we can use it. + model = Model() + + # Connect to the currently active Juju model + await model.connect_current() + + # Deploy a single unit of the ubuntu charm, using revision 0 from the + # stable channel of the Charm Store. + ubuntu_app = await model.deploy( + 'ubuntu-0', + application_name='ubuntu', + series='xenial', + channel='stable', + ) + + # Disconnect from the api server and cleanup. + model.disconnect() + + + def main(): + # Set logging level to debug so we can see verbose output from the + # juju library. + logging.basicConfig(level=logging.DEBUG) + + # Quiet logging from the websocket library. If you want to see + # everything sent over the wire, set this to DEBUG. + ws_logger = logging.getLogger('websockets.protocol') + ws_logger.setLevel(logging.INFO) + + # Run the deploy coroutine in an asyncio event loop, using a helper + # that abstracts loop creation and teardown. + loop.run(deploy()) + + + if __name__ == '__main__': + main()