From 16a555ceec857570cd7217592b2710bb66beb48b Mon Sep 17 00:00:00 2001 From: Christophe Angeli Date: Sat, 16 Jan 2016 18:49:22 +0100 Subject: [PATCH] add interface option for pipework script + iterate the networks --- lib/vagrant-lxc/action/private_networks.rb | 15 ++++++++------- lib/vagrant-lxc/driver.rb | 9 +++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/vagrant-lxc/action/private_networks.rb b/lib/vagrant-lxc/action/private_networks.rb index f96f76d..e6f3bda 100644 --- a/lib/vagrant-lxc/action/private_networks.rb +++ b/lib/vagrant-lxc/action/private_networks.rb @@ -22,16 +22,17 @@ module Vagrant end 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 - container_name = env[:machine].provider.driver.container_name - address_type = config[:type] - ip = config[:ip] - bridge_ip = config.fetch(:lxc__bridge_ip) { build_bridge_ip(ip) } - bridge = config.fetch(:lxc__bridge_name) + container_name = env[:machine].provider.driver.container_name + container_interface = config[:interface] + address_type = config[:type] + ip = config[:ip] + bridge_ip = config.fetch(:lxc__bridge_ip) { build_bridge_ip(ip) } + 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 diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index e2304bf..ff86f0e 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -126,8 +126,11 @@ module Vagrant @cli.attach(*command) end - 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}" + def configure_private_network(bridge_name, bridge_ip, container_name, container_interface, address_type, ip) + 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 ip += '/24' end @@ -166,6 +169,8 @@ module Vagrant cmd = [ Vagrant::LXC.source_root.join('scripts/pipework').to_s, bridge_name, + "-i", + container_interface, container_name, ip ||= "dhcp" ]