7
7
from sonic_py_common import multi_asic
8
8
9
9
class Crm :
10
- def __init__ (self ):
10
+ def __init__ (self , db = None ):
11
11
self .cli_mode = None
12
12
self .addr_family = None
13
13
self .res_type = None
14
14
self .db = None
15
- self .config_db = None
15
+ self .cfgdb = db
16
16
self .multi_asic = multi_asic_util .MultiAsic ()
17
17
18
18
@multi_asic_util .run_on_multi_asic
19
19
def config (self , attr , val ):
20
20
"""
21
21
CRM handler for 'config' CLI commands.
22
22
"""
23
+ if self .cfgdb :
24
+ self .config_db = self .cfgdb
23
25
self .config_db .mod_entry ("CRM" , 'Config' , {attr : val })
24
26
25
27
def show_summary (self ):
26
28
"""
27
29
CRM Handler to display general information.
28
30
"""
29
31
30
- # Get the namespace list
31
- namespaces = multi_asic .get_namespace_list ()
32
+ configdb = self .cfgdb
33
+ if configdb is None :
34
+ # Get the namespace list
35
+ namespaces = multi_asic .get_namespace_list ()
32
36
33
- configdb = swsssdk .ConfigDBConnector (namespace = namespaces [0 ])
34
- configdb .connect ()
37
+ configdb = swsssdk .ConfigDBConnector (namespace = namespaces [0 ])
38
+ configdb .connect ()
35
39
36
40
crm_info = configdb .get_entry ('CRM' , 'Config' )
37
41
@@ -45,11 +49,13 @@ def show_thresholds(self, resource):
45
49
CRM Handler to display thresholds information.
46
50
"""
47
51
48
- # Get the namespace list
49
- namespaces = multi_asic .get_namespace_list ()
52
+ configdb = self .cfgdb
53
+ if configdb is None :
54
+ # Get the namespace list
55
+ namespaces = multi_asic .get_namespace_list ()
50
56
51
- configdb = swsssdk .ConfigDBConnector (namespace = namespaces [0 ])
52
- configdb .connect ()
57
+ configdb = swsssdk .ConfigDBConnector (namespace = namespaces [0 ])
58
+ configdb .connect ()
53
59
54
60
crm_info = configdb .get_entry ('CRM' , 'Config' )
55
61
@@ -190,8 +196,11 @@ def cli(ctx):
190
196
"""
191
197
Utility entry point.
192
198
"""
199
+ # Use the db object if given as input.
200
+ db = None if ctx .obj is None else ctx .obj .cfgdb
201
+
193
202
context = {
194
- "crm" : Crm ()
203
+ "crm" : Crm (db )
195
204
}
196
205
197
206
ctx .obj = context
0 commit comments