From 0780c345240c334e402dc1da7ba6dfe7324890dc Mon Sep 17 00:00:00 2001 From: sgherdao <104869962+sgherdao@users.noreply.github.com> Date: Sun, 14 Apr 2024 20:55:07 +0100 Subject: [PATCH] enhance tabulate views for lab and nodes. For lab, use textwrap to wrap the description and use lab.username instead of lab.owner (UUID). For nodes, use the newline char instead of comma for IP addresses separator (see tabulate Mutline Cells). --- virl/api/cml.py | 4 ++++ virl/cli/views/labs/lab_views.py | 8 +++++--- virl/cli/views/nodes/node_views.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/virl/api/cml.py b/virl/api/cml.py index 4870a17..777c824 100644 --- a/virl/api/cml.py +++ b/virl/api/cml.py @@ -60,3 +60,7 @@ def statistics(self): @property def owner(self): return "N/A" + + @property + def username(self): + return "N/A" diff --git a/virl/cli/views/labs/lab_views.py b/virl/cli/views/labs/lab_views.py index 1036729..c4d01a0 100644 --- a/virl/cli/views/labs/lab_views.py +++ b/virl/cli/views/labs/lab_views.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import textwrap + import click import tabulate @@ -13,14 +15,14 @@ def lab_list_table(labs, cached_labs=None): def print_labs(labs): table = list() - # TODO: Do we truncate description as it can be kind of long? headers = ["ID", "Title", "Description", "Owner", "Status", "Nodes", "Links", "Interfaces"] for lab in labs: tr = list() tr.append(lab.id) tr.append(lab.title) - tr.append(lab.description) - tr.append(lab.owner) + wrapped_description = textwrap.fill(lab.description, width=40) + tr.append(wrapped_description) + tr.append(lab.username) status = lab.state() stats = lab.statistics if status in {"BOOTED", "STARTED"}: diff --git a/virl/cli/views/nodes/node_views.py b/virl/cli/views/nodes/node_views.py index c0e0276..10c810a 100644 --- a/virl/cli/views/nodes/node_views.py +++ b/virl/cli/views/nodes/node_views.py @@ -67,7 +67,7 @@ def node_list_table(nodes, computes): if disc_ipv6: intfs += disc_ipv6 - tr.append(",".join(intfs)) + tr.append("\n".join(intfs)) table.append(tr) # wrap the output in this try/except block as some terminals # may have problem with the 'fancy_grid'