support containers with dhcp private networking
This commit is contained in:
parent
c9cd671a32
commit
5da3fc8be5
2 changed files with 20 additions and 10 deletions
|
@ -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
|
||||||
|
|
|
@ -140,17 +140,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',
|
||||||
|
@ -162,6 +161,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)
|
||||||
|
|
Loading…
Reference in a new issue