Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MacOS lease file detection #16

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion go_src/vagrant-vmware-utility/driver/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

const PORTFWD_PREFIX = "vagrant: "
const VMWARE_VERSION_PATTERN = `(?i)VMware\s+(?P<product>[A-Za-z0-9-]+)\s+(?P<version>[\d.]+)\s*(?P<build>\S+)?\s*(?P<type>[A-Za-z0-9-]+)?`
const VMWARE_VERSION_PATTERN = `(?i)VMware\s+(?P<product>[A-Za-z0-9-]+)\s+(?P<version>[\d.]+|e.x.p)\s*(?P<build>\S+)?\s*(?P<type>[A-Za-z0-9-]+)?`

type BaseDriver struct {
Natfile func(string) (*utility.VMWareNatFile, error)
Expand Down Expand Up @@ -86,6 +86,14 @@ func NewBaseDriver(vmxPath *string, licenseOverride string, logger hclog.Logger)
return nil, err
}

// DHCP Lease Path can vary based on version for some platforms
err = drv.vmwarePaths.UpdateVmwareDhcpLeasePath(i.Version)
if err != nil {
logger.Error("dhcp path loading failure", "error", err)
return nil, err
}
logger.Debug("dhcp lease file", "filepath", drv.vmwarePaths.DhcpLease)

logger.Debug("initial vmware information loaded", "license", i.License)
if licenseOverride != "" {
logger.Debug("applying user defined license override", "original", i.License,
Expand Down
11 changes: 11 additions & 0 deletions go_src/vagrant-vmware-utility/driver/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ func CreateDriver(vmxPath *string, b *BaseDriver, logger hclog.Logger) (Driver,
logger.Error("failed to get VMware information", "error", err)
return d, err
}

// Assume advanced driver for experimental builds
if info.Version == "e.x.p" {
logger.Debug("creating new advanced driver")
d, err = NewAdvancedDriver(vmxPath, b, logger)
if err != nil {
return d, err
}
return d, nil
}

verParts := strings.Split(info.Version, ".")
if len(verParts) < 1 {
logger.Warn("failed to determine major version, using simple driver",
Expand Down
56 changes: 43 additions & 13 deletions go_src/vagrant-vmware-utility/utility/vmware_paths_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package utility

import (
"errors"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
)

func (v *VmwarePaths) Load() error {
Expand All @@ -14,19 +17,6 @@ func (v *VmwarePaths) Load() error {
}
v.BridgePid = "/var/run/vmnet-bridge.pid"
v.Networking = "/Library/Preferences/VMware Fusion/networking"
// Starting on Big Sur, VMware is using the native vmnet framework instead
// of their internal tools. This means that the dhcpd being used is also
// provided by the platform and not VMware internal tools
darwin, err := GetDarwinMajor()
if err != nil {
// Assume non-Big Sur by default
darwin = 19
}
if darwin >= 20 {
v.DhcpLease = "/var/db/dhcpd_leases"
} else {
v.DhcpLease = "/var/db/vmware/vmnet-dhcpd-{{device}}.leases"
}
v.NatConf = "/Library/Preferences/VMware Fusion/{{device}}/nat.conf"
v.VmnetCli = filepath.Join(v.InstallDir, "Contents/Library/vmnet-cli")
v.Vnetlib = filepath.Join(v.InstallDir, "Contents/Library/vmnet-cfgcli")
Expand All @@ -37,3 +27,43 @@ func (v *VmwarePaths) Load() error {
v.Vdiskmanager = filepath.Join(v.InstallDir, "Contents/Library/vmware-vdiskmanager")
return nil
}

func (v *VmwarePaths) UpdateVmwareDhcpLeasePath(version string) error {
// default to using VMware dhcp lease file
v.DhcpLease = "/var/db/vmware/vmnet-dhcpd-{{device}}.leases"

// In Big Sur, VMware started using the native vmnet framework instead
// of their internal tools. This means that the dhcpd being used is also
// provided by the platform and not VMware internal tools.
// However, issues with transiting VPNs required migrating back to the
// VMware DHCP implementation.

// New experimental pre-releases use VMware DHCP
if version == "e.x.p" {
return nil
}

darwin, err := GetDarwinMajor()
if darwin != 20 {
return nil
}

// Big Sur and Fusion 12.0 or 12.1 used the native framework
verParts := strings.Split(version, ".")
if len(verParts) < 2 {
return errors.New("Invalid version string")
}
major, err := strconv.Atoi(verParts[0])
if err != nil {
return fmt.Errorf("Invalid major version number: %s", verParts[0])
}
minor, err := strconv.Atoi(verParts[1])
if err != nil {
return fmt.Errorf("Invalid minor version number: %s", verParts[1])
}
if major == 12 && (minor == 0 || minor == 1) {
v.DhcpLease = "/var/db/dhcpd_leases"
}

return nil
}
4 changes: 4 additions & 0 deletions go_src/vagrant-vmware-utility/utility/vmware_paths_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ func (v *VmwarePaths) Load() (err error) {
v.Vmrest = "/bin/false"
return
}

func (v *VmwarePaths) UpdateVmwareDhcpLeasePath(version string) error {
return nil
}
4 changes: 4 additions & 0 deletions go_src/vagrant-vmware-utility/utility/vmware_paths_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ func (v *VmwarePaths) Load() error {

return nil
}

func (v *VmwarePaths) UpdateVmwareDhcpLeasePath(version string) error {
return nil
}