Skip to content

Commit

Permalink
Move GetNetAddr.
Browse files Browse the repository at this point in the history
The build constraints in vmnet.go cause issues.
  • Loading branch information
dlorenc committed Jan 2, 2018
1 parent af5a475 commit 919fee1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
21 changes: 21 additions & 0 deletions pkg/drivers/hyperkit/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import (
"bufio"
"fmt"
"io"
"net"
"os"
"os/exec"
"regexp"
"strings"
)

const (
DHCPLeasesFile = "/var/db/dhcpd_leases"
CONFIG_PLIST = "/Library/Preferences/SystemConfiguration/com.apple.vmnet"
NET_ADDR_KEY = "Shared_Net_Address"
)

type DHCPEntry struct {
Expand Down Expand Up @@ -108,3 +112,20 @@ func trimMacAddress(rawUUID string) string {

return mac
}

func GetNetAddr() (net.IP, error) {
_, err := os.Stat(CONFIG_PLIST + ".plist")
if err != nil {
return nil, fmt.Errorf("Does not exist %s", CONFIG_PLIST+".plist")
}

out, err := exec.Command("defaults", "read", CONFIG_PLIST, NET_ADDR_KEY).Output()
if err != nil {
return nil, err
}
ip := net.ParseIP(strings.TrimSpace(string(out)))
if ip == nil {
return nil, fmt.Errorf("Could not get the network address for vmnet")
}
return ip, nil
}
28 changes: 0 additions & 28 deletions pkg/drivers/hyperkit/vmnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,9 @@ limitations under the License.
package hyperkit

import (
"fmt"
"net"
"os"
"os/exec"
"strings"

vmnet "github.com/zchee/go-vmnet"
)

const (
CONFIG_PLIST = "/Library/Preferences/SystemConfiguration/com.apple.vmnet"
NET_ADDR_KEY = "Shared_Net_Address"
)

func GetMACAddressFromUUID(UUID string) (string, error) {
return vmnet.GetMACAddressFromUUID(UUID)
}

func GetNetAddr() (net.IP, error) {
_, err := os.Stat(CONFIG_PLIST + ".plist")
if err != nil {
return nil, fmt.Errorf("Does not exist %s", CONFIG_PLIST+".plist")
}

out, err := exec.Command("defaults", "read", CONFIG_PLIST, NET_ADDR_KEY).Output()
if err != nil {
return nil, err
}
ip := net.ParseIP(strings.TrimSpace(string(out)))
if ip == nil {
return nil, fmt.Errorf("Could not get the network address for vmnet")
}
return ip, nil
}
4 changes: 3 additions & 1 deletion pkg/drivers/hyperkit/vmnet_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ limitations under the License.

package hyperkit

import "errors"
import (
"errors"
)

func GetMACAddressFromUUID(UUID string) (string, error) {
return "", errors.New("Function not supported on CGO_ENABLED=0 binaries")
Expand Down

0 comments on commit 919fee1

Please sign in to comment.