Merge pull request #294 from bkkrw/lxc-attach_support
Add fallback mechanism for platforms without attach support
This commit is contained in:
commit
3fe6cc094e
3 changed files with 26 additions and 3 deletions
|
@ -197,8 +197,14 @@ module Vagrant
|
||||||
def self.action_fetch_ip
|
def self.action_fetch_ip
|
||||||
Builder.new.tap do |b|
|
Builder.new.tap do |b|
|
||||||
b.use Builtin::ConfigValidate
|
b.use Builtin::ConfigValidate
|
||||||
b.use FetchIpWithLxcAttach
|
b.use Builtin::Call, Builtin::IsState, :running do |env, b2|
|
||||||
b.use FetchIpFromDnsmasqLeases
|
if env[:result]
|
||||||
|
b2.use FetchIpWithLxcAttach if env[:machine].provider.driver.supports_attach?
|
||||||
|
b2.use FetchIpFromDnsmasqLeases
|
||||||
|
else
|
||||||
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,10 @@ module Vagrant
|
||||||
@cli.destroy
|
@cli.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def supports_attach?
|
||||||
|
@cli.supports_attach?
|
||||||
|
end
|
||||||
|
|
||||||
def attach(*command)
|
def attach(*command)
|
||||||
@cli.attach(*command)
|
@cli.attach(*command)
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,7 +77,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
attach '/sbin/halt'
|
attach '/sbin/halt' if supports_attach?
|
||||||
run :stop, '--name', @name
|
run :stop, '--name', @name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -126,6 +126,19 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def supports_attach?
|
||||||
|
unless defined?(@supports_attach)
|
||||||
|
begin
|
||||||
|
@supports_attach = true
|
||||||
|
run(:attach, '--name', @name, 'true')
|
||||||
|
rescue LXC::Errors::ExecuteError
|
||||||
|
@supports_attach = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return @supports_attach
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def run(command, *args)
|
def run(command, *args)
|
||||||
|
|
Loading…
Reference in a new issue