X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Fexamples%2Fdeploy.py;fp=modules%2Flibjuju%2Fexamples%2Fdeploy.py;h=e6c306a1aeedea0f7bd335d10576b95b18aa39e2;hp=0000000000000000000000000000000000000000;hb=68858c1915122c2dbc8999a5cd3229694abf5f3a;hpb=032a71b2a6692b8b4e30f629a1f906d246f06736 diff --git a/modules/libjuju/examples/deploy.py b/modules/libjuju/examples/deploy.py new file mode 100644 index 0000000..e6c306a --- /dev/null +++ b/modules/libjuju/examples/deploy.py @@ -0,0 +1,40 @@ +""" +This example: + +1. Connects to the current model +2. Deploy a charm and waits until it reports itself active +3. Destroys the unit and application + +""" +from juju import loop +from juju.model import Model + + +async def main(): + model = Model() + print('Connecting to model') + await model.connect_current() + + try: + print('Deploying ubuntu') + application = await model.deploy( + 'ubuntu-10', + application_name='ubuntu', + series='trusty', + channel='stable', + ) + + print('Waiting for active') + await model.block_until( + lambda: all(unit.workload_status == 'active' + for unit in application.units)) + + print('Removing ubuntu') + await application.remove() + finally: + print('Disconnecting from model') + await model.disconnect() + + +if __name__ == '__main__': + loop.run(main())