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

Pass of ALIAS support across supported providers. Allow ALIAS ttl

Supports ALIAS for Dnsimple, Dyn, Ns1, and PowerDNS. Notes added to readme about
some of the quirks found while working with them. TTL seems to mostly be
accepted on ALIAS records so it has been added back, what it means seems to vary
across providers, thus notes.
This commit is contained in:
Ross McFarland
2017-06-03 09:44:05 -07:00
parent 82ed633669
commit 11cf155477
6 changed files with 38 additions and 19 deletions

View File

@@ -158,6 +158,12 @@ The above command pulled the existing data out of Route53 and placed the results
| [TinyDNSSource](/octodns/source/tinydns.py) | A, CNAME, MX, NS, PTR | No | read-only |
| [YamlProvider](/octodns/provider/yaml.py) | All | Yes | config |
#### Notes
* ALIAS support varies a lot fromm provider to provider care should be taken to verify that your needs are met in detail.
* Dyn's UI doesn't allow editing or view of TTL, but the API accepts and stores the value provided, this value does not appear to be used when served
* Dnsimple's API throws errors when TTL is modified, but it can be edited in the UI and seems to be used when served, there's also a secondary TXT record created alongside the ALIAS that octoDNS ignores
## Custom Sources and Providers
You can check out the [source](/octodns/source/) and [provider](/octodns/provider/) directory to see what's currently supported. Sources act as a source of record information. TinyDnsProvider is currently the only OSS source, though we have several others internally that are specific to our environment. These include something to pull host data from [gPanel](https://githubengineering.com/githubs-metal-cloud/) and a similar provider that sources information about our network gear to create both `A` & `PTR` records for their interfaces. Things that might make good OSS sources might include an `ElbSource` that pulls information about [AWS Elastic Load Balancers](https://aws.amazon.com/elasticloadbalancing/) and dynamically creates `CNAME`s for them, or `Ec2Source` that pulls instance information so that records can be created for hosts similar to how our `GPanelProvider` works. An `AxfrSource` could be really interesting as well. Another case where a source may make sense is if you'd like to export data from a legacy service that you have no plans to push changes back into.

View File

@@ -120,6 +120,8 @@ class DnsimpleProvider(BaseProvider):
'value': '{}.'.format(record['content'])
}
_data_for_ALIAS = _data_for_CNAME
def _data_for_MX(self, _type, records):
values = []
for record in records:
@@ -238,6 +240,10 @@ class DnsimpleProvider(BaseProvider):
_type = record['type']
if _type == 'SOA':
continue
elif _type == 'TXT' and record['content'].startswith('ALIAS for'):
# ALIAS has a "ride along" TXT record with 'ALIAS for XXXX',
# we're ignoring it
continue
values[record['name']][record['type']].append(record)
before = len(zone.records)
@@ -273,6 +279,7 @@ class DnsimpleProvider(BaseProvider):
'type': record._type
}
_params_for_ALIAS = _params_for_single
_params_for_CNAME = _params_for_single
_params_for_PTR = _params_for_single

View File

@@ -109,6 +109,7 @@ class DynProvider(BaseProvider):
RECORDS_TO_TYPE = {
'a_records': 'A',
'aaaa_records': 'AAAA',
'alias_records': 'ALIAS',
'cname_records': 'CNAME',
'mx_records': 'MX',
'naptr_records': 'NAPTR',
@@ -119,19 +120,7 @@ class DynProvider(BaseProvider):
'srv_records': 'SRV',
'txt_records': 'TXT',
}
TYPE_TO_RECORDS = {
'A': 'a_records',
'AAAA': 'aaaa_records',
'CNAME': 'cname_records',
'MX': 'mx_records',
'NAPTR': 'naptr_records',
'NS': 'ns_records',
'PTR': 'ptr_records',
'SSHFP': 'sshfp_records',
'SPF': 'spf_records',
'SRV': 'srv_records',
'TXT': 'txt_records',
}
TYPE_TO_RECORDS = {v: k for k, v in RECORDS_TO_TYPE.items()}
# https://help.dyn.com/predefined-geotm-regions-groups/
REGION_CODES = {
@@ -194,6 +183,15 @@ class DynProvider(BaseProvider):
_data_for_AAAA = _data_for_A
def _data_for_ALIAS(self, _type, records):
# See note on ttl in _kwargs_for_ALIAS
record = records[0]
return {
'type': _type,
'ttl': record.ttl,
'value': record.alias
}
def _data_for_CNAME(self, _type, records):
record = records[0]
return {
@@ -385,6 +383,16 @@ class DynProvider(BaseProvider):
'ttl': record.ttl,
}]
def _kwargs_for_ALIAS(self, record):
# NOTE: Dyn's UI doesn't allow editing of ALIAS ttl, but the API seems
# to accept and store the values we send it just fine. No clue if they
# do anything with them. I'd assume they just obey the TTL of the
# record that we're pointed at which makes sense.
return [{
'alias': record.value,
'ttl': record.ttl,
}]
def _kwargs_for_MX(self, record):
return [{
'preference': v.priority,

View File

@@ -48,6 +48,7 @@ class Ns1Provider(BaseProvider):
'value': record['short_answers'][0],
}
_data_for_ALIAS = _data_for_CNAME
_data_for_PTR = _data_for_CNAME
def _data_for_MX(self, _type, record):
@@ -140,6 +141,7 @@ class Ns1Provider(BaseProvider):
def _params_for_CNAME(self, record):
return {'answers': [record.value], 'ttl': record.ttl}
_params_for_ALIAS = _params_for_CNAME
_params_for_PTR = _params_for_CNAME
def _params_for_MX(self, record):

View File

@@ -64,6 +64,7 @@ class PowerDnsBaseProvider(BaseProvider):
'ttl': rrset['ttl']
}
_data_for_ALIAS = _data_for_single
_data_for_CNAME = _data_for_single
_data_for_PTR = _data_for_single
@@ -191,6 +192,7 @@ class PowerDnsBaseProvider(BaseProvider):
def _records_for_single(self, record):
return [{'content': record.value, 'disabled': False}]
_records_for_ALIAS = _records_for_single
_records_for_CNAME = _records_for_single
_records_for_PTR = _records_for_single

View File

@@ -316,12 +316,6 @@ class _ValueMixin(object):
class AliasRecord(_ValueMixin, Record):
_type = 'ALIAS'
def __init__(self, zone, name, data, source=None):
data = dict(data)
# TODO: this is an ugly way to fake the lack of ttl :-(
data['ttl'] = 0
super(AliasRecord, self).__init__(zone, name, data, source)
def _process_value(self, value):
if not value.endswith('.'):
raise Exception('Invalid record {}, value ({}) missing trailing .'