diff --git a/module/common/cli_parser.py b/module/common/cli_parser.py index 8101aaa..1dbbf14 100644 --- a/module/common/cli_parser.py +++ b/module/common/cli_parser.py @@ -50,6 +50,10 @@ def parse_command_line(version=None, self_description=None, version_date=None, d parser.add_argument("-l", "--log_level", choices=valid_log_levels, dest="log_level", help="set log level (overrides config)") + parser.add_argument("-n", "--dry_run", action="store_true", + help="Operate as usual but don't change anything in NetBox. Great if you want to test " + "and see what would be changed.") + parser.add_argument("-p", "--purge", action="store_true", help="Remove (almost) all synced objects which were create by this script. " "This is helpful if you want to start fresh or stop using this script.") diff --git a/netbox-sync.py b/netbox-sync.py index 8a09c58..d8190fc 100755 --- a/netbox-sync.py +++ b/netbox-sync.py @@ -105,6 +105,10 @@ def main(): # if purge was selected we go ahead and remove all items which were managed by this tools if args.purge is True: + + if args.dry_run is True: + do_error_exit("Purge not available with option 'dry_run'") + nb_handler.just_delete_all_the_things() # that's it, we are done here @@ -142,6 +146,11 @@ def main(): # update all IP addresses inventory.query_ptr_records_for_all_ips() + if args.dry_run is True: + log.info("This is a dry run and we stop here. Running time: %s" % + get_relative_time(datetime.now() - start_time)) + exit(0) + # update data in NetBox nb_handler.update_instance()