1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Handle domains not registred at Gandi or not using Gandi's DNS

This commit is contained in:
Jonathan Leroy
2020-10-27 11:23:22 +01:00
parent 7161baa262
commit 6d17b4671a
3 changed files with 61 additions and 10 deletions

View File

@@ -41,6 +41,12 @@ class GandiClientNotFound(GandiClientException):
super(GandiClientNotFound, self).__init__(r.text)
class GandiClientUnknownDomainName(GandiClientException):
def __init__(self, msg):
super(GandiClientUnknownDomainName, self).__init__(msg)
class GandiClient(object):
def __init__(self, token):
@@ -63,6 +69,16 @@ class GandiClient(object):
r.raise_for_status()
return r
def zone(self, zone_name):
return self._request('GET', '/livedns/domains/{}'
.format(zone_name)).json()
def zone_create(self, zone_name):
return self._request('POST', '/livedns/domains', data={
'fqdn': zone_name,
'zone': {}
}).json()
def zone_records(self, zone_name):
records = self._request('GET', '/livedns/domains/{}/records'
.format(zone_name)).json()
@@ -318,9 +334,25 @@ class GandiProvider(BaseProvider):
def _apply(self, plan):
desired = plan.desired
changes = plan.changes
zone = desired.name[:-1]
self.log.debug('_apply: zone=%s, len(changes)=%d', desired.name,
len(changes))
try:
self._client.zone(zone)
except GandiClientNotFound:
self.log.info('_apply: no existing zone, trying to create it')
try:
self._client.zone_create(zone)
self.log.info('_apply: zone has been successfully created')
except GandiClientNotFound:
raise GandiClientUnknownDomainName('This domain is not '
'registred at Gandi. '
'Please register or '
'transfer it here '
'to be able to manage its '
'DNS zone.')
# Force records deletion to be done before creation in order to avoid
# "CNAME record must be the only record" error when an existing CNAME
# record is replaced by an A/AAAA record.