Commit 6f6d29da authored by Sigmund Augdal's avatar Sigmund Augdal

Added utils to list and remove dns records

parent f6696a7d
......@@ -87,6 +87,11 @@ class PowerRESTClient(object):
return False
def get_records(self):
r = self.get("/records")
records = r.json()
return records
# Return list of records with the given content
def get_records_by_content(self, content):
r = self.get("/records")
......
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function, unicode_literals
import argparse
from nova_router import dns_rr
try:
from configparser import SafeConfigParser # pylint: disable=F0401
except ImportError:
from ConfigParser import SafeConfigParser # pylint: disable=F0401
DESCRIPTION = "List DNS records for domain"
def parse_args():
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('--config', default="nova.cfg",
help="Config file to use")
parser.add_argument('domain', help="domain to list")
return parser.parse_args()
def main(args):
domain = args.domain
conf = SafeConfigParser()
conf.read(args.config)
dns = dns_rr.client_from_conf(conf)
domain_id = dns.get_domain_id(domain)
records = dns.get_records()
for record in records:
if record['domain_id'] != domain_id:
continue
print("{}, {}, {}, {}, {}, {}".format(record['name'], record['type'], record['content'],
record['ttl'], record['prio'], record['id']))
if __name__ == '__main__':
args = parse_args()
main(args)
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function, unicode_literals
import argparse
import sys
from nova_router import dns_rr
try:
from configparser import SafeConfigParser # pylint: disable=F0401
except ImportError:
from ConfigParser import SafeConfigParser # pylint: disable=F0401
DESCRIPTION = "Remove DNS record"
def parse_args():
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('--config', default="nova.cfg",
help="Config file to use")
parser.add_argument('name', help="name of record to remove")
parser.add_argument('id', help="id of record to remove")
return parser.parse_args()
def main(args):
conf = SafeConfigParser()
conf.read(args.config)
dns = dns_rr.client_from_conf(conf)
records = dns.get_records()
for record in records:
if record['name'] == args.name and int(record['id']) == int(args.id):
dns.remove_record(record['id'])
print("Removed record")
sys.exit(0)
print("No record found matching name and id")
sys.exit(1)
if __name__ == '__main__':
args = parse_args()
main(args)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment