I am trying to make an API using a script. It runs but I need to make it iterate the CSV file without appending port_config to each line:
Reading this CSV File:
device_id,port,description
4444,eth1/1,test1
1111,eth1/2,test2
2222,eth1/3,test3
1234,eth1/4,test4
The code I have so far:
for device_id,port,description in devices:
print(device_id,port,description)
payload="{\n \"port_config\": { \"%s\": { \"description\": \"%s\"
}\n}\n}" % (port,description)
print(payload)
Result of above:
{
"port_config": { "interfacex/x": { "description": "test1" }
}
}
{
"port_config": { "interfacex/x": { "description": "test2" }
}
}
{
"port_config": { "interfacex/x": { "description": "test3" }
}
}
{
"port_config": { "interfacex/x": { "description": "test4" }
}
}
Desired results:
{
"port_config": {
"eth1/1": {"description": "test0,"},
"eth1/2": {"description": "test1,"},
"eth1/3": {"description": "test2,"},
"eth1/4": {"description": "test3,"}
}
}