redhat distribution implemention for host only network

This commit is contained in:
Michael Bearne 2010-12-16 13:30:44 +00:00
parent 135de3f0ec
commit d143fa965e
7 changed files with 79 additions and 34 deletions

View File

@ -1,8 +1,8 @@
GIT
remote: git://github.com/mitchellh/virtualbox.git
revision: 041996145591d20acf3e04fef3d4709f826d878a
revision: c79de55b05dd5703fa157e9900efecaaf1da5861
specs:
virtualbox (0.7.6.dev)
virtualbox (0.7.8.dev)
ffi (~> 0.6.3)
PATH
@ -25,28 +25,28 @@ GEM
abstract (1.0.0)
archive-tar-minitar (0.5.2)
bluecloth (2.0.9)
columnize (0.3.1)
columnize (0.3.2)
contest (0.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
ffi (0.6.3)
rake (>= 0.8.7)
i18n (0.4.1)
i18n (0.4.2)
json (1.4.6)
linecache (0.43)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
mario (0.0.6)
mocha (0.9.8)
mocha (0.9.10)
rake
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-ssh (2.0.23)
rake (0.8.7)
ruby-debug (0.10.3)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.3.0)
ruby-debug-base (0.10.3)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-debug-base19 (0.11.24)
columnize (>= 0.3.1)
@ -58,8 +58,8 @@ GEM
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.4)
archive-tar-minitar (>= 0.5.2)
thor (0.14.3)
yard (0.6.1)
thor (0.14.6)
yard (0.6.3)
PLATFORMS
ruby

View File

@ -21,8 +21,8 @@ module Vagrant
if enable_network?
@env.ui.info I18n.t("vagrant.actions.vm.network.enabling")
@env["vm"].system.prepare_host_only_network
@env.env.config.vm.network_options.compact.each do |network_options|
@env["vm"].system.prepare_host_only_network(network_options)
@env["vm"].system.enable_host_only_network(network_options)
end
end

View File

@ -62,27 +62,39 @@ module Vagrant
end
end
def prepare_host_only_network
def prepare_host_only_network(net_options)
# Remove any previous host only network additions to the
# interface file.
vm.ssh.execute do |ssh|
# Verify debian/ubuntu
ssh.exec!("cat /etc/debian_version", :error_class => LinuxError, :_key => :network_not_debian)
# 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 su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'")
case distribution(ssh)
when :debian
# 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 su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'")
when :redhat
ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/sysconfig/network-scripts/ifcfg-eth#{net_options[:adapter]} > /tmp/vagrant-ifcfg-eth#{net_options[:adapter]}")
ssh.exec!("sudo su -c 'cat /tmp/vagrant-ifcfg-eth#{net_options[:adapter]} > /etc/sysconfig/network-scripts/ifcfg-eth#{net_options[:adapter]}'")
end
end
end
def enable_host_only_network(net_options)
entry = TemplateRenderer.render('network_entry', :net_options => net_options)
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
vm.ssh.execute do |ssh|
case distribution(ssh)
when :debian
entry = TemplateRenderer.render('debian_network_entry', :net_options => net_options)
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null")
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/network/interfaces'")
ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}")
vm.ssh.execute do |ssh|
ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null")
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/network/interfaces'")
ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}")
when :redhat
entry = TemplateRenderer.render('redhat_network_entry', :net_options => net_options)
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null")
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/sysconfig/network-scripts/ifcfg-eth#{net_options[:adapter]}'")
ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}")
end
end
end
@ -110,6 +122,30 @@ module Vagrant
sleep sleeptime
end
end
def debian?(ssh)
ssh.exec!("test -e /etc/debian_version") do |ch, type, data|
return true if type == :exit_status && data == 0
end
false
end
def redhat?(ssh)
ssh.exec!("test -e /etc/redhat-release ") do |ch, type, data|
return true if type == :exit_status && data == 0
end
false
end
def distribution(ssh)
if debian?(ssh)
:debian
elsif redhat?(ssh)
:redhat
else
raise LinuxError.new(:distribution_not_supported)
end
end
end
class Linux < Base

BIN
templates/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -432,16 +432,17 @@ en:
systems:
linux:
attempting_halt: "Attempting graceful shutdown of linux..."
mount_fail: "Failed to mount shared folders. `vboxsf` was not available."
network_not_debian: |-
Host only networking is only supported for Debian/Ubuntu by the built-in
"Linux" system. If you're using some other distro and want to implement
host only networking, please subclass the `Vagrant::Systems::Linux` class
and implement the `prepare_host_only_network` and `enable_host_only_network`
methods.
mount_fail: "Failed to mount shared folders. `vboxsf` was not available."
distribution_not_supported: |-
Host only networking is only supported for Debian/Ubuntu and Redhat Distributions by the built-in
"Linux" system. If you're using some other distro and want to implement
host only networking, please subclass the `Vagrant::Systems::Linux` class
and implement the `prepare_host_only_network` and `enable_host_only_network`
methods.
Otherwise, please report your distro and how to modify network interfaces
to the Vagrant mailing list or IRC and we'll probably be glad to add it
to the internal systems.
Otherwise, please report your distro and how to modify network interfaces
to the Vagrant mailing list or IRC and we'll probably be glad to add it
to the internal systems.
solaris:
attempting_halt: "Attempting graceful shutdown of solaris..."

View File

@ -0,0 +1,8 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant.
# Please do not modify any of these contents.
BOOTPROTO=static
DHCPCLASS=
IPADDR=<%= net_options[:ip] %>
NETMASK=<%= net_options[:netmask] %>
#VAGRANT-END