diff --git a/lib/vagrant/action/vm/bridged_network.rb b/lib/vagrant/action/vm/bridged_network.rb index 946fa6a2d..7a1c8be57 100644 --- a/lib/vagrant/action/vm/bridged_network.rb +++ b/lib/vagrant/action/vm/bridged_network.rb @@ -68,12 +68,31 @@ module Vagrant def determine_bridged_interface(networks) bridgedifs = @env[:vm].driver.read_bridged_interfaces + # Output all the interfaces that are available for choices + @env[:ui].info I18n.t("vagrant.actions.vm.bridged_networking.available", + :prefix => false) + + bridgedifs.each_index do |index| + interface = bridgedifs[index] + + @env[:ui].info("#{index + 1}) #{interface[:name]}", :prefix => false) + end + + valid = Range.new(1, bridgedifs.length) + results = [] networks.each do |network| - # TODO: Allow choosing the bridged interface. For now, we just use the - # first one blindly. + option = nil + while !valid.include?(option) + option = @env[:ui].ask("What network should adapter #{network[:adapter]} bridge to? ") + + # We need the numeric value since it will be an index + option = option.to_i + end + + # Duplicate the options so that we return a new dictionary options = network.dup - options[:bridge] = bridgedifs[0][:name] + options[:bridge] = bridgedifs[option - 1][:name] @logger.info("Bridging #{options[:adapter]} => #{options[:bridge]}") results << options diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index a1b3d4727..d026b8725 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -17,7 +17,7 @@ module Vagrant @resource = resource end - [:warn, :error, :info, :success].each do |method| + [:ask, :warn, :error, :info, :success].each do |method| define_method(method) do |message, *opts| # Log normal console messages @logger.info { "#{method}: #{message}" } @@ -48,6 +48,21 @@ module Vagrant CODE end + def ask(message, opts=nil) + super(message) + + # Setup the options so that the new line is suppressed + opts ||= {} + opts[:new_line] = false if !opts.has_key?(:new_line) + opts[:prefix] = false if !opts.has_key?(:prefix) + + # Output the data + say(:info, message, opts) + + # Get the results and chomp off the newline + STDIN.gets.chomp + end + # This is used to output progress reports to the UI. # Send this method progress/total and it will output it # to the UI. Send `clear_line` to clear the line to show diff --git a/templates/locales/en.yml b/templates/locales/en.yml index d24cc859a..13a0e5bae 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -281,6 +281,8 @@ en: Failed to connect to VM via SSH. Please verify the VM successfully booted by looking at the VirtualBox GUI. bridged_networking: + available: |- + Available bridged network interfaces: bridging: |- Bridging adapter #%{adapter} to '%{bridge}' enabling: |-