@@ -30,7 +30,10 @@ def show_summary(self):
30
30
31
31
crm_info = configdb .get_entry ('CRM' , 'Config' )
32
32
33
- print '\n Polling Interval: ' + crm_info ['polling_interval' ] + ' second(s)\n '
33
+ if crm_info :
34
+ print '\n Polling Interval: ' + crm_info ['polling_interval' ] + ' second(s)\n '
35
+ else :
36
+ print '\n Error! Could not get CRM configuration.\n '
34
37
35
38
def show_thresholds (self , resource ):
36
39
"""
@@ -44,13 +47,16 @@ def show_thresholds(self, resource):
44
47
header = ("Resource Name" , "Threshold Type" , "Low Threshold" , "High Threshold" )
45
48
data = []
46
49
47
- if resource == 'all' :
48
- for res in ["ipv4_route" , "ipv6_route" , "ipv4_nexthop" , "ipv6_nexthop" , "ipv4_neighbor" , "ipv6_neighbor" ,
49
- "nexthop_group_member" , "nexthop_group" , "acl_table" , "acl_group" , "acl_entry" ,
50
- "acl_counter" , "fdb_entry" ]:
51
- data .append ([res , crm_info [res + "_threshold_type" ], crm_info [res + "_low_threshold" ], crm_info [res + "_high_threshold" ]])
50
+ if crm_info :
51
+ if resource == 'all' :
52
+ for res in ["ipv4_route" , "ipv6_route" , "ipv4_nexthop" , "ipv6_nexthop" , "ipv4_neighbor" , "ipv6_neighbor" ,
53
+ "nexthop_group_member" , "nexthop_group" , "acl_table" , "acl_group" , "acl_entry" ,
54
+ "acl_counter" , "fdb_entry" ]:
55
+ data .append ([res , crm_info [res + "_threshold_type" ], crm_info [res + "_low_threshold" ], crm_info [res + "_high_threshold" ]])
56
+ else :
57
+ data .append ([resource , crm_info [resource + "_threshold_type" ], crm_info [resource + "_low_threshold" ], crm_info [resource + "_high_threshold" ]])
52
58
else :
53
- data . append ([ resource , crm_info [ resource + "_threshold_type" ], crm_info [ resource + "_low_threshold" ], crm_info [ resource + "_high_threshold" ]])
59
+ print ' \n Error! Could not get CRM configuration.'
54
60
55
61
print '\n '
56
62
print tabulate (data , headers = header , tablefmt = "simple" , missingval = "" )
@@ -68,12 +74,15 @@ def show_resources(self, resource):
68
74
header = ("Resource Name" , "Used Count" , "Available Count" )
69
75
data = []
70
76
71
- if resource == 'all' :
72
- for res in ["ipv4_route" , "ipv6_route" , "ipv4_nexthop" , "ipv6_nexthop" , "ipv4_neighbor" , "ipv6_neighbor" ,
73
- "nexthop_group_member" , "nexthop_group" , "fdb_entry" ]:
74
- data .append ([res , crm_stats ['crm_stats_' + res + "_used" ], crm_stats ['crm_stats_' + res + "_available" ]])
77
+ if crm_stats :
78
+ if resource == 'all' :
79
+ for res in ["ipv4_route" , "ipv6_route" , "ipv4_nexthop" , "ipv6_nexthop" , "ipv4_neighbor" , "ipv6_neighbor" ,
80
+ "nexthop_group_member" , "nexthop_group" , "fdb_entry" ]:
81
+ data .append ([res , crm_stats ['crm_stats_' + res + "_used" ], crm_stats ['crm_stats_' + res + "_available" ]])
82
+ else :
83
+ data .append ([resource , crm_stats ['crm_stats_' + resource + "_used" ], crm_stats ['crm_stats_' + resource + "_available" ]])
75
84
else :
76
- data . append ([ resource , crm_stats [ 'crm_stats_' + resource + "_used" ], crm_stats [ 'crm_stats_' + resource + "_available" ]])
85
+ print ' \n CRM counters are not ready. They would be populated after the polling interval.'
77
86
78
87
print '\n '
79
88
print tabulate (data , headers = header , tablefmt = "simple" , missingval = "" )
@@ -118,15 +127,17 @@ def show_acl_table_resources(self):
118
127
proc = Popen ("docker exec -i database redis-cli --raw -n 2 KEYS *CRM:ACL_TABLE_STATS*" , stdout = PIPE , stderr = PIPE , shell = True )
119
128
out , err = proc .communicate ()
120
129
121
- for key in out .splitlines ():
130
+ for key in out .splitlines () or [ None ] :
122
131
data = []
123
- id = key .replace ('CRM:ACL_TABLE_STATS:' , '' )
124
132
125
- crm_stats = countersdb .get_all (countersdb .COUNTERS_DB , key )
133
+ if key :
134
+ id = key .replace ('CRM:ACL_TABLE_STATS:' , '' )
135
+
136
+ crm_stats = countersdb .get_all (countersdb .COUNTERS_DB , key )
126
137
127
- for res in ['acl_entry' , 'acl_counter' ]:
128
- if ('crm_stats_' + res + '_used' in crm_stats ) and ('crm_stats_' + res + '_available' in crm_stats ):
129
- data .append ([id , res , crm_stats ['crm_stats_' + res + '_used' ], crm_stats ['crm_stats_' + res + '_available' ]])
138
+ for res in ['acl_entry' , 'acl_counter' ]:
139
+ if ('crm_stats_' + res + '_used' in crm_stats ) and ('crm_stats_' + res + '_available' in crm_stats ):
140
+ data .append ([id , res , crm_stats ['crm_stats_' + res + '_used' ], crm_stats ['crm_stats_' + res + '_available' ]])
130
141
131
142
print '\n '
132
143
print tabulate (data , headers = header , tablefmt = "simple" , missingval = "" )
@@ -459,14 +470,14 @@ def table(ctx):
459
470
elif ctx .obj ["crm" ].cli_mode == 'resources' :
460
471
ctx .obj ["crm" ].show_acl_table_resources ()
461
472
462
- @acl .group ()
473
+ @acl .command ()
463
474
@click .pass_context
464
475
def group (ctx ):
465
476
"""Show CRM information for acl group resource"""
466
477
if ctx .obj ["crm" ].cli_mode == 'thresholds' :
467
478
ctx .obj ["crm" ].show_thresholds ('acl_group' )
468
479
elif ctx .obj ["crm" ].cli_mode == 'resources' :
469
- ctx .obj ["crm" ].show_resources ( 'acl_group' )
480
+ ctx .obj ["crm" ].show_acl_resources ( )
470
481
471
482
@resources .command ()
472
483
@click .pass_context
0 commit comments