from .cfg_app import PpCfgAppError, PpConfigApplication
-__version__ = '0.4.3'
+__version__ = '0.4.4'
LOG = logging.getLogger(__name__)
# =============================================================================
'invalid': 0,
},
'tsigkeys': {
- 'has_domain': True,
+ 'has_domain': False,
'total': 0,
'valid': 0,
'invalid': 0,
try:
self.get_src_info()
self.clean_tgt_db()
+ self.import_supermasters()
self.import_domains()
self.import_cryptokeys()
self.import_domainmetadata()
self.import_records()
+ self.import_tsigkeys()
finally:
self._close_all()
%(type)s, %(notified_serial)s, %(account)s)
''').strip()
if self.verbose > 1:
- LOG.debug("Source SQL:\n{}".format(tgt_sql))
+ LOG.debug("Target SQL:\n{}".format(tgt_sql))
with self.tgt_connection.cursor() as tgt_cursor:
VALUES (%(id)s, %(domain_id)s, %(flags)s, %(active)s, %(content)s)
''').strip()
if self.verbose > 1:
- LOG.debug("Source SQL:\n{}".format(tgt_sql))
+ LOG.debug("Target SQL:\n{}".format(tgt_sql))
with self.tgt_connection.cursor() as tgt_cursor:
VALUES (%(id)s, %(domain_id)s, %(kind)s, %(content)s)
''').strip()
if self.verbose > 1:
- LOG.debug("Source SQL:\n{}".format(tgt_sql))
+ LOG.debug("Target SQL:\n{}".format(tgt_sql))
with self.tgt_connection.cursor() as tgt_cursor:
%(ordername)s, %(auth)s)
''').strip()
if self.verbose > 1:
- LOG.debug("Source SQL:\n{}".format(tgt_sql))
+ LOG.debug("Target SQL:\n{}".format(tgt_sql))
with self.tgt_connection.cursor() as tgt_cursor:
LOG.debug("Commiting changes ...")
self.tgt_connection.commit()
+ # -------------------------------------------------------------------------
+ def import_supermasters(self):
+
+ LOG.info("Importing all supermasters ...")
+
+ src_sql = textwrap.dedent('''\
+ SELECT ip, nameserver, account
+ FROM supermasters
+ ORDER by nameserver
+ ''').strip()
+ if self.verbose > 1:
+ LOG.debug("Source SQL:\n{}".format(src_sql))
+
+ tgt_sql = textwrap.dedent('''\
+ INSERT INTO supermasters (ip, nameserver, account)
+ VALUES (%(ip)s, %(nameserver)s, %(account)s)
+ ''').strip()
+ 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:
+
+ i = 0
+ src_cursor.execute(src_sql)
+ results = src_cursor.fetchall()
+
+ if self.verbose > 2:
+ LOG.debug("Got supermasters:\n{}".format(pp(results)))
+
+ if not results:
+ LOG.info("No supermasters in source database.")
+ LOG.debug("Commiting changes ...")
+ self.tgt_connection.commit()
+ return
+
+ for result in results:
+ i += 1
+ tgt_cursor.execute(tgt_sql, result)
+ LOG.info("Imported {} supermasters.".format(i))
+
+ LOG.debug("Commiting changes ...")
+ self.tgt_connection.commit()
+
+ # -------------------------------------------------------------------------
+ def import_tsigkeys(self):
+
+ LOG.info("Importing all tsigkeys ...")
+
+ src_sql = textwrap.dedent('''\
+ SELECT id, name, algorithm, secret
+ FROM tsigkeys
+ ''').strip()
+ if self.verbose > 1:
+ LOG.debug("Source SQL:\n{}".format(src_sql))
+
+ tgt_sql = textwrap.dedent('''\
+ INSERT INTO tsigkeys (id, name, algorithm, secret)
+ VALUES (%(id)s, %(name)s, %(algorithm)s, %(secret)s)
+ ''').strip()
+ 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:
+
+ i = 0
+ src_cursor.execute(src_sql)
+ results = src_cursor.fetchall()
+
+ if self.verbose > 2:
+ LOG.debug("Got tsigkeys:\n{}".format(pp(results)))
+
+ if not results:
+ LOG.info("No tsigkeys in source database.")
+ LOG.debug("Commiting changes ...")
+ self.tgt_connection.commit()
+ return
+
+ for result in results:
+ i += 1
+ tgt_cursor.execute(tgt_sql, result)
+ LOG.info("Imported {} tsigkeys.".format(i))
+
+ LOG.debug("Get max. TsigKey Id ...")
+ sql = "SELECT MAX(id) AS max_id FROM tsigkeys"
+ if self.verbose > 1:
+ LOG.debug("SQL: {}".format(sql))
+ tgt_cursor.execute(sql)
+ result = tgt_cursor.fetchone()
+ if self.verbose > 2:
+ LOG.debug("Got max TsigKey Id:\n{}".format(pp(result)))
+ max_id = int(result[0])
+ sql = "SELECT SETVAL('tsigkeys_id_seq', %s)"
+ 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, ))
+
+ LOG.debug("Commiting changes ...")
+ self.tgt_connection.commit()
+
# -------------------------------------------------------------------------
def _close_all(self):