from .pdns_zone import PdnsApiZone
from .pdns_record import PdnsApiRecord, PdnsSoaData, PdnsApiRrset
-__version__ = '0.6.3'
+__version__ = '0.6.4'
LOG = logging.getLogger(__name__)
_LIBRARY_NAME = "pp-pdns-api-client"
self._api_host = self.api_hosts['global']
self._api_port = self.default_api_port
self._api_servername = self.default_api_servername
+ self._api_server_version = 'unknown'
self._user_agent = '{}/{}'.format(_LIBRARY_NAME, self.version)
self._timeout = self.default_timeout
raise PpPDNSAppError("Invalid API server name {!r} given.".format(value))
self._api_servername = str(value).strip()
+ # -----------------------------------------------------------
+ @property
+ def api_server_version(self):
+ "The version of the PowerDNS server, how provided by API."
+ return self._api_server_version
+
# -----------------------------------------------------------
@property
def user_agent(self):
res['environment'] = self.environment
res['timeout'] = self.timeout
res['user_agent'] = self.user_agent
+ res['api_server_version'] = self.api_server_version
return res
logging.getLogger("requests").setLevel(logging.WARNING)
super(PpPDNSApplication, self).pre_run()
+ self.get_api_server_version()
# -------------------------------------------------------------------------
def _run(self):
if self.verbose > 1:
LOG.debug("executing post_run() ...")
+ # -------------------------------------------------------------------------
+ def get_api_server_version(self):
+
+ path = "/servers/{}".format(self.api_servername)
+ try:
+ json_response = self.perform_request(path)
+ except (PDNSApiNotFoundError, PDNSApiValidationError) as e:
+ LOG.error("Could not found server info.")
+ return None
+ if self.verbose > 2:
+ LOG.debug("Got a response:\n{}".format(pp(json_response)))
+
+ if 'version' in json_response:
+ self._api_server_version = json_response['version']
+ LOG.info("PowerDNS server version {!r}.".format(self.api_server_version))
+ return self.api_server_version
+ LOG.error("Did not found version info in server info:\n{}".format(pp(json_response)))
+ return None
+
# -------------------------------------------------------------------------
def _build_url(self, path):