Last active
December 24, 2016 18:47
-
-
Save jamesbeedy/18fc2c910716cd92343bc876af8c7bb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import functools | |
| import sys | |
| import signal | |
| import asyncio | |
| import aiohttp | |
| import logging | |
| from juju.model import Model | |
| username = sys.argv[1] | |
| password = sys.argv[2] | |
| controller_endpoint = sys.argv[3] | |
| model_uuid = sys.argv[4] | |
| cacert = None | |
| model = Model() | |
| async def connect_to_model(): | |
| await model.connect( | |
| controller_endpoint, | |
| model_uuid, | |
| username, | |
| password, | |
| cacert) | |
| async def main(loop): | |
| async with aiohttp.ClientSession(loop=loop) as session: | |
| await connect_to_model() | |
| # Print out applications once we have connected to the model | |
| for i in model.applications: | |
| print(i) | |
| def shutdown(loop): | |
| logging.info('received stop signal, cancelling tasks...') | |
| for task in asyncio.Task.all_tasks(): | |
| task.cancel() | |
| logging.info('bye, exiting in a minute...') | |
| if __name__ == "__main__": | |
| logging.getLogger().setLevel(logging.INFO) | |
| loop = asyncio.get_event_loop() | |
| loop.add_signal_handler(signal.SIGHUP, functools.partial(shutdown, loop)) | |
| loop.add_signal_handler(signal.SIGTERM, functools.partial(shutdown, loop)) | |
| try: | |
| loop.run_until_complete(main(loop)) | |
| except KeyboardInterrupt: | |
| pass | |
| loop.close() | |
| sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment