mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 11:00:25 +00:00
linuxrun: add -vsock-ports option to HyperKit
When `-vsock-ports` is specified, the listed guest vsock ports will be made available through unix domain sockets in the state directory. Signed-off-by: Magnus Skjegstad <magnus@skjegstad.com>
This commit is contained in:
parent
11bd203a91
commit
f0e7e41424
@ -32,6 +32,7 @@ func runHyperKit(args []string) {
|
|||||||
data := flags.String("data", "", "Metadata to pass to VM (either a path to a file or a string)")
|
data := flags.String("data", "", "Metadata to pass to VM (either a path to a file or a string)")
|
||||||
ipStr := flags.String("ip", "", "IP address for the VM")
|
ipStr := flags.String("ip", "", "IP address for the VM")
|
||||||
state := flags.String("state", "", "Path to directory to keep VM state in")
|
state := flags.String("state", "", "Path to directory to keep VM state in")
|
||||||
|
vsockports := flags.String("vsock-ports", "", "List of vsock ports to forward from the guest on startup (comma separated). A unix domain socket for each port will be created in the state directory")
|
||||||
|
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
log.Fatal("Unable to parse args")
|
log.Fatal("Unable to parse args")
|
||||||
@ -100,6 +101,10 @@ func runHyperKit(args []string) {
|
|||||||
log.Fatalln("Error creating hyperkit: ", err)
|
log.Fatalln("Error creating hyperkit: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if h.VSockPorts, err = stringToIntArray(*vsockports, ","); err != nil {
|
||||||
|
log.Fatalln("Unable to parse vsock-ports: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
h.Kernel = prefix + "-kernel"
|
h.Kernel = prefix + "-kernel"
|
||||||
h.Initrd = prefix + "-initrd.img"
|
h.Initrd = prefix + "-initrd.img"
|
||||||
h.VPNKitKey = vpnKitKey
|
h.VPNKitKey = vpnKitKey
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getStringValue(envKey string, flagVal string, defaultVal string) string {
|
func getStringValue(envKey string, flagVal string, defaultVal string) string {
|
||||||
@ -81,3 +82,18 @@ func getBoolValue(envKey string, flagVal bool) bool {
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stringToIntArray(l string, sep string) ([]int, error) {
|
||||||
|
var err error
|
||||||
|
if l == "" {
|
||||||
|
return []int{}, err
|
||||||
|
}
|
||||||
|
s := strings.Split(l, sep)
|
||||||
|
i := make([]int, len(s))
|
||||||
|
for idx := range s {
|
||||||
|
if i[idx], err = strconv.Atoi(s[idx]); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user