# Third party modules
import requests
-import six
import psutil
# Own modules
-from .common import pp, to_bool
+from .common import pp
from .cfg_app import PpCfgAppError, PpConfigApplication
from .pdns_zone import PdnsApiZone
-from .pdns_record import PdnsApiRecord, PdnsSoaData, PdnsApiRrset
+from .pdns_record import PdnsSoaData
-__version__ = '0.6.4'
+__version__ = '0.6.5'
LOG = logging.getLogger(__name__)
_LIBRARY_NAME = "pp-pdns-api-client"
class PpPDNSAppError(PpCfgAppError):
"""Base error class for all exceptions happened during
execution this configured application"""
-
pass
+
# =============================================================================
class PDNSApiError(PpPDNSAppError):
"""Base class for more complex exceptions"""
# =============================================================================
class PDNSApiNotAuthorizedError(PDNSApiError):
"""The authorization information provided is not correct"""
+ pass
# =============================================================================
class PDNSApiNotFoundError(PDNSApiError):
"""The ProfitBricks entity was not found"""
+ pass
# =============================================================================
class PDNSApiValidationError(PDNSApiError):
"""The HTTP data provided is not valid"""
+ pass
# =============================================================================
class PDNSApiRateLimitExceededError(PDNSApiError):
"""The number of requests sent have exceeded the allowed API rate limit"""
+ pass
# =============================================================================
class PDNSApiRequestError(PDNSApiError):
"""Base error for request failures"""
+ pass
# =============================================================================
class PDNSApiTimeoutError(PDNSApiRequestError):
"""Raised when a request does not finish in the given time span."""
-
+ pass
# =============================================================================
# -------------------------------------------------------------------------
def __init__(
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,
- environment='global'):
+ 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,
+ environment='global'):
self._api_key = self.api_keys['global']
self._api_host = self.api_hosts['global']
s = str(stem).strip()
if not s:
msg = "Invalid configuration stem {!r} given.".format(stem)
- raise PpLdapAppError(msg)
+ raise PpPDNSAppError(msg)
stems.append(s)
else:
s = str(cfg_stems).strip()
if not s:
msg = "Invalid configuration stem {!r} given.".format(cfg_stems)
- raise PpLdapAppError(msg)
+ raise PpPDNSAppError(msg)
stems.append(s)
else:
stems = [self.appname]
pdns_group.add_argument(
'-p', '--port',
metavar="PORT", type=int, dest='api_port', default=self.default_api_port,
- help=("Which port to connect to PowerDNS API, default: {}.".format(self.default_api_port)),
+ help=("Which port to connect to PowerDNS API, default: {}.".format(
+ self.default_api_port)),
)
pdns_group.add_argument(
if section_name.lower() in (
'powerdns-api', 'powerdns_api', 'powerdnsapi',
- 'pdns-api', 'pdns_api', 'pdnsapi' ):
+ 'pdns-api', 'pdns_api', 'pdnsapi'):
self.set_cfg_api_options(section, section_name)
# -------------------------------------------------------------------------
"a port must be greater than 0 and less than {}.".format(2**16))
except (TypeError, ValueError) as e:
LOG.error("Wrong port number {!r} in configuration section {!r}: {}".format(
- section['port'], section_name, e))
+ section['port'], section_name, e))
self.config_has_errors = True
else:
self.api_port = port
path = "/servers/{}".format(self.api_servername)
try:
json_response = self.perform_request(path)
- except (PDNSApiNotFoundError, PDNSApiValidationError) as e:
+ except (PDNSApiNotFoundError, PDNSApiValidationError):
LOG.error("Could not found server info.")
return None
if self.verbose > 2:
path = "/servers/{}/zones/{}".format(self.api_servername, zone_name)
try:
json_response = self.perform_request(path)
- except (PDNSApiNotFoundError, PDNSApiValidationError) as e:
+ except (PDNSApiNotFoundError, PDNSApiValidationError):
LOG.error("The given zone {} was not found.".format(zout))
return None
if self.verbose > 2:
LOG.debug("Got a response:\n{}".format(pp(json_response)))
zone = PdnsApiZone.init_from_dict(
- json_response, appname=self.appname, verbose=self.verbose, base_dir=self. base_dir)
+ json_response, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
if self.verbose > 2:
LOG.debug("Zone object:\n{}".format(pp(zone.as_dict())))