Improve checking for support for fetching IP with lxc-attach
[GH-118]
This commit is contained in:
parent
a087023365
commit
f9dd5392ff
3 changed files with 11 additions and 10 deletions
|
@ -12,20 +12,14 @@ module Vagrant
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
env[:machine_ip] ||= assigned_ip(env)
|
env[:machine_ip] ||= assigned_ip(env)
|
||||||
rescue LXC::Errors::ExecuteError
|
rescue LXC::Errors::NamespacesNotSupported
|
||||||
@logger.info 'Unable to fetch IP with `lxc-attach`!'
|
@logger.info 'The `lxc-attach` command available does not support the --namespaces parameter, falling back to dnsmasq leases to fetch container ip'
|
||||||
ensure
|
ensure
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assigned_ip(env)
|
def assigned_ip(env)
|
||||||
driver = env[:machine].provider.driver
|
driver = env[:machine].provider.driver
|
||||||
version = driver.version.match(/^(\d+\.\d+)\./)[1].to_f
|
|
||||||
unless version >= 0.8
|
|
||||||
@logger.debug "lxc version does not support the --namespaces argument to lxc-attach"
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
ip = ''
|
ip = ''
|
||||||
retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 3) do
|
retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 3) do
|
||||||
unless ip = get_container_ip_from_ip_addr(driver)
|
unless ip = get_container_ip_from_ip_addr(driver)
|
||||||
|
|
|
@ -81,7 +81,12 @@ module Vagrant
|
||||||
if cmd.last.is_a?(Hash)
|
if cmd.last.is_a?(Hash)
|
||||||
opts = cmd.pop
|
opts = cmd.pop
|
||||||
namespaces = Array(opts[:namespaces]).map(&:upcase).join('|')
|
namespaces = Array(opts[:namespaces]).map(&:upcase).join('|')
|
||||||
|
|
||||||
|
if run(:attach, '-h').include?('--namespaces')
|
||||||
extra = ['--namespaces', namespaces] if namespaces
|
extra = ['--namespaces', namespaces] if namespaces
|
||||||
|
else
|
||||||
|
raise LXC::Errors::NamespacesNotSupported
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
run :attach, '--name', @name, *((extra || []) + cmd)
|
run :attach, '--name', @name, *((extra || []) + cmd)
|
||||||
|
|
|
@ -6,6 +6,8 @@ module Vagrant
|
||||||
class ExecuteError < Vagrant::Errors::VagrantError
|
class ExecuteError < Vagrant::Errors::VagrantError
|
||||||
error_key(:lxc_execute_error)
|
error_key(:lxc_execute_error)
|
||||||
end
|
end
|
||||||
|
class NamespacesNotSupported < Vagrant::Errors::VagrantError
|
||||||
|
end
|
||||||
|
|
||||||
class LxcNotInstalled < Vagrant::Errors::VagrantError
|
class LxcNotInstalled < Vagrant::Errors::VagrantError
|
||||||
error_key(:lxc_not_installed)
|
error_key(:lxc_not_installed)
|
||||||
|
|
Loading…
Add table
Reference in a new issue