diff options
-rw-r--r-- | LICENSE | 19 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rwxr-xr-x | octodns-custom-providers/provider/zonefile.py | 65 | ||||
-rwxr-xr-x | setup.py | 23 |
4 files changed, 108 insertions, 0 deletions
@@ -0,0 +1,19 @@ +Copyright (c) 2020 Jonas Gunz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c5d6b7e --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# octodns-phpipam-source diff --git a/octodns-custom-providers/provider/zonefile.py b/octodns-custom-providers/provider/zonefile.py new file mode 100755 index 0000000..2019a8d --- /dev/null +++ b/octodns-custom-providers/provider/zonefile.py @@ -0,0 +1,65 @@ +#from octodns.zone import Zone +from octodns.provider.base import BaseProvider +from octodns.provider.plan import Plan +#from octodns.source.axfr import ZoneFileSource + +import logging + +import dns.zone +import dns.rdataclass +import dns.rdatatype + +class ZoneFileProvider(BaseProvider): + SUPPORTS_GEO=False + SUPPORTS = set(('A', 'AAAA', 'CAA', 'CNAME', 'MX', 'NS', 'PTR', 'SPF', + 'SRV', 'TXT')) + + + def __init__(self, id, directory, check_origin=True): + ''' + Arguments + ========= + id: str + directory: str + check_origin: bool + ''' + self.log = logging.getLogger('ZoneFileProvider[{}]'.format(id)) + self.log.debug('__init__: directory={}'.format(directory)) + + self.directory = directory + + super(ZoneFileProvider, self).__init__(id) + + def populate(self, zone, target=False, lenient=False): + self.log.warn("ZoneFileProvider only implements target, for source octodns.source.axfr.ZoneFileSource should be used.") + + def _apply(self,plan): + ''' + Arguments + ========= + plan: octodns.provider.plan.Plan + ''' + # self.desired to dns.zone -> to file + records = plan.desired.records + zone = dns.zone.Zone(plan.desired.name) + + for record in plan.desired.records: + data = record.data + name = record.name + + rdset = dns.rdataset.Rdataset(dns.rdataclass.IN, dns.rdatatype.from_text(record._type)) + + if 'value' in data: + rdset.add(dns.rdata.from_text(dns.rdataclass.IN, + dns.rdatatype.from_text(record._type), data['value']), ttl=int(data['ttl'] )) + elif 'values' in data: + for value in data['values']: + rdset.add(dns.rdata.from_text(dns.rdataclass.IN, + dns.rdatatype.from_text(record._type), value), ttl=int(data['ttl'] )) + else: + self.log.warning("neither value nor values found in {}".format(name)) + continue + + zone.replace_rdataset(name, rdset) + + zone.to_file( self.directory + '/' + plan.desired.name) diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..c7a19ed --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +from distutils.core import setup +import setuptools + +setup( + name='octodns-custom-providers', + version='0.0.0-dev', + author="Jonas Gunz", + description="Custom sources for OctoDNS", + packages=setuptools.find_packages(), + install_requires=[ + "octodns", + "phpipam" + ], + license='MIT', + long_description=open('README.md').read(), + long_description_content_type="text/markdown", + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT", + "Operating System :: OS Independent", + ], +) + |