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

Default Switch using special characters might fail start (VM creation in driver) #758

Closed
gbraad opened this issue Oct 23, 2019 · 5 comments · Fixed by #759
Closed

Default Switch using special characters might fail start (VM creation in driver) #758

gbraad opened this issue Oct 23, 2019 · 5 comments · Fixed by #759
Assignees

Comments

@gbraad
Copy link
Contributor

gbraad commented Oct 23, 2019

In Swedish the Default Switch is named "Standardväxel" which might cause issues upon creation of the VM.

image

INFO Creating CodeReady Containers VM for OpenShift 4.2.0-0.nightly-2019-09-26-192831...

ERRO Error occurred: Error creating host: Error creating the VM. Error with pre-create check: "virtual switch \"Standardv�xel\" not found"
@gbraad gbraad self-assigned this Oct 23, 2019
@gbraad
Copy link
Contributor Author

gbraad commented Oct 23, 2019

Along the way I will refactor and perhaps even remove some code related to 'choosing the Virtual Switch': https://github.com/code-ready/machine/blob/0fde37b5d95b668d82659ec4aa1d60b054a08e46/drivers/hyperv/hyperv.go#L179 as the code still picks up the first one by default? Ref: https://github.com/code-ready/machine/blob/0fde37b5d95b668d82659ec4aa1d60b054a08e46/drivers/hyperv/hyperv.go#L227-L264

func (d *Driver) chooseVirtualSwitch() (string, error) {
	if d.VirtualSwitch == "" {
		// Default to the first external switch and in the process avoid DockerNAT
		stdout, err := cmdOut("[Console]::OutputEncoding = [Text.Encoding]::UTF8; (Hyper-V\\Get-VMSwitch -SwitchType External).Name")
		if err != nil {
			return "", err
		}


		switches := parseLines(stdout)


		if len(switches) < 1 {
			return "", fmt.Errorf("no external virtual switch found. A valid virtual switch must be available for this command to run")
		}


		return switches[0], nil
	}


	stdout, err := cmdOut("[Console]::OutputEncoding = [Text.Encoding]::UTF8; (Hyper-V\\Get-VMSwitch).Name")
	if err != nil {
		return "", err
	}


	switches := parseLines(stdout)


	found := false
	for _, name := range switches {
		if name == d.VirtualSwitch {
			found = true
			break
		}
	}


	if !found {
		return "", fmt.Errorf("virtual switch %q not found", d.VirtualSwitch)
	}


	return d.VirtualSwitch, nil
}

@gbraad
Copy link
Contributor Author

gbraad commented Oct 23, 2019

Force encoding with [Console]::OutputEncoding = [Text.Encoding]::UTF8; for now ...

@gbraad
Copy link
Contributor Author

gbraad commented Oct 23, 2019

@robin-owen What about documentation around this? As a known issue we can detail that this can happen. However, it is solved now and will be fixed in the next release.

@kowen-rh
Copy link
Contributor

@gbraad Is there a workaround for this issue other than setting the OS language to English?

@gbraad
Copy link
Contributor Author

gbraad commented Nov 1, 2019

@robin-owen there is, in the form of a new release. this change has been merged and 'should' work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants