mirror of
https://github.com/bb-Ricardo/netbox-sync.git
synced 2026-01-29 04:19:10 -06:00
adds dry run CLI option to test the program without changing data
This commit is contained in:
@@ -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.")
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user