From af2ee9e023fa971b4f367a1fd11f9d0b32b7ba16 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 1 Mar 2017 16:09:30 -0800 Subject: [PATCH 1/4] infrakit: Use template based instance configuratio This change now allows setting the Disk size, memory, and number of CPUs for an instance via the JSON config file. We now also write the hyperkit command line to the VM directory. Signed-off-by: Rolf Neugebauer --- tools/infrakit.hyperkit/cmd/instance.go | 118 ++++++++++-------- tools/infrakit.hyperkit/cmd/main.go | 19 ++- tools/infrakit.hyperkit/hyperkit.json | 4 +- tools/infrakit.hyperkit/vendor.conf | 4 +- .../golang.org/x/sys/unix/syscall_linux.go | 1 + .../x/sys/unix/zerrors_linux_386.go | 2 + .../x/sys/unix/zerrors_linux_amd64.go | 2 + .../x/sys/unix/zerrors_linux_arm.go | 2 + .../x/sys/unix/zerrors_linux_arm64.go | 2 + .../x/sys/unix/zerrors_linux_mips.go | 2 + .../x/sys/unix/zerrors_linux_mips64.go | 2 + .../x/sys/unix/zerrors_linux_mips64le.go | 2 + .../x/sys/unix/zerrors_linux_mipsle.go | 2 + .../x/sys/unix/zerrors_linux_ppc64.go | 2 + .../x/sys/unix/zerrors_linux_ppc64le.go | 2 + .../x/sys/unix/zerrors_linux_s390x.go | 2 + .../x/sys/unix/zerrors_linux_sparc64.go | 2 + .../x/sys/unix/zsyscall_linux_386.go | 17 +++ .../x/sys/unix/zsyscall_linux_amd64.go | 17 +++ .../x/sys/unix/zsyscall_linux_arm.go | 17 +++ .../x/sys/unix/zsyscall_linux_arm64.go | 17 +++ .../x/sys/unix/zsyscall_linux_mips.go | 17 +++ .../x/sys/unix/zsyscall_linux_mips64.go | 17 +++ .../x/sys/unix/zsyscall_linux_mips64le.go | 17 +++ .../x/sys/unix/zsyscall_linux_mipsle.go | 17 +++ .../x/sys/unix/zsyscall_linux_ppc64.go | 17 +++ .../x/sys/unix/zsyscall_linux_ppc64le.go | 17 +++ .../x/sys/unix/zsyscall_linux_s390x.go | 17 +++ .../x/sys/unix/zsyscall_linux_sparc64.go | 21 +++- 29 files changed, 316 insertions(+), 62 deletions(-) diff --git a/tools/infrakit.hyperkit/cmd/instance.go b/tools/infrakit.hyperkit/cmd/instance.go index 5bcdb3d7a..b9b2062b3 100644 --- a/tools/infrakit.hyperkit/cmd/instance.go +++ b/tools/infrakit.hyperkit/cmd/instance.go @@ -10,18 +10,25 @@ import ( "os/exec" "path" "strconv" + "strings" log "github.com/Sirupsen/logrus" + "github.com/docker/infrakit/pkg/spi/instance" + "github.com/docker/infrakit/pkg/template" "github.com/docker/infrakit/pkg/types" ) // NewHyperKitPlugin creates an instance plugin for hyperkit. -func NewHyperKitPlugin(vmLib, vmDir, hyperkit, vpnkitSock string) instance.Plugin { +func NewHyperKitPlugin(vmLib, vmDir, hyperkit, vpnkitSock string, thyper, tkern *template.Template) instance.Plugin { return &hyperkitPlugin{VMLib: vmLib, VMDir: vmDir, HyperKit: hyperkit, - VPNKitSock: vpnkitSock} + VPNKitSock: vpnkitSock, + + HyperKitTmpl: thyper, + KernelTmpl: tkern, + } } type hyperkitPlugin struct { @@ -37,6 +44,9 @@ type hyperkitPlugin struct { // VPNKitSock is the path to the VPNKit Unix domain socket. VPNKitSock string + + HyperKitTmpl *template.Template + KernelTmpl *template.Template } const ( @@ -62,41 +72,31 @@ func (v hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) { if properties["Moby"] == nil { return nil, errors.New("Property 'Moby' must be set") } - mobyStr, ok := properties["Moby"].(string) - if !ok { - return nil, errors.New("Property 'Moby' must be a string") - } if properties["CPUs"] == nil { properties["CPUs"] = 1 } - numCPUs, ok := properties["CPUs"].(int) - if !ok { - return nil, errors.New("Property 'CPUs' must be a integer") - } if properties["Memory"] == nil { properties["Memory"] = 512 } - memSz, ok := properties["Memory"].(int) - if !ok { - return nil, errors.New("Property 'Memory' must be a integer") - } - if properties["Disk"] == nil { - properties["Disk"] = 256 - } - diskSz, ok := properties["Disk"].(int) - if !ok { - return nil, errors.New("Property 'Disk' must be a integer") + properties["Disk"] = float64(256) } instanceDir, err := ioutil.TempDir(v.VMDir, "infrakit-") if err != nil { return nil, err } - id := instance.ID(path.Base(instanceDir)) - err = v.execHyperKit(instanceDir, mobyStr, numCPUs, memSz, diskSz) + // Apply parameters + params := map[string]interface{}{ + "VMLocation": instanceDir, + "VMLib": v.VMLib, + "VPNKitSock": v.VPNKitSock, + "Properties": properties, + } + + err = v.execHyperKit(params) if err != nil { v.Destroy(id) return nil, err @@ -243,42 +243,49 @@ func (v hyperkitPlugin) DescribeInstances(tags map[string]string) ([]instance.De return descriptions, nil } -func (v hyperkitPlugin) execHyperKit(instanceDir, moby string, cpus, memSz, diskSz int) error { - err := createDisk(instanceDir, diskSz) +const hyperkitArgs = "-A -u -F {{.VMLocation}}/hyperkit.pid " + + "-c {{.Properties.CPUs}} -m {{.Properties.Memory}}M " + + "-s 0:0,hostbridge -s 31,lpc -s 5,virtio-rnd " + + "-s 4,virtio-blk,{{.VMLocation}}/disk.img " + + "-s 2:0,virtio-vpnkit,path={{.VPNKitSock}} " + + "-l com1,autopty={{.VMLocation}}/tty,log={{.VMLocation}}/console-ring" +const hyperkitKernArgs = "kexec," + + "{{.VMLib}}/{{.Properties.Moby}}/vmlinuz64," + + "{{.VMLib}}/{{.Properties.Moby}}/initrd.img," + + "earlyprintk=serial console=ttyS0 panic=1 vsyscall=emulate page_poison=1 ntp=gateway" + +func (v hyperkitPlugin) execHyperKit(params map[string]interface{}) error { + + instanceDir := params["VMLocation"].(string) + + args, err := v.HyperKitTmpl.Render(params) + if err != nil { + return err + } + kernArgs, err := v.KernelTmpl.Render(params) if err != nil { return err } - id := path.Base(instanceDir) + // Build arguments + c := []string{v.HyperKit} + c = append(c, strings.Split(args, " ")...) + c = append(c, "-f", kernArgs) - c := []string{v.HyperKit, "-A", "-u"} + // Write command line to state + if err := ioutil.WriteFile(path.Join(instanceDir, "cmdline"), []byte(strings.Join(c, " ")), 0666); err != nil { + return err + } - // Pid file - c = append(c, "-F", path.Join(instanceDir, hyperkitPid)) - - // CPU and Memory - c = append(c, "-c", fmt.Sprintf("%d", cpus)) - c = append(c, "-m", fmt.Sprintf("%dM", memSz)) - - // Devices - c = append(c, "-s", "0:0,hostbridge") - c = append(c, "-s", "31,lpc") - c = append(c, "-s", "5,virtio-rnd") - c = append(c, "-s", fmt.Sprintf("4,virtio-blk,%s", path.Join(instanceDir, "disk.img"))) - c = append(c, "-s", fmt.Sprintf("2:0,virtio-vpnkit,path=%s", v.VPNKitSock)) - c = append(c, "-l", fmt.Sprintf("com1,autopty=%s,log=%s", - path.Join(instanceDir, "tty"), - path.Join(instanceDir, "console-ring"))) - - // Kernel command line - // Note, it is important that the kernel is one argv, not multiple - kernStr := fmt.Sprintf("kexec,%s,%s,", - path.Join(v.VMLib, moby, "vmlinuz64"), - path.Join(v.VMLib, moby, "initrd.img")) - kernStr += "earlyprintk=serial console=ttyS0" - kernStr += " panic=1 vsyscall=emulate page_poison=1" - kernStr += " ntp=gateway " - c = append(c, "-f", kernStr) + prop := params["Properties"].(map[string]interface{}) + sz, ok := prop["Disk"].(float64) + if !ok { + return fmt.Errorf("Unable to extract Disk Size: %s", prop["Disk"]) + } + err = createDisk(instanceDir, int(sz)) + if err != nil { + return err + } cmd := exec.Command(c[0], c[1:]...) cmd.Env = os.Environ() @@ -304,18 +311,19 @@ func (v hyperkitPlugin) execHyperKit(instanceDir, moby string, cpus, memSz, disk for { select { case stderrl := <-stderrChan: - log.Warningln("HyperKit ", id, " STDERR: ", stderrl) + log.Warningln("HyperKit STDERR: ", stderrl) case stdoutl := <-stdoutChan: - log.Infoln("HyperKit ", id, " STDOUT: ", stdoutl) + log.Infoln("HyperKit STDOUT: ", stdoutl) case <-done: return } } }() - log.Infoln("Starting ", id, ": ", c) + log.Infoln("Starting: ", c) err = cmd.Start() + return err } diff --git a/tools/infrakit.hyperkit/cmd/main.go b/tools/infrakit.hyperkit/cmd/main.go index 6bd827b9c..4dd4edc55 100644 --- a/tools/infrakit.hyperkit/cmd/main.go +++ b/tools/infrakit.hyperkit/cmd/main.go @@ -7,12 +7,15 @@ import ( "path" log "github.com/Sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/docker/infrakit/pkg/cli" + "github.com/docker/infrakit/pkg/discovery" "github.com/docker/infrakit/pkg/plugin/metadata" instance_plugin "github.com/docker/infrakit/pkg/rpc/instance" metadata_plugin "github.com/docker/infrakit/pkg/rpc/metadata" instance_spi "github.com/docker/infrakit/pkg/spi/instance" - "github.com/spf13/cobra" + "github.com/docker/infrakit/pkg/template" ) const ( @@ -56,9 +59,21 @@ func main() { vpnkitSock := cmd.Flags().String("vpnkit-sock", defaultVPNKitSock, "Path to VPNKit UNIX domain socket") cmd.RunE = func(c *cobra.Command, args []string) error { + opts := template.Options{ + SocketDir: discovery.Dir(), + } + thyper, err := template.NewTemplate("str://"+hyperkitArgs, opts) + if err != nil { + return err + } + tkern, err := template.NewTemplate("str://"+hyperkitKernArgs, opts) + if err != nil { + return err + } + cli.SetLogLevel(*logLevel) cli.RunPlugin(*name, - instance_plugin.PluginServer(NewHyperKitPlugin(*vmLib, *vmDir, *hyperkit, *vpnkitSock)), + instance_plugin.PluginServer(NewHyperKitPlugin(*vmLib, *vmDir, *hyperkit, *vpnkitSock, thyper, tkern)), metadata_plugin.PluginServer(metadata.NewPluginFromData( map[string]interface{}{ "version": Version, diff --git a/tools/infrakit.hyperkit/hyperkit.json b/tools/infrakit.hyperkit/hyperkit.json index e7fc95f6f..4782e76a9 100644 --- a/tools/infrakit.hyperkit/hyperkit.json +++ b/tools/infrakit.hyperkit/hyperkit.json @@ -8,7 +8,9 @@ "Plugin": "instance-hyperkit", "Properties": { "Moby": "default", - "Note": "Instance properties version 1.0" + "Disk" : 512, + "CPUs" : 2, + "Memory" : 1024 } }, "Flavor": { diff --git a/tools/infrakit.hyperkit/vendor.conf b/tools/infrakit.hyperkit/vendor.conf index 04365c456..c2b7fc9d8 100644 --- a/tools/infrakit.hyperkit/vendor.conf +++ b/tools/infrakit.hyperkit/vendor.conf @@ -1,7 +1,7 @@ github.com/Masterminds/sprig 2d2df7bd8bda53b5a55ed04422173cedd50500ea github.com/Sirupsen/logrus 0208149b40d863d2c1a2f8fe5753096a9cf2cc8b github.com/aokoli/goutils 9c37978a95bd5c709a15883b6242714ea6709e64 -github.com/docker/infrakit 594813c1dc9b1b617cd8d1527c51390c76c0feaa +github.com/docker/infrakit ecc0561f7bd44e832ce7dc07222b913082aeff6e github.com/gorilla/context 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 github.com/gorilla/mux 599cba5e7b6137d46ddf58fb1765f5d928e69604 github.com/gorilla/rpc 22c016f3df3febe0c1f6727598b6389507e03a18 @@ -11,5 +11,5 @@ github.com/satori/go.uuid b061729afc07e77a8aa4fad0a2fd840958f1942a github.com/spf13/cobra fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c github.com/spf13/pflag 9ff6c6923cfffbcd502984b8e0c80539a94968b7 golang.org/x/crypto 453249f01cfeb54c3d549ddb75ff152ca243f9d8 -golang.org/x/sys 21f2569f6feb83b68a25c98c1b20eca5d4e1e6ae +golang.org/x/sys 76cc09b634294339fa19ec41b5f2a0b3932cea8b gopkg.in/tylerb/graceful.v1 4654dfbb6ad53cb5e27f37d99b02e16c1872fbbb diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/syscall_linux.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/syscall_linux.go index 326be811c..c01194742 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/syscall_linux.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/syscall_linux.go @@ -1038,6 +1038,7 @@ func Getpgrp() (pid int) { //sysnb Getpid() (pid int) //sysnb Getppid() (ppid int) //sys Getpriority(which int, who int) (prio int, err error) +//sys Getrandom(buf []byte, flags int) (n int, err error) //sysnb Getrusage(who int, rusage *Rusage) (err error) //sysnb Getsid(pid int) (sid int, err error) //sysnb Gettid() (tid int) diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_386.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_386.go index c13799fa5..297b0b47f 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_386.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_386.go @@ -437,6 +437,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 IBSHIFT = 0x10 ICANON = 0x2 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go index 1937e466f..908df5bb5 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go @@ -437,6 +437,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 IBSHIFT = 0x10 ICANON = 0x2 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go index d64a12921..4ce3deef1 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go @@ -422,6 +422,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 IBSHIFT = 0x10 ICANON = 0x2 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go index c0acbb561..10e97ed26 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go @@ -451,6 +451,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 IBSHIFT = 0x10 ICANON = 0x2 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go index 6eece7e2f..a3c826120 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go @@ -427,6 +427,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 IBSHIFT = 0x10 ICANON = 0x2 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go index a11dbb37d..1fdb64137 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go @@ -426,6 +426,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 ICANON = 0x2 ICMPV6_FILTER = 0x1 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go index 9058318c4..3341d4d14 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go @@ -426,6 +426,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 ICANON = 0x2 ICMPV6_FILTER = 0x1 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go index 974b375f9..f363c0417 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go @@ -466,6 +466,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 IBSHIFT = 0x10 ICANON = 0x2 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go index 58b13c0a0..1101fd6cc 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go @@ -456,6 +456,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x4000 IBSHIFT = 0x10 ICANON = 0x100 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go index 91c3ccca8..c3e701569 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go @@ -449,6 +449,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x4000 IBSHIFT = 0x10 ICANON = 0x100 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go index 702894a89..75d2d8487 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go @@ -462,6 +462,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x2 F_WRLCK = 0x1 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 IBSHIFT = 0x10 ICANON = 0x2 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go index 4c56e2ffa..679008f44 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go @@ -470,6 +470,8 @@ const ( F_ULOCK = 0x0 F_UNLCK = 0x3 F_WRLCK = 0x2 + GRND_NONBLOCK = 0x1 + GRND_RANDOM = 0x2 HUPCL = 0x400 IBSHIFT = 0x10 ICANON = 0x2 diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go index a01725b8e..d4ec806db 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go index 1c1b25e67..8b2e87dfc 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go index 2359fd715..82d36a411 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go index c3dbcad4b..f6cc3200d 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go index 3fd164a9d..f91afb481 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go index a26cad413..657d11eff 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go index 7cc92ad48..31ff1774c 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go index 79f26e5b2..797e6336e 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go index 27befca49..307dbb5bd 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go index 0dc288e23..f458a63ad 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go index 33c086b5e..b1d5a9bc3 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { diff --git a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go index 071b85c93..ce3ec585b 100644 --- a/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +++ b/tools/infrakit.hyperkit/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go @@ -1,7 +1,7 @@ -// mksyscall.pl syscall_linux.go syscall_linux_sparc64.go +// mksyscall.pl -tags linux,sparc64 syscall_linux.go syscall_linux_sparc64.go // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT -// +build +// +build linux,sparc64 package unix @@ -543,6 +543,23 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrandom(buf []byte, flags int) (n int, err error) { + var _p0 unsafe.Pointer + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { From 95fa38f879b0ab6bf6b6fc7bf80b775ec2c39f6e Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 1 Mar 2017 16:52:37 -0800 Subject: [PATCH 2/4] infrakit: removed vm-lib from arguments Instead pass the directory where to find initrd/vmlinuz via the "Moby" entry in the instance JSON config. Signed-off-by: Rolf Neugebauer --- tools/infrakit.hyperkit/README.md | 4 ---- tools/infrakit.hyperkit/cmd/instance.go | 14 ++++---------- tools/infrakit.hyperkit/cmd/main.go | 3 +-- tools/infrakit.hyperkit/hyperkit.json | 2 +- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/tools/infrakit.hyperkit/README.md b/tools/infrakit.hyperkit/README.md index 47fa3fbc0..7f677905f 100644 --- a/tools/infrakit.hyperkit/README.md +++ b/tools/infrakit.hyperkit/README.md @@ -9,10 +9,6 @@ each instance keeps some state in a sub-directory. The VM state directory can be specified at the kernel command line using the `--vm-dir` option. -The plugin also needs to know where the kernel and `initrd` images are -located. The `--vm-lib` command line argument to the plugin specifies -the directory. Inside the VM library directory every kernel/initrd configuration should be stored in a sub-directory. The sub-directory name is used in the instance configuration. - ## Building ```sh diff --git a/tools/infrakit.hyperkit/cmd/instance.go b/tools/infrakit.hyperkit/cmd/instance.go index b9b2062b3..019cce87a 100644 --- a/tools/infrakit.hyperkit/cmd/instance.go +++ b/tools/infrakit.hyperkit/cmd/instance.go @@ -20,9 +20,8 @@ import ( ) // NewHyperKitPlugin creates an instance plugin for hyperkit. -func NewHyperKitPlugin(vmLib, vmDir, hyperkit, vpnkitSock string, thyper, tkern *template.Template) instance.Plugin { - return &hyperkitPlugin{VMLib: vmLib, - VMDir: vmDir, +func NewHyperKitPlugin(vmDir, hyperkit, vpnkitSock string, thyper, tkern *template.Template) instance.Plugin { + return &hyperkitPlugin{VMDir: vmDir, HyperKit: hyperkit, VPNKitSock: vpnkitSock, @@ -32,10 +31,6 @@ func NewHyperKitPlugin(vmLib, vmDir, hyperkit, vpnkitSock string, thyper, tkern } type hyperkitPlugin struct { - // VMLib is the path to a directory where each sub-directory - // contains a vmlinuz and a initrd image - VMLib string - // VMDir is the path to a directory where per VM state is kept VMDir string @@ -91,7 +86,6 @@ func (v hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) { // Apply parameters params := map[string]interface{}{ "VMLocation": instanceDir, - "VMLib": v.VMLib, "VPNKitSock": v.VPNKitSock, "Properties": properties, } @@ -250,8 +244,8 @@ const hyperkitArgs = "-A -u -F {{.VMLocation}}/hyperkit.pid " + "-s 2:0,virtio-vpnkit,path={{.VPNKitSock}} " + "-l com1,autopty={{.VMLocation}}/tty,log={{.VMLocation}}/console-ring" const hyperkitKernArgs = "kexec," + - "{{.VMLib}}/{{.Properties.Moby}}/vmlinuz64," + - "{{.VMLib}}/{{.Properties.Moby}}/initrd.img," + + "{{.Properties.Moby}}/vmlinuz64," + + "{{.Properties.Moby}}/initrd.img," + "earlyprintk=serial console=ttyS0 panic=1 vsyscall=emulate page_poison=1 ntp=gateway" func (v hyperkitPlugin) execHyperKit(params map[string]interface{}) error { diff --git a/tools/infrakit.hyperkit/cmd/main.go b/tools/infrakit.hyperkit/cmd/main.go index 4dd4edc55..1099897e9 100644 --- a/tools/infrakit.hyperkit/cmd/main.go +++ b/tools/infrakit.hyperkit/cmd/main.go @@ -52,7 +52,6 @@ func main() { name := cmd.Flags().String("name", "instance-hyperkit", "Plugin name to advertise for discovery") logLevel := cmd.Flags().Int("log", cli.DefaultLogLevel, "Logging level. 0 is least verbose. Max is 5") - vmLib := cmd.Flags().String("vm-lib", "", "Directory with subdirectories of kernels/initrds combinations") vmDir := cmd.Flags().String("vm-dir", defaultVMDir, "Directory where to store VM state") hyperkit := cmd.Flags().String("hyperkit", defaultHyperKit, "Path to HyperKit executable") @@ -73,7 +72,7 @@ func main() { cli.SetLogLevel(*logLevel) cli.RunPlugin(*name, - instance_plugin.PluginServer(NewHyperKitPlugin(*vmLib, *vmDir, *hyperkit, *vpnkitSock, thyper, tkern)), + instance_plugin.PluginServer(NewHyperKitPlugin(*vmDir, *hyperkit, *vpnkitSock, thyper, tkern)), metadata_plugin.PluginServer(metadata.NewPluginFromData( map[string]interface{}{ "version": Version, diff --git a/tools/infrakit.hyperkit/hyperkit.json b/tools/infrakit.hyperkit/hyperkit.json index 4782e76a9..73921aa74 100644 --- a/tools/infrakit.hyperkit/hyperkit.json +++ b/tools/infrakit.hyperkit/hyperkit.json @@ -7,7 +7,7 @@ "Instance": { "Plugin": "instance-hyperkit", "Properties": { - "Moby": "default", + "Moby": "./vms/default", "Disk" : 512, "CPUs" : 2, "Memory" : 1024 From d1ad02e07994f986c7d56458b2c8eb51824e8ff0 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 1 Mar 2017 17:13:17 -0800 Subject: [PATCH 3/4] infrakit: Move default VM directory to .infrakit/hyperkit-vms Signed-off-by: Rolf Neugebauer --- tools/infrakit.hyperkit/README.md | 10 +++++----- tools/infrakit.hyperkit/cmd/main.go | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/tools/infrakit.hyperkit/README.md b/tools/infrakit.hyperkit/README.md index 7f677905f..46e2a6cf8 100644 --- a/tools/infrakit.hyperkit/README.md +++ b/tools/infrakit.hyperkit/README.md @@ -4,10 +4,10 @@ This is a Hyper/Kit Moby instance plugin for infrakit. The instance plugin is capable to start/manage several hyperkit instances with with different configurations and Moby configurations. -The plugin keeps state in a local directory (default `./vms`) where -each instance keeps some state in a sub-directory. The VM state -directory can be specified at the kernel command line using the -`--vm-dir` option. +The plugin keeps state in a local directory (default +`.infrakit/hyperkit-vms`) where each instance keeps some state in a +sub-directory. The VM state directory can be specified at the kernel +command line using the `--vm-dir` option. ## Building @@ -20,7 +20,7 @@ make To play round with the plugin, simply follow the [infrakit tutorial](https://github.com/docker/infrakit/blob/master/docs/tutorial.md) and replace the file instance plugin with: ``` -./build/infrakit-instance-hyperkit --vm-lib ./vmlib +./build/infrakit-instance-hyperkit ``` where `./vmlib` contains a sub-directory named `default` with a `vmlinuz64` and `initrd.img` image. diff --git a/tools/infrakit.hyperkit/cmd/main.go b/tools/infrakit.hyperkit/cmd/main.go index 1099897e9..0ec95743c 100644 --- a/tools/infrakit.hyperkit/cmd/main.go +++ b/tools/infrakit.hyperkit/cmd/main.go @@ -4,7 +4,9 @@ import ( "encoding/json" "fmt" "os" + "os/user" "path" + "path/filepath" log "github.com/Sirupsen/logrus" "github.com/spf13/cobra" @@ -40,14 +42,9 @@ func main() { Use: os.Args[0], Short: "HyperKit instance plugin", } - defaultVMDir, err := os.Getwd() - if err != nil { - log.Error(err) - os.Exit(1) - } - defaultVMDir = path.Join(defaultVMDir, "vms") - homeDir := os.Getenv("HOME") - defaultVPNKitSock = path.Join(homeDir, defaultVPNKitSock) + + defaultVMDir := filepath.Join(getHome(), ".infrakit/hyperkit-vms") + defaultVPNKitSock = path.Join(getHome(), defaultVPNKitSock) name := cmd.Flags().String("name", "instance-hyperkit", "Plugin name to advertise for discovery") logLevel := cmd.Flags().Int("log", cli.DefaultLogLevel, "Logging level. 0 is least verbose. Max is 5") @@ -70,6 +67,8 @@ func main() { return err } + os.MkdirAll(*vmDir, os.ModePerm) + cli.SetLogLevel(*logLevel) cli.RunPlugin(*name, instance_plugin.PluginServer(NewHyperKitPlugin(*vmDir, *hyperkit, *vpnkitSock, thyper, tkern)), @@ -105,3 +104,10 @@ func main() { os.Exit(1) } } + +func getHome() string { + if usr, err := user.Current(); err == nil { + return usr.HomeDir + } + return os.Getenv("HOME") +} From 1c3f4b4865f8dc12ef3437ad7dbc935ea5f3f6c2 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 1 Mar 2017 17:26:44 -0800 Subject: [PATCH 4/4] infrakit: Make Destroy() usable elsewhere Don't return if the process does not exist. Instead proceed and delete the state directory. This allows us to use the Destroy() method elsewhere to clean up the state. Signed-off-by: Rolf Neugebauer --- tools/infrakit.hyperkit/cmd/instance.go | 28 ++++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/tools/infrakit.hyperkit/cmd/instance.go b/tools/infrakit.hyperkit/cmd/instance.go index 019cce87a..110c4c585 100644 --- a/tools/infrakit.hyperkit/cmd/instance.go +++ b/tools/infrakit.hyperkit/cmd/instance.go @@ -149,12 +149,12 @@ func (v hyperkitPlugin) Destroy(id instance.ID) error { p, err := getProcess(instanceDir) if err != nil { log.Warningln("Can't find processes: ", err) - return err - } - err = p.Kill() - if err != nil { - log.Warningln("Can't kill processes with pid: ", p.Pid, err) - return err + } else { + err = p.Kill() + if err != nil { + log.Warningln("Can't kill processes with pid: ", p.Pid, err) + return err + } } if err := os.RemoveAll(instanceDir); err != nil { @@ -205,10 +205,12 @@ func (v hyperkitPlugin) DescribeInstances(tags map[string]string) ([]instance.De if allMatched { var logicalID *instance.LogicalID + id := instance.ID(file.Name()) + pidData, err := ioutil.ReadFile(path.Join(instanceDir, hyperkitPid)) if err == nil { - id := instance.LogicalID(pidData) - logicalID = &id + lid := instance.LogicalID(pidData) + logicalID = &lid } else { if !os.IsNotExist(err) { return nil, err @@ -217,17 +219,13 @@ func (v hyperkitPlugin) DescribeInstances(tags map[string]string) ([]instance.De // Check if process is running if _, err := getProcess(instanceDir); err != nil { - log.Warningln("Process not running: Instance ", file.Name()) - if err := os.RemoveAll(instanceDir); err != nil { - log.Warningln("Can't remove instance dir ", instanceDir, " error ", err) - - } - + log.Warningln("Process not running: Instance ", id) + v.Destroy(id) continue } descriptions = append(descriptions, instance.Description{ - ID: instance.ID(file.Name()), + ID: id, LogicalID: logicalID, Tags: instanceTags, })