Fix style

This commit is contained in:
Antonio J. Delgado 2024-12-09 13:50:29 +02:00
parent 10421cc86a
commit a5d4abfe95

View file

@ -42,14 +42,19 @@ class odi6:
) )
ipv4, ipv6 = self._determine_ip() ipv4, ipv6 = self._determine_ip()
self._log.debug( self._log.debug(
f"IPv4: {ipv4}. IPv6: {ipv6}" "IPv4: %s. IPv6: %s",
ipv4,
ipv6
) )
try: try:
self._update_a_record(ipv4) self._update_a_record(ipv4)
if ipv6: if ipv6:
self._update_aaaa_record(ipv6) self._update_aaaa_record(ipv6)
result = self.ovh.post(f"/domain/zone/{self.config['domain']}/refresh") result = self.ovh.post(f"/domain/zone/{self.config['domain']}/refresh")
self._log.debug(f"Zone refresh result: {result}") self._log.debug(
"Zone refresh result: %s",
result
)
except Exception as error: except Exception as error:
self._log.error( self._log.error(
"Error updating records. %s", error "Error updating records. %s", error
@ -68,8 +73,8 @@ class odi6:
if data['subDomain'] == self.config['hostname']: if data['subDomain'] == self.config['hostname']:
record_exists = data record_exists = data
self._log.debug( self._log.debug(
f"""Found a record that match the 'subDomain' with "Found a record that match the 'subDomain' with the hostname: %s",
the hostname: {data}""" data
) )
params = { params = {
'fieldType': "A", 'fieldType': "A",
@ -80,8 +85,8 @@ the hostname: {data}"""
if record_exists: if record_exists:
if record_exists['target'] != ipv4: if record_exists['target'] != ipv4:
self._log.debug( self._log.debug(
f"""An A record ({record_exists}) exists for this "An A record (%s) exists for this hostname, updating it.",
hostname, updating it.""" record_exists
) )
uri = f"/domain/zone/{self.config['domain']}/record/{record_exists['id']}" uri = f"/domain/zone/{self.config['domain']}/record/{record_exists['id']}"
try: try:
@ -91,7 +96,9 @@ hostname, updating it."""
) )
except Exception as error: except Exception as error:
self._log.error( self._log.error(
f"Error updating record with URI {uri}. {error}" "Error updating record with URI %s. %s",
uri,
error
) )
sys.exit(1) sys.exit(1)
else: else:
@ -105,7 +112,10 @@ target, doing nothing."
f"/domain/zone/{self.config['domain']}/record", f"/domain/zone/{self.config['domain']}/record",
**params, **params,
) )
self._log.debug(f"Result: {result}") self._log.debug(
"Result: %s",
result
)
def _update_aaaa_record(self, ipv6): def _update_aaaa_record(self, ipv6):
aaaa_records = self.ovh.get( aaaa_records = self.ovh.get(
@ -120,8 +130,8 @@ target, doing nothing."
if data['subDomain'] == self.config['hostname']: if data['subDomain'] == self.config['hostname']:
record_exists = data record_exists = data
self._log.debug( self._log.debug(
f"Found a record that match the 'subDomain' with\ "Found a record that match the 'subDomain' with the hostname: %s",
the hostname: {data}" data
) )
params = { params = {
'fieldType': "AAAA", 'fieldType': "AAAA",
@ -132,8 +142,9 @@ the hostname: {data}"
if record_exists: if record_exists:
if record_exists['target'] != ipv6: if record_exists['target'] != ipv6:
self._log.debug( self._log.debug(
f"""A AAAA record ({record_exists}) exists for this "A AAAA record (%s) exists for this hostname, updating it with '%s'.",
hostname, updating it with '{params}'.""" record_exists,
params
) )
result = self.ovh.put( result = self.ovh.put(
f"""/domain/zone/{self.config['domain']}/record/{record_exists['id']}""", f"""/domain/zone/{self.config['domain']}/record/{record_exists['id']}""",
@ -199,16 +210,20 @@ same target, doing nothing."""
if match: if match:
ipv6 = match.group(0).decode() ipv6 = match.group(0).decode()
except Exception as error: except Exception as error:
self._log.debug(f"Exception reaching IPv6 URL. {error}") self._log.debug(
"Exception reaching IPv6 URL. %s",
error
)
return ipv4, ipv6 return ipv4, ipv6
self._log.error( self._log.error(
f"""Unable to determine the IP using "Unable to determine the IP using '%s'. Returned data: %s",
'{self.config['web_service_url']}'. Returned data: {result.content}""" self.config['web_service_url'],
result.content
) )
else: else:
self._log.error( self._log.error(
f"""Selected method '{self.config['ip_method']}' "Selected method '%s' has not been implemented.",
has not been implemented.""" self.config['ip_method']
) )
return False return False