Fine tune of get_relation_info.py

This commit is contained in:
2025-12-29 09:01:18 +00:00
parent 268ba99f70
commit a364a3fecb

View File

@@ -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="<unit>",
help="Unit to run against", dest="unit_name",
required=True)
# parser.add_argument('-a', '--application', metavar="<application>",
# help="Application to run against",
# dest="app_name")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-u', '--unit', metavar="<unit>",
help="Unit to run against", dest="unit_name")
group.add_argument('-a', '--application', metavar="<application>",
help="Application to run against",
dest="app_name")
parser.add_argument('-b', '--binding', metavar="<binding>",
help="Only check <binding> for the relational data",
dest="bind_check")