This repository has been archived by the owner on Nov 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
duplicates.py
executable file
·104 lines (85 loc) · 3.3 KB
/
duplicates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
import csv
import sys
def unique_vlans():
netbox_list = set()
with open('ipplan_vlans.csv', newline='') as ipplan_csv, open('netbox_vlans.csv', newline='') as netbox_csv, open('unique_vlans.csv', 'w', newline='') as outfile:
# setup header for csv file
fieldnames = [
'site',
'group_name',
'vid',
'name',
'tenant',
'status',
'role',
'description',
]
writer = csv.DictWriter(outfile, fieldnames=fieldnames, dialect='unix')
writer.writeheader()
netbox = csv.DictReader(netbox_csv, dialect='unix', delimiter=',', quotechar='"')
for vlan in netbox:
net = '{group_name}-v{vid}'.format(group_name=vlan['group_name'], vid=vlan['vid']).lower()
netbox_list.add(net)
ipplan = csv.DictReader(ipplan_csv, dialect='unix', delimiter=',', quotechar='"')
for vlan in ipplan:
ip = '{group_name}-v{vid}'.format(group_name=vlan['group_name'], vid=vlan['vid']).lower()
if ip not in netbox_list:
writer.writerow(vlan)
def unique_prefixes():
netbox_list = set()
with open('ipplan_prefixes.csv', newline='') as ipplan_csv, open('netbox_prefixes.csv', newline='') as netbox_csv, open('unique_prefixes.csv', 'w', newline='') as outfile:
# setup header for csv file
fieldnames = [
'prefix',
'vrf',
'tenant',
'site',
'vlan_group',
'vlan_vid',
'status',
'role',
'is_pool',
'description',
]
writer = csv.DictWriter(outfile, fieldnames=fieldnames, dialect='unix')
writer.writeheader()
netbox = csv.DictReader(netbox_csv, dialect='unix', delimiter=',', quotechar='"')
for prefix in netbox:
netbox_list.add(prefix['prefix'])
ipplan = csv.DictReader(ipplan_csv, dialect='unix', delimiter=',', quotechar='"')
for prefix in ipplan:
if prefix['prefix'] not in netbox_list:
writer.writerow(prefix)
def unique_addresses():
netbox_list = set()
with open('ipplan_addresses.csv', newline='') as ipplan_csv, open('netbox_addresses.csv', newline='') as netbox_csv, open('unique_addresses.csv', 'w', newline='') as outfile:
# setup header for csv file
fieldnames = [
'address',
'vrf',
'tenant',
'status',
'role',
'device',
'virtual_machine',
'interface_name',
'is_primary',
'description',
]
writer = csv.DictWriter(outfile, fieldnames=fieldnames, dialect='unix')
writer.writeheader()
netbox = csv.DictReader(netbox_csv, dialect='unix', delimiter=',', quotechar='"')
for address in netbox:
netbox_list.add(address['address'])
ipplan = csv.DictReader(ipplan_csv, dialect='unix', delimiter=',', quotechar='"')
for address in ipplan:
if address['address'] not in netbox_list:
writer.writerow(address)
def main():
unique_vlans()
unique_prefixes()
unique_addresses()
if __name__ == '__main__':
main()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4