Merge pull request #88 from cerc-io/dboreham/fix-ps-command

Fix ps display for containers with no mapped ports
This commit is contained in:
David Boreham 2023-01-04 10:39:49 -07:00 committed by GitHub
commit fdb04d46b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -92,9 +92,15 @@ def command(ctx, include, exclude, cluster, command, services):
for container in container_list: for container in container_list:
print(f"id: {container.id}, name: {container.name}, ports: ", end="") print(f"id: {container.id}, name: {container.name}, ports: ", end="")
ports = container.network_settings.ports ports = container.network_settings.ports
comma = ""
for port_mapping in ports.keys(): for port_mapping in ports.keys():
print(f"{ports[port_mapping][0]['HostIp']}:{ports[port_mapping][0]['HostPort']}->{port_mapping}", end=",") mapping = ports[port_mapping]
# TODO: fix the extra comma print(comma, end="")
if mapping is None:
print(f"{port_mapping}", end="")
else:
print(f"{mapping[0]['HostIp']}:{mapping[0]['HostPort']}->{port_mapping}", end="")
comma = ", "
print() print()
else: else:
print("No containers running") print("No containers running")