-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_to_yml.py
29 lines (23 loc) · 950 Bytes
/
csv_to_yml.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
#!/usr/bin/env python
import sys
import csv
import yaml
import yamlloader
l2vni_data = []
my_csv_file = '/home/contiv/vxlan-evpn/l2vni_vars.csv'
my_vars_file = '/home/contiv/vxlan-evpn/roles/l2vni_overlay/vars/main.yml'
with open(my_csv_file, mode='r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
l2vni_data.append(row)
with open(my_vars_file) as data:
data_loaded = yaml.load(data, Loader=yamlloader.ordereddict.CLoader)
yaml.dump(data_loaded, sys.stdout)
with open(my_vars_file, "w") as file:
file.write('---\n')
yaml.dump({'nxos_provider': data_loaded['nxos_provider']}, file, Dumper=yamlloader.ordereddict.CDumper)
file.write('\n')
file.write('# vars for creation of l2vni and vlan interface configuration\n')
with open(my_vars_file, "a") as file:
file.write('\n')
yaml.dump({'l2vni': l2vni_data}, file, Dumper=yamlloader.ordereddict.CDumper)