0436259ccb432ab8d5fe728c422e011cce72924b
4 1. Connects to current model and resets it.
5 2. Deploys one ubuntu unit.
6 3. Runs an action against the unit.
7 4. Waits for the action results to come back, then exits.
13 from juju
.model
import Model
, ModelObserver
15 async def run_stuff_on_unit(unit
):
16 print('Running command on unit', unit
.name
)
18 # unit.run() returns a client.ActionResults instance
19 action
= await unit
.run('unit-get public-address')
21 print("Action results: {}".format(action
.results
))
23 # Inform asyncio that we're done.
24 await unit
.model
.disconnect()
25 unit
.model
.loop
.stop()
28 class MyModelObserver(ModelObserver
):
29 async def on_unit_add(self
, delta
, old
, new
, model
):
30 loop
.create_task(run_stuff_on_unit(new
))
35 await model
.connect_current()
36 await model
.reset(force
=True)
37 model
.add_observer(MyModelObserver())
41 application_name
='ubuntu',
47 logging
.basicConfig(level
=logging
.DEBUG
)
48 ws_logger
= logging
.getLogger('websockets.protocol')
49 ws_logger
.setLevel(logging
.INFO
)
50 loop
= asyncio
.get_event_loop()
52 loop
.create_task(run())