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)
|
||||
env[:machine_ip] ||= assigned_ip(env)
|
||||
rescue LXC::Errors::ExecuteError
|
||||
@logger.info 'Unable to fetch IP with `lxc-attach`!'
|
||||
rescue LXC::Errors::NamespacesNotSupported
|
||||
@logger.info 'The `lxc-attach` command available does not support the --namespaces parameter, falling back to dnsmasq leases to fetch container ip'
|
||||
ensure
|
||||
@app.call(env)
|
||||
end
|
||||
|
||||
def assigned_ip(env)
|
||||
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 = ''
|
||||
retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 3) do
|
||||
unless ip = get_container_ip_from_ip_addr(driver)
|
||||
|
|
|
@ -81,7 +81,12 @@ module Vagrant
|
|||
if cmd.last.is_a?(Hash)
|
||||
opts = cmd.pop
|
||||
namespaces = Array(opts[:namespaces]).map(&:upcase).join('|')
|
||||
|
||||
if run(:attach, '-h').include?('--namespaces')
|
||||
extra = ['--namespaces', namespaces] if namespaces
|
||||
else
|
||||
raise LXC::Errors::NamespacesNotSupported
|
||||
end
|
||||
end
|
||||
|
||||
run :attach, '--name', @name, *((extra || []) + cmd)
|
||||
|
|
|
@ -6,6 +6,8 @@ module Vagrant
|
|||
class ExecuteError < Vagrant::Errors::VagrantError
|
||||
error_key(:lxc_execute_error)
|
||||
end
|
||||
class NamespacesNotSupported < Vagrant::Errors::VagrantError
|
||||
end
|
||||
|
||||
class LxcNotInstalled < Vagrant::Errors::VagrantError
|
||||
error_key(:lxc_not_installed)
|
||||
|
|
Loading…
Reference in a new issue