From f6f57c9d4d9776858d82e2de692af78d5cf34fe1 Mon Sep 17 00:00:00 2001 From: Wiktor Grzywacz Date: Thu, 16 Jan 2025 18:46:30 +0100 Subject: [PATCH 1/2] osfv_cli/src/osfv/cli/cli.py: add ad-hoc-mode --- osfv_cli/src/osfv/cli/cli.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/osfv_cli/src/osfv/cli/cli.py b/osfv_cli/src/osfv/cli/cli.py index 7a61e9e..0507475 100755 --- a/osfv_cli/src/osfv/cli/cli.py +++ b/osfv_cli/src/osfv/cli/cli.py @@ -594,6 +594,8 @@ def main(): help="Output as JSON (if applicable)", ) + parser.add_argument('--adhoc', action='store_true', help="Enable ad-hoc mode to use any RTE.") + subparsers = parser.add_subparsers( title="commands", dest="command", help="Command to execute" ) @@ -880,7 +882,11 @@ def main(): if asset_id: check_out_asset(snipeit_api, asset_id) else: - print(f"No asset found with RTE IP: {args.rte_ip}") + if args.adhoc: + print(f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Proceeding with ad-hoc configuration.") + else: + print(f"No asset found with RTE IP: {args.rte_ip}") + sys.exit(1) elif args.snipeit_cmd == "check_in": if args.asset_id: check_in_asset(snipeit_api, args.asset_id) @@ -889,7 +895,11 @@ def main(): if asset_id: check_in_asset(snipeit_api, asset_id) else: - print(f"No asset found with RTE IP: {args.rte_ip}") + if args.adhoc: + print(f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Proceeding with ad-hoc configuration.") + else: + print(f"No asset found with RTE IP: {args.rte_ip}") + sys.exit(1) elif args.snipeit_cmd == "check_in_my": check_in_my(snipeit_api, args) elif args.snipeit_cmd == "user_add": @@ -905,7 +915,11 @@ def main(): if not args.skip_snipeit: asset_id = snipeit_api.get_asset_id_by_rte_ip(args.rte_ip) if not asset_id: - print(f"No asset found with RTE IP: {args.rte_ip}") + if args.adhoc: + print(f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Skipping Snipe-IT checks.") + else: + print(f"No asset found with RTE IP: {args.rte_ip}") + sys.exit(1) if args.model: print(f"DUT model retrieved from cmdline, skipping Snipe-IT query") @@ -1009,7 +1023,11 @@ def main(): asset_id = snipeit_api.get_asset_id_by_sonoff_ip(sonoff_ip) if not asset_id: - print(f"No asset found with RTE IP: {args.rte_ip}") + if args.adhoc: + print(f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Skipping Snipe-IT checks.") + else: + print(f"No asset found with RTE IP: {args.rte_ip}") + sys.exit(1) print( f"Using rte command is invasive action, checking first if the device is not used..." From e0b26f97b2e38fac2842473921dc75dd1730ae67 Mon Sep 17 00:00:00 2001 From: Wiktor Grzywacz Date: Thu, 16 Jan 2025 18:50:01 +0100 Subject: [PATCH 2/2] osfv_cli/src/osfv/cli/cli.py: fix pre-commit --- osfv_cli/src/osfv/cli/cli.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/osfv_cli/src/osfv/cli/cli.py b/osfv_cli/src/osfv/cli/cli.py index 0507475..8cd8642 100755 --- a/osfv_cli/src/osfv/cli/cli.py +++ b/osfv_cli/src/osfv/cli/cli.py @@ -594,7 +594,11 @@ def main(): help="Output as JSON (if applicable)", ) - parser.add_argument('--adhoc', action='store_true', help="Enable ad-hoc mode to use any RTE.") + parser.add_argument( + "--adhoc", + action="store_true", + help="Enable ad-hoc mode to use any RTE.", + ) subparsers = parser.add_subparsers( title="commands", dest="command", help="Command to execute" @@ -883,7 +887,9 @@ def main(): check_out_asset(snipeit_api, asset_id) else: if args.adhoc: - print(f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Proceeding with ad-hoc configuration.") + print( + f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Proceeding with ad-hoc configuration." + ) else: print(f"No asset found with RTE IP: {args.rte_ip}") sys.exit(1) @@ -896,7 +902,9 @@ def main(): check_in_asset(snipeit_api, asset_id) else: if args.adhoc: - print(f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Proceeding with ad-hoc configuration.") + print( + f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Proceeding with ad-hoc configuration." + ) else: print(f"No asset found with RTE IP: {args.rte_ip}") sys.exit(1) @@ -916,7 +924,9 @@ def main(): asset_id = snipeit_api.get_asset_id_by_rte_ip(args.rte_ip) if not asset_id: if args.adhoc: - print(f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Skipping Snipe-IT checks.") + print( + f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Skipping Snipe-IT checks." + ) else: print(f"No asset found with RTE IP: {args.rte_ip}") sys.exit(1) @@ -1024,7 +1034,9 @@ def main(): asset_id = snipeit_api.get_asset_id_by_sonoff_ip(sonoff_ip) if not asset_id: if args.adhoc: - print(f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Skipping Snipe-IT checks.") + print( + f"Ad-hoc mode: No asset found with RTE IP: {args.rte_ip}. Skipping Snipe-IT checks." + ) else: print(f"No asset found with RTE IP: {args.rte_ip}") sys.exit(1)