from __future__ import absolute_import
# Standard modules
-import os
import logging
import logging.config
import re
-import pwd
import textwrap
import traceback
import socket
-import ipaddress
import datetime
import time
# Third party modules
-import six
-
import psycopg2
import pymysql
from .pdns_record import PdnsSoaData
-__version__ = '0.9.3'
+__version__ = '0.9.4'
LOG = logging.getLogger(__name__)
# =============================================================================
class ImportPdnsdataError(PpCfgAppError):
- pass;
+ pass
# =============================================================================
class ImportPdnsdataApp(PpConfigApplication):
# -------------------------------------------------------------------------
def __init__(self, appname=None, version=__version__):
-
description = textwrap.dedent('''\
Importing complete Database for PowerDNS from old DB into the new one.
''').strip()
if 'host' in section:
host = section['host'].lower().strip()
if not host:
- LOG.error('Invalid source hostname {!r} in configuration section {!r} found.'.format(
- section['host'], section_name))
+ LOG.error(
+ 'Invalid source hostname {!r} in configuration section {!r} found.'.format(
+ section['host'], section_name))
else:
try:
- _ = socket.getaddrinfo(host, 3306, proto=socket.IPPROTO_TCP)
+ _ = socket.getaddrinfo(host, 3306, proto=socket.IPPROTO_TCP) # noqa
except socket.gaierror as e:
msg = 'Invalid source hostname {!r} in configuration section {!r}: {}'.format(
section['host'], section_name, e)
raise ValueError("port number must be less than {}".format((2 ** 16)))
except (ValueError, TypeError) as e:
msg = 'Invalid source port number {!r} in configuration section {!r}: {}'.format(
- section['port'],section_name, e)
+ section['port'], section_name, e)
LOG.error(msg)
self.config_has_errors = True
else:
if 'schema' in section:
schema = section['schema'].lower().strip()
if not schema:
- LOG.error('Invalid source database name {!r} in configuration section {!r} found.'.format(
- section['schema'], section_name))
+ LOG.error((
+ 'Invalid source database name {!r} '
+ 'in configuration section {!r} found.').format(
+ section['schema'], section_name))
else:
self.src_db_schema = schema
if 'user' in section:
user = section['user'].lower().strip()
if not user:
- LOG.error('Invalid source database user {!r} in configuration section {!r} found.'.format(
- section['user'], section_name))
+ LOG.error((
+ 'Invalid source database user {!r} '
+ 'in configuration section {!r} found.').format(
+ section['user'], section_name))
self.config_has_errors = True
else:
self.src_db_user = user
if 'host' in section:
host = section['host'].lower().strip()
if not host:
- LOG.error('Invalid target hostname {!r} in configuration section {!r} found.'.format(
- section['host'], section_name))
+ LOG.error(
+ 'Invalid target hostname {!r} in configuration section {!r} found.'.format(
+ section['host'], section_name))
self.config_has_errors = True
else:
try:
- _ = socket.getaddrinfo(host, 3306, proto=socket.IPPROTO_TCP)
+ _ = socket.getaddrinfo(host, 3306, proto=socket.IPPROTO_TCP) # noqa
except socket.gaierror as e:
msg = 'Invalid target hostname {!r} in configuration section {!r}: {}'.format(
section['host'], section_name, e)
raise ValueError("port number must be less than {}".format((2 ** 16)))
except (ValueError, TypeError) as e:
msg = 'Invalid target port number {!r} in configuration section {!r}: {}'.format(
- section['port'],section_name, e)
+ section['port'], section_name, e)
LOG.error(msg)
self.config_has_errors = True
else:
if 'schema' in section:
schema = section['schema'].lower().strip()
if not schema:
- LOG.error('Invalid target database name {!r} in configuration section {!r} found.'.format(
- section['schema'], section_name))
+ LOG.error((
+ 'Invalid target database name {!r} '
+ 'in configuration section {!r} found.').format(
+ section['schema'], section_name))
else:
self.tgt_db_schema = schema
if 'user' in section:
user = section['user'].lower().strip()
if not user:
- LOG.error('Invalid target database user {!r} in configuration section {!r} found.'.format(
+ LOG.error((
+ 'Invalid target database user {!r} '
+ 'in configuration section {!r} found.').format(
section['user'], section_name))
self.config_has_errors = True
else:
else:
self.connect_tgt_db_psql()
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
def connect_tgt_db_mysql(self):
result = None
e.__class__.__name__, e))
self.exit(6)
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
def connect_tgt_db_psql(self):
result = None
else:
cur_account += ', local'
if self.verbose > 1:
- LOG.debug("Setting account information of zone {!r} to {!r}.".format(
- result['name'], cur_account))
+ LOG.debug(
+ "Setting account information of zone {!r} to {!r}.".format(
+ result['name'], cur_account))
result['account'] = cur_account
if self.verbose > 1:
LOG.debug("SQL for insert domain:\n{}".format(
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:
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:
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:
soa = PdnsSoaData(
primary=ns_used, email=mail_addr, serial=serial,
refresh=refresh, retry=retry, expire=expire, ttl=ttl,
- appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
+ appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
)
LOG.debug("Inserting SOA {!r} ...".format(soa.data))