First stab at handling a custom lxc-dhcp IP

Will help on #23
This commit is contained in:
Fabio Rehm 2013-03-08 02:19:48 -03:00
parent 3e7488f613
commit 9a168950fe
4 changed files with 17 additions and 9 deletions

View file

@ -6,8 +6,15 @@ module Vagrant
# @return [Array]
attr_reader :start_opts
# The ip set for the built in LXC dhcp server (defaults to configured ip
# at /etc/default/lxc or 10.0.3.1)
#
# @return [String]
attr_accessor :lxc_dhcp_ip
def initialize
@start_opts = []
@lxc_dhcp_ip = '10.0.3.1'
end
end
end

View file

@ -115,7 +115,7 @@ module Vagrant
end
end
def dhcp_ip
def dhcp_ip(server_ip)
ip = ''
# Right after creation lxc reports the container as running
# before DNS is returning the right IP, so have to wait for a while
@ -123,7 +123,7 @@ module Vagrant
# By default LXC supplies a dns server on 10.0.3.1 so we request the IP
# of our target from there.
# Tks to: https://github.com/neerolyte/vagueant/blob/master/bin/vagueant#L340
r = (raw 'dig', @name, '@10.0.3.1', '+short')
r = (raw 'dig', @name, "@#{server_ip}", '+short')
# If the command was a failure then raise an exception that is nicely
# handled by Vagrant.
@ -131,7 +131,7 @@ module Vagrant
if @interrupted
@logger.info("Exit code != 0, but interrupted. Ignoring.")
else
raise LXC::Errors::ExecuteError, :command => command.inspect
raise LXC::Errors::ExecuteError, :command => ['dig', @name, "@#{server_ip}", '+short'].inspect
end
end

View file

@ -52,7 +52,7 @@ module Vagrant
return nil if state == :not_created
{
:host => @container.dhcp_ip,
:host => @container.dhcp_ip(@machine.provider_config.lxc_dhcp_ip),
:port => 22 # @driver.ssh_port(@machine.config.ssh.guest_port)
}
end

View file

@ -182,7 +182,8 @@ describe Vagrant::LXC::Container do
describe 'dhcp ip' do
let(:name) { 'random-container-name' }
let(:ip) { "10.0.3.123" }
let(:ip) { "10.0.4.123" }
let(:server_ip) { "10.0.4.1" }
before do
subject.stub(:raw) {
@ -191,8 +192,8 @@ describe Vagrant::LXC::Container do
end
it 'digs the container ip from lxc dns server' do
subject.dhcp_ip.should == ip
subject.should have_received(:raw).with('dig', name, '@10.0.3.1', '+short')
subject.dhcp_ip(server_ip).should == ip
subject.should have_received(:raw).with('dig', name, "@#{server_ip}", '+short')
end
end
end