forked from jwegner89/netbox-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
duplicates_ipam.py
executable file
·48 lines (37 loc) · 1.26 KB
/
duplicates_ipam.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
#!/usr/bin/env python3
import csv
import ipaddress
import sys
def unique_addresses():
netbox_list = set()
with open('ipplan_addresses.csv', newline='') as ipplan_csv, open('netbox_ipam_ipaddress.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)
for address in netbox:
ip = ipaddress.ip_interface(address['address'])
netbox_list.add(str(ip))
ipplan = csv.DictReader(ipplan_csv)
for address in ipplan:
ip = ipaddress.ip_interface(address['address'])
print('Processing {ip}'.format(ip=ip))
if str(ip) not in netbox_list:
writer.writerow(address)
def main():
unique_addresses()
if __name__ == '__main__':
main()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4