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

Vagrant up with Hyper-V fails on -switchname for import_vm_vmcx.ps1 script #9774

Closed
MJLHThomassen opened this issue May 4, 2018 · 10 comments · Fixed by #9781
Closed

Vagrant up with Hyper-V fails on -switchname for import_vm_vmcx.ps1 script #9774

MJLHThomassen opened this issue May 4, 2018 · 10 comments · Fixed by #9781
Assignees
Milestone

Comments

@MJLHThomassen
Copy link

Vagrant version

2.1.0

Host operating system

Widnows 10 Pro

Guest operating system

Ubuntu 16.04

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu1604"
end

Debug output

https://gist.github.com/MJLHThomassen/58600432c1e8427bf023cda68c2da9a5

Expected behavior

The VM should start

Actual behavior

The powershell script import_vm_vmcx.ps1 was passed a -switchname parameter while it only accepts a -switchid parameter when choosing the network switch.

Steps to reproduce

  1. Get a pc with Windows 10 pro x64
  2. Install Vagrant 2.1.0
  3. Place the contents of the mentioned Vagrantfile above in a Vagrantfile in some directory
  4. Start powershell as administrator (Click on the windows logo on your windows taskbar, type "powershell", right-click the "Windows Powershell" entry and click the "Run as Administrator" option.
  5. Navigate to the directory with the above mentioned Vagrantfile in the powershell window (type: cd "c:\directory\with\vagrantfile" and press enter)
  6. Type: vagrant up and press enter
@oldluke92
Copy link

Same Problem here.

This was broken in commit e47e1df.

The Parameter was renamed in import_vm_vmcx.ps1, but not in import.rb (line 143) where the script is called. Changing it there restores functionality for me but might break something else - I don't know as I didn't dig in too far.

@kopfpilot
Copy link

kopfpilot commented May 5, 2018

The switchid is a uuid, which is returned by e.g. (Get-VMSwitch -Name "$Switchname").Id.
Wouldn't it make more sense to stick with the switch name and add an additional setting to allow the uuid as a fallback?

Though, after applying the change from commit 2730fe7, I was able to get rid of the switch error with adding the default switch like this to my Vagrantfile:
config.vm.network "private_network", bridge: "c08cb7b8-9b3c-408e-8e30-5e16a3aeb444"

@shurick81
Copy link

So it was introduced in 2.1.0 and it should work in previous release?

@shurick81
Copy link

Yes, seems to be working after this:

choco uninstall -y vagrant
choco install -y vagrant  --version 2.0.4

@vstiebe
Copy link

vstiebe commented May 10, 2018

After upgrading to 2.1.1 I'm getting an error on import_vm_xml.ps1 because there is no switchid parameter on this script.

@jrich523
Copy link

Same here.
After reviewing the code it pointed me to, i see no reference at all to "switchid" its all for "switchname" so i have no idea where this is coming from.

I just installed vagrant to a custom folder (d:\tools\vagrant) and after doing an up i get this

D:\tools\Vagrant\embedded\gems\2.1.1\gems\vagrant-2.1.1\plugins\providers\hyperv\scripts\import_vm_xml.ps1 : A parameter cannot be found that matches
parameter name 'switchid'.
At line:1 char:322

That file has no mention what so ever of 'switchid' so some weird stuff is happening.

Also, as a heavy powershell user it blows my mind you'd use combine to add in functions. There is a Import-Module cmdlet or dot sourcing to help with this, whats done here is down right blasphemy lol

@v-zhuravlev
Copy link

v-zhuravlev commented May 14, 2018

It doesn't work in freshly installed 2.1.1 ( Win Pro 10). I had to downgrade to 2.0.4 where everything works with hyperv.

Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Importing a Hyper-V instance
    default: Please choose a switch to attach to your Hyper-V instance.
    default: If none of these are appropriate, please open the Hyper-V manager
    default: to create a new virtual switch.
    default:
    default: 1) myswitch
    default: 2) DockerNAT
    default: 3) Default Switch
    default:
    default: What switch would you like to use? 3
    default: Cloning virtual hard drive...
    default: 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_xml.ps1
Error:

C:\HashiCorp\Vagrant\embedded\gems\2.1.1\gems\vagrant-2.1.1\plugins\providers\hyperv\scripts\import_vm_xml.ps1 : A para
meter cannot be found that matches parameter name 'switchid'.
At line:1 char:329
+ ... achines/default/hyperv/Virtual Hard Disks/disk.vhd' -switchid 'c08cb7 ...
+                                                         ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [import_vm_xml.ps1], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,import_vm_xml.ps1

@PhilSpouse
Copy link

PhilSpouse commented May 14, 2018

Ditto, still seems to be an issue. Fresh install of 2.1.1 on a Win2k12 machine and I have the same error. This is my first time trying to use Vagrant so I thought I may be doing something wrong but it looks like I'm not alone.

I can see in PowerShell logs it's trying to execute this... (Note: I have replaced my user with XXX)
C:\Windows\System32\WindowsPowerShell\v1.0\/powershell.EXE -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass &('C:\HashiCorp\Vagrant\embedded\gems\2.1.1\gems\vagrant-2.1.1\plugins\providers\hyperv\scripts\import_vm_xml.ps1') -vm_config_file 'C:\Users\XXX\.vagrant.d\boxes\hashicorp-VAGRANTSLASH-precise64\1.1.0\hyperv\Virtual Machines\6C85D451-6B8B-410B-927C-8DE28E84DAD6.XML' -dest_path 'D:/VagrantTesting/.vagrant/machines/default/hyperv/Virtual Hard Disks/precise64.vhdx' -switchid '763f1071-7961-4208-951f-e8d0baf8f633' -ErrorAction Stop

So it looks like import_vm_xml.ps1 does not want the "switchid" parameter and that's what is causing the error.

If I edit import_vm_xml.ps1 and just add a dummy parameter...
[string]$switchid
And then as the first line I specify the switch name I want to use... (VLAN is example)
$switchname="MYVLAN"
I can get it to work. So seems like an issue but that's a workaround.

Core problem though is that the hyperv import.rb uses...
options[:switchid]
But the import_vm_xml.ps1 expects and needs switchname. That script needs updating.

@TonyApuzzo
Copy link
Contributor

Please go back to using Switch Name and not SwitchID --- SwitchID is a bad smell in my opinion, the SwitchID can change when windows is updated, for example between v1607 and v1709 and again when v1803 WIndows removed and re-added virtual switches with different IDs but the same name. See also #9818 with other people having this same problem.

@ghost
Copy link

ghost commented Mar 29, 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 29, 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.

10 participants