|
| 1 | +# Containerlab VS Code Extension |
| 2 | + |
| 3 | +The lab-as-code approach taken by Containerlab means labs are "written" in YAML in a text editor or IDE. It also means you have to manage your labs via the command-line. |
| 4 | + |
| 5 | +[VS Code](https://code.visualstudio.com/download) is a powerful text editor used by many for this purpose, and with the YAML schema provided by Containerlab the topology writing experience is made even easier. |
| 6 | + |
| 7 | +We decided to further improve the experience with VS Code with a Containerlab [VS Code extension](https://marketplace.visualstudio.com/items?itemName=srl-labs.vscode-containerlab). |
| 8 | + |
| 9 | +The Containerlab VS Code extension aims to greatly simplify and improve the labbing workflow, allowing you to perform essential lab operations within VS Code. |
| 10 | + |
| 11 | +If you prefer to sit back and watch a video about this extension, say no more! |
| 12 | + |
| 13 | +-{{youtube(url='https://www.youtube.com/embed/NIw1PbfCyQ4')}}- |
| 14 | + |
| 15 | +/// admonition | Support |
| 16 | +If you have any questions about this extension, please join us in the [Containerlab Discord](https://discord.gg/vAyddtaEV9). |
| 17 | +/// |
| 18 | + |
| 19 | +## Features |
| 20 | + |
| 21 | +The Containerlab extension packs a lot of features hidden under the icons or context menus. Here is a list of the main features, and we are always looking for new feature requests: |
| 22 | + |
| 23 | +### Explorer |
| 24 | + |
| 25 | +In the activity bar of VS Code, you will notice a Containerlab icon. Clicking on this icon will open the explorer. |
| 26 | + |
| 27 | +The explorer is similar to the VS Code file explorer but instead of finding files, it discovers Containerlab topologies, running labs, containers and their interfaces. |
| 28 | + |
| 29 | +The explorer will discover all labs in your local directory (and subdirectories), as well as any running labs on the system. |
| 30 | + |
| 31 | +The explorer is a Treeview and for running labs, you can expand the labs to see running containers and you can expand running containers to see their interfaces. |
| 32 | + |
| 33 | +### Editor |
| 34 | + |
| 35 | +In the editor title actions when a Containerlab topology is open, there is a 'run' action and a 'graph' button. |
| 36 | + |
| 37 | +This allows easy deployment and graphing of the lab from within the editor context. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +#### Command palette |
| 42 | + |
| 43 | +When you have a topology open and active in the editor you can execute common actions from the command palette that you can open up with `CTRL+SHIFT+P`/`CMD+SHIFT+P`. |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +#### Keybindings |
| 48 | + |
| 49 | +We have also set some default keybindings you can use to interact with the lab when you are editing a topology. |
| 50 | + |
| 51 | +| Keys | Action | |
| 52 | +| ------------ | -------- | |
| 53 | +| `CTRL+ALT+D` | Deploy | |
| 54 | +| `CTRL+ALT+R` | Redeploy | |
| 55 | +| `CTRL+ALT+K` | Destroy | |
| 56 | +| `CTRL+ALT+G` | Graph | |
| 57 | + |
| 58 | +### TopoViewer |
| 59 | + |
| 60 | +Integrated into the extension as a 'graph' action is the [TopoViewer](https://github.com/asadarafat/topoViewer) project by @asadarafat. |
| 61 | + |
| 62 | +TopoViewer is an interactive way to visualize your containerlab topologies. The topology must be running for the TopoViewer to be able to visualize it. |
| 63 | + |
| 64 | +### Packet capture |
| 65 | + |
| 66 | +In the explorer you can expand running labs and containers to view all the discovered interfaces for that container. You can either right click on the interface and start a packet capture or click the shark icon on the interface label. |
| 67 | + |
| 68 | +Packet capture relies on the [Edgeshark integration](wireshark.md#edgeshark-integration). Install Edgeshark first, and then use the context menu or the fin icon next to the interface name. |
| 69 | + |
| 70 | +## Settings reference |
| 71 | + |
| 72 | +Below is a reference to the available settings that can be modified in the Containerlab VS Code extension. |
| 73 | + |
| 74 | +### `containerlab.defaultSshUser` |
| 75 | + |
| 76 | +The default username used to connect to a node via SSH. |
| 77 | + |
| 78 | +| Type | Default | |
| 79 | +| -------- | ------- | |
| 80 | +| `string` | `admin` | |
| 81 | + |
| 82 | +### `containerlab.sudoEnabledByDefault` |
| 83 | + |
| 84 | +Whether or not to append `sudo` to any commands executed by the extension. |
| 85 | + |
| 86 | +| Type | Default | |
| 87 | +| --------- | ------- | |
| 88 | +| `boolean` | `true` | |
| 89 | + |
| 90 | +### `containerlab.refreshInterval` |
| 91 | + |
| 92 | +The time interval (in milliseconds) for which the extension automatically refreshes. |
| 93 | + |
| 94 | +On each refresh the extension will discover all local and running labs, as well as containers and interfaces of containers belonging to running labs. |
| 95 | + |
| 96 | +By default this is 10 seconds. |
| 97 | + |
| 98 | +| Type | Default | |
| 99 | +| -------- | ------- | |
| 100 | +| `number` | `10000` | |
| 101 | + |
| 102 | +### `containerlab.node.execCommandMapping` |
| 103 | + |
| 104 | +The a mapping between the node kind and command executed on the 'node attach' action. |
| 105 | + |
| 106 | +The 'node attach' action performs the `docker exec -it <node> <command>` command. The `execCommandMapping` allows you to change the command executed by default on a per-kind basis. |
| 107 | + |
| 108 | +By default this setting is empty, it should be used to override the [default mappings](https://github.com/srl-labs/vscode-containerlab/blob/main/resources/exec_cmd.json). |
| 109 | + |
| 110 | +| Type | Default | |
| 111 | +| -------- | ----------- | |
| 112 | +| `object` | `undefined` | |
| 113 | + |
| 114 | +#### Example |
| 115 | + |
| 116 | +```json |
| 117 | +{ |
| 118 | + "nokia_srl": "sr_cli", |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +In the settings UI, simply set the 'Item' field to the kind and the 'Value' field to `nokia_srl` and the command to `sr_cli`. |
0 commit comments