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

show ports in table after deployment / inspect #1430

Merged
merged 9 commits into from Jun 23, 2023

Conversation

steiler
Copy link
Collaborator

@steiler steiler commented Jun 14, 2023

INFO[0000] Parsing & checking topology file: linux.clab.yml 
+---+-----------------+--------------+---------------+-------+---------+----------------+----------------------+--------------------------+
| # |      Name       | Container ID |     Image     | Kind  |  State  |  IPv4 Address  |     IPv6 Address     |          Ports           |
+---+-----------------+--------------+---------------+-------+---------+----------------+----------------------+--------------------------+
| 1 | clab-linux01-l1 | d7ddd9653556 | alpine:latest | linux | running | 172.20.20.3/24 | 2001:172:20:20::3/64 | 0.0.0.0:6010/tcp -> 8080 |
|    |                 |              |               |       |         |                |                      | :::6010/tcp -> 8080      |
| 2 | clab-linux01-l2 | 013154efda2b | alpine:latest | linux | running | 172.20.20.2/24 | 2001:172:20:20::2/64 | 0.0.0.0:6009/tcp -> 8080 |
|    |                 |              |               |       |         |                |                      | :::6009/tcp -> 8080      |
+---+-----------------+--------------+---------------+-------+---------+----------------+----------------------+--------------------------+

What is not sooo nice is, that the table gets wider and you therefore have to have a wider screen to not have any line breaks within a row.

another option might be to also introduce a port command as docker has, to figure out the ports in a seperate output.

This cmd lists port bindings:

❯ docker ps --format "table {{.Names}}\t{{.Ports}}" 
NAMES           PORTS
clab-ports-l1   0.0.0.0:32778->80/tcp, :::32778->80/tcp
clab-srl-srl

@hellt
Copy link
Member

hellt commented Jun 16, 2023

@steiler yeah, I agree having a long table is not great.
Maybe we just put it in the docs that users could use docker ports command? Or indeed clab ports list

@steiler
Copy link
Collaborator Author

steiler commented Jun 19, 2023

Alright, so the port-bindings field in now part of the auto.tmpl. Hence will be outputted as part of the topology-data.json.
Further did I remove the port field in the output table again.

@steiler
Copy link
Collaborator Author

steiler commented Jun 19, 2023

So we have the below now.
I'm not sure if this is maybe already sufficient or if we need another ports list command that prints tables.

sudo ./containerlab -t /home/mava/projects/containerlab/lab-examples/linux.clab.yml inspect -f json --details
INFO[0000] Parsing & checking topology file: linux.clab.yml
[
  {
    "Names": [
      "clab-linux01-l1"
    ],
    "ID": "5fd2631796d82a4caf220a14577eb4a1ed4244ca53d7ea27857ea56f4cdb0c6e",
    "ShortID": "5fd2631796d8",
    "Image": "alpine:latest",
    "State": "running",
    "Status": "Up About a minute",
    "Labels": {
      "clab-mgmt-net-bridge": "br-6fd285acdfec",
      "clab-node-group": "",
      "clab-node-kind": "linux",
      "clab-node-lab-dir": "/home/mava/projects/containerlab/clab-linux01/l1",
      "clab-node-name": "l1",
      "clab-node-type": "",
      "clab-topo-file": "/home/mava/projects/containerlab/lab-examples/linux.clab.yml",
      "containerlab": "linux01"
    },
    "Pid": 0,
    "NetworkSettings": {
      "IPv4addr": "172.20.20.2",
      "IPv4pLen": 24,
      "IPv4Gw": "172.20.20.1",
      "IPv6addr": "2001:172:20:20::2",
      "IPv6pLen": 64,
      "IPv6Gw": "2001:172:20:20::1"
    },
    "Mounts": [
      {
        "Source": "",
        "Destination": ""
      }
    ],
    "Ports": [
      {
        "host_ip": "0.0.0.0",
        "host_port": 6089,
        "port": 8080,
        "protocol": "tcp"
      },
      {
        "host_ip": "::",
        "host_port": 6089,
        "port": 8080,
        "protocol": "tcp"
      },
      {
        "host_ip": "0.0.0.0",
        "host_port": 6088,
        "port": 8081,
        "protocol": "tcp"
      },
      {
        "host_ip": "::",
        "host_port": 6088,
        "port": 8081,
        "protocol": "tcp"
      },
      {
        "host_ip": "0.0.0.0",
        "host_port": 6087,
        "port": 8082,
        "protocol": "tcp"
      },
      {
        "host_ip": "::",
        "host_port": 6087,
        "port": 8082,
        "protocol": "tcp"
      }
    ]
  },
  {
    "Names": [
      "clab-linux01-l2"
    ],
    "ID": "d06fd4ca34fcd966f249d951aefe936f3fdacc346f3bc6a88d9f8584efd72dbf",
    "ShortID": "d06fd4ca34fc",
    "Image": "alpine:latest",
    "State": "running",
    "Status": "Up About a minute",
    "Labels": {
      "clab-mgmt-net-bridge": "br-6fd285acdfec",
      "clab-node-group": "",
      "clab-node-kind": "linux",
      "clab-node-lab-dir": "/home/mava/projects/containerlab/clab-linux01/l2",
      "clab-node-name": "l2",
      "clab-node-type": "",
      "clab-topo-file": "/home/mava/projects/containerlab/lab-examples/linux.clab.yml",
      "containerlab": "linux01"
    },
    "Pid": 0,
    "NetworkSettings": {
      "IPv4addr": "172.20.20.3",
      "IPv4pLen": 24,
      "IPv4Gw": "172.20.20.1",
      "IPv6addr": "2001:172:20:20::3",
      "IPv6pLen": 64,
      "IPv6Gw": "2001:172:20:20::1"
    },
    "Mounts": [
      {
        "Source": "",
        "Destination": ""
      }
    ],
    "Ports": [
      {
        "host_ip": "0.0.0.0",
        "host_port": 6090,
        "port": 8080,
        "protocol": "tcp"
      },
      {
        "host_ip": "::",
        "host_port": 6090,
        "port": 8080,
        "protocol": "tcp"
      }
    ]
  }
]

@steiler steiler marked this pull request as ready for review June 21, 2023 06:54
types/types.go Outdated
@@ -129,7 +129,7 @@ type NodeConfig struct {
// Bind mounts strings (src:dest:options).
Binds []string `json:"binds,omitempty"`
// PortBindings define the bindings between the container ports and host ports
PortBindings nat.PortMap `json:"portbindings,omitempty"`
PortBindings nat.PortMap `json:"-"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this removed for testing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you removed it because portbindings is now substituted by port-bindings which is calculated based on runtime state?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the latter was my thinking. The assumption is, that you're interested in the actual running state, which is a concret port per mapping and the possible range is pretty much of no interest...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clab/export.go Outdated
Comment on lines 73 to 76
gc, err := n.GetContainers(ctx)
if err != nil {
return err
}
Copy link
Member

@hellt hellt Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steiler works nicely, this piece is the only thing that I am hesitant about.
Doing an API Get for all nodes just to fetch port bindings is not optimal:

  1. not all nodes have port bindings defined.
    ADD1: unless we do not call the Get API when no port bindings are defined.
  2. and even if they have them, maybe we can just update the binding information once we created the node? I wonder if we already receive the port binding info as a result of a container create?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you've now made it part of NodeConfig, we should be able to get this info earlier on as part of the deployment, yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remembered, that we had a function designed just for this

see 9e5952e

@codecov
Copy link

codecov bot commented Jun 23, 2023

Codecov Report

Merging #1430 (1e5fd39) into main (922259d) will decrease coverage by 0.07%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #1430      +/-   ##
==========================================
- Coverage   20.58%   20.51%   -0.07%     
==========================================
  Files          58       58              
  Lines        6558     6579      +21     
==========================================
  Hits         1350     1350              
- Misses       5085     5106      +21     
  Partials      123      123              
Impacted Files Coverage Δ
clab/export.go 0.00% <0.00%> (ø)
cmd/deploy.go 6.83% <0.00%> (ø)
runtime/docker/docker.go 0.14% <0.00%> (-0.01%) ⬇️
types/types.go 0.00% <0.00%> (ø)

@hellt
Copy link
Member

hellt commented Jun 23, 2023

Thanks @steiler
This looks good now. Let's ship it

@hellt hellt merged commit be5aeac into srl-labs:main Jun 23, 2023
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants