Skip to content

Commit

Permalink
export all feature added, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
weidenba committed Oct 25, 2024
1 parent 391ac5b commit d1bfe8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/nac/management/commands/clean_ldap_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def handle(self, *args, **options):
setup_console_logger(options['verbosity'])
self.config = get_config_from_file(options['config_file'])

logging.info('dry run? %s', options['dry_run'])

self.ldap_connection = connect_to_ldap_server(
self.config['ldap-server']['address'],
self.config['ldap-server']['user'],
Expand All @@ -60,7 +58,9 @@ def handle(self, *args, **options):
try:
Device.objects.get(appl_NAC_Hostname=entry['attributes']['appl-NAC-Hostname'])
except ObjectDoesNotExist:
if not options['dry_run']:
if options['dry_run']:
logging.warning('%s would be deleted (DRY RUN)', entry['attributes']['appl-NAC-Hostname'])
else:
delete_device(entry['attributes']['appl-NAC-Hostname'], self.ldap_connection, self.config['ldap-server']['search_base'])

self.ldap_connection.unbind()
6 changes: 5 additions & 1 deletion src/nac/management/commands/export_to_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument('-c', '--config_file', default=DEFAULT_CONFIG, help='use a specific config file [src/ldap.cfg]')
parser.add_argument('-a', '--all', action='store_true', help='sync all devices')

def handle(self, *args, **options):
setup_console_logger(options['verbosity'])
self.config = get_config_from_file(options['config_file'])

devices_to_sync = self._get_all_changed_devices()
if options['all']:
devices_to_sync = Device.objects.all()
else:
devices_to_sync = self._get_all_changed_devices()

self.ldap_connection = connect_to_ldap_server(
self.config['ldap-server']['address'],
Expand Down

0 comments on commit d1bfe8c

Please sign in to comment.