diff options
Diffstat (limited to 'netmap-csv.py')
-rw-r--r-- | netmap-csv.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/netmap-csv.py b/netmap-csv.py index fc4216b..165cbd2 100644 --- a/netmap-csv.py +++ b/netmap-csv.py @@ -28,6 +28,24 @@ import argparse def main(args): + """ + Two different formats are needed. The network dict reflects how the + XMLRPC will output the data and is a closer match to the spreadsheet + so that updates are easier to check. + The devices dict is the output equivalent to the device dictionary + import, output as device-specific Jinja2 files. + e.g. + {% extends 'vland.yaml' %} + {% set interfaces = ['eth0', 'eth1'] %} + {% set sysfs = { + 'eth0': "/sys/devices/pci0000:00/0000:00:19.0/net/eth0", + 'eth1': "/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1"} %} + {% set mac_addr = {'eth0': "f0:de:f1:46:8c:21", 'eth1': "00:24:d7:9b:c0:8c"} %} + {% set tags = {'eth0': ['1G', '10G'], 'eth1': ['1G']} %} + {% set map = {'eth0': {'192.168.0.2': 5}, 'eth1': {'192.168.0.2': 7}} %} + + All output occurs in the ./output/ directory. + """ parser = argparse.ArgumentParser(description='network map CSV import') parser.add_argument( '--input', metavar='FILE', type=str, @@ -36,6 +54,7 @@ def main(args): args = parser.parse_args() rows = [] network = {} + devices = {} with open(args.filename, 'r') as csvfile: content = csv.DictReader(csvfile) for row in content: @@ -53,8 +72,29 @@ def main(args): 'hostname': row['Device'].replace('*', '') } network['switches'][str(value)].append(data) + elif key == 'Device' and value: + name = row['Device'].replace('*', '') + devices.setdefault(name, {}) + devices[name]['extends'] = '' # needs to be Device Type + devices[name].setdefault('interfaces', []) + iface = row['Device eth port'] + devices[name]['interfaces'].append(iface) + devices[name].setdefault('sysfs', {}) + devices[name]['sysfs'][iface] = '' + devices[name].setdefault('mac_addr', {}) + devices[name]['mac_addr'][iface] = row['Device eth MAC/unique ID'] + devices[name].setdefault('tags', {}) + devices[name]['tags'][iface] = [] + devices[name].setdefault('map', {}) + devices[name]['map'].setdefault(iface, {}) + devices[name]['map'][iface].update({ + row['Switch']: row['Switch Port'] + }) + for key, value in devices.items(): + with open('./output/%s' % key, 'w') as device_output: + yaml.dump(value, device_output, default_flow_style=False) with open('./output/output.yaml', 'w') as output: - yaml.dump(network, output, default_flow_style=False) + yaml.dump(network, output, default_flow_style=False) return 0 if __name__ == '__main__': |