Juju Library - Holiday Success
James Beedy
jamesbeedy at gmail.com
Sat Dec 24 18:37:38 UTC 2016
Just wanted to share my progress on scripting with the juju library.
Initially, It took me a moment to wrap my head around (mostly due to my
inexperience with asynchronous programming) how to interface to the juju
library, and write a simple script that exits cleanly (without spewing
tracebacks http://paste.ubuntu.com/23678912/). I iterated on this for some
time yesterday, then came back to it for a few moments this morning.
Combining a few of my ideas from yesterday, I ended finding a combination
that worked for what I was after [1]. This solution requires a few critical
pieces to all exist, in order to function as I was intending. The key
pieces needed to make this work correctly for me; use aiohttp context while
accessing juju lib objects [2] (this seems mandatory in order to get a
response back from juju lib), use signal handlers that cancel the remaining
tasks correctly [3], call 'sys.exit(1)' after closing the loop [4]. After
pulling these pieces together, I ended up with something that I think I can
work with moving forward.
Hopefully this helps others get things kicked off with lib juju a bit
faster!
Happy holidays all!
~James
[1] https://gist.github.com/jamesbeedy/18fc2c910716cd92343bc876af8c7bb6
[2]
https://gist.github.com/jamesbeedy/18fc2c910716cd92343bc876af8c7bb6#file-model_connect-py-L31
[3]
https://gist.github.com/jamesbeedy/18fc2c910716cd92343bc876af8c7bb6#file-model_connect-py-L50,L51
[4]
https://gist.github.com/jamesbeedy/18fc2c910716cd92343bc876af8c7bb6#file-model_connect-py-L60
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju-dev/attachments/20161224/0e1de3ef/attachment.html>
More information about the Juju-dev
mailing list