]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding simulation mode to import-pdnsdata
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 14 Jul 2017 09:47:03 +0000 (11:47 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 14 Jul 2017 09:47:03 +0000 (11:47 +0200)
pp_lib/import_pdnsdata.py

index 9fd81c326f71068db22f2fc27eec9adef5b5a537..de5fa6484f331b8b11ba9b377cf4fc1b57ec6c39 100644 (file)
@@ -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()