File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515
1616async def run_command (unit ):
1717 logging .debug ('Running command on unit %s' , unit .name )
18-
19- # unit.run() returns a juju.action.Action instance
18+ # unit.run() returns a juju.action.Action instance,
19+ # it needs to be wait()'ed to get the results
2020 action = await unit .run ('unit-get public-address' )
21- logging .debug ("Action results: %s" , action .results )
21+ await action .wait ()
22+
23+ out1 = f"Action status: { action .status } "
24+ logging .debug (out1 )
25+ print (out1 )
26+ # 'completed'
27+
28+ out2 = f"Action results: { action .results } "
29+ logging .debug (out2 )
30+ print (out2 )
31+ # {'return-code': 0, 'stdout': '<IP Addr>\n'}
2232
2333
2434async def main ():
@@ -36,11 +46,21 @@ async def main():
3646 for unit in app .units :
3747 await run_command (unit )
3848
49+ await app .remove ()
50+
3951 await model .disconnect ()
4052
4153
4254if __name__ == '__main__' :
43- logging .basicConfig (level = logging .DEBUG )
44- ws_logger = logging .getLogger ('websockets.protocol' )
45- ws_logger .setLevel (logging .INFO )
55+ # Uncomment below to get logging output
56+
57+ # logging.basicConfig(level=logging.DEBUG)
58+ # ws_logger = logging.getLogger('websockets.protocol')
59+ # ws_logger.setLevel(logging.INFO)
60+ """
61+ Should see something like the following in the output if using LOGGING
62+
63+ DEBUG:root:Action status: completed
64+ DEBUG:root:Action results: {'return-code': 0, 'stdout': '10.42.51.101\n '}
65+ """
4666 jasyncio .run (main ())
You can’t perform that action at this time.
0 commit comments