Skip to content

Commit

Permalink
enhance tabulate views for lab and nodes.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
sgherdao committed Apr 14, 2024
1 parent 9337a0c commit 0780c34
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions virl/api/cml.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ def statistics(self):
@property
def owner(self):
return "N/A"

@property
def username(self):
return "N/A"
8 changes: 5 additions & 3 deletions virl/cli/views/labs/lab_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import textwrap

import click
import tabulate

Expand All @@ -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"}:
Expand Down
2 changes: 1 addition & 1 deletion virl/cli/views/nodes/node_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 0780c34

Please sign in to comment.