providrs/hyperv: ask for the vswitch to use
This commit is contained in:
parent
3ddc63c88f
commit
729f0f5db8
|
@ -40,6 +40,29 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
env[:ui].output("Importing a Hyper-V instance")
|
||||
|
||||
switches = env[:machine].provider.driver.execute("get_switches.ps1", {})
|
||||
raise Errors::NoSwitches if switches.empty?
|
||||
|
||||
switch = switches[0]["Name"]
|
||||
if switches.length > 1
|
||||
env[:ui].detail(I18n.t("vagrant_hyperv.choose_switch") + "\n ")
|
||||
switches.each_index do |i|
|
||||
switch = switches[i]
|
||||
env[:ui].detail("#{i+1}) #{switch["Name"]}")
|
||||
end
|
||||
env[:ui].detail(" ")
|
||||
|
||||
switch = nil
|
||||
while !switch
|
||||
switch = env[:ui].ask("What switch would you like to use? ")
|
||||
next if !switch
|
||||
switch = switch.to_i - 1
|
||||
switch = nil if switch < 0 || switch >= switches.length
|
||||
end
|
||||
switch = switches[switch]["Name"]
|
||||
end
|
||||
|
||||
env[:ui].detail("Cloning virtual hard drive...")
|
||||
source_path = vhdx_path.to_s
|
||||
dest_path = env[:machine].data_dir.join("disk.vhdx").to_s
|
||||
|
@ -52,6 +75,7 @@ module VagrantPlugins
|
|||
vm_xml_config: config_path.to_s.gsub("/", "\\"),
|
||||
vhdx_path: vhdx_path.to_s.gsub("/", "\\")
|
||||
}
|
||||
options[:switchname] = switch if switch
|
||||
|
||||
env[:ui].detail("Creating and registering the VM...")
|
||||
server = env[:machine].provider.driver.execute(
|
||||
|
|
|
@ -18,6 +18,10 @@ module VagrantPlugins
|
|||
error_key(:ip_addr_timeout)
|
||||
end
|
||||
|
||||
class NoSwitches < HyperVError
|
||||
error_key(:no_switches)
|
||||
end
|
||||
|
||||
class PowerShellError < HyperVError
|
||||
error_key(:powershell_error)
|
||||
end
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
# 0 - Private
|
||||
# 1 - Internal
|
||||
#
|
||||
# Include the following modules
|
||||
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
||||
|
||||
$Switches = @(Get-VMSwitch `
|
||||
| Select-Object Name,SwitchType,NetAdapterInterfaceDescription)
|
||||
Write-Output $(ConvertTo-JSON $Switches)
|
||||
Write-Output-Message $(ConvertTo-JSON $Switches)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
en:
|
||||
vagrant_hyperv:
|
||||
choose_switch: |-
|
||||
Please choose a switch to attach to your Hyper-V instance.
|
||||
If none of these are appropriate, please open the Hyper-V manager
|
||||
to create a new virtual switch.
|
||||
message_already_running: |-
|
||||
Hyper-V instance already running.
|
||||
message_not_created: |-
|
||||
|
@ -37,6 +41,16 @@ en:
|
|||
machine doesn't have the latest Hyper-V integration drivers. Please
|
||||
research for your operating system how to install these in order
|
||||
for the VM to properly communicate its IP address to Hyper-V.
|
||||
no_switches: |-
|
||||
There are no virtual switches created for Hyper-V! Please open
|
||||
the Hyper-V Manager, go to the "Virtual Switch Manager", and create
|
||||
at least one virtual switch.
|
||||
|
||||
A virtual switch is required for Vagrant to create a Hyper-V
|
||||
machine that is connected to a network so it can access it.
|
||||
|
||||
For more help, please see the documentation on the Vagrant website
|
||||
for Hyper-V.
|
||||
powershell_error: |-
|
||||
An error occurred while executing a PowerShell script. This error
|
||||
is shown below. Please read the error message and see if this is
|
||||
|
|
Loading…
Reference in New Issue