Changeset 13524 in genesis for tools


Ignore:
Timestamp:
Dec 16, 2015, 8:54:23 PM (9 years ago)
Author:
rick
Message:

Quirck to group DHCP interfaces into newly defined bridge0 interface and all
others (which do not have DHCP by definition) are to be set as non autoritive ones.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r13516 r13524  
    509509# Interface definitions
    510510#
    511 \n""").render(datadump)
     511\n\n""").render(datadump)
     512
     513
     514  # TODO: Use textwrap.fill instead
     515  def indent(text, count):
     516    return '\n'.join(map(lambda x: ' ' * count + x, text.split('\n')))
    512517
    513518  dhcp_out = defaultdict(list)
     
    518523
    519524    if dhcp_type(datadump[iface_key]) != DHCP_SERVER:
    520       dhcp_out[iface_key].append("  ## %(autogen_ifname)s - %(comment)s\n" % datadump[iface_key])
     525      dhcp_out[iface_key].append("## %(autogen_ifname)s - %(comment)s\n" % datadump[iface_key])
    521526    else:
    522       dhcp_out[ifname].append("  ## %(autogen_ifname)s - %(comment)s\n" % datadump[iface_key])
     527      dhcp_out['bridge0'].append("   ## %(autogen_ifname)s - %(comment)s\n" % datadump[iface_key])
    523528
    524529    (addr, mask) = datadump[iface_key]['ip'].split('/')
     
    526531    datadump[iface_key]['autogen_netmask'] = cidr2netmask(mask)
    527532    datadump[iface_key]['autogen_subnet'] = get_network(addr, mask)
     533
    528534    if dhcp_type(datadump[iface_key]) != DHCP_SERVER:
    529       dhcp_out[iface_key].append("  subnet %(autogen_subnet)s netmask %(autogen_netmask)s {\n    ### not autoritive\n  }\n" % \
    530         datadump[iface_key])
     535      dhcp_out[iface_key].append(textwrap.dedent("""\
     536        subnet %(autogen_subnet)s netmask %(autogen_netmask)s {
     537          ### not autoritive
     538        }
     539      """ % datadump[iface_key]))
    531540      continue
    532541
     
    540549      fixed = 5
    541550      for mac in datadump['no_portal']:
    542         dhcp_out[ifname].append("""\
     551        dhcp_out['bridge0'].append("""\
    543552   host fixed-%(ifname)s-%(fixed)s {
    544553     hardware ethernet %(mac)s;
     
    548557      fixed += 1
    549558
    550     dhcp_out[ifname].append("""\
     559    dhcp_out['bridge0'].append("""\
    551560   subnet %(autogen_subnet)s netmask %(autogen_netmask)s {
    552561     range %(autogen_dhcp_start)s %(autogen_dhcp_stop)s;
     
    554563     option domain-name-servers %(autogen_addr)s;
    555564   }
     565
    556566""" % datadump[iface_key])
    557567
    558568  for ifname,value in dhcp_out.iteritems():
    559     output += ("shared-network %s {\n" % ifname) + ''.join(value)  + '}\n\n'
     569    if ifname == 'bridge0':
     570      output += ("shared-network %s {\n" % ifname) + ''.join(value)  + '}\n\n'
     571    else:
     572      output += ''.join(value) + "\n\n"
    560573  return output
    561574
Note: See TracChangeset for help on using the changeset viewer.