-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Balaji Vijayakumar <[email protected]>
- Loading branch information
1 parent
f0282b2
commit 00a3f9d
Showing
25 changed files
with
976 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/lima-vm/lima/pkg/networks/usernet" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newUsernetCommand() *cobra.Command { | ||
var hostagentCommand = &cobra.Command{ | ||
Use: "usernet", | ||
Short: "run usernet", | ||
Args: cobra.ExactArgs(0), | ||
RunE: usernetAction, | ||
Hidden: true, | ||
} | ||
hostagentCommand.Flags().StringP("pidfile", "p", "", "write pid to file") | ||
hostagentCommand.Flags().StringP("endpoint", "e", "", "exposes usernet api(s) on this endpoint") | ||
hostagentCommand.Flags().String("listen-qemu", "", "listen for qemu connections") | ||
hostagentCommand.Flags().String("listen", "", "listen on a Unix socket and receive Bess-compatible FDs as SCM_RIGHTS messages") | ||
hostagentCommand.Flags().Int("mtu", 1500, "mtu") | ||
return hostagentCommand | ||
} | ||
|
||
func usernetAction(cmd *cobra.Command, args []string) error { | ||
pidfile, err := cmd.Flags().GetString("pidfile") | ||
if err != nil { | ||
return err | ||
} | ||
if pidfile != "" { | ||
if _, err := os.Stat(pidfile); !errors.Is(err, os.ErrNotExist) { | ||
return fmt.Errorf("pidfile %q already exists", pidfile) | ||
} | ||
if err := os.WriteFile(pidfile, []byte(strconv.Itoa(os.Getpid())+"\n"), 0644); err != nil { | ||
return err | ||
} | ||
defer os.RemoveAll(pidfile) | ||
} | ||
endpoint, err := cmd.Flags().GetString("endpoint") | ||
if err != nil { | ||
return err | ||
} | ||
qemuSocket, err := cmd.Flags().GetString("listen-qemu") | ||
if err != nil { | ||
return err | ||
} | ||
fdSocket, err := cmd.Flags().GetString("listen") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mtu, err := cmd.Flags().GetInt("mtu") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
os.RemoveAll(endpoint) | ||
os.RemoveAll(qemuSocket) | ||
os.RemoveAll(fdSocket) | ||
|
||
return usernet.StartGVisorNetstack(cmd.Context(), &usernet.GVisorNetstackOpts{ | ||
MTU: mtu, | ||
Endpoint: endpoint, | ||
QemuSocket: qemuSocket, | ||
FdSocket: fdSocket, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Example to run vz instance with experimental user-v2 network enabled | ||
vmType: "vz" | ||
images: | ||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img" | ||
arch: "x86_64" | ||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img" | ||
arch: "aarch64" | ||
|
||
mounts: | ||
- location: "~" | ||
- location: "/tmp/lima" | ||
writable: true | ||
mountType: "virtiofs" | ||
networks: | ||
- lima: user-v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.