Permalink
Browse files

If there is only one bridgable interface, just use that [GH-655]

  • Loading branch information...
1 parent f022e9e commit 4ead6e3f8205879f97919b829f52daeb600ea134 @mitchellh mitchellh committed Jan 20, 2012
Showing with 28 additions and 15 deletions.
  1. +2 −0 CHANGELOG.md
  2. +26 −15 lib/vagrant/action/vm/network.rb
View
@@ -13,6 +13,8 @@
the behavior seems different/wrong.
- Give a nice error if `:vagrant` is used as a JSON key, since Vagrant
uses this. [GH-661]
+ - If there is only one bridgable interface, use that without asking
+ the user. [GH-655]
## 0.9.1 (January 18, 2012)
@@ -314,29 +314,40 @@ def bridged_config(args)
def bridged_adapter(config)
bridgedifs = @env[:vm].driver.read_bridged_interfaces
- # Output all the interfaces that are available as 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
+ chosen_bridge = nil
+ if bridgedifs.length == 1
+ # One bridgable interface? Just use it.
+ chosen_bridge = bridgedifs[0][:name]
+ else
+ # More than one bridgable interface requires a user decision, so
+ # show options to choose from.
+ @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
- # The range of valid choices
- valid = Range.new(1, bridgedifs.length)
+ # The range of valid choices
+ valid = Range.new(1, bridgedifs.length)
- # The choice that the user has chosen as the bridging interface
- choice = nil
- while !valid.include?(choice)
- choice = @env[:ui].ask("What interface should the network bridge to? ")
- choice = choice.to_i
+ # The choice that the user has chosen as the bridging interface
+ choice = nil
+ while !valid.include?(choice)
+ choice = @env[:ui].ask("What interface should the network bridge to? ")
+ choice = choice.to_i
+ end
+
+ chosen_bridge = bridgedifs[choice - 1][:name]
end
+ @logger.info("Bridging adapter #{config[:adapter]} to #{bridge}")
+
# Given the choice we can now define the adapter we're using
return {
:adapter => config[:adapter],
:type => :bridged,
- :bridge => bridgedifs[choice - 1][:name],
+ :bridge => chosen_bridge,
:mac_address => config[:mac]
}
end

0 comments on commit 4ead6e3

Please sign in to comment.