Enabling bridged networks on Debian

This commit is contained in:
Mitchell Hashimoto 2011-12-31 11:53:04 -08:00
parent 42883cbd20
commit 474ac3a63d
6 changed files with 65 additions and 8 deletions

View File

@ -42,8 +42,10 @@ module Vagrant
@env[:ui].info I18n.t("vagrant.actions.vm.bridged_networking.enabling")
# Prepare for new networks
@env[:vm].guest.prepare_bridged_networks(networks)
# Enable the networks
@env[:vm].guest.enable_bridged_networks(networks)
end
end

View File

@ -79,8 +79,22 @@ module Vagrant
# @param [Hash] net_options The options for the network.
def enable_host_only_network(net_options); end
# Prepares the guest for bridged networks.
#
# @param [Array] networks Array of networks to prepare for.
def prepare_bridged_networks(networks)
raise BaseError, :_key => :unsupported_host_only
end
# Enable bridged networks on a guest.
#
# @param [Array] networks Array of networks to prepare for.
def enable_bridged_networks(networks)
raise BaseError, :_key => :unsupported_bridged
end
def change_host_name(name)
raise BaseError, :_key => :unsupported_host_name
raise BaseError, :_key => :unsupported_bridged
end
end
end

View File

@ -2,17 +2,16 @@ module Vagrant
module Guest
class Debian < Linux
def prepare_host_only_network(net_options=nil)
# Remove any previous host only network additions to the
# interface file.
# Remove any previous host only network additions to the interface file.
vm.ssh.execute do |ssh|
# Clear out any previous entries
ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces")
ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-HOSTONLY/,/^#VAGRANT-END-HOSTONLY/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces")
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'")
end
end
def enable_host_only_network(net_options)
entry = TemplateRenderer.render('network_entry_debian', :net_options => net_options)
entry = TemplateRenderer.render('guests/debian/network_hostonly',
:net_options => net_options)
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
vm.ssh.execute do |ssh|
@ -22,6 +21,33 @@ module Vagrant
end
end
def prepare_bridged_networks(networks)
# Remove any previous bridged network additions to the interface file.
vm.ssh.execute do |ssh|
ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-BRIDGED/,/^#VAGRANT-END-BRIDGED/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces")
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'")
end
end
def enable_bridged_networks(networks)
entry = TemplateRenderer.render('guests/debian/network_bridged',
:networks => networks)
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
vm.ssh.execute do |ssh|
networks.each do |network|
ssh.exec!("sudo /sbin/ifdown eth#{network[:adapter]} 2> /dev/null")
end
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/network/interfaces'")
networks.each do |network|
ssh.exec!("sudo /sbin/ifup eth#{network[:adapter]}")
end
end
end
def change_host_name(name)
vm.ssh.execute do |ssh|
if !ssh.test?("sudo hostname | grep '#{name}'")

View File

@ -0,0 +1,7 @@
<% networks.each do |network| -%>
#VAGRANT-BEGIN-BRIDGED
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth<%= network[:adapter] %>
iface eth<%= network[:adapter] %> inet dhcp
#VAGRANT-END-BRIDGED
<% end -%>

View File

@ -1,8 +1,8 @@
#VAGRANT-BEGIN
#VAGRANT-BEGIN-HOSTONLY
# The contents below are automatically generated by Vagrant.
# Please do not modify any of these contents.
auto eth<%= net_options[:adapter] %>
iface eth<%= net_options[:adapter] %> inet static
address <%= net_options[:ip] %>
netmask <%= net_options[:netmask] %>
#VAGRANT-END
#VAGRANT-END-HOSTONLY

View File

@ -564,6 +564,14 @@ en:
guest:
base:
unsupported_bridged: |-
Bridged networking is very distro-specific. Vagrant has support for many
distros built-in: Debian, Ubuntu, Gentoo, and RedHat. The distro of your VM
couldn't be detected, or isn't supported for host only networking.
Most of the time this is simply due to the fact that no one has contributed
back the SSH commands necessary to set this up. Please report a bug and this
will be fixed for your distro.
unsupported_host_only: |-
Host only networking is very distro-specific. Vagrant has support for many
distros built-in: Debian, Ubuntu, Gentoo, and RedHat. The distro of your VM