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

Hyper-V switch selection does not work with non ascii names. #9679

Closed
kmpm opened this issue Apr 11, 2018 · 5 comments · Fixed by #9747
Closed

Hyper-V switch selection does not work with non ascii names. #9679

kmpm opened this issue Apr 11, 2018 · 5 comments · Fixed by #9747

Comments

@kmpm
Copy link

kmpm commented Apr 11, 2018

Vagrant version

> vagrant -v
Vagrant 2.0.2

Host operating system

Windows 10 Pro, Version 1709, Swedish UI, Locale and Input

Guest operating system

This fails before getting this far but I was trying with Windows Server 2016 Standard

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
  config.vm.define "dev01"
  config.vm.box = "windows_2016"
  config.vm.hostname = "mu01-dev01"
  config.vm.communicator = "winrm"
  config.vm.guest = :windows
  config.winrm.username = "vagrant"
  config.winrm.password = "vagrant"
  config.vm.network "forwarded_port", guest: 3389, host: 13389, auto_correct: true
  config.vm.network "forwarded_port", guest: 5985, host: 15985, id: "winrm", auto_correct:true
  #config.vm.network "private_network", ip: "192.168.56.60"
  
  config.vm.provider 'parallels' do |prl|
    prl.linked_clone = true
  end
  
  config.vm.provider "virtualbox" do |v|
    v.linked_clone = true
    v.memory = 4096
    v.cpus = 4
    v.gui = false
  end
end

Debug output

https://gist.github.com/kmpm/d5a44847741180f96615da3fc0057264

Expected behavior

The chosen switch called "Standardväxel" should have been used.

Actual behavior

It tries to use the right name but with wrong encoding and hyper-v does not accept that.

Hyper-V\Connect-VMNetworkAdapter : Hyper-V was unable to find a virtual switch with name "Standardväxel".
At C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-2.0.2\plugins\providers\hyperv\scripts\import_vm_vmcx.ps1:96 char:1
+ Hyper-V\Connect-VMNetworkAdapter -VMNetworkAdapter $vmNetworkAdapter  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Connect-VMNetworkAdapter], VirtualizationException
    + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.ConnectVMNetworkAdapter

Steps to reproduce

  1. Use a host installed with Hyper-V and Swedish as language (or my guess any language that creates a default switch
    with non US-ASCII characters in name).
  2. Open a command prompt and run vagrant up
  3. When asked about virtual switch to use, select "Standardväxel"

Notes

When running vagrant in debug mode it prompts the switch as Standardväxel (see linked log at about line 914) but running without debug shows the correct name Standardväxel but seems to use the other internally.
I can not change name on this switch since it is the default switch always created in newer hyper-v installations on Windows 10. On an English machine it's called "Default Switch". See https://blogs.technet.microsoft.com/virtualization/2017/11/13/whats-new-in-hyper-v-for-windows-10-fall-creators-update/

In packer I can configure the switch to use with the switch_name argument and enter the string as "Standardväxel" but I can't find such a workaround in vagrant.

normal output

PS> vagrant up --provider hyperv
Bringing machine 'dev01' up with 'hyperv' provider...
==> dev01: Verifying Hyper-V is enabled...
==> dev01: Importing a Hyper-V instance
    dev01: Please choose a switch to attach to your Hyper-V instance.
    dev01: If none of these are appropriate, please open the Hyper-V manager
    dev01: to create a new virtual switch.
    dev01:
    dev01: 1) LAN
    dev01: 2) Standardväxel
    dev01:
    dev01: What switch would you like to use? 2
    dev01: Cloning virtual hard drive...
    dev01: Creating and registering the VM...
An error occurred while executing a PowerShell script. This error
is shown below. Please read the error message and see if this is
a configuration error with your system. If it is not, then please
report a bug.

Script: import_vm_vmcx.ps1
Error:

Hyper-V\Connect-VMNetworkAdapter : Hyper-V was unable to find a virtual switch with name "Standardväxel".
At C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-2.0.2\plugins\providers\hyperv\scripts\import_vm_vmcx.ps1:96 char:1
+ Hyper-V\Connect-VMNetworkAdapter -VMNetworkAdapter $vmNetworkAdapter  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Connect-VMNetworkAdapter], VirtualizationException
    + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.ConnectVMNetworkAdapter
@kmpm
Copy link
Author

kmpm commented Apr 11, 2018

This is probably a duplicate of #9451 and/or #8794
Sorry for not looking careful enough.

It probably relates to #9678 and #7915 which might have a workaround.

A possible solution is described in commit 73e73d2 that is a part of #8510

@kmpm
Copy link
Author

kmpm commented Apr 11, 2018

The possible workaround with adding config.vm.network "public_network", bridge: "Standardväxel" does not work. It messes with the encoding of the letter ä here as well.

vagrant up --provider hyperv
Bringing machine 'dev01' up with 'hyperv' provider...
==> dev01: Verifying Hyper-V is enabled...
==> dev01: Importing a Hyper-V instance
Looking for switch with name: Standardväxel
Found switch: Standardväxel
Looking for switch with name: Standardväxel
Found switch: Standardväxel
    dev01: Cloning virtual hard drive...
    dev01: Creating and registering the VM...
An error occurred while executing a PowerShell script. This error
is shown below. Please read the error message and see if this is
a configuration error with your system. If it is not, then please
report a bug.

Script: import_vm_vmcx.ps1
Error:

Hyper-V\Connect-VMNetworkAdapter : Hyper-V was unable to find a virtual switch with name "Standardväxel".
At C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-2.0.2\plugins\providers\hyperv\scripts\import_vm_vmcx.ps1:96 char:1
+ Hyper-V\Connect-VMNetworkAdapter -VMNetworkAdapter $vmNetworkAdapter  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Connect-VMNetworkAdapter], VirtualizationException
    + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.ConnectVMNetworkAdapter

@kmpm
Copy link
Author

kmpm commented Apr 11, 2018

a simple puts options.inspect in driver.rb gives that...

{:vm_config_file=>"C:\\Users\\peter\\.vagrant.d\\boxes\\windows_2016\\0\\hyperv\\Virtual Machines\\88C799B5-1EB2-4A37-B645-347CDB48A13F.vmcx", :source_path=>"C:/Users/peter/.vagrant.d/boxes/windows_2016/0/hyperv/Virtual Hard Disks/vagrant.vhdx", :dest_path=>"C:/code/mu01/.vagrant/machines/dev01/hyperv/Virtual Hard Disks/vagrant.vhdx", :data_path=>"C:\\code\\mu01\\.vagrant\\machines\\dev01\\hyperv", :switchname=>"Standardv\u00E4xel"}

If any help to someone.

@kmpm
Copy link
Author

kmpm commented Apr 11, 2018

Adding options[:switchname] = options[:switchname].encode('windows-1252') in VagrantPlugins::HyperV::Driver::import ( vagrant/plugins/providers/hyperv/driver.rb ) made it work.

This is probably not the best solution since it's only for switchname but it's the minimum thing to make it work.

chrisroberts added a commit to chrisroberts/vagrant that referenced this issue Apr 27, 2018
Keep track of selected Hyper-V switch using the ID instead of name
to prevent any encoding issues that may occur switching between
PowerShell and Ruby. With the IDs staying consistent, the switch
name can be fetched from the provided ID.

Fixes hashicorp#9679 hashicorp#8794 hashicorp#9451
@ghost
Copy link

ghost commented Mar 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants