From e92b0007da5628c18a4d3d2e64c5f8114acec152 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 14 Jul 2017 11:47:03 +0200 Subject: [PATCH] Adding simulation mode to import-pdnsdata --- pp_lib/import_pdnsdata.py | 42 +++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/pp_lib/import_pdnsdata.py b/pp_lib/import_pdnsdata.py index 9fd81c3..de5fa64 100644 --- a/pp_lib/import_pdnsdata.py +++ b/pp_lib/import_pdnsdata.py @@ -29,7 +29,7 @@ from .common import pp from .cfg_app import PpCfgAppError, PpConfigApplication -__version__ = '0.4.4' +__version__ = '0.5.1' LOG = logging.getLogger(__name__) # ============================================================================= @@ -69,6 +69,8 @@ class ImportPdnsdataApp(PpConfigApplication): self.src_connection = None self.tgt_connection = None + self._show_simulate_opt = True + super(ImportPdnsdataApp, self).__init__( appname=appname, version=version, description=description, cfg_stems='import-pdnsdata' @@ -248,7 +250,8 @@ class ImportPdnsdataApp(PpConfigApplication): sql = 'TRUNCATE TABLE {} RESTART IDENTITY CASCADE'.format(table) if self.verbose > 1: LOG.debug("SQL: {}".format(sql)) - tgt_cursor.execute(sql) + if not self.simulate: + tgt_cursor.execute(sql) LOG.debug("Commiting changes ...") self.tgt_connection.commit() @@ -274,7 +277,6 @@ class ImportPdnsdataApp(PpConfigApplication): if self.verbose > 1: LOG.debug("Target SQL:\n{}".format(tgt_sql)) - with self.tgt_connection.cursor() as tgt_cursor: with self.src_connection.cursor() as src_cursor: @@ -287,7 +289,8 @@ class ImportPdnsdataApp(PpConfigApplication): for result in results: i += 1 - tgt_cursor.execute(tgt_sql, result) + if not self.simulate: + tgt_cursor.execute(tgt_sql, result) LOG.info("Imported {} domains.".format(i)) LOG.debug("Get max. Domain Id ...") @@ -303,7 +306,8 @@ class ImportPdnsdataApp(PpConfigApplication): LOG.debug("Setting curval of domains_id_seq to {} ...".format(max_id)) if self.verbose > 1: LOG.debug("SQL: {}".format(sql)) - tgt_cursor.execute(sql, (max_id, )) + if not self.simulate: + tgt_cursor.execute(sql, (max_id, )) LOG.debug("Commiting changes ...") self.tgt_connection.commit() @@ -352,7 +356,8 @@ class ImportPdnsdataApp(PpConfigApplication): result['active'] = True else: result['active'] = False - tgt_cursor.execute(tgt_sql, result) + if not self.simulate: + tgt_cursor.execute(tgt_sql, result) LOG.info("Imported {} cryptokeys.".format(i)) LOG.debug("Get max. CryptoKey Id ...") @@ -368,7 +373,8 @@ class ImportPdnsdataApp(PpConfigApplication): LOG.debug("Setting curval of cryptokeys_id_seq to {} ...".format(max_id)) if self.verbose > 1: LOG.debug("SQL: {}".format(sql)) - tgt_cursor.execute(sql, (max_id, )) + if not self.simulate: + tgt_cursor.execute(sql, (max_id, )) LOG.debug("Commiting changes ...") self.tgt_connection.commit() @@ -413,7 +419,8 @@ class ImportPdnsdataApp(PpConfigApplication): for result in results: i += 1 - tgt_cursor.execute(tgt_sql, result) + if not self.simulate: + tgt_cursor.execute(tgt_sql, result) LOG.info("Imported {} domainmetadata.".format(i)) LOG.debug("Get max. DomainMetadata Id ...") @@ -429,7 +436,8 @@ class ImportPdnsdataApp(PpConfigApplication): LOG.debug("Setting curval of domainmetadata_id_seq to {} ...".format(max_id)) if self.verbose > 1: LOG.debug("SQL: {}".format(sql)) - tgt_cursor.execute(sql, (max_id, )) + if not self.simulate: + tgt_cursor.execute(sql, (max_id, )) LOG.debug("Commiting changes ...") self.tgt_connection.commit() @@ -486,7 +494,8 @@ class ImportPdnsdataApp(PpConfigApplication): result['auth'] = True else: result['auth'] = False - tgt_cursor.execute(tgt_sql, result) + if not self.simulate: + tgt_cursor.execute(tgt_sql, result) LOG.info("Imported {} records.".format(i)) LOG.debug("Get max. records Id ...") @@ -502,7 +511,8 @@ class ImportPdnsdataApp(PpConfigApplication): LOG.debug("Setting curval of records_id_seq to {} ...".format(max_id)) if self.verbose > 1: LOG.debug("SQL: {}".format(sql)) - tgt_cursor.execute(sql, (max_id, )) + if not self.simulate: + tgt_cursor.execute(sql, (max_id, )) LOG.debug("Commiting changes ...") self.tgt_connection.commit() @@ -527,7 +537,6 @@ class ImportPdnsdataApp(PpConfigApplication): if self.verbose > 1: LOG.debug("Target SQL:\n{}".format(tgt_sql)) - with self.tgt_connection.cursor() as tgt_cursor: with self.src_connection.cursor() as src_cursor: @@ -546,7 +555,8 @@ class ImportPdnsdataApp(PpConfigApplication): for result in results: i += 1 - tgt_cursor.execute(tgt_sql, result) + if not self.simulate: + tgt_cursor.execute(tgt_sql, result) LOG.info("Imported {} supermasters.".format(i)) LOG.debug("Commiting changes ...") @@ -590,7 +600,8 @@ class ImportPdnsdataApp(PpConfigApplication): for result in results: i += 1 - tgt_cursor.execute(tgt_sql, result) + if not self.simulate: + tgt_cursor.execute(tgt_sql, result) LOG.info("Imported {} tsigkeys.".format(i)) LOG.debug("Get max. TsigKey Id ...") @@ -606,7 +617,8 @@ class ImportPdnsdataApp(PpConfigApplication): LOG.debug("Setting curval of tsigkeys_id_seq to {} ...".format(max_id)) if self.verbose > 1: LOG.debug("SQL: {}".format(sql)) - tgt_cursor.execute(sql, (max_id, )) + if not self.simulate: + tgt_cursor.execute(sql, (max_id, )) LOG.debug("Commiting changes ...") self.tgt_connection.commit() -- 2.39.5