1 # Juju Asyncronous API #
14 As of R2, the SO is using the older syncronous Juju API. This can lead the SO
15 to appear "frozen" while it blocks waiting for a Juju operation to complete.
17 To address this issue, we would like the SO to convert to using
18 [libjuju](https://github.com/juju/python-libjuju) python library. It offers
19 the following benefits:
20 - Asynchronous, using the asyncio and async/await features of python 3.5+
21 - Websocket-level bindings are programmatically generated (indirectly) from the
22 Juju golang code, ensuring full api coverage
23 - Provides an OO layer which encapsulates much of the websocket api and
24 provides familiar nouns and verbs (e.g. Model.deploy(), Application.add_unit(),
27 ## Demo or definition of done ##
28 Demos of using libjuju can be found in the
29 [quickstart](https://github.com/juju/python-libjuju#quickstart) and in the
30 [examples](https://github.com/juju/python-libjuju/tree/master/examples) folder.
32 Here is a simple implementation that deploys a charm:
40 from juju.model import Model
44 # Create a Model instance. We need to connect our Model to a Juju api
45 # server before we can use it.
48 # Connect to the currently active Juju model
49 await model.connect_current()
51 # Deploy a single unit of the ubuntu charm, using revision 0 from the
52 # stable channel of the Charm Store.
53 ubuntu_app = await model.deploy(
55 application_name='ubuntu',
60 # Disconnect from the api server and cleanup.
65 # Set logging level to debug so we can see verbose output from the
67 logging.basicConfig(level=logging.DEBUG)
69 # Quiet logging from the websocket library. If you want to see
70 # everything sent over the wire, set this to DEBUG.
71 ws_logger = logging.getLogger('websockets.protocol')
72 ws_logger.setLevel(logging.INFO)
74 # Run the deploy coroutine in an asyncio event loop, using a helper
75 # that abstracts loop creation and teardown.
79 if __name__ == '__main__':