From d3e683d3a123c2eb2e2e2884a8c8a0f7e5b89206 Mon Sep 17 00:00:00 2001
From: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Date: Wed, 16 Oct 2024 02:19:51 +0900
Subject: [PATCH] templates: remove `vz`, `vmnet`, etc. in favor of the limactl
 CLI args

- `experimental/vz`: Merged into the default template in Lima v1.0.
  See also <https://lima-vm.io/docs/config/vmtype/>.
- `vmnet`: Removed in Lima v1.0.
  Use `limactl create --network=lima:shared template://default` instead.
  See also <https://lima-vm.io/docs/config/network/>.
- `experimental/net-user-v2`: Removed in Lima v1.0.
  Use `limactl create --network=lima:user-v2 template://default` instead.
  See also <https://lima-vm.io/docs/config/network/>.
- `experimental/9p`: Removed in Lima v1.0.
  Use `limactl create --vm-type=qemu --mount-type=9p template://default` instead.
  See also <https://lima-vm.io/docs/config/mount/>.
- `experimental/virtiofs-linux`: Removed in Lima v1.0.
  Use `limactl create --mount-type=virtiofs template://default` instead.
  See also <https://lima-vm.io/docs/config/mount/>.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
---
 .github/workflows/test.yml                | 17 ++++++-----
 cmd/limactl/start.go                      | 10 ++++++
 examples/README.md                        | 10 +++---
 examples/experimental/9p.yaml             | 37 -----------------------
 examples/experimental/net-user-v2.yaml    | 17 -----------
 examples/experimental/virtiofs-linux.yaml | 26 ----------------
 examples/experimental/vz.yaml             | 35 ---------------------
 examples/vmnet.yaml                       | 36 ----------------------
 hack/common.inc.sh                        |  2 ++
 hack/test-templates.sh                    | 25 ++++++++++-----
 hack/test-templates/test-misc.yaml        |  4 +++
 11 files changed, 47 insertions(+), 172 deletions(-)
 delete mode 100644 examples/experimental/9p.yaml
 delete mode 100644 examples/experimental/net-user-v2.yaml
 delete mode 100644 examples/experimental/virtiofs-linux.yaml
 delete mode 100644 examples/experimental/vz.yaml
 delete mode 100644 examples/vmnet.yaml

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 8f7b2e0ac0db..bcea97f72349 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -217,18 +217,17 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
+        # Most templates use 9p as the mount type
         template:
         - alpine.yaml
-        - debian.yaml
+        - debian.yaml  # reverse-sshfs
         - fedora.yaml
         # cloud-init 24.3.1-1 package has a regression: https://github.com/lima-vm/lima/issues/2714
         # - archlinux.yaml
         - opensuse.yaml
-        - experimental/net-user-v2.yaml
-        - experimental/9p.yaml
         - docker.yaml
         - ../hack/test-templates/alpine-iso-9p-writable.yaml  # Covers alpine-iso.yaml
-        - ../hack/test-templates/test-misc.yaml
+        - ../hack/test-templates/test-misc.yaml  # net-user-v2
     steps:
     - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871  # v4.2.1
       with:
@@ -345,13 +344,15 @@ jobs:
       run: make
     - name: Install
       run: make install
+    - name: "Adjust LIMACTL_CREATE_ARGS"
+      run: echo "LIMACTL_CREATE_ARGS=${LIMACTL_CREATE_ARGS} --network=lima:shared" >>$GITHUB_ENV
     - name: "Inject `no_timer_check` to kernel cmdline"
       # workaround to https://github.com/lima-vm/lima/issues/84
-      run: ./hack/inject-cmdline-to-template.sh templates/vmnet.yaml no_timer_check
-    - name: Cache image used by vmnet.yaml
+      run: ./hack/inject-cmdline-to-template.sh templates/default.yaml no_timer_check
+    - name: Cache image used by default .yaml
       uses: ./.github/actions/setup_cache_for_template
       with:
-        template: templates/vmnet.yaml
+        template: templates/default.yaml
     - name: Install test dependencies
       run: brew install qemu bash coreutils iperf3
     - name: Install socket_vmnet
@@ -376,7 +377,7 @@ jobs:
         timeout_minutes: 30
         retry_on: error
         max_attempts: 3
-        command: ./hack/test-templates.sh templates/vmnet.yaml
+        command: ./hack/test-templates.sh templates/default.yaml
     - if: always()
       uses: ./.github/actions/upload_failure_logs_if_exists
 
diff --git a/cmd/limactl/start.go b/cmd/limactl/start.go
index e7311d5ab700..3825bc5e683e 100644
--- a/cmd/limactl/start.go
+++ b/cmd/limactl/start.go
@@ -132,10 +132,20 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (*
 		templateName := filepath.Join(templateURL.Host, templateURL.Path)
 		logrus.Debugf("interpreting argument %q as a template name %q", arg, templateName)
 		switch templateName {
+		case "experimental/vz":
+			logrus.Warn("template://experimental/vz was merged into the default template in Lima v1.0. See also <https://lima-vm.io/docs/config/vmtype/>.")
 		case "experimental/riscv64":
 			logrus.Warn("template://experimental/riscv64 was merged into the default template in Lima v1.0. Use `limactl create --arch=riscv64 template://default` instead.")
 		case "experimental/armv7l":
 			logrus.Warn("template://experimental/armv7l was merged into the default template in Lima v1.0. Use `limactl create --arch=armv7l template://default` instead.")
+		case "vmnet":
+			logrus.Warn("template://vmnet was removed in Lima v1.0. Use `limactl create --network=lima:shared template://default` instead. See also <https://lima-vm.io/docs/config/network/>.")
+		case "experimental/net-user-v2":
+			logrus.Warn("template://experimental/net-user-v2 was removed in Lima v1.0. Use `limactl create --network=lima:user-v2 template://default` instead. See also <https://lima-vm.io/docs/config/network/>.")
+		case "experimental/9p":
+			logrus.Warn("template://experimental/9p was removed in Lima v1.0. Use `limactl create --vm-type=qemu --mount-type=9p template://default` instead. See also <https://lima-vm.io/docs/config/mount/>.")
+		case "experimental/virtiofs-linux":
+			logrus.Warn("template://experimental/virtiofs-linux was removed in Lima v1.0. Use `limactl create --mount-type=virtiofs template://default` instead. See also <https://lima-vm.io/docs/config/mount/>.")
 		}
 		if st.instName == "" {
 			// e.g., templateName = "deprecated/centos-7" , st.instName = "centos-7"
diff --git a/examples/README.md b/examples/README.md
index 9632b0831c12..fecb3b126f92 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -49,11 +49,6 @@ Container orchestration:
 - [`experimental/u7s`](./experimental/u7s.yaml): [Usernetes](https://github.com/rootless-containers/usernetes): Rootless Kubernetes
 
 Optional feature enablers:
-- [`vmnet`](./vmnet.yaml): ⭐enable [`vmnet.framework`](../docs/network.md)
-- [`experimental/9p`](./experimental/9p.yaml): [experimental] use 9p mount type
-- [`experimental/virtiofs-linux`](./experimental/9p.yaml): [experimental] use virtiofs mount type for Linux
-- [`experimental/net-user-v2`](./experimental/net-user-v2.yaml): [experimental] user-v2 network
-  to enable VM-to-VM communication without root privilege
 - [`experimental/vnc`](./experimental/vnc.yaml): [experimental] use vnc display and xorg server
 - [`experimental/alsa`](./experimental/alsa.yaml): [experimental] use alsa and default audio device
 
@@ -68,8 +63,13 @@ Lost+found:
 - ~`nomad`~: Removed in Lima v0.17.1, as Nomad is [no longer free software](https://github.com/hashicorp/nomad/commit/b3e30b1dfa185d9437a25830522da47b91f78816)
 - ~`centos-stream-8`~: Remove in Lima v0.23.0, as CentOS Stream 8 reached [EOL](https://blog.centos.org/2023/04/end-dates-are-coming-for-centos-stream-8-and-centos-linux-7/).
 - ~`deprecated/centos-7`~: Remove in Lima v0.23.0, as CentOS 7 reached [EOL](https://blog.centos.org/2023/04/end-dates-are-coming-for-centos-stream-8-and-centos-linux-7/).
+- ~`experimental/vz`~: Merged into the default template in Lima v1.0. See also <https://lima-vm.io/docs/config/vmtype/>.
 - ~`experimental/armv7l`~: Merged into the `default` template in Lima v1.0. Use `limactl create --arch=armv7l template://default`.
 - ~`experimental/riscv64`~: Merged into the `default` template in Lima v1.0. Use `limactl create --arch=riscv64 template://default`.
+- ~`vmnet`~: Removed in Lima v1.0. Use `limactl create --network=lima:shared template://default` instead. See also <https://lima-vm.io/docs/config/network/>.
+- ~`experimental/net-user-v2`~: Removed in Lima v1.0. Use `limactl create --network=lima:user-v2 template://default` instead. See also <https://lima-vm.io/docs/config/network/>.
+- ~`experimental/9p`~: Removed in Lima v1.0. Use `limactl create --vm-type=qemu --mount-type=9p template://default` instead. See also <https://lima-vm.io/docs/config/mount/>.
+- ~`experimental/virtiofs-linux`~: Removed in Lima v1.0. Use `limactl create --mount-type=virtiofs-linux template://default` instead. See also <https://lima-vm.io/docs/config/mount/>.
 
 ## Tier
 
diff --git a/examples/experimental/9p.yaml b/examples/experimental/9p.yaml
deleted file mode 100644
index bb10abe5745f..000000000000
--- a/examples/experimental/9p.yaml
+++ /dev/null
@@ -1,37 +0,0 @@
-# ⚠️ ⚠️ ⚠️ `template://experimental/9p` will be removed in Lima v1.0,
-# as 9p will graduate from experimental and will be the default mount type for QEMU.
-#
-# For Lima v1.0 and later, use the following command instead:
-# ```
-# limactl create --vm-type=qemu template://default
-# ```
-
-# This template requires Lima v0.10.0 or later.
-# On macOS hosts, QEMU needs to be v7.0.0 or later. Homebrew's QEMU v6.2.0_1 can be used too.
-# This template is planned to be merged to default.yaml in Lima v1.0 (ETA: 2022 Q2).
-images:
-# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-amd64.img"
-  arch: "x86_64"
-  digest: "sha256:0e25ca6ee9f08ec5d4f9910054b66ae7163c6152e81a3e67689d89bd6e4dfa69"
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-arm64.img"
-  arch: "aarch64"
-  digest: "sha256:5ecac6447be66a164626744a87a27fd4e6c6606dc683e0a233870af63df4276a"
-# Fallback to the latest release image.
-# Hint: run `limactl prune` to invalidate the cache
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
-  arch: "x86_64"
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img"
-  arch: "aarch64"
-
-mounts:
-- location: "~"
-  9p:
-    # Try choosing "mmap" or "none" if you see a stability issue with the default "fscache".
-    cache: "fscache"
-- location: "/tmp/lima"
-  writable: true
-  9p:
-    cache: "mmap"
-
-mountType: "9p"
diff --git a/examples/experimental/net-user-v2.yaml b/examples/experimental/net-user-v2.yaml
deleted file mode 100644
index 3c1682e2d5cf..000000000000
--- a/examples/experimental/net-user-v2.yaml
+++ /dev/null
@@ -1,17 +0,0 @@
-# A template to run lima instance with experimental user-v2 network enabled
-# This template requires Lima v0.16.0 or later.
-images:
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
-  arch: "x86_64"
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img"
-  arch: "aarch64"
-
-hostResolver:
-  hosts:
-    host.docker.internal: host.lima.internal
-mounts:
-- location: "~"
-- location: "/tmp/lima"
-  writable: true
-networks:
-- lima: user-v2
diff --git a/examples/experimental/virtiofs-linux.yaml b/examples/experimental/virtiofs-linux.yaml
deleted file mode 100644
index 51afc2e5420a..000000000000
--- a/examples/experimental/virtiofs-linux.yaml
+++ /dev/null
@@ -1,26 +0,0 @@
-# This template requires Lima v0.17.0 or later, running on Linux with:
-# - QEMU v4.2.0 or later.
-# - virtiofsd's Rust implementation: https://gitlab.com/virtio-fs/virtiofsd
-#   The QEMU version (qemu-virtiofsd) will *not* work, as it requires root access
-#   for all operations.
-images:
-# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-amd64.img"
-  arch: "x86_64"
-  digest: "sha256:0e25ca6ee9f08ec5d4f9910054b66ae7163c6152e81a3e67689d89bd6e4dfa69"
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-arm64.img"
-  arch: "aarch64"
-  digest: "sha256:5ecac6447be66a164626744a87a27fd4e6c6606dc683e0a233870af63df4276a"
-# Fallback to the latest release image.
-# Hint: run `limactl prune` to invalidate the cache
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
-  arch: "x86_64"
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img"
-  arch: "aarch64"
-
-mounts:
-- location: "~"
-- location: "/tmp/lima"
-  writable: true
-
-mountType: "virtiofs"
diff --git a/examples/experimental/vz.yaml b/examples/experimental/vz.yaml
deleted file mode 100644
index 8620a8d19dbd..000000000000
--- a/examples/experimental/vz.yaml
+++ /dev/null
@@ -1,35 +0,0 @@
-# ⚠️ ⚠️ ⚠️ `template://experimental/vz` will be removed in Lima v1.0,
-# as vz will graduate from experimental and will be the default vmType.
-#
-# For Lima v1.0 and later, use the following command instead:
-# ```
-# limactl create template://default
-# ```
-
-# A template to run ubuntu using vmType: vz instead of qemu (Default)
-# This template requires Lima v0.14.0 or later and macOS 13.
-vmType: "vz"
-rosetta:
-  # Enable Rosetta for Linux.
-  # Hint: try `softwareupdate --install-rosetta` if Lima gets stuck at `Installing rosetta...`
-  enabled: true
-  # Register rosetta to /proc/sys/fs/binfmt_misc
-  binfmt: true
-
-# Note: On Intel Mac, macOS >= 13.5 is required to boot kernel v6.2 (used by Ubuntu 23.04, Fedora 38, etc.) with vz.
-# https://github.com/lima-vm/lima/issues/1577
-images:
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
-  arch: "x86_64"
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img"
-  arch: "aarch64"
-
-mounts:
-- location: "~"
-- location: "/tmp/lima"
-  writable: true
-mountType: "virtiofs"
-
-networks:
-# The "vzNAT" IP address is accessible from the host, but not from other guests.
-- vzNAT: true
diff --git a/examples/vmnet.yaml b/examples/vmnet.yaml
deleted file mode 100644
index cd92752fe6a0..000000000000
--- a/examples/vmnet.yaml
+++ /dev/null
@@ -1,36 +0,0 @@
-# A template to enable vmnet.framework.
-
-# Install socket_vmnet: https://lima-vm.io/docs/config/network/#socket_vmnet
-
-# This template requires Lima v0.7.0 or later.
-# Older versions of Lima were using a different syntax for supporting vmnet.framework.
-images:
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-amd64.img"
-  arch: "x86_64"
-  digest: "sha256:0e25ca6ee9f08ec5d4f9910054b66ae7163c6152e81a3e67689d89bd6e4dfa69"
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-arm64.img"
-  arch: "aarch64"
-  digest: "sha256:5ecac6447be66a164626744a87a27fd4e6c6606dc683e0a233870af63df4276a"
-# Fallback to the latest release image.
-# Hint: run `limactl prune` to invalidate the cache
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
-  arch: "x86_64"
-- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img"
-  arch: "aarch64"
-
-mounts:
-- location: "~"
-- location: "/tmp/lima"
-  writable: true
-networks:
-# The instance can get routable IP addresses from the vmnet framework using
-# https://github.com/lima-vm/socket_vmnet (since Lima v0.12).
-#
-# Available networks are defined in
-# $LIMA_HOME/_config/networks.yaml. Supported network types are "host",
-# "shared", or "bridged".
-#
-# Interface "lima0": shared mode  (IP is assigned by macOS's bootpd)
-- lima: shared
-# Interface "lima1": bridged mode (IP is assigned by a DHCP server on the physical network)
-# - lima: bridged
diff --git a/hack/common.inc.sh b/hack/common.inc.sh
index f8aee55949d0..9cfdf9e52a00 100644
--- a/hack/common.inc.sh
+++ b/hack/common.inc.sh
@@ -22,3 +22,5 @@ if [[ ${BASH_VERSINFO:-0} -lt 4 ]]; then
 	ERROR "Bash version is too old: ${BASH_VERSION}"
 	exit 1
 fi
+
+: "${LIMA_HOME:=$HOME/.lima}"
diff --git a/hack/test-templates.sh b/hack/test-templates.sh
index 3e3aa25b0cac..37455a2a1f9e 100755
--- a/hack/test-templates.sh
+++ b/hack/test-templates.sh
@@ -56,9 +56,6 @@ case "$NAME" in
 	# ● run-r2b459797f5b04262bfa79984077a65c7.service                                       loaded failed failed    /usr/bin/systemctl start man-db-cache-update
 	CHECKS["systemd-strict"]=
 	;;
-"vmnet")
-	CHECKS["vmnet"]=1
-	;;
 "test-misc")
 	CHECKS["disk"]=1
 	CHECKS["snapshot-online"]="1"
@@ -67,10 +64,6 @@ case "$NAME" in
 	CHECKS["provision-ansible"]="1"
 	CHECKS["param-env-variables"]="1"
 	;;
-"net-user-v2")
-	CHECKS["port-forwards"]=""
-	CHECKS["user-v2"]=1
-	;;
 "docker")
 	CONTAINER_ENGINE="docker"
 	;;
@@ -81,6 +74,22 @@ if limactl ls -q | grep -q "$NAME"; then
 	exit 1
 fi
 
+# Create ${NAME}-tmp to inspect the enabled features.
+# TODO: skip downloading and converting the image here.
+# Probably `limactl create` should have "dry run" mode that just generates `lima.yaml`.
+# shellcheck disable=SC2086
+"${LIMACTL_CREATE[@]}" ${LIMACTL_CREATE_ARGS} --set ".additionalDisks=null" --name="${NAME}-tmp" "$FILE"
+case "$(yq '.networks[].lima' "${LIMA_HOME}/${NAME}-tmp/lima.yaml")" in
+"shared")
+	CHECKS["vmnet"]=1
+	;;
+"user-v2")
+	CHECKS["port-forwards"]=""
+	CHECKS["user-v2"]=1
+	;;
+esac
+limactl rm -f "${NAME}-tmp"
+
 if [[ -n ${CHECKS["port-forwards"]} ]]; then
 	tmpconfig="$HOME/lima-config-tmp"
 	mkdir -p "${tmpconfig}"
@@ -381,7 +390,7 @@ fi
 if [[ -n ${CHECKS["user-v2"]} ]]; then
 	INFO "Testing user-v2 network"
 	secondvm="$NAME-1"
-	"${LIMACTL_CREATE[@]}" "$FILE" --name "$secondvm"
+	"${LIMACTL_CREATE[@]}" --set ".additionalDisks=null" "$FILE" --name "$secondvm"
 	if ! limactl start "$secondvm"; then
 		ERROR "Failed to start \"$secondvm\""
 		diagnose "$secondvm"
diff --git a/hack/test-templates/test-misc.yaml b/hack/test-templates/test-misc.yaml
index 6284c4acc679..9b227b499e10 100644
--- a/hack/test-templates/test-misc.yaml
+++ b/hack/test-templates/test-misc.yaml
@@ -1,6 +1,7 @@
 # The test template for testing misc configurations:
 # - disk
 # - snapshots
+# - user-v2 network
 # - (More to come)
 #
 # This template requires Lima v1.0.0-alpha.0 or later.
@@ -58,3 +59,6 @@ probes:
 # $ limactl disk create data --size 10G
 additionalDisks:
 - "data"
+
+networks:
+- lima: user-v2