|
1 | 1 | #!/usr/bin/python |
2 | 2 | from __future__ import print_function |
3 | 3 | import sys |
4 | | -from swsscommon.swsscommon import SonicDBConfig |
| 4 | +from swsscommon.swsscommon import SonicDBConfig, SonicDBKey |
5 | 5 | import redis |
6 | 6 | import argparse |
| 7 | +import os |
| 8 | + |
| 9 | +NETNS = os.environ.get("NETNS", "") |
7 | 10 |
|
8 | 11 | def centralize_to_target_db(target_dbname): |
9 | | - target_dbport = SonicDBConfig.getDbPort(target_dbname) |
10 | | - target_dbhost = SonicDBConfig.getDbHostname(target_dbname) |
| 12 | + SonicDBConfig.initializeGlobalConfig() |
| 13 | + key = SonicDBKey() |
| 14 | + key.netns = NETNS |
| 15 | + target_dbport = SonicDBConfig.getDbPort(target_dbname, key) |
| 16 | + target_dbhost = SonicDBConfig.getDbHostname(target_dbname, key) |
11 | 17 |
|
12 | | - dblists = SonicDBConfig.getDbList() |
| 18 | + dblists = SonicDBConfig.getDbList(key) |
13 | 19 | for dbname in dblists: |
14 | | - dbport = SonicDBConfig.getDbPort(dbname) |
15 | | - dbhost = SonicDBConfig.getDbHostname(dbname) |
| 20 | + dbport = SonicDBConfig.getDbPort(dbname, key) |
| 21 | + dbhost = SonicDBConfig.getDbHostname(dbname, key) |
16 | 22 | # if the db is on the same instance, no need to move |
17 | 23 | if dbport == target_dbport and dbhost == target_dbhost: |
18 | 24 | continue |
19 | 25 |
|
20 | | - dbsocket = SonicDBConfig.getDbSock(dbname) |
21 | | - dbid = SonicDBConfig.getDbId(dbname) |
| 26 | + dbsocket = SonicDBConfig.getDbSock(dbname, key) |
| 27 | + dbid = SonicDBConfig.getDbId(dbname, key) |
22 | 28 |
|
23 | 29 | r = redis.Redis(host=dbhost, unix_socket_path=dbsocket, db=dbid) |
24 | 30 |
|
|
0 commit comments