Skip to content

Instantly share code, notes, and snippets.

@fcelda
Created March 21, 2017 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcelda/ab862ae7054068e8cfe5019a0076a7a4 to your computer and use it in GitHub Desktop.
Save fcelda/ab862ae7054068e8cfe5019a0076a7a4 to your computer and use it in GitHub Desktop.
Prototype script to remove delegation with glue records using libknot control interface
#!/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