Changeset 10410 in genesis
- Timestamp:
- Apr 9, 2012, 11:15:50 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gformat.py
r10400 r10410 65 65 'authorized_keys', 66 66 'dnsmasq.conf', 67 'dhcpd.conf', 67 68 'rc.conf.local', 68 69 'resolv.conf', … … 327 328 328 329 329 330 def netmask2subnet(netmask): 330 def cidr2netmask(netmask): 331 331 """ Given a 'netmask' return corresponding CIDR """ 332 332 return showaddr(0xffffffff & (0xffffffff << (32 - int(netmask)))) 333 334 def get_network(addr, mask): 335 return showaddr(parseaddr(addr) & ~((1 << (32 - int(mask))) - 1)) 336 337 338 def generate_dhcpd_conf(datadump): 339 """ Generate config file '/usr/local/etc/dhcpd.conf """ 340 output = generate_header() 341 output += Template("""\ 342 # option definitions common to all supported networks... 343 option domain-name "dhcp.{{ autogen_fqdn }}"; 344 345 default-lease-time 600; 346 max-lease-time 7200; 347 348 # Use this to enble / disable dynamic dns updates globally. 349 #ddns-update-style none; 350 351 # If this DHCP server is the official DHCP server for the local 352 # network, the authoritative directive should be uncommented. 353 authoritative; 354 355 # Use this to send dhcp log messages to a different log file (you also 356 # have to hack syslog.conf to complete the redirection). 357 log-facility local7; 358 359 # 360 # Interface definitions 361 # 362 363 } 364 \n""").render(datadump) 365 366 for iface_key in datadump['autogen_iface_keys']: 367 if not datadump[iface_key].has_key('comment'): 368 datadump[iface_key]['comment'] = none 369 output += "## %(interface)s - %(desc)s - %(comment)s\n" % datadump[iface_key] 370 371 (addr, mask) = datadump[iface_key]['ip'].split('/') 372 datadump[iface_key]['addr'] = addr 373 datadump[iface_key]['netmask'] = cidr2netmask(mask) 374 datadump[iface_key]['subnet'] = get_network(addr, mask) 375 try: 376 (dhcp_start, dhcp_stop) = datadump[iface_key]['dhcp'].split('-') 377 except (AttributeError, ValueError): 378 output += "subnet %(subnet)s netmask %(netmask)s {\n ### not autoritive\n}\n\n" % datadump[iface_key] 379 continue 380 381 dhcp_part = ".".join(addr.split('.')[0:3]) 382 datadump[iface_key]['dhcp_start'] = dhcp_part + "." + dhcp_start 383 datadump[iface_key]['dhcp_stop'] = dhcp_part + "." + dhcp_stop 384 output += """\ 385 subnet %(subnet)s netmask %(netmask)s { 386 range %(dhcp_start)s %(dhcp_stop)s; 387 option routers %(addr)s; 388 option domain-name-servers %(addr)s; 389 } 390 \n""" % datadump[iface_key] 391 392 return output 333 393 334 394 … … 353 413 for iface_key in datadump['autogen_iface_keys']: 354 414 if not datadump[iface_key].has_key('comment'): 355 datadump[iface_key]['comment'] = None415 datadump[iface_key]['comment'] = none 356 416 output += "## %(interface)s - %(desc)s - %(comment)s\n" % datadump[iface_key] 357 417 358 418 try: 359 419 (dhcp_start, dhcp_stop) = datadump[iface_key]['dhcp'].split('-') 360 (ip, netmask) = datadump[iface_key]['ip'].split('/')361 datadump[iface_key][' subnet'] = netmask2subnet(netmask)420 (ip, cidr) = datadump[iface_key]['ip'].split('/') 421 datadump[iface_key]['netmask'] = cidr2netmask(cidr) 362 422 except (AttributeError, ValueError): 363 423 output += "# not autoritive\n\n" … … 367 427 datadump[iface_key]['dhcp_start'] = dhcp_part + "." + dhcp_start 368 428 datadump[iface_key]['dhcp_stop'] = dhcp_part + "." + dhcp_stop 369 output += "dhcp-range=%(interface)s,%(dhcp_start)s,%(dhcp_stop)s,%( subnet)s,24h\n\n" % datadump[iface_key]429 output += "dhcp-range=%(interface)s,%(dhcp_start)s,%(dhcp_stop)s,%(netmask)s,24h\n\n" % datadump[iface_key] 370 430 371 431 return output … … 701 761 elif config == 'dnsmasq.conf': 702 762 output += generate_dnsmasq_conf(datadump) 763 elif config == 'dhcpd.conf': 764 output += generate_dhcpd_conf(datadump) 703 765 elif config == 'rc.conf.local': 704 766 output += generate_rc_conf_local(datadump) … … 791 853 for iface_key in get_interface_keys(datadump): 792 854 iface_name = datadump[iface_key]['interface'].replace(':',"-alias-") 793 (ip, netmask) = datadump[iface_key]['ip'].split('/')855 (ip, cidr) = datadump[iface_key]['ip'].split('/') 794 856 try: 795 857 (dhcp_start, dhcp_stop) = datadump[iface_key]['dhcp'].split('-') 796 datadump[iface_key][' subnet'] = netmask2subnet(netmask)858 datadump[iface_key]['netmask'] = cidr2netmask(cidr) 797 859 dhcp_part = ".".join(ip.split('.')[0:3]) 798 860 if ip != datadump['masterip']:
Note:
See TracChangeset
for help on using the changeset viewer.