#!/usr/bin/env python3 import json from findzone import * import sys import subprocess record = sys.argv[1].strip() apihost = str(os.environ.get('PDNS_PRIMARY_SSH')).split("@")[1] apischeme = str(os.environ.get('PDNS_API_SCHEME')) if os.environ.get('PDNS_API_SCHEME') else "http" apiport = int(str(os.environ.get('PDNS_API_PORT'))) if os.environ.get('PDNS_API_PORT') else 8081 zone = findzone(record) if not zone: print(f"[ERROR] no suitable zone found for {record}") exit(1) request_body = { "rrsets": [ { "changetype": "DELETE", "type": "CNAME", "name": f"{record}." } ] } print(f"+ curl -X PATCH --data '{json.dumps(request_body)}' -H 'X-API-Key: *****' {apischeme}://{apihost}:{apiport}/api/v1/servers/localhost/zones/{zone}. -s") subprocess.check_output(["curl", "-X", "PATCH", "--data", json.dumps(request_body), "-H", f'X-API-Key: {str(os.environ.get("PDNS_APIKEY"))}', f"{apischeme}://{apihost}:{apiport}/api/v1/servers/localhost/zones/{zone}.", "-s" ])