Skip to content

Commit

Permalink
Fix --topology option (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcaiazzi committed Nov 20, 2024
1 parent 6692c95 commit f72bbc1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/Kathara/cli/ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def create_topology_table(lab: Lab) -> Optional[RenderableType]:

table = Table(title=ts_header, show_lines=True, box=box.SQUARE_DOUBLE_HEAD)

if not lab.links:
return Group(
Text(ts_header, style="italic", justify="center"),
create_panel("No Collision Domains Found", style="red bold", justify="center", box=box.DOUBLE)
)

for link in sorted(lab.links.values(), key=lambda x: x.name):
row_data = {
'LINK NAME': link.name,
Expand Down
4 changes: 3 additions & 1 deletion src/Kathara/manager/docker/DockerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,6 @@ def get_lab_from_api(self, lab_hash: Optional[str] = None, lab_name: Optional[st
device.meta["sysctls"] = container.attrs["HostConfig"]["Sysctls"]

if "none" not in container.attrs["NetworkSettings"]["Networks"]:

if "bridge" in container.attrs["NetworkSettings"]["Networks"].keys():
device.add_meta("bridged", True)
container.attrs["NetworkSettings"]["Networks"].pop("bridge")
Expand Down Expand Up @@ -763,6 +762,9 @@ def update_lab_from_api(self, lab: Lab) -> None:
if "bridge" in container.attrs["NetworkSettings"]["Networks"].keys():
container.attrs["NetworkSettings"]["Networks"].pop("bridge")

if "none" in container.attrs["NetworkSettings"]["Networks"].keys():
container.attrs["NetworkSettings"]["Networks"].pop("none")

current_ifaces = [
(lab.get_or_new_link(deployed_networks[name].attrs["Labels"]["name"]), options)
for name, options in sorted(container.attrs["NetworkSettings"]["Networks"].items(),
Expand Down
19 changes: 16 additions & 3 deletions src/Kathara/manager/docker/stats/DockerMachineStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ def __init__(self, machine_api_object: Container):
self.container_name: str = machine_api_object.name
self.user: Optional[str] = machine_api_object.labels['user']
self.image: str = machine_api_object.image.tags[0]
self.interfaces: str = ",".join(sorted(
[f"{v['DriverOpts']['kathara.iface']}:{v['DriverOpts']['kathara.link']}" for n, v in
machine_api_object.attrs['NetworkSettings']['Networks'].items()]))
# Dynamic Information
self.status: Optional[str] = None
self.pids: Optional[int] = None
self.interfaces: str = "-"
self.cpu_usage: str = "-"
self.mem_usage: str = "- / -"
self.mem_percent: str = "-"
Expand All @@ -65,6 +63,21 @@ def update(self) -> None:

self.status = self.machine_api_object.status
self.pids = updated_stats['pids_stats']['current'] if 'current' in updated_stats['pids_stats'] else 0

if self.name == "pc2":
print(self.machine_api_object.attrs['NetworkSettings'])

networks = self.machine_api_object.attrs['NetworkSettings']['Networks']
if 'none' in networks:
networks.pop('none')
if 'bridge' in networks:
networks.pop('bridge')
if networks:
self.interfaces = ", ".join(sorted(
[f"{v['DriverOpts']['kathara.iface']}:{v['DriverOpts']['kathara.link']}" for n, v in networks.items()]))
else:
self.interfaces = "-"

if "system_cpu_usage" in updated_stats["cpu_stats"]:
cpu_usage = updated_stats["cpu_stats"]["cpu_usage"]["total_usage"] / \
updated_stats["cpu_stats"]["system_cpu_usage"]
Expand Down

0 comments on commit f72bbc1

Please sign in to comment.