Exemplo n.º 1
0
def touch_zone(zone_name):
    """
    - Find the zone file at /var/cache/bind/<zone_name>.zone
    - Parse out the serial from the zone file
    - Rewrite the zone file with the updated serial
    - rndc reload the zone
    """
    zone_file = get_zone_filename(zone_name)
    fullpath = os.path.join(ZONE_FILE_DIR, zone_file)
    if not os.path.exists(fullpath):
        raise Exception("touch_zone: zone file '%s' not found" % fullpath)

    zone_file_text = open(fullpath, 'r').read()
    if DEBUG: print 'touch_zone: read zone file %s\n%s' % (fullpath, zone_file_text)

    serial = _parse_soa_serial(zone_file_text)
    serial += 1
    if DEBUG: print 'touch_zone: new_serial is %s' % serial

    new_zone_file_text = generate_zone_file(zone_name, serial=serial)
    write_zone_file(zone_file, new_zone_file_text)
    rndc.reload(zone_name)
Exemplo n.º 2
0
def update_zone(zone_name, serial, ip):
    zone_file_text = generate_zone_file(zone_name, serial=serial, ip=ip)
    zone_file = get_zone_filename(zone_name)
    write_zone_file(zone_file, zone_file_text)
    rndc.reload(zone_name)