import re
import pwd
import textwrap
+import traceback
# Third party modules
import six
+import psycopg2
import pymysql
# Own modules
src_db_user = 'pdns'
src_db_pass = 'ohtior4KaFei'
+ # Target DB data
+ tgt_db_host = 'systemshare.pixelpark.com'
+ tgt_db_port = 5432
+ tgt_db_schema = 'pdns'
+ tgt_db_user = 'pdns'
+ tgt_db_pass = 'oo?fah7gai7X'
+
# -------------------------------------------------------------------------
def __init__(self, appname=None, version=__version__):
self.default_mail_recipients = ['frank.brehm@pixelpark.com']
self.src_connection = None
+ self.tgt_connection = None
super(ImportPdnsdataApp, self).__init__(
appname=appname, version=version, description=description,
cursorclass=pymysql.cursors.DictCursor
)
except ValueError as e:
- LOG.error("Could not connect to source databasei ({}): {}".format(
+ LOG.error("Could not connect to source database ({}): {}".format(
e.__class__.__name__, e))
+ traceback.print_exc()
+ self.exit(6)
+
+ try:
+ self.tgt_connection = psycopg2.connect(
+ host=self.tgt_db_host,
+ port=self.tgt_db_port,
+ dbname=self.tgt_db_schema,
+ user=self.tgt_db_user,
+ password=self.tgt_db_pass,
+ )
+ except ValueError as e:
+ LOG.error("Could not connect to target database ({}): {}".format(
+ e.__class__.__name__, e))
+ traceback.print_exc()
+ self.exit(7)
# -------------------------------------------------------------------------
def _run(self):
if self.src_connection:
LOG.debug("Closing source database connection.")
- self.src_connection.close()
+ try:
+ self.src_connection.close()
+ except Exception as e:
+ LOG.error("Could not close source database connection ({}): {}".format(
+ e.__class__.__name__, e))
+ traceback.print_exc()
self.src_connection = None
+ if self.tgt_connection:
+ LOG.debug("Closing target database connection.")
+ try:
+ self.tgt_connection.close()
+ except Exception as e:
+ LOG.error("Could not close target database connection ({}): {}".format(
+ e.__class__.__name__, e))
+ traceback.print_exc()
+ self.tgt_connection = None
+
# -------------------------------------------------------------------------
def post_run(self):