Changeset 13403 in genesis for tools/gformat.py
- Timestamp:
- Sep 20, 2015, 7:02:20 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gformat.py
r13398 r13403 214 214 for key in get_interface_keys(datadump, True): 215 215 datadump[key]['autogen_ifbase'] = key.split('_')[1] 216 datadump[key]['autogen_vlan'] = False 217 216 218 datadump[key]['autogen_gateway'] = datadump[key]['ip'].split('/')[0] 217 219 if datadump[key]['type'] in ['11a', '11b', '11g', 'wireless']: … … 219 221 wlan_count += 1 220 222 else: 221 datadump[key]['autogen_ifname'] = datadump[key]['autogen_ifbase'] 223 datadump[key]['autogen_ifname'] = '_'.join(key.split('_')[1:]) 224 if len(key.split('_')) > 2 and key.split('_')[2].isdigit(): 225 datadump[key]['autogen_vlan'] = key.split('_')[2] 226 222 227 datadump[key]['autogen_bridge'] = datadump[key]['autogen_ifbase'].startswith('bridge') 223 228 if datadump[key]['autogen_bridge'] and not 'alias' in key: 224 229 datadump[key]['autogen_bridge_interfaces'] = datadump[key]['members'].split() 225 except Exception as e:230 except Exception: 226 231 print "# Error while processing interface %s" % key 227 232 raise … … 230 235 if dhcp_type(datadump[key]) == DHCP_SERVER] 231 236 232 datadump['autogen_dhcp_interfaces'] = dhcp_interfaces237 datadump['autogen_dhcp_interfaces'] = [x.replace('_','.') for x in dhcp_interfaces] 233 238 datadump['autogen_item'] = item 234 239 … … 237 242 datadump['autogen_fqdn'] = datadump['autogen_realname'] + '.' + datadump['autogen_domain'] 238 243 datadump_cache[item] = datadump.copy() 239 except Exception as e:244 except Exception: 240 245 print "# Error while processing %s" % item 241 246 raise … … 607 612 # least one interface, so if not used assign to lo0 608 613 addrs_list = { 'lo0' : [("127.0.0.1/8", "LocalHost"), ("172.31.255.1/32","Proxy IP")] } 614 vlan_list = defaultdict(list) 609 615 dhclient_if = {'lo0' : False} 610 616 … … 623 629 ifacedump = datadump[iface_key] 624 630 ifname = ifacedump['autogen_ifname'] 631 632 # If defined as vlan interface 633 if ifacedump['autogen_vlan']: 634 vlan_list[ifacedump['autogen_ifbase']].append(ifacedump['autogen_vlan']) 625 635 626 636 # Flag dhclient is possible … … 675 685 assert False, "Unknown type " + ifacedump['type'] 676 686 677 store = (addrs_list, dhclient_if, output)687 store = (addrs_list, vlan_list, dhclient_if, output) 678 688 interface_list_cache[datadump['autogen_item']] = store 679 689 return(store) … … 866 876 """) 867 877 868 (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump) 869 output += extra_ouput.strip() + "\n" 878 (addrs_list, vlan_list, dhclient_if, extra_ouput) = make_interface_list(datadump) 879 for iface, vlans in vlan_list.items(): 880 output += 'vlans_%s="%s"\n' % (iface, ' '.join(vlans)) 881 882 # Details like SSID 883 if extra_ouput: 884 output += extra_ouput.strip() + "\n" 870 885 871 886 # Print IP address which needs to be assigned over here … … 886 901 cmp=lambda x,y: cmp(1 if x == '172' else 0, 1 if y == '172' else 0) 887 902 ) 888 addr_str = " ".join([x[0] for x in addrs]) 889 output += "ipv4_addrs_%s='%s'\n\n" % (iface, addr_str) 903 output += "ifconfig_%s='inet %s'\n" % (iface, addrs[0][0]) 904 for idx, addr in enumerate(addrs[1:]): 905 output += "ifconfig_%s_alias%s='inet %s'\n" % (iface, idx, addr[0]) 906 output += "\n" 890 907 891 908 rc_conf_local_cache[datadump['autogen_item']] = output 892 909 return output 893 894 910 895 911 … … 947 963 948 964 def get_neighbours(datadump): 949 (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump)965 (addrs_list, _, dhclient_if, extra_ouput) = make_interface_list(datadump) 950 966 951 967 (poel, errors) = make_relations() … … 1115 1131 return lines 1116 1132 1117 (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump)1133 (addrs_list, vlan_list, dhclient_if, extra_ouput) = make_interface_list(datadump) 1118 1134 table = [] 1119 1135 for iface,addrs in sorted(addrs_list.iteritems()): … … 1201 1217 output += " %-11s: %s\n" % (key, format_yaml_value(datadump[iface_key][key])) 1202 1218 output += "\n\n" 1203 except Exception as e:1219 except Exception: 1204 1220 print "# Error while processing interface %s" % iface_key 1205 1221 raise … … 1673 1689 try: 1674 1690 node = sys.argv[2] 1675 datadump = get_yaml(node)1676 1691 except IndexError: 1677 1692 print "Invalid argument" … … 1680 1695 print e 1681 1696 exit(1) 1697 1698 datadump = get_yaml(node) 1682 1699 1683 1700 … … 2092 2109 datadump['monitoring_group'] = 'wleiden' 2093 2110 2094 except Exception as e:2111 except Exception: 2095 2112 print "# Error while processing interface %s" % iface_key 2096 2113 raise 2097 2114 store_yaml(datadump) 2098 except Exception as e:2115 except Exception: 2099 2116 print "# Error while processing %s" % host 2100 2117 raise
Note:
See TracChangeset
for help on using the changeset viewer.