X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Fdocs%2Freadme.rst;h=87666d0ba3c9781881f2448ba075911b3bc74e6f;hp=ecfbc5a4b90600949baf988ac55e1da585a7265d;hb=7b4702c2e118bab49def498b4b4c236d430dbc13;hpb=68858c1915122c2dbc8999a5cd3229694abf5f3a diff --git a/modules/libjuju/docs/readme.rst b/modules/libjuju/docs/readme.rst index ecfbc5a..87666d0 100644 --- a/modules/libjuju/docs/readme.rst +++ b/modules/libjuju/docs/readme.rst @@ -38,18 +38,15 @@ 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. +ubuntu charm, then exits: .. code:: python - #!/usr/bin/python3.5 + #!/usr/bin/python3 - import asyncio import logging + import sys from juju import loop from juju.model import Model @@ -63,26 +60,28 @@ and in the documentation. # 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', - ) + try: + # Deploy a single unit of the ubuntu charm, using the latest revision + # from the stable channel of the Charm Store. + ubuntu_app = await model.deploy( + 'ubuntu', + application_name='ubuntu', + series='xenial', + channel='stable', + ) - # Disconnect from the api server and cleanup. - model.disconnect() + if '--wait' in sys.argv: + # optionally block until the application is ready + await model.block_until(lambda: ubuntu_app.status == 'active') + finally: + # Disconnect from the api server and cleanup. + await model.disconnect() def main(): - # Set logging level to debug so we can see verbose output from the - # juju library. - logging.basicConfig(level=logging.DEBUG) + logging.basicConfig(level=logging.INFO) - # Quiet logging from the websocket library. If you want to see - # everything sent over the wire, set this to DEBUG. + # 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) @@ -93,3 +92,12 @@ and in the documentation. if __name__ == '__main__': main() + + +More examples can be found in the docs, as well as in the ``examples/`` +directory of the source tree which can be run using ``tox``. For +example, to run ``examples/connect_current_model.py``, use: + +.. code:: bash + + tox -e example -- examples/connect_current_model.py