55#
66import argparse
77import os
8+ import pathlib
89import subprocess
910import sys
1011import typing
@@ -138,7 +139,9 @@ def display_active_labs(topology: Box,args: argparse.Namespace,lab_states: Box)
138139def 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+
227243def 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