From a364a3fecb9d81f59b351af347e73f7aa6b1b8b0 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Mon, 29 Dec 2025 09:01:18 +0000 Subject: [PATCH] Fine tune of get_relation_info.py --- get_relation_info.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/get_relation_info.py b/get_relation_info.py index eb39744..e65a723 100755 --- a/get_relation_info.py +++ b/get_relation_info.py @@ -9,6 +9,7 @@ from juju.model import Model async def main(args): unit_name = args.unit_name + app_name = args.app_name if args.bind_check: bind_check = args.bind_check @@ -16,7 +17,11 @@ async def main(args): await model.connect_current() try: - app = unit_name.split('/')[0] + if unit_name is not None: + app = unit_name.split('/')[0] + elif app_name is not None: + app = app_name + print("Grab relational data from the lead unit ...") juju_status = await model.get_status() @@ -28,7 +33,9 @@ async def main(args): if ((binding is not None and "bind_check" not in locals()) or ("bind_check" in locals() and binding == bind_check)): for unit in units: - if unit.name == unit_name: + if ((unit_name is not None and unit.name == unit_name) + or (app_name is not None + and await unit.is_leader_from_status())): await _check_binding(unit, binding) finally: @@ -66,12 +73,12 @@ async def _get_rel_ids(unit, binding): def _parse_args(): parser = argparse.ArgumentParser() - parser.add_argument('-u', '--unit', metavar="", - help="Unit to run against", dest="unit_name", - required=True) - # parser.add_argument('-a', '--application', metavar="", - # help="Application to run against", - # dest="app_name") + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument('-u', '--unit', metavar="", + help="Unit to run against", dest="unit_name") + group.add_argument('-a', '--application', metavar="", + help="Application to run against", + dest="app_name") parser.add_argument('-b', '--binding', metavar="", help="Only check for the relational data", dest="bind_check")