Skip to content

Commit

Permalink
[MultiDB] add new API to get instance name from db name (sonic-net#90)
Browse files Browse the repository at this point in the history
* [MultiDB] add new API to get instance name from db name
* [MultiDB] reuse get_instancename in get_instance
  • Loading branch information
dzhangalibaba authored Oct 28, 2020
1 parent 7d7b76c commit 748c404
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/swsssdk/dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,19 @@ def get_ns_list():

@staticmethod
def get_instance(db_name, namespace=None):
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
inst_name = SonicDBConfig.get_instancename(db_name, namespace)
return SonicDBConfig._sonic_db_config[namespace]["INSTANCES"][inst_name]

@staticmethod
def get_instancename(db_name, namespace=None):
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
if not SonicDBConfig._sonic_db_config_init:
SonicDBConfig.load_sonic_db_config()
SonicDBConfig.db_name_validation(db_name, namespace)
inst_name = SonicDBConfig._sonic_db_config[namespace]["DATABASES"][db_name]["instance"]
SonicDBConfig.inst_name_validation(inst_name, namespace)
return SonicDBConfig._sonic_db_config[namespace]["INSTANCES"][inst_name]
return inst_name

@staticmethod
def get_instancelist(namespace=None):
Expand Down

0 comments on commit 748c404

Please sign in to comment.