infrakit: Fix the VPNKit key to set the IP address

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2017-04-14 11:03:38 -05:00
parent e374cb3543
commit 0ca76f63d9

View File

@ -76,7 +76,7 @@ func (p hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) {
log.Infof("[%s] New instance", id) log.Infof("[%s] New instance", id)
logicalID := string(id) logicalID := string(id)
uuidStr := "" vpnkitKeyStr := ""
diskImage := "" diskImage := ""
if spec.LogicalID != nil { if spec.LogicalID != nil {
@ -85,12 +85,12 @@ func (p hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) {
// it into a magic UUID which cause VPNKit to assign a // it into a magic UUID which cause VPNKit to assign a
// fixed IP address // fixed IP address
if ip := net.ParseIP(logicalID); len(ip) > 0 { if ip := net.ParseIP(logicalID); len(ip) > 0 {
uuid := make([]byte, 16) vpnkitkey := make([]byte, 16)
uuid[12] = ip.To4()[0] vpnkitkey[12] = ip.To4()[0]
uuid[13] = ip.To4()[1] vpnkitkey[13] = ip.To4()[1]
uuid[14] = ip.To4()[2] vpnkitkey[14] = ip.To4()[2]
uuid[15] = ip.To4()[3] vpnkitkey[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:]) vpnkitKeyStr = fmt.Sprintf("%x-%x-%x-%x-%x", vpnkitkey[0:4], vpnkitkey[4:6], vpnkitkey[6:8], vpnkitkey[8:10], vpnkitkey[10:])
} }
// If a LogicalID is supplied and the Disk size is // If a LogicalID is supplied and the Disk size is
// non-zero, we place the disk in a special directory // non-zero, we place the disk in a special directory
@ -115,7 +115,7 @@ func (p hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) {
} }
log.Infof("[%s] LogicalID: %s", id, logicalID) log.Infof("[%s] LogicalID: %s", id, logicalID)
log.Debugf("[%s] UUID: %s", id, uuidStr) log.Debugf("[%s] VPNKitKey: %s", id, vpnkitKeyStr)
// Start a HyperKit instance // Start a HyperKit instance
h, err := hyperkit.New(p.HyperKit, p.VPNKitSock, instanceDir) h, err := hyperkit.New(p.HyperKit, p.VPNKitSock, instanceDir)
@ -124,7 +124,7 @@ func (p hyperkitPlugin) Provision(spec instance.Spec) (*instance.ID, error) {
} }
h.Kernel = properties["kernel+initrd"].(string) + "-bzImage" h.Kernel = properties["kernel+initrd"].(string) + "-bzImage"
h.Initrd = properties["kernel+initrd"].(string) + "-initrd.img" h.Initrd = properties["kernel+initrd"].(string) + "-initrd.img"
h.UUID = uuidStr h.VPNKitKey = vpnkitKeyStr
h.DiskImage = diskImage h.DiskImage = diskImage
h.ISOImage = isoImage h.ISOImage = isoImage
h.CPUs = int(properties["CPUs"].(float64)) h.CPUs = int(properties["CPUs"].(float64))