Merge pull request #352 from ccope/private_dhcp

Support private networking using DHCP
This commit is contained in:
Fabio Rehm 2015-04-06 10:56:38 -03:00
commit 55bbadef6f
2 changed files with 20 additions and 10 deletions

View file

@ -26,16 +26,19 @@ module Vagrant
next if type.to_sym != :private_network next if type.to_sym != :private_network
container_name = env[:machine].provider.driver.container_name container_name = env[:machine].provider.driver.container_name
address_type = config[:type]
ip = config[:ip] ip = config[:ip]
bridge_ip = config.fetch(:lxc__bridge_ip) { build_bridge_ip(ip) } bridge_ip = config.fetch(:lxc__bridge_ip) { build_bridge_ip(ip) }
bridge = config.fetch(:lxc__bridge_name) bridge = config.fetch(:lxc__bridge_name)
env[:machine].provider.driver.configure_private_network(bridge, bridge_ip, container_name, ip) env[:machine].provider.driver.configure_private_network(bridge, bridge_ip, container_name, address_type, ip)
end end
end end
def build_bridge_ip(ip) def build_bridge_ip(ip)
ip.sub(/^(\d+\.\d+\.\d+)\.\d+/, '\1.254') if ip
ip.sub(/^(\d+\.\d+\.\d+)\.\d+/, '\1.254')
end
end end
end end
end end

View file

@ -128,17 +128,16 @@ module Vagrant
@cli.attach(*command) @cli.attach(*command)
end end
def configure_private_network(bridge_name, bridge_ip, container_name, ip) def configure_private_network(bridge_name, bridge_ip, container_name, address_type, ip)
@logger.info "Configuring network interface for #{container_name} using #{ip} and bridge #{bridge_name}" @logger.info "Configuring network interface for #{container_name} using #{ip} and bridge #{bridge_name}"
cmd = [ if ip
Vagrant::LXC.source_root.join('scripts/pipework').to_s, ip += '/24'
bridge_name, end
container_name,
"#{ip}/24"
]
@sudo_wrapper.run(*cmd)
if ! bridge_has_an_ip?(bridge_name) if ! bridge_has_an_ip?(bridge_name)
if not bridge_ip
raise "Bridge has no IP and none was specified!"
end
@logger.info "Adding #{bridge_ip} to the bridge #{bridge_name}" @logger.info "Adding #{bridge_ip} to the bridge #{bridge_name}"
cmd = [ cmd = [
'ip', 'ip',
@ -150,6 +149,14 @@ module Vagrant
] ]
@sudo_wrapper.run(*cmd) @sudo_wrapper.run(*cmd)
end end
cmd = [
Vagrant::LXC.source_root.join('scripts/pipework').to_s,
bridge_name,
container_name,
ip ||= "dhcp"
]
@sudo_wrapper.run(*cmd)
end end
def bridge_has_an_ip?(bridge_name) def bridge_has_an_ip?(bridge_name)