Generate VM UUID

Signed-off-by: Ilya Dmitrichenko <errordeveloper@gmail.com>
This commit is contained in:
Ilya Dmitrichenko 2017-04-12 17:32:33 +01:00
parent 4504e6d386
commit 31f5a0baa8

View File

@ -10,6 +10,7 @@ import (
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/docker/hyperkit/go" "github.com/docker/hyperkit/go"
"github.com/rneugeba/iso9660wrap" "github.com/rneugeba/iso9660wrap"
"github.com/satori/go.uuid"
) )
// Process the run arguments and execute run // Process the run arguments and execute run
@ -66,7 +67,7 @@ func runHyperKit(args []string) {
} }
} }
uuidStr := "" vpnKitKey := ""
if *ipStr != "" { if *ipStr != "" {
// If an IP address was requested construct a "special" UUID // If an IP address was requested construct a "special" UUID
// for the VM. // for the VM.
@ -76,10 +77,13 @@ func runHyperKit(args []string) {
uuid[13] = ip.To4()[1] uuid[13] = ip.To4()[1]
uuid[14] = ip.To4()[2] uuid[14] = ip.To4()[2]
uuid[15] = ip.To4()[3] uuid[15] = ip.To4()[3]
uuidStr = fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]) vpnKitKey = fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:])
} }
} }
// Generate new UUID, otherwise /sys/class/dmi/id/product_uuid is identical on all VMs
vmUUID := uuid.NewV4().String()
// Run // Run
cmdline, err := ioutil.ReadFile(prefix + "-cmdline") cmdline, err := ioutil.ReadFile(prefix + "-cmdline")
if err != nil { if err != nil {
@ -97,7 +101,8 @@ func runHyperKit(args []string) {
h.Kernel = prefix + "-bzImage" h.Kernel = prefix + "-bzImage"
h.Initrd = prefix + "-initrd.img" h.Initrd = prefix + "-initrd.img"
h.UUID = uuidStr h.VPNKitKey = vpnKitKey
h.UUID = vmUUID
h.DiskImage = *disk h.DiskImage = *disk
h.ISOImage = isoPath h.ISOImage = isoPath
h.CPUs = *cpus h.CPUs = *cpus