diff --git a/lib/vagrant-lxc/config.rb b/lib/vagrant-lxc/config.rb index 2dc5e3a..b03f662 100644 --- a/lib/vagrant-lxc/config.rb +++ b/lib/vagrant-lxc/config.rb @@ -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 = [] + @start_opts = [] + @lxc_dhcp_ip = '10.0.3.1' end end end diff --git a/lib/vagrant-lxc/container.rb b/lib/vagrant-lxc/container.rb index 223459a..3de6be3 100644 --- a/lib/vagrant-lxc/container.rb +++ b/lib/vagrant-lxc/container.rb @@ -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 diff --git a/lib/vagrant-lxc/provider.rb b/lib/vagrant-lxc/provider.rb index 43f6a63..a4d8d3b 100644 --- a/lib/vagrant-lxc/provider.rb +++ b/lib/vagrant-lxc/provider.rb @@ -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 diff --git a/spec/unit/container_spec.rb b/spec/unit/container_spec.rb index 0d0d4e8..5dff6f2 100644 --- a/spec/unit/container_spec.rb +++ b/spec/unit/container_spec.rb @@ -181,8 +181,9 @@ describe Vagrant::LXC::Container do end describe 'dhcp ip' do - let(:name) { 'random-container-name' } - let(:ip) { "10.0.3.123" } + let(:name) { 'random-container-name' } + 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