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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AkihiroSuda
Copy link
Member

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 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 3 times, most recently from 037643a to 5b71e30 Compare July 3, 2025 08:06
Fix issue 3672

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
@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...

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