summaryrefslogtreecommitdiffstats
path: root/server/backends.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/backends.py')
-rw-r--r--server/backends.py50
1 files changed, 44 insertions, 6 deletions
diff --git a/server/backends.py b/server/backends.py
index be95f8c..4546807 100644
--- a/server/backends.py
+++ b/server/backends.py
@@ -1,11 +1,15 @@
+import requests
+import json
+
+
class Backend(object):
def __init__(self, config):
self.config = config
- def add(self, name, value):
+ def add(self, name, value, type_):
raise NotImplemented
- def remove(self, name):
+ def delete(self, name, type_):
raise NotImplemented
@@ -27,19 +31,53 @@ class OVHBackend(Backend):
])
print(req)
- def add(self, name, value):
+ def add(self, name, value, type_):
if not name.endswith(self.config['OVH_ZONE']):
raise Exception()
v = self.client.post('/domain/zone/%s/record' % (self.config['OVH_ZONE'],),
- fieldType='TXT', subDomain=name+'.', target=value)
+ fieldType=type_, subDomain=name+'.', target=value)
print(v)
self.client.post('/domain/zone/%s/refresh' % (self.config['OVH_ZONE'],))
- def remove(self, name):
+ def delete(self, name, type_):
ids = self.client.get(
- '/domain/zone/%s/record' % (self.config['OVH_ZONE'],), fieldType='TXT', subDomain=name+'.')
+ '/domain/zone/%s/record' % (self.config['OVH_ZONE'],), fieldType=type_, subDomain=name+'.')
for i in ids:
print('Removing', i)
self.client.delete('/domain/zone/%s/record/%d' % (self.config['OVH_ZONE'], i))
self.client.post('/domain/zone/%s/refresh' % (self.config['OVH_ZONE'],))
+
+
+class PowerDNSBackend(Backend):
+ def do_patch(self, reqdata):
+ api_url = '%s/api/v1/servers/localhost/zones/%s.' % (
+ self.config.get('PDNS_URL', 'http://127.0.0.1:8081'),
+ self.config['PDNS_ZONE'],
+ )
+ return requests.patch(api_url, data=json.dumps(reqdata), headers={
+ 'X-API-Key': self.config['PDNS_TOKEN']
+ }).json()
+
+ def add(self, name, value, type_):
+ self.do_patch({
+ "rrsets": [{
+ "name": name + ".",
+ "type": "A",
+ "ttl": 86400,
+ "changetype": "REPLACE",
+ "records": [{
+ "content": value,
+ "disabled": False
+ }]
+ }]
+ })
+
+ def delete(self, name, type_):
+ self.do_patch({
+ "rrsets": [{
+ "name": name + ".",
+ "type": type_,
+ "changetype": "DELETE",
+ }]
+ })