Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #352 from ccope/private_dhcp
Browse files Browse the repository at this point in the history
Support private networking using DHCP
  • Loading branch information
fgrehm committed Apr 6, 2015
2 parents f52df5d + 5da3fc8 commit 55bbade
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
7 changes: 5 additions & 2 deletions lib/vagrant-lxc/action/private_networks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ def configure_private_networks(env)
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)

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

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
Expand Down
23 changes: 15 additions & 8 deletions lib/vagrant-lxc/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,16 @@ def attach(*command)
@cli.attach(*command)
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}"
cmd = [
Vagrant::LXC.source_root.join('scripts/pipework').to_s,
bridge_name,
container_name,
"#{ip}/24"
]
@sudo_wrapper.run(*cmd)
if ip
ip += '/24'
end

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}"
cmd = [
'ip',
Expand All @@ -150,6 +149,14 @@ def configure_private_network(bridge_name, bridge_ip, container_name, ip)
]
@sudo_wrapper.run(*cmd)
end

cmd = [
Vagrant::LXC.source_root.join('scripts/pipework').to_s,
bridge_name,
container_name,
ip ||= "dhcp"
]
@sudo_wrapper.run(*cmd)
end

def bridge_has_an_ip?(bridge_name)
Expand Down

0 comments on commit 55bbade

Please sign in to comment.