Created
March 21, 2017 11:44
-
-
Save fcelda/ab862ae7054068e8cfe5019a0076a7a4 to your computer and use it in GitHub Desktop.
Prototype script to remove delegation with glue records using libknot control interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Prototype script to remove delegation with glue records using libknot control interface. | |
""" | |
import libknot.control | |
# libknot configuration | |
libknot.control.load_lib("/Users/jvcelak/devel/knot/_build.osx/src/.libs/libknot.dylib") | |
ctl_socket = "/Users/jvcelak/devel/knot/_server/master/knot.sock" | |
ctl_timeout = 3 | |
# delegation to be removed | |
zone = "example.com." | |
deleg = "child.example.com." | |
if __name__ == "__main__": | |
ctl = libknot.control.KnotCtl() | |
ctl.connect(ctl_socket) | |
ctl.set_timeout(ctl_timeout) | |
try: | |
# begin transaction | |
ctl.send_block("zone-begin", zone) | |
ctl.receive_block() | |
# get target NS record | |
ctl.send_block("zone-get", zone=zone, owner=deleg, rtype="NS") | |
data = ctl.receive_block() | |
# remove glue records | |
for server in data[zone][deleg]["NS"]["data"]: | |
if server.endswith(deleg): | |
ctl.send_block("zone-unset", zone=zone, owner=server) | |
ctl.receive_block() | |
# remove delegation | |
ctl.send_block("zone-unset", zone=zone, owner=deleg) | |
ctl.receive_block() | |
# commit changes | |
ctl.send_block("zone-commit", zone) | |
ctl.receive_block() | |
finally: | |
ctl.send(libknot.control.KnotCtlType.END) | |
ctl.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment