Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(152): cml ls --all-users display wrong owner #153

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def setup_mocks(self, m):
"labs/{}/topology".format(self.get_test_id()): MockCMLServer.get_topology,
"labs/{}/topology".format(self.get_alt_id()): MockCMLServer.get_alt_topology,
"labs/{}/topology".format(self.get_cml23_id()): MockCMLServer.get_topology_23,
"labs/{}".format(self.get_test_id()): MockCMLServer.get_lab_details,
"labs/{}".format(self.get_alt_id()): MockCMLServer.get_lab_alt_details,
"labs/{}".format(self.get_cml23_id()): MockCMLServer.get_lab_details_23,
"labs/{}/lab_element_state".format(self.get_test_id()): MockCMLServer.get_lab_element_state,
"labs/{}/lab_element_state".format(self.get_cml23_id()): MockCMLServer.get_lab_element_state_23,
"system_information": MockCMLServer.get_sys_info,
Expand Down
57 changes: 57 additions & 0 deletions tests/v2/mocks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,63 @@ def get_labs(req, ctx=None):
response = ["5eaea5", "5f0d96", "88119b68-9d08-40c4-90f5-6dc533fd0254"]
return response

@staticmethod
def get_lab_details(req, ctx=None):
response = {
"created": "2020-08-18 22:47:56",
"groups": [],
"id": "5f0d96",
"lab_description": "",
"lab_notes": "",
"lab_title": "Mock Test",
"link_count": 1,
"modified": "2023-06-06T11:25:32+00:00",
"node_count": 2,
"owner": "00000000-0000-4000-a000-000000000000",
"owner_fullname": "",
"owner_username": "admin",
"state": "STARTED",
}
return response

@staticmethod
def get_lab_alt_details(req, ctx=None):
response = {
"created": "2020-07-21 09:10:39",
"groups": [],
"id": "5eaea5",
"lab_description": "",
"lab_notes": "",
"lab_title": "Other Lab",
"link_count": 2,
"modified": "2023-06-06T11:25:32+00:00",
"node_count": 1,
"owner": "00000000-0000-4000-a000-000000000000",
"owner_fullname": "",
"owner_username": "admin",
"state": "STOPPED",
}
return response

@staticmethod
def get_lab_details_23(req, ctx=None):
response = {
"created": "2020-08-18 22:47:56",
"groups": [],
"id": "88119b68-9d08-40c4-90f5-6dc533fd0254",
"lab_description": "",
"lab_notes": "",
"lab_title": "Mock Test 2.3",
"link_count": 1,
"modified": "2023-06-06T11:25:32+00:00",
"node_count": 2,
"owner": "00000000-0000-4000-a000-000000000000",
"owner_fullname": "",
"owner_username": "admin",
"state": "STARTED",
}
return response

@staticmethod
def download_lab(req, ctx=None):
response = """
Expand Down
17 changes: 17 additions & 0 deletions virl/api/cml.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,20 @@ def owner(self):
@property
def username(self):
return "N/A"

def details(self):
return {
"state": self.state(),
"created": "N/A",
"modified": "N/A",
"lab_title": self.__title,
"lab_description": self.__description,
"lab_notes": "",
"owner": self.owner,
"owner_username": "N/A",
"owner_fullname": "N/A",
"node_count": self.__stats["nodes"],
"link_count": self.__stats["links"],
"id": self.__id,
"groups": [],
}
6 changes: 1 addition & 5 deletions virl/cli/ls/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ def ls(all, all_users):
"""
server = VIRLServer()
client = get_cml_client(server)
labs = []
cached_labs = None

lab_ids = client.get_lab_list(all_users)
for id in lab_ids:
labs.append(client.join_existing_lab(id))
labs = client.all_labs(show_all=all_users)

if all:
cached_labs = []
Expand Down
21 changes: 11 additions & 10 deletions virl/cli/views/labs/lab_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@ def lab_list_table(labs, cached_labs=None):


def print_labs(labs):
table = list()
table = []
headers = ["ID", "Title", "Description", "Owner", "Status", "Nodes", "Links", "Interfaces"]
for lab in labs:
tr = list()
tr.append(lab.id)
tr.append(lab.title)
wrapped_description = textwrap.fill(lab.description, width=40)
lab_details = lab.details()
tr = []
tr.append(lab_details["owner_username"])
tr.append(lab_details["lab_title"])
wrapped_description = textwrap.fill(lab_details["lab_description"], width=40)
tr.append(wrapped_description)
tr.append(lab.username)
status = lab.state()
stats = lab.statistics
tr.append(lab_details["owner_username"])
status = lab_details["state"]
if status in {"BOOTED", "STARTED"}:
color = "green"
elif status in {"QUEUED"}:
color = "yellow"
else:
color = "red"
tr.append(click.style(status, fg=color))
tr.append(stats["nodes"])
tr.append(stats["links"])
tr.append(lab_details["node_count"])
tr.append(lab_details["link_count"])
stats = lab.statistics
tr.append(stats["interfaces"])
table.append(tr)
# wrap the output in this try/except block as some terminals
Expand Down
Loading