X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Fexamples%2Faction.py;fp=modules%2Flibjuju%2Fexamples%2Faction.py;h=0f25647d78d147c13ef8258d9773bbcd24ec069b;hp=0000000000000000000000000000000000000000;hb=68858c1915122c2dbc8999a5cd3229694abf5f3a;hpb=032a71b2a6692b8b4e30f629a1f906d246f06736 diff --git a/modules/libjuju/examples/action.py b/modules/libjuju/examples/action.py new file mode 100644 index 0000000..0f25647 --- /dev/null +++ b/modules/libjuju/examples/action.py @@ -0,0 +1,50 @@ +""" +This example: + +1. Connects to current model and resets it. +2. Deploys a git unit. +3. Runs an action against the unit. +4. Waits for the action results to come back, then exits. + +""" +import asyncio +import logging + +from juju import loop +from juju.model import Model + + +async def run_action(unit): + logging.debug('Running action on unit %s', unit.name) + + # unit.run() returns a juju.action.Action instance + action = await unit.run_action('add-repo', repo='myrepo') + # wait for the action to complete + action = await action.wait() + + logging.debug("Action results: %s", action.results) + + +async def main(): + model = Model() + await model.connect_current() + await model.reset(force=True) + + app = await model.deploy( + 'git', + application_name='git', + series='trusty', + channel='stable', + ) + + for unit in app.units: + await run_action(unit) + + await model.disconnect() + + +if __name__ == '__main__': + logging.basicConfig(level=logging.DEBUG) + ws_logger = logging.getLogger('websockets.protocol') + ws_logger.setLevel(logging.INFO) + loop.run(main())