Changeset 13618 in genesis
- Timestamp:
- Aug 26, 2016, 9:43:15 AM (8 years ago)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
nodes/Rustdam/wleiden.yaml
r13587 r13618 86 86 status : "up" 87 87 88 iface_bridge0: 89 comment : "Access Point" 90 type : "eth" 91 ip : "172.17.37.1/24" 92 dhcp : "10-240" 88 93 94 95 iface_re1_204: 96 comment : "Access Point" 97 parent : "bridge0" 98 sdesc : "2veld" 99 mode : "ap-wds" 100 type : "vlan" 101 ssid : "Wifi Zoeterwoude" 102 ns_ip : "172.17.37.2/24" 103 ns_mac : "00:00:00:00:00:00" 104 ns_type : "lm2" 105 bridge_type: "LocoM2" 106 status : "up" 107 108 109 iface_re1_205: 110 comment : "Access Point" 111 parent : "bridge0" 112 sdesc : "2veld" 113 mode : "ap-wds" 114 type : "vlan" 115 ssid : "Wifi Zoeterwoude" 116 ns_ip : "172.17.37.3/24" 117 ns_mac : "00:00:00:00:00:00" 118 ns_type : "lm2" 119 bridge_type: "LocoM2" 120 status : "up" 121 122 123 124 -
tools/gformat.py
r13617 r13618 216 216 datadump[key]['autogen_vlan'] = False 217 217 218 datadump[key]['autogen_gateway'] = datadump[key]['ip'].split('/')[0] 218 datadump[key]['autogen_bridge_member'] = datadump[key].has_key('parent') 219 datadump[key]['autogen_bridge'] = datadump[key]['autogen_ifbase'].startswith('bridge') 220 221 if datadump[key].has_key('ip'): 222 datadump[key]['autogen_gateway'] = datadump[key]['ip'].split('/')[0] 223 219 224 if datadump[key]['type'] in ['11a', '11b', '11g', 'wireless']: 220 225 datadump[key]['autogen_ifname'] = 'wlan%i' % wlan_count 226 datadump[key]['autogen_iface'] = 'wlan%i' % wlan_count 221 227 wlan_count += 1 222 228 else: … … 224 230 if len(key.split('_')) > 2 and key.split('_')[2].isdigit(): 225 231 datadump[key]['autogen_vlan'] = key.split('_')[2] 226 227 datadump[key]['autogen_bridge'] = datadump[key]['autogen_ifbase'].startswith('bridge')228 if datadump[key]['autogen_bridge'] and not 'alias' in key:229 datadump[key]['autogen_bridge_interfaces'] = datadump[key]['members'].split() 232 datadump[key]['autogen_iface'] = '.'.join(key.split('_')[1:]) 233 else: 234 datadump[key]['autogen_iface'] = '_'.join(key.split('_')[1:]) 235 230 236 except Exception: 231 237 print "# Error while processing interface %s" % key … … 522 528 datadump[iface_key]['comment'] = None 523 529 524 if dhcp_type(datadump[iface_key]) != DHCP_SERVER:525 dhcp_out[ifname].append("## %(autogen_ifname)s - %(comment)s\n" % datadump[iface_key])526 else: 527 dhcp_out['bridge0'].append(" ## %(autogen_ifname)s - %(comment)s\n" % datadump[iface_key])530 if not datadump[iface_key].has_key('ip'): 531 continue 532 533 dhcp_out[iface_key].append("## %(autogen_iface)s - %(comment)s\n" % datadump[iface_key]) 528 534 529 535 (addr, mask) = datadump[iface_key]['ip'].split('/') … … 533 539 534 540 if dhcp_type(datadump[iface_key]) != DHCP_SERVER: 535 dhcp_out[if name].append(textwrap.dedent("""\541 dhcp_out[iface_key].append(textwrap.dedent("""\ 536 542 subnet %(autogen_subnet)s netmask %(autogen_netmask)s { 537 543 ### not autoritive … … 549 555 fixed = 5 550 556 for mac in datadump['no_portal']: 551 dhcp_out[ 'bridge0'].append("""\552 host fixed-%(ifname)s-%(fixed)s {553 hardware ethernet %(mac)s;554 fixed-address %(prefix)s.%(fixed)s;555 }556 """ % { 'ifname' : ifname, 'mac' : mac, 'prefix': dhcp_part, 'fixed' : fixed })557 dhcp_out[iface_key].append(textwrap.dedent("""\ 558 host fixed-%(ifname)s-%(fixed)s { 559 hardware ethernet %(mac)s; 560 fixed-address %(prefix)s.%(fixed)s; 561 } 562 """ % { 'ifname' : ifname, 'mac' : mac, 'prefix': dhcp_part, 'fixed' : fixed })) 557 563 fixed += 1 558 564 559 dhcp_out['bridge0'].append("""\ 560 subnet %(autogen_subnet)s netmask %(autogen_netmask)s { 561 range %(autogen_dhcp_start)s %(autogen_dhcp_stop)s; 562 option routers %(autogen_addr)s; 563 option domain-name-servers %(autogen_addr)s; 564 } 565 566 """ % datadump[iface_key]) 565 dhcp_out[iface_key].append(textwrap.dedent("""\ 566 subnet %(autogen_subnet)s netmask %(autogen_netmask)s { 567 range %(autogen_dhcp_start)s %(autogen_dhcp_stop)s; 568 option routers %(autogen_addr)s; 569 option domain-name-servers %(autogen_addr)s; 570 } 571 """ % datadump[iface_key])) 567 572 568 573 for ifname,value in dhcp_out.iteritems(): 569 if ifname == 'bridge0': 570 output += ("shared-network %s {\n" % ifname) + ''.join(value) + '}\n\n' 571 elif len(value) > 2: 574 if len(value) > 2: 572 575 output += ("shared-network %s {\n" % ifname) + indent(''.join(value), 2) + '\n}\n\n' 573 576 else: … … 610 613 datadump[iface_key]['autogen_dhcp_start'] = dhcp_part + "." + dhcp_start 611 614 datadump[iface_key]['autogen_dhcp_stop'] = dhcp_part + "." + dhcp_stop 612 output += "dhcp-range=%(autogen_if name)s,%(autogen_dhcp_start)s,%(autogen_dhcp_stop)s,%(autogen_netmask)s,24h\n\n" % datadump[iface_key]615 output += "dhcp-range=%(autogen_iface)s,%(autogen_dhcp_start)s,%(autogen_dhcp_stop)s,%(autogen_netmask)s,24h\n\n" % datadump[iface_key] 613 616 614 617 return output … … 633 636 addrs_list = { 'lo0' : [("127.0.0.1/8", "LocalHost"), ("172.31.255.1/32","Proxy IP")] } 634 637 vlan_list = defaultdict(list) 638 bridge_list = defaultdict(list) 635 639 flags_if = AutoVivification() 636 640 dhclient_if = {'lo0' : False} … … 641 645 masterip_used = False 642 646 for iface_key in get_interface_keys(datadump): 643 if datadump[iface_key] ['ip'].startswith(datadump['masterip']):647 if datadump[iface_key].has_key('ip') and datadump[iface_key]['ip'].startswith(datadump['masterip']): 644 648 masterip_used = True 645 649 break … … 655 659 vlan_list[ifacedump['autogen_ifbase']].append(ifacedump['autogen_vlan']) 656 660 661 # If defined as bridge interface 662 if ifacedump['autogen_bridge_member']: 663 bridge_list[ifacedump['parent']].append(ifacedump['autogen_iface']) 664 657 665 # Flag dhclient is possible 658 666 if not dhclient_if.has_key(ifname) or dhclient_if[ifname] == False: … … 663 671 flags_if[ifname]['ether'] = ifacedump['ether'] 664 672 665 # DHCP interfaces are to be added to bridge0666 if ifname.replace('_','.') in datadump['autogen_dhcp_interfaces']:667 ifname_base = 'bridge0'668 else:669 ifname_base = ifname670 671 673 # Add interface IP to list 672 item = (ifacedump['ip'], ifacedump['comment']) 673 if addrs_list.has_key(ifname_base): 674 addrs_list[ifname_base].append(item) 675 else: 676 addrs_list[ifname_base] = [item] 674 if ifacedump.has_key('ip'): 675 item = (ifacedump['ip'], ifacedump['comment']) 676 if addrs_list.has_key(ifname): 677 addrs_list[ifname].append(item) 678 else: 679 addrs_list[ifname] = [item] 677 680 678 681 # Alias only needs IP assignment for now, this might change if we … … 710 713 elif ifacedump['type'] in ['ethernet', 'eth']: 711 714 # No special config needed besides IP 712 if ifacedump['autogen_bridge']: 713 output += "cloned_interfaces='%(autogen_ifname)s'\n" % ifacedump 714 output += "ifconfig_%s='addm %s up'\n" % (ifacedump['autogen_ifname'], ' addm '.join(ifacedump['autogen_bridge_interfaces'])) 715 for member in ifacedump['autogen_bridge_interfaces']: 716 output += "ifconfig_%s='up'\n" % member 717 output += "\n" 715 pass 716 elif ifacedump['type'] in ['vlan']: 717 # VLAN member has no special configuration 718 pass 718 719 else: 719 720 assert False, "Unknown type " + ifacedump['type'] 720 721 721 store = (addrs_list, vlan_list, dhclient_if, flags_if, output)722 store = (addrs_list, vlan_list, bridge_list, dhclient_if, flags_if, output) 722 723 interface_list_cache[datadump['autogen_item']] = store 723 724 return(store) … … 807 808 " 808 809 809 captive_portal_interfaces=" bridge0"810 captive_portal_interfaces="{{ autogen_dhcp_interfaces|join(',') }}" 810 811 externalif="{{ externalif|default('vr0', true) }}" 811 812 masterip="{{ masterip }}" … … 874 875 {% if autogen_dhcp_interfaces -%} 875 876 dhcpd_enable="YES" 876 dhcpd_flags="$dhcpd_flags bridge0"877 dhcpd_flags="$dhcpd_flags {{ autogen_dhcp_interfaces|join(' ') }}" 877 878 {% endif -%} 878 879 {% elif board == "apu1d" %} … … 884 885 {% if autogen_dhcp_interfaces -%} 885 886 dhcpd_enable="YES" 886 dhcpd_flags="$dhcpd_flags bridge0"887 dhcpd_flags="$dhcpd_flags {{ autogen_dhcp_interfaces|join(' ') }}" 887 888 {% endif -%} 888 889 {% endif -%} … … 901 902 """) 902 903 903 (addrs_list, vlan_list, dhclient_if, flags_if, extra_ouput) = make_interface_list(datadump)904 (addrs_list, vlan_list, bridge_list, dhclient_if, flags_if, extra_ouput) = make_interface_list(datadump) 904 905 for iface, vlans in vlan_list.items(): 905 906 output += 'vlans_%s="%s"\n' % (iface, ' '.join(vlans)) … … 910 911 output += "ifconfig_%s='up'\n" % iface 911 912 913 output += "\n" 914 915 # Bridge configuration: 916 if bridge_list.keys(): 917 output += "cloned_interfaces='%s'\n" % ' '.join(bridge_list.keys()) 918 919 for iface in bridge_list.keys(): 920 output += "create_args_%s='%s'\n" % (iface, ' '.join(['addm %(iface)s private %(iface)s' % {'iface': x} for x in bridge_list[iface]])) 921 922 # Bridge member interfaces not containing a configuration should be marked active explcitly. 923 for _,members in bridge_list.items(): 924 for iface in members: 925 if not iface in addrs_list.keys(): 926 output += "ifconfig_%s='up'\n" % iface 927 912 928 output += "\n" 913 929 … … 936 952 937 953 idx_offset = 0 938 if iface == 'bridge0': 939 output += "cloned_interfaces='bridge0'\n" 940 output += "create_args_bridge0='%s'\n" % ' '.join(['addm %s private %s' % (x, x) for x in datadump['autogen_dhcp_interfaces']]) 941 output += "ifconfig_bridge0='%s up'\n" % addrs[0][0] 942 else: 943 if flags_if[iface].has_key('ether'): 944 output += "ifconfig_%s='link %s'\n" % (iface, flags_if[iface]['ether']) 945 output += "ifconfig_%s_alias0='inet %s'\n" % (iface, addrs[0][0]) 946 idx_offset += 1 947 else: 948 output += "ifconfig_%s='inet %s'\n" % (iface, addrs[0][0]) 954 # Set MAC is required 955 if flags_if[iface].has_key('ether'): 956 output += "ifconfig_%s='link %s'\n" % (iface, flags_if[iface]['ether']) 957 output += "ifconfig_%s_alias0='inet %s'\n" % (iface, addrs[0][0]) 958 idx_offset += 1 959 else: 960 output += "ifconfig_%s='inet %s'\n" % (iface, addrs[0][0]) 949 961 950 962 for idx, addr in enumerate(addrs[1:]): 951 963 output += "ifconfig_%s_alias%s='inet %s'\n" % (iface, idx + idx_offset, addr[0]) 952 if iface == 'bridge0': 953 for dhcp_iface in datadump['autogen_dhcp_interfaces']: 954 output += "ifconfig_%s='up'\n" % dhcp_iface.replace('.','_') 964 955 965 output += "\n" 956 966 … … 1008 1018 1009 1019 def get_neighbours(datadump): 1010 (addrs_list, _, dhclient_if, _, extra_ouput) = make_interface_list(datadump)1020 (addrs_list, _, _, dhclient_if, _, extra_ouput) = make_interface_list(datadump) 1011 1021 1012 1022 (poel, errors) = make_relations() … … 1022 1032 for neighbour in poel[network(addr)]: 1023 1033 if neighbour[0] != datadump['autogen_item']: 1024 table.append((iface, neighbour[1]['ip'].split('/')[0], neighbour[0] + " (" + neighbour[1]['autogen_if name'] + ")", neighbour[1]['comment']))1034 table.append((iface, neighbour[1]['ip'].split('/')[0], neighbour[0] + " (" + neighbour[1]['autogen_iface'] + ")", neighbour[1]['comment'])) 1025 1035 return table 1026 1036 … … 1029 1039 table = [] 1030 1040 for iface_key in get_interface_keys(datadump, True): 1031 # Quick to avoid listing ath(4) interface as attached device 1032 if 'ath0' in iface_key: 1041 ifacedump = datadump[iface_key] 1042 1043 if not ifacedump.has_key('ns_ip'): 1033 1044 continue 1034 ifacedump = datadump[iface_key] 1035 if ifacedump.has_key('ns_ip'): 1036 x_ip = ifacedump['ns_ip'].split('/')[0] 1037 else: 1038 x_ip = ifacedump['ip'].split('/')[0] 1045 1046 x_ip = ifacedump['ns_ip'].split('/')[0] 1039 1047 1040 1048 if 'mode' in ifacedump: … … 1048 1056 device_type = 'Unknown' 1049 1057 1050 table.append((ifacedump['autogen_if name'], x_mode, 'http://%s' % x_ip if url else x_ip, device_type))1058 table.append((ifacedump['autogen_iface'], x_mode, 'http://%s' % x_ip if url else x_ip, device_type)) 1051 1059 return table 1052 1060 … … 1170 1178 col_width = [max(len(x) for x in col) for col in zip(*table)] 1171 1179 for row in table: 1172 lines += " - " + " || ".join("{:{}}".format(x, col_width[i]) for i, x in enumerate(row)) + "\n" 1180 # replace('_','.') is a hack to convert vlan interfaces to proper named interfaces 1181 lines += " - " + " || ".join("{:{}}".format(x.replace('_','.'), col_width[i]) for i, x in enumerate(row)) + "\n" 1173 1182 return lines 1174 1183 1175 (addrs_list, vlan_list, dhclient_if, flags_if, extra_ouput) = make_interface_list(datadump)1184 (addrs_list, vlan_list, bridge_list, dhclient_if, flags_if, extra_ouput) = make_interface_list(datadump) 1176 1185 table = [] 1177 1186 for iface,addrs in sorted(addrs_list.iteritems()): … … 1225 1234 key_order = ( 1226 1235 ('comment', True), 1227 ('ip', True), 1236 ('parent', False), 1237 ('ip', False), 1228 1238 ('ether', False), 1229 1239 ('desc', True), … … 1245 1255 ('ns_type', False), 1246 1256 ('bridge_type', False), 1247 ('members', True),1248 1257 ('status', True), 1249 1258 ) … … 1802 1811 ip2host[datadump['masterip']] = datadump['autogen_fqdn'] 1803 1812 for iface in get_interface_keys(datadump): 1804 ip2host[datadump[iface]['autogen_gateway']] = datadump['autogen_fqdn'] 1813 if datadump[iface].has_key('autogen_gateway'): 1814 ip2host[datadump[iface]['autogen_gateway']] = datadump['autogen_fqdn'] 1805 1815 1806 1816 # Find dependency tree based on output of lvrouted.mytree of nearest node -
tools/syntax-checker.py
r12574 r13618 23 23 iface_keys = [elem for elem in datadump.keys() if (elem.startswith('iface_') and not "lo0" in elem)] 24 24 for iface_key in iface_keys: 25 # Virtual interfaces bridge interfaces do not have IP addreses 26 if not datadump[iface_key].has_key('ip'): 27 continue 28 25 29 l = datadump[iface_key]['ip'] 26 30 addr, mask = l.split('/')
Note:
See TracChangeset
for help on using the changeset viewer.