From 70a27b667eaab2182a7b27539df5812896e3d9b1 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Mon, 10 Apr 2017 15:56:38 +0100 Subject: [PATCH] infrakit: Adjust hyperkit instance plugin to new API The new API does not provide the option to pass in user data anymore. Roll our own ISO instead. Signed-off-by: Rolf Neugebauer --- .../infrakit-instance-hyperkit/instance.go | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/cmd/infrakit-instance-hyperkit/instance.go b/src/cmd/infrakit-instance-hyperkit/instance.go index 79039a129..917bd641a 100644 --- a/src/cmd/infrakit-instance-hyperkit/instance.go +++ b/src/cmd/infrakit-instance-hyperkit/instance.go @@ -9,11 +9,10 @@ import ( "path" log "github.com/Sirupsen/logrus" - "github.com/docker/hyperkit/go" - "github.com/docker/infrakit/pkg/spi/instance" "github.com/docker/infrakit/pkg/types" + "github.com/rneugeba/iso9660wrap" ) // NewHyperKitPlugin creates an instance plugin for hyperkit. @@ -98,28 +97,39 @@ func (p hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) { // so it persists across reboots. if diskSize != 0 { diskImage = path.Join(p.DiskDir, logicalID+".img") - // Make sure the directory exists - err = os.MkdirAll(p.DiskDir, 0755) - if err != nil { - return nil, err - } } } + + isoImage := "" + if spec.Init != "" { + isoImage = path.Join(instanceDir, "data.iso") + outfh, err := os.OpenFile(isoImage, os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + log.Fatalf("Cannot create user data ISO: %s", err) + } + err = iso9660wrap.WriteBuffer(outfh, []byte(spec.Init), "config") + if err != nil { + log.Fatalf("Cannot write user data ISO: %s", err) + } + outfh.Close() + } + log.Infof("[%s] LogicalID: %s", id, logicalID) log.Debugf("[%s] UUID: %s", id, uuidStr) // Start a HyperKit instance - h, err := hyperkit.New(p.HyperKit, instanceDir, p.VPNKitSock, diskImage) + h, err := hyperkit.New(p.HyperKit, p.VPNKitSock, instanceDir) if err != nil { return nil, err } h.Kernel = properties["Moby"].(string) + "-bzImage" h.Initrd = properties["Moby"].(string) + "-initrd.img" + h.UUID = uuidStr + h.DiskImage = diskImage + h.ISOImage = isoImage h.CPUs = int(properties["CPUs"].(float64)) h.Memory = int(properties["Memory"].(float64)) h.DiskSize = diskSize - h.UUID = uuidStr - h.UserData = spec.Init h.Console = hyperkit.ConsoleFile log.Infof("[%s] Booting: %s/%s", id, h.Kernel, h.Initrd) log.Infof("[%s] %d CPUs, %dMB Memory, %dMB Disk (%s)", id, h.CPUs, h.Memory, h.DiskSize, h.DiskImage)