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] # @return [Array]
attr_reader :start_opts 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 def initialize
@start_opts = [] @start_opts = []
@lxc_dhcp_ip = '10.0.3.1'
end end
end end
end end

View file

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

View file

@ -52,7 +52,7 @@ module Vagrant
return nil if state == :not_created 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) :port => 22 # @driver.ssh_port(@machine.config.ssh.guest_port)
} }
end end

View file

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