Skip to content

Commit be4fe89

Browse files
committed
Fix: Add topology file information to 'netlab status' printout
Closes #3258
1 parent d65fdb5 commit be4fe89

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

netsim/cli/status.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
import argparse
77
import os
8+
import pathlib
89
import subprocess
910
import sys
1011
import typing
@@ -138,7 +139,9 @@ def display_active_labs(topology: Box,args: argparse.Namespace,lab_states: Box)
138139
def show_lab_instance(iid: Lab_Instance_ID, lab_state: Box) -> None:
139140
print(f'Lab {iid} in {lab_state.dir}')
140141
if lab_state.status:
141-
print(f' status: {lab_state.status}')
142+
print(f' status: {lab_state.status}')
143+
if lab_state.topology:
144+
print(f' topology: {lab_state.topology}')
142145
if lab_state.providers:
143146
print(f' provider(s): {",".join(lab_state.providers)}')
144147
print()
@@ -224,6 +227,19 @@ def get_lab_status(lab_state: Box) -> str:
224227

225228
return lab_state.status
226229

230+
#
231+
# Get lab topology filename from the snapshot file, try to make it
232+
# relative to the current directory
233+
#
234+
def get_topology_file(topology: Box, curdir: str) -> typing.Optional[str]:
235+
if not topology.input:
236+
return None
237+
topo_name = topology.input[0]
238+
try:
239+
return str(pathlib.Path(topo_name).relative_to(curdir))
240+
except ValueError:
241+
return topo_name
242+
227243
def show_lab(args: argparse.Namespace,lab_states: Box) -> None:
228244
iid = get_instance(args,lab_states)
229245
lab_state = cleanup_state(lab_states[iid])
@@ -239,6 +255,7 @@ def show_lab(args: argparse.Namespace,lab_states: Box) -> None:
239255
if topology is None:
240256
log.fatal(f'Cannot read topology snapshot file {snapshot}')
241257

258+
lab_state.topology = get_topology_file(topology,wdir)
242259
lab_status = get_lab_status(lab_state)
243260
if 'started' not in lab_status:
244261
err = 'Lab is not started, cannot display node/tool status'

0 commit comments

Comments
 (0)