Merge pull request #5207 from mwrock/switch_name

select a Hyper-V switch based on a network_name
This commit is contained in:
Seth Vargo 2015-05-30 11:45:09 -07:00
commit 39a1a5c7ba
1 changed files with 31 additions and 15 deletions

View File

@ -55,23 +55,39 @@ module VagrantPlugins
switches = env[:machine].provider.driver.execute("get_switches.ps1", {}) switches = env[:machine].provider.driver.execute("get_switches.ps1", {})
raise Errors::NoSwitches if switches.empty? raise Errors::NoSwitches if switches.empty?
switch = switches[0]["Name"] switch = nil
if switches.length > 1 env[:machine].config.vm.networks.each do |type, opts|
env[:ui].detail(I18n.t("vagrant_hyperv.choose_switch") + "\n ") next if type != :public_network && type != :private_network
switches.each_index do |i|
switch = switches[i]
env[:ui].detail("#{i+1}) #{switch["Name"]}")
end
env[:ui].detail(" ")
switch = nil switchToFind = opts[:bridge]
while !switch
switch = env[:ui].ask("What switch would you like to use? ") if switchToFind
next if !switch puts "Looking for switch with name: #{switchToFind}"
switch = switch.to_i - 1 switch = switches.find { |s| s["Name"].downcase == switchToFind.downcase }["Name"]
switch = nil if switch < 0 || switch >= switches.length puts "Found switch: #{switch}"
end
end
if switch.nil?
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"]
else
switch = switches[0]["Name"]
end end
switch = switches[switch]["Name"]
end end
env[:ui].detail("Cloning virtual hard drive...") env[:ui].detail("Cloning virtual hard drive...")