diff options
author | Jon Clausen <jac@nordu.net> | 2018-08-28 09:59:36 +0200 |
---|---|---|
committer | Jon Clausen <jac@nordu.net> | 2018-08-28 09:59:36 +0200 |
commit | 08e39677ad3cc3a2f939a921a88fb04eb33707c6 (patch) | |
tree | ba0c1531d7a717caa952d9846b207bbedd993f8b | |
parent | 9a266bcc29864b85410b55882d83cceedfb613a8 (diff) |
handle EX switches with no active vlans configured
-rwxr-xr-x | code/vlanscrape | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/code/vlanscrape b/code/vlanscrape index 5da322e..44411fc 100755 --- a/code/vlanscrape +++ b/code/vlanscrape @@ -93,6 +93,9 @@ def look_in_juniper_vlans_section(hostName, hostConfig): break else: j += 1 + if (i + j) >= len(hostConfig): + vlan="none" + break vlanDict[vlan] = name vlanList=vlanDict.items() @@ -153,26 +156,29 @@ def write_list_to_file(outFile, outList): def check_out_vs_dst(hostName, vlanList): outFile = outputDir + "/" + hostName outList = [] - for l in sorted(vlanList, key=lambda x: int(x[0])): - o='' - for i, sl in enumerate(l): - if o == '': - o = str(sl) - else: - o = o + ";" + str(sl) - # we want the resulting 'csv' to have the same number of fields, whether - # or not the source config has 'interface' for the vlan: - if i == 1: - o = o + ";" - o = o + "\n" - outList.append(o) - if os.path.isfile(outFile): - dstList = open(outFile, 'r').readlines() - compare = set(sorted(outList)) & set(sorted(dstList)) - if (len(compare) != len(dstList)) or (len(compare) != len(outList)): - write_list_to_file(outFile, outList) + if (len(vlanList) == 1) and ("none" in vlanList[0]): + print "no vlans in", hostName else: - write_list_to_file(outFile, outList) + for l in sorted(vlanList, key=lambda x: int(x[0])): + o='' + for i, sl in enumerate(l): + if o == '': + o = str(sl) + else: + o = o + ";" + str(sl) + # we want the resulting 'csv' to have the same number of fields, whether + # or not the source config has 'interface' for the vlan: + if i == 1: + o = o + ";" + o = o + "\n" + outList.append(o) + if os.path.isfile(outFile): + dstList = open(outFile, 'r').readlines() + compare = set(sorted(outList)) & set(sorted(dstList)) + if (len(compare) != len(dstList)) or (len(compare) != len(outList)): + write_list_to_file(outFile, outList) + else: + write_list_to_file(outFile, outList) def is_juniper(hostName): |