From: Frank Brehm Date: Wed, 8 Nov 2017 17:36:25 +0000 (+0100) Subject: Start refactoring bin/dns-deploy-zones X-Git-Tag: 0.1.2~97 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=c84ff22e6d055d0f36997d3c5d21ffde80e8fb5e;p=pixelpark%2Fadmin-tools.git Start refactoring bin/dns-deploy-zones --- diff --git a/bin/dns-deploy-zones b/bin/dns-deploy-zones index ddfb931..04f0b0c 100755 --- a/bin/dns-deploy-zones +++ b/bin/dns-deploy-zones @@ -17,7 +17,8 @@ module_dir = os.path.join(base_dir, 'pp_lib') if os.path.exists(module_dir): sys.path.insert(0, base_dir) -from pp_lib.config_named_app import PpConfigNamedApp +#from pp_lib.config_named_app import PpConfigNamedApp +from pp_lib.deploy_zones_from_pdns import PpDeployZonesApp log = logging.getLogger(__name__) @@ -28,7 +29,7 @@ appname = os.path.basename(sys.argv[0]) locale.setlocale(locale.LC_ALL, '') -app = PpConfigNamedApp(appname=appname) +app = PpDeployZonesApp(appname=appname, base_dir=base_dir) app.initialized = True if app.verbose > 2: diff --git a/pp_lib/deploy_zones_from_pdns.py b/pp_lib/deploy_zones_from_pdns.py index cea4168..6dfe1a3 100644 --- a/pp_lib/deploy_zones_from_pdns.py +++ b/pp_lib/deploy_zones_from_pdns.py @@ -29,11 +29,12 @@ from six.moves.urllib.parse import urlunsplit from .common import pp, compare_fqdn, to_str from .common import RE_DOT_AT_END -from .pdns_app import PpPDNSAppError, PpPDNSApplication, PDNSApiNotFoundError, PDNSApiValidationError +from .pdns_app import PpPDNSAppError, PpPDNSApplication +from .pdns_app import PDNSApiNotFoundError, PDNSApiValidationError from .pdns_zone import PdnsApiZone from .pdns_record import compare_rrsets -__version__ = '0.1.1' +__version__ = '0.1.2' LOG = logging.getLogger(__name__) @@ -50,20 +51,20 @@ class PpDeployZonesApp(PpPDNSApplication): """ # ------------------------------------------------------------------------- - def __init__(self, appname=None, version=__version__): + def __init__(self, appname=None, base_dir=None, version=__version__): self.zones = [] description = textwrap.dedent('''\ - Lists all available zones from given PowerDNS API. + Generation of the BIND9 configuration file for slave zones. ''') - super(PpPDNSShowZoneApp, self).__init__( + super(PpDeployZonesApp, self).__init__( appname=appname, version=version, description=description, + base_dir=base_dir, cfg_stems='dns-deploy-zones', environment="public", ) self.initialized = True - # ============================================================================= diff --git a/pp_lib/pdns_app.py b/pp_lib/pdns_app.py index 6f3d0b3..dd827de 100644 --- a/pp_lib/pdns_app.py +++ b/pp_lib/pdns_app.py @@ -24,7 +24,7 @@ from .common import pp, to_bool from .cfg_app import PpCfgAppError, PpConfigApplication -__version__ = '0.2.1' +__version__ = '0.2.2' LOG = logging.getLogger(__name__) _LIBRARY_NAME = "pp-pdns-api-client" @@ -103,7 +103,8 @@ class PpPDNSApplication(PpConfigApplication): self, appname=None, verbose=0, version=__version__, base_dir=None, initialized=None, usage=None, description=None, argparse_epilog=None, argparse_prefix_chars='-', env_prefix=None, - cfg_dir=None, cfg_stems=None, cfg_encoding='utf-8', need_config_file=False): + cfg_dir=None, cfg_stems=None, cfg_encoding='utf-8', need_config_file=False, + environment='global'): self._api_key = self.api_keys['global'] self._api_host = self.api_hosts['global'] @@ -142,6 +143,8 @@ class PpPDNSApplication(PpConfigApplication): ) self._user_agent = '{}/{}'.format(_LIBRARY_NAME, self.version) + if environment != 'global': + self.environment = environment # ----------------------------------------------------------- @property diff --git a/pp_lib/pdns_record.py b/pp_lib/pdns_record.py index 0664d9c..49eb286 100644 --- a/pp_lib/pdns_record.py +++ b/pp_lib/pdns_record.py @@ -17,8 +17,6 @@ import re import datetime import json -from json import JSONDecodeError - # Third party modules # Own modules @@ -27,7 +25,7 @@ from .common import pp, compare_fqdn, to_bytes, to_utf8 from .errors import PpError from .obj import PpBaseObjectError, PpBaseObject -__version__ = '0.3.1' +__version__ = '0.3.2' LOG = logging.getLogger(__name__) @@ -344,7 +342,7 @@ class PdnsApiRrset(PpBaseObject): mtime.isoformat(' '), cmt['account'], cmt['content']) else: line = "; {} {}\n".format(mtime.isoformat(' '), cmt['account']) - except JSONDecodeError as e: + except Exception as e: LOG.warn("Could not decode comment {!r}: {}".format(comment, e)) line = '; {}\n'.format(comment)