From d1ad02e07994f986c7d56458b2c8eb51824e8ff0 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 1 Mar 2017 17:13:17 -0800 Subject: [PATCH] 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") +}