Skip to content

Commit

Permalink
Issue crc-org#579 Localize switch name
Browse files Browse the repository at this point in the history
  • Loading branch information
gbraad committed Sep 16, 2019
1 parent 1af59dc commit 0c2080a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/crc/services/dns/dns_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/code-ready/crc/pkg/os/windows/win32"
)

const hypervDefaultVirtualSwitchId = "c08cb7b8-9b3c-408e-8e30-5e16a3aeb444"

func runPostStartForOS(serviceConfig services.ServicePostStartConfig, result *services.ServicePostStartResult) (services.ServicePostStartResult, error) {
// bailout for Virtualbox
if serviceConfig.DriverName == "virtualbox" {
Expand All @@ -22,8 +24,8 @@ func runPostStartForOS(serviceConfig services.ServicePostStartConfig, result *se
return *result, nil
}

// TODO: localize
networkInterface := "vEthernet (Default Switch)" //getMainInterface()
_, switchName := getDefaultSwitchName()
networkInterface := fmt.Sprintf("vEthernet (%s)", switchName)

setInterfaceNameserverValue(networkInterface, serviceConfig.IP)

Expand Down Expand Up @@ -92,3 +94,15 @@ func parseLines(input string) []string {

return output
}

func getDefaultSwitchName() (bool, string) {
getDefaultSwitchNameCmd := fmt.Sprintf("Get-VMSwitch -Id %s | ForEach-Object { $_.Name }", hypervDefaultVirtualSwitchId)
stdOut, stdErr, _ := powershell.Execute(getDefaultSwitchNameCmd)

// If stdErr contains the command then execution failed
if strings.Contains(stdErr, "Get-VMSwitch") {
return false, ""
}

return true, strings.TrimSpace(stdOut)
}

0 comments on commit 0c2080a

Please sign in to comment.