Created
September 4, 2023 15:02
-
-
Save lukassup/adfc0d5c61c00f58542d3cffb67cb3b8 to your computer and use it in GitHub Desktop.
SONiC scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
from utilities_common.db import Db | |
def get_vlan_info(): | |
db = Db() | |
vlan_data = db.cfgdb.get_table('VLAN') | |
vlan_ip_data = db.cfgdb.get_table('VLAN_INTERFACE') | |
vlan_ports_data = db.cfgdb.get_table('VLAN_MEMBER') | |
output = vlan_data | |
for k, v in vlan_ip_data.items(): | |
if type(k) == tuple: | |
vlan_id, interface_ip = k | |
output[vlan_id].update({'ip_address': interface_ip}) | |
else: | |
output[k].update(v) | |
output[k]['ports'] = [] | |
for (vlan_id, port), v in vlan_ports_data.items(): | |
output[vlan_id]['ports'] += [port] | |
return output | |
if __name__ == '__main__': | |
print(json.dumps(get_vlan_info())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment