Skip to content
Draft
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
38 changes: 38 additions & 0 deletions docs/extool/netlab-ui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(extool-netlab-ui)=
# netlab-ui

[netlab-ui](https://github.com/Muddyblack/netlab-ui) is a web-based topology editor and lab manager for _netlab_.
It displays the lab topology, lets you edit nodes, links, and module parameters, starts and stops the lab, and opens shells and log streams to lab devices in the browser. Just like the containerlab-app does but with direct support for netlab logic.

Add the following lines to a lab topology file to start netlab-ui together with the lab:

```
tools:
netlab_ui:
```

The URL of the web interface is printed during the **netlab up** process. You can also display it with the **netlab connect netlab_ui** command.

## Parameters

You can change these tool parameters in the lab topology or in [user defaults](tools-enable-default) (**defaults.tools.netlab_ui**):

* **host** -- the IP address the web server listens on. The default (`127.0.0.1`) accepts connections only from the lab server; use an SSH tunnel (for example, `ssh -L 8000:localhost:8000 labserver`) to reach it from your workstation, or set it to `0.0.0.0` together with **auth**.
* **port** -- the TCP port of the web interface (default: `8000`). The [multilab plugin](plugin-multilab) ID is added to the port number, so you can use netlab-ui with several lab instances on the same server.
* **auth** -- `user:password`. When set, the web interface, its API, and device terminals require HTTP basic authentication.
* **image** -- the container image (default: `ghcr.io/muddyblack/netlab-ui:latest`). The image contains only the UI; it runs the _netlab_, Ansible, and _containerlab_ installed on the lab server, as the user who owns `~/.netlab`.

For example, to make netlab-ui reachable from other hosts:

```
tools:
netlab_ui:
host: 0.0.0.0
auth: admin:changeme
```

## Notes

* netlab-ui manages the lab in the directory in which you executed **netlab up**. The container runs with the same privileges as _containerlab_ (privileged mode, host network, and host PID namespace) and has access to the Docker socket, the lab directory, and the `~/.netlab` directory in which _netlab_ tracks running labs.
* The container is removed when you shut down the lab with **netlab down**. When you stop or restart the lab from the netlab-ui web interface, the tool keeps running.
* netlab-ui also runs without a lab topology. Install it as a Python package with `pipx install netlab-ui` (from [PyPI](https://pypi.org/project/netlab-ui/)) and start it with `netlab-ui`, or run the container with `docker compose`. See the [netlab-ui quick start](https://github.com/Muddyblack/netlab-ui#quick-start) for details.
1 change: 1 addition & 0 deletions docs/extools.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ _netlab_ includes definitions for the following tools:
extool/nso.md
extool/nuts.md
extool/network_xray.md
extool/netlab-ui.md
```

It's relatively easy to add your own tools to the **defaults.tools** dictionary. Read [](dev/extools.md) for more details.
39 changes: 39 additions & 0 deletions netsim/tools/netlab_ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# netlab-ui: web-based topology editor and lab manager for netlab
# https://github.com/Muddyblack/netlab-ui
#
# The container is the UI only. It runs the netlab, Ansible and containerlab installed on this
# host by entering the host namespaces (nsenter), so it needs the same access containerlab has
# (privileged, host network and PID namespace), the Docker socket, the lab directory mounted at
# the same path (containerlab bind-mounts node files by path through the host Docker daemon),
# and ~/.netlab (the lab registry) so 'netlab status' on the host and the UI see the same labs.
#
# Without a lab topology, install it with 'pipx install netlab-ui' instead.
#
---
runtime: docker
image: ghcr.io/muddyblack/netlab-ui:latest
host: 127.0.0.1 # Listen on loopback; set to 0.0.0.0 (with 'auth') to reach it remotely
port: 8000 # Plus the multilab ID when using the multilab plugin
auth: '' # 'user:password' enables HTTP Basic authentication
docker:
up:
docker inspect '{name}_netlab_ui' >/dev/null 2>&1 ||
docker run -d
--name '{name}_netlab_ui'
--restart unless-stopped
--privileged --network host --pid host
-v /var/run/docker.sock:/var/run/docker.sock
-v /var/run/netns:/var/run/netns
-v "$(pwd):$(pwd)" -e NETLAB_WORKSPACE="$(pwd)"
-v "$HOME/.netlab:/root/.netlab"
-e NETLAB_UI_CONTAINER='{name}_netlab_ui'
-e UVICORN_HOST='{tools.netlab_ui.host or defaults.tools.netlab_ui.host}'
-e UVICORN_PORT={(tools.netlab_ui.port or defaults.tools.netlab_ui.port) + (defaults.multilab.id or 0)}
-e NETLAB_UI_AUTH='{tools.netlab_ui.auth or defaults.tools.netlab_ui.auth}'
'{tools.netlab_ui.image or defaults.tools.netlab_ui.image}'
message: >-
Open http://{sys.ipurl}:{(tools.netlab_ui.port or defaults.tools.netlab_ui.port) + (defaults.multilab.id or 0)}
in your browser (on a remote server, use an SSH tunnel unless netlab_ui.host is set)
down:
test -n "$NETLAB_UI_RUN" || docker rm -f '{name}_netlab_ui' >/dev/null
2 changes: 2 additions & 0 deletions tests/topology/expected/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ provider: libvirt
tools:
graphite:
runtime: docker
netlab_ui:
runtime: docker
suzieq:
runtime: docker
1 change: 1 addition & 0 deletions tests/topology/input/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ nodes:
tools:
graphite:
suzieq:
netlab_ui:
Loading