Skip to content

Implement limactl network (list|create|delete) #3677

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

Merged
merged 1 commit into from
Jul 8, 2025

Conversation

AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Jul 3, 2025

Fix #3672

e.g.,

$ limactl network create foo --gateway 192.168.42.1/24

$ limactl network list
NAME       MODE       GATEWAY             INTERFACE
bridged    bridged    -                   en0
foo        user-v2    192.168.42.1/24     -
host       host       192.168.106.1/24    -
shared     shared     192.168.105.1/24    -
user-v2    user-v2    192.168.104.1/24    -

$ limactl network list --json foo bridged
{"mode":"user-v2","gateway":"192.168.42.1","netmask":"255.255.255.0"}
{"mode":"bridged","interface":"en0"}

$ limactl network delete --force foo

@AkihiroSuda AkihiroSuda added this to the v1.1.2 milestone Jul 3, 2025
@AkihiroSuda AkihiroSuda added area/cli limactl CLI user experience component/network/user-v2 labels Jul 3, 2025
@AkihiroSuda AkihiroSuda changed the title Implement 'limactl network (list|create|delete)' Implement limactl network (list|create|delete) Jul 3, 2025
@AkihiroSuda AkihiroSuda force-pushed the limactl-network branch 4 times, most recently from 5b71e30 to fba510b Compare July 3, 2025 08:20
@nirs
Copy link
Member

nirs commented Jul 4, 2025

$ limactl network list --json foo bridged
{"mode":"user-v2","gateway":"192.168.42.1","netmask":"255.255.255.0"}
{"mode":"bridged","interface":"en0"}

This is not json format, this is jsonlines format:
https://jsonlines.org

Trying to parse this string:

{"mode":"user-v2","gateway":"192.168.42.1","netmask":"255.255.255.0"}
{"mode":"bridged","interface":"en0"}

will not work with most json parsers.

The fact that Go json encoded and decoder supports this format does not make it json.

To make this valid json we need to return a list:

[
  {"mode":"user-v2","gateway":"192.168.42.1","netmask":"255.255.255.0"},
  {"mode":"bridged","interface":"en0"}
]

jsonlines format makes sense for logs when you want to stream the data.

$ limactl network delete foo

How the case of deleting a network in use is handled? For example deleting the shared network when instances are running using it. I think rejecting the request is the simplest way to avoid issues.

If we have command to create/list/delete networks, maybe support also start/stop and simplify socket_vmnet network management?

@AkihiroSuda
Copy link
Member Author

jsonlines

Intentionally adopted for consistency with limactl ls and limactl disk ls

in use

Not handled yet

@nirs
Copy link
Member

nirs commented Jul 4, 2025

jsonlines

Intentionally adopted for consistency with limactl ls and limactl disk ls

Makes sense.

Using --json is ok if we document in the help message that we return jsonlines format.
This is easy to handle by reading lines and parsing them separately.

@jandubois
Copy link
Member

jsonlines format makes sense for logs when you want to stream the data.

It also makes sense for anything that is processed with a pipeline. It makes your jq commands simpler because you don't need to start with .[]. And you can always wrap the objects in an array with jq -s, but I find I virtually never need that.

FWIW, docker images --format json also uses jsonlines format...

@AkihiroSuda AkihiroSuda requested review from jandubois and nirs July 8, 2025 00:32
jandubois
jandubois previously approved these changes Jul 8, 2025
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

I kind of expected to also have a limactl network edit command, but that can be added later.

Fix issue 3672

Signed-off-by: Akihiro Suda <[email protected]>
if !force {
return errors.New("`limactl network delete` currently always requires `--force`")
// Because the command currently does not check whether the network being removed is in use
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the PR to always require --force for now

@AkihiroSuda AkihiroSuda requested a review from jandubois July 8, 2025 06:12
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@jandubois jandubois merged commit c62e4c3 into lima-vm:master Jul 8, 2025
36 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jul 27, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [lima-vm/lima](https://github.com/lima-vm/lima) | minor | `v1.1.1` -> `v1.2.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>lima-vm/lima (lima-vm/lima)</summary>

### [`v1.2.1`](https://github.com/lima-vm/lima/releases/tag/v1.2.1)

[Compare Source](lima-vm/lima@v1.2.0...v1.2.1)

#### Changes

- Cherry-picks from `master` to `release/1.2` ([#&#8203;3750](lima-vm/lima#3750))
  - portfwd: create separate gRPC streams for each UDP client ([#&#8203;3724](lima-vm/lima#3724), thanks to [@&#8203;stek29](https://github.com/stek29))
  - qemuimgutil: fix "Failed to get "write" lock" error ([#&#8203;3742](lima-vm/lima#3742), thanks to [@&#8203;pavelanni](https://github.com/pavelanni))
  - Embed templates edited from the user interface ([#&#8203;3745](lima-vm/lima#3745), thanks to [@&#8203;afbjorklund](https://github.com/afbjorklund))

#### Usage

```console
$ limactl create
$ limactl start
...
INFO[0029] READY. Run `lima` to open the shell.

$ lima uname
Linux
```

***

The binaries were built automatically on GitHub Actions.
The build log is available for 90 days: https://github.com/lima-vm/lima/actions/runs/16405168554

The sha256sum of the SHA256SUMS file itself is `fda636e062d8f75a689071b308a94dc902111620f7122746fc0d172959d7d26a` .

***

Release manager: [@&#8203;AkihiroSuda](https://github.com/AkihiroSuda)

### [`v1.2.0`](https://github.com/lima-vm/lima/releases/tag/v1.2.0)

[Compare Source](lima-vm/lima@v1.1.1...v1.2.0)

#### Changes

- `limactl` CLI:
  - Add `limactl network (list|create|delete)` commands ([#&#8203;3677](lima-vm/lima#3677))
  - Add `limactl clone OLDINST NEWINST` command. Not to be confused with `limactl copy`, which copies files. ([#&#8203;3673](lima-vm/lima#3673))
  - Add `limactl edit --mount-none` flag ([#&#8203;3647](lima-vm/lima#3647))
- Port forwarding:
  - Improve stability ([#&#8203;3684](lima-vm/lima#3684). [#&#8203;3708](lima-vm/lima#3708), thanks to [@&#8203;balajiv113](https://github.com/balajiv113))
  - De-deprecate `LIMA_SSH_PORT_FORWARDER` that was once deprecated in v1.1 ([#&#8203;3709](lima-vm/lima#3709))
- nerdctl:
  - Update from v2.1.2 to [v2.1.3](https://github.com/containerd/nerdctl/releases/tag/v2.1.3) ([#&#8203;3701](lima-vm/lima#3701))
- Templates:
  - `default`: update from Ubuntu 24.10 to 25.04 ([#&#8203;3643](lima-vm/lima#3643))
  - `fedora`: update from Fedora 41 to 42 ([#&#8203;3643](lima-vm/lima#3643))
  - `almalinux-10`: new template ([#&#8203;3602](lima-vm/lima#3602), thanks to [@&#8203;refi64](https://github.com/refi64))
  - `rocky-10`: new template ([#&#8203;3642](lima-vm/lima#3642))
  - `experimental/debian-testing`: new template ([#&#8203;3645](lima-vm/lima#3645))
  - `experimental/ubuntu-next`: new template ([#&#8203;3645](lima-vm/lima#3645))
- Makefile:
  - Kconfig: deprecate ([#&#8203;3706](lima-vm/lima#3706))

> \[!NOTE]
> On Intel Mac, macOS 15.5 or later is needed to boot the default Ubuntu 25.04 template.
>
> Workarounds for macOS <= 15.4 :
>
> - Option 1: Use QEMU
>
> ```
> limactl create --vm-type=qemu
> ```
>
> - Option2: Use Ubuntu 24.04 template
>
> ```
> limactl create --name=default template://ubuntu-24.04
> ```

Full changes: https://github.com/lima-vm/lima/milestone/61?closed=1

Thanks to
[@&#8203;AkinoKaede](https://github.com/AkinoKaede) [@&#8203;Horiodino](https://github.com/Horiodino) [@&#8203;afbjorklund](https://github.com/afbjorklund) [@&#8203;alexandear](https://github.com/alexandear) [@&#8203;arixmkii](https://github.com/arixmkii) [@&#8203;balajiv113](https://github.com/balajiv113) [@&#8203;fruzitent](https://github.com/fruzitent) [@&#8203;jandubois](https://github.com/jandubois) [@&#8203;kachick](https://github.com/kachick) [@&#8203;mazzz1y](https://github.com/mazzz1y) [@&#8203;nirs](https://github.com/nirs) [@&#8203;refi64](https://github.com/refi64) [@&#8203;songponssw](https://github.com/songponssw) [@&#8203;thomasjm](https://github.com/thomasjm) [@&#8203;unsuman](https://github.com/unsuman)

#### Usage

```console
$ limactl create
$ limactl start
...
INFO[0029] READY. Run `lima` to open the shell.

$ lima uname
Linux
```

***

The binaries were built automatically on GitHub Actions.
The build log is available for 90 days: https://github.com/lima-vm/lima/actions/runs/16187325385

The sha256sum of the SHA256SUMS file itself is `f4d57cdd637022ead291af680c0c88a8d07fd35fd6a779b7c6348e2c9a2ec2cc` .

***

Release manager: [@&#8203;AkihiroSuda](https://github.com/AkihiroSuda)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC42Mi4xIiwidXBkYXRlZEluVmVyIjoiNDAuNjIuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli limactl CLI user experience component/network/user-v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

limactl network CLI for manipulating ~/.lima/_config/networks.yaml
3 participants