mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-20 12:22:23 -06:00
29 lines
598 B
Python
Executable File
29 lines
598 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import csv
|
|
import sys
|
|
import yaml
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(description='Netbox csv export to initializer yaml')
|
|
parser.add_argument(
|
|
'input',
|
|
type=argparse.FileType('r'),
|
|
metavar='export.csv',
|
|
help='netbox csv export'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'output',
|
|
type=argparse.FileType('w'),
|
|
help='parsed yaml output'
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
data = [r for r in csv.reader(args.input)]
|
|
header = data.pop(0)
|
|
output = [dict(zip(header, r)) for r in data]
|
|
args.output.write(yaml.dump(output, default_flow_style=False))
|