|
11 | 11 | from natsort import natsorted
|
12 | 12 | from tabulate import tabulate
|
13 | 13 | from swsssdk import ConfigDBConnector
|
| 14 | +from swsssdk import SonicV2Connector |
14 | 15 |
|
15 | 16 | import mlnx
|
16 | 17 |
|
@@ -780,7 +781,7 @@ def cpu(verbose):
|
780 | 781 | # Run top in batch mode to prevent unexpected newline after each newline
|
781 | 782 | cmd = "top -bn 1 -o %CPU"
|
782 | 783 | run_command(cmd, display_cmd=verbose)
|
783 |
| - |
| 784 | + |
784 | 785 | # 'memory' subcommand
|
785 | 786 | @processes.command()
|
786 | 787 | @click.option('--verbose', is_flag=True, help="Enable verbose output")
|
@@ -1174,6 +1175,90 @@ def line():
|
1174 | 1175 | """Show all /dev/ttyUSB lines and their info"""
|
1175 | 1176 | cmd = "consutil show"
|
1176 | 1177 | run_command(cmd, display_cmd=verbose)
|
| 1178 | + return |
| 1179 | + |
| 1180 | + |
| 1181 | +@cli.group(cls=AliasedGroup, default_if_no_args=False) |
| 1182 | +def warm_restart(): |
| 1183 | + """Show warm restart configuration and state""" |
| 1184 | + pass |
| 1185 | + |
| 1186 | +@warm_restart.command() |
| 1187 | +@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection') |
| 1188 | +def state(redis_unix_socket_path): |
| 1189 | + """Show warm restart state""" |
| 1190 | + kwargs = {} |
| 1191 | + if redis_unix_socket_path: |
| 1192 | + kwargs['unix_socket_path'] = redis_unix_socket_path |
| 1193 | + |
| 1194 | + data = {} |
| 1195 | + db = SonicV2Connector(host='127.0.0.1') |
| 1196 | + db.connect(db.STATE_DB, False) # Make one attempt only |
| 1197 | + |
| 1198 | + TABLE_NAME_SEPARATOR = '|' |
| 1199 | + prefix = 'WARM_RESTART_TABLE' + TABLE_NAME_SEPARATOR |
| 1200 | + _hash = '{}{}'.format(prefix, '*') |
| 1201 | + table_keys = db.keys(db.STATE_DB, _hash) |
| 1202 | + |
| 1203 | + def remove_prefix(text, prefix): |
| 1204 | + if text.startswith(prefix): |
| 1205 | + return text[len(prefix):] |
| 1206 | + return text |
| 1207 | + |
| 1208 | + table = [] |
| 1209 | + for tk in table_keys: |
| 1210 | + entry = db.get_all(db.STATE_DB, tk) |
| 1211 | + r = [] |
| 1212 | + r.append(remove_prefix(tk, prefix)) |
| 1213 | + r.append(entry['restart_count']) |
| 1214 | + |
| 1215 | + if 'state' not in entry: |
| 1216 | + r.append("") |
| 1217 | + else: |
| 1218 | + r.append(entry['state']) |
| 1219 | + |
| 1220 | + table.append(r) |
| 1221 | + |
| 1222 | + header = ['name', 'restart_count', 'state'] |
| 1223 | + click.echo(tabulate(table, header)) |
| 1224 | + |
| 1225 | +@warm_restart.command() |
| 1226 | +@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection') |
| 1227 | +def config(redis_unix_socket_path): |
| 1228 | + """Show warm restart config""" |
| 1229 | + kwargs = {} |
| 1230 | + if redis_unix_socket_path: |
| 1231 | + kwargs['unix_socket_path'] = redis_unix_socket_path |
| 1232 | + config_db = ConfigDBConnector(**kwargs) |
| 1233 | + config_db.connect(wait_for_init=False) |
| 1234 | + data = config_db.get_table('WARM_RESTART') |
| 1235 | + keys = data.keys() |
| 1236 | + |
| 1237 | + def tablelize(keys, data): |
| 1238 | + table = [] |
| 1239 | + |
| 1240 | + for k in keys: |
| 1241 | + r = [] |
| 1242 | + r.append(k) |
| 1243 | + |
| 1244 | + if 'enable' not in data[k]: |
| 1245 | + r.append("false") |
| 1246 | + else: |
| 1247 | + r.append(data[k]['enable']) |
| 1248 | + |
| 1249 | + if 'neighsyncd_timer' in data[k]: |
| 1250 | + r.append("neighsyncd_timer") |
| 1251 | + r.append(data[k]['neighsyncd_timer']) |
| 1252 | + else: |
| 1253 | + r.append("NULL") |
| 1254 | + r.append("NULL") |
| 1255 | + |
| 1256 | + table.append(r) |
| 1257 | + |
| 1258 | + return table |
| 1259 | + |
| 1260 | + header = ['name', 'enable', 'timer_name', 'timer_duration'] |
| 1261 | + click.echo(tabulate(tablelize(keys, data), header)) |
1177 | 1262 |
|
1178 | 1263 |
|
1179 | 1264 | if __name__ == '__main__':
|
|
0 commit comments