Skip to content

Commit

Permalink
add helpers for fetching entries on multi-asic
Browse files Browse the repository at this point in the history
  • Loading branch information
bktsim-arista authored and arista-nwolfe committed Mar 25, 2024
1 parent 610685d commit 59b57b8
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions src/sonic-py-common/sonic_py_common/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,27 +271,60 @@ def get_port_table(namespace=None):
Returns:
a dict of all the ports
"""
all_ports = {}
return get_table(PORT_CFG_DB_TABLE, namespace)


def get_table(table, namespace=None):
"""
Retrieves a merged table containing all entries across specified namespaces
Returns:
a dict of all entries of table across namespaces
"""
merged_table = {}
ns_list = get_namespace_list(namespace)

for ns in ns_list:
ports = get_port_table_for_asic(ns)
all_ports.update(ports)
ns_table = get_table_for_asic(table, ns)
merged_table.update(ns_table)

return merged_table

return all_ports

def get_port_entry_for_asic(port, namespace):

config_db = connect_config_db_for_ns(namespace)
ports = config_db.get_entry(PORT_CFG_DB_TABLE, port)
return ports
return get_table_entry_for_asic(PORT_CFG_DB_TABLE, port, namespace)


def get_table_entry_for_asic(table, entry, namespace):

config_db = connect_config_db_for_ns(namespace)
return config_db.get_entry(table, entry)

def get_port_table_for_asic(namespace):

return get_table_for_asic(PORT_CFG_DB_TABLE, namespace)


def get_table_for_asic(table, namespace):

config_db = connect_config_db_for_ns(namespace)
ports = config_db.get_table(PORT_CFG_DB_TABLE)
return ports
return config_db.get_table(table)


def mod_entry(table, key, value, namespace=None, modIfExists=False):
"""
Modifies an entry in a table with a value in a specified namespace.
If no namespace is specified all namespaces are modified.
If modIfExists is true, the entry will be modified only if the key
already exists in the table.
"""
ns_list = get_namespace_list(namespace)

for ns in ns_list:
if not modIfExists or get_table_entry_for_asic(table, key, ns):
config_db = connect_config_db_for_ns(ns)
config_db.mod_entry(table, key, value)


def get_namespace_for_port(port_name):
Expand Down

0 comments on commit 59b57b8

Please sign in to comment.