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:
Magnus Skjegstad 2017-05-15 18:07:51 +02:00
parent 11bd203a91
commit f0e7e41424
2 changed files with 21 additions and 0 deletions

View File

@ -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)")
ipStr := flags.String("ip", "", "IP address for the VM")
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 {
log.Fatal("Unable to parse args")
@ -100,6 +101,10 @@ func runHyperKit(args []string) {
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.Initrd = prefix + "-initrd.img"
h.VPNKitKey = vpnKitKey

View File

@ -3,6 +3,7 @@ package main
import (
"os"
"strconv"
"strings"
)
func getStringValue(envKey string, flagVal string, defaultVal string) string {
@ -81,3 +82,18 @@ func getBoolValue(envKey string, flagVal bool) bool {
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
}