add interface option for pipework script + iterate the networks

This commit is contained in:
Christophe Angeli 2016-01-16 18:49:22 +01:00
parent aa5fb7a932
commit 16a555ceec
2 changed files with 15 additions and 9 deletions

View file

@ -22,16 +22,17 @@ module Vagrant
end end
def configure_private_networks(env) def configure_private_networks(env)
env[:machine].config.vm.networks.find do |type, config| env[:machine].config.vm.networks.find_all.each do |type, config|
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
container_interface = config[:interface]
address_type = config[:type] 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, address_type, ip) env[:machine].provider.driver.configure_private_network(bridge, bridge_ip, container_name, container_interface, address_type, ip)
end end
end end

View file

@ -126,8 +126,11 @@ module Vagrant
@cli.attach(*command) @cli.attach(*command)
end end
def configure_private_network(bridge_name, bridge_ip, container_name, address_type, ip) def configure_private_network(bridge_name, bridge_ip, container_name, container_interface, address_type, ip)
@logger.info "Configuring network interface for #{container_name} using #{ip} and bridge #{bridge_name}" if ! container_interface
container_interface = "eth1"
end
@logger.info "Configuring network interface #{container_interface} for #{container_name} using #{ip} and bridge #{bridge_name}"
if ip if ip
ip += '/24' ip += '/24'
end end
@ -166,6 +169,8 @@ module Vagrant
cmd = [ cmd = [
Vagrant::LXC.source_root.join('scripts/pipework').to_s, Vagrant::LXC.source_root.join('scripts/pipework').to_s,
bridge_name, bridge_name,
"-i",
container_interface,
container_name, container_name,
ip ||= "dhcp" ip ||= "dhcp"
] ]