Created
July 27, 2017 05:32
-
-
Save mjs/484dd863dd6bc593bb2690f7450d7cc6 to your computer and use it in GitHub Desktop.
This file contains 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/python3.5 | |
import asyncio | |
import logging | |
from juju import loop | |
from juju.model import Model, ModelObserver | |
class ModelWatcher(ModelObserver): | |
async def on_machine_add(self, delta, old, new, model): | |
self._print("ADD", delta.data) | |
async def on_machine_change(self, delta, old, new, model): | |
self._print("CHANGE", delta.data) | |
def _print(self, label, data): | |
machine_id = data["id"] | |
status = data.get("instance-status", {}) | |
print("machine {} {}: {} ({})".format( | |
machine_id, | |
label, | |
status["current"], | |
status["message"])) | |
async def setup(): | |
model = Model() | |
await model.connect_current() | |
model.add_observer(ModelWatcher()) | |
logging.basicConfig(level=logging.WARNING) | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(setup()) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: