Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #294 from bkkrw/lxc-attach_support
Browse files Browse the repository at this point in the history
Add fallback mechanism for platforms without attach support
  • Loading branch information
fgrehm committed Jun 9, 2014
2 parents 3a4c0ca + a4768c2 commit 3fe6cc0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/vagrant-lxc/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,14 @@ def self.action_package
def self.action_fetch_ip
Builder.new.tap do |b|
b.use Builtin::ConfigValidate
b.use FetchIpWithLxcAttach
b.use FetchIpFromDnsmasqLeases
b.use Builtin::Call, Builtin::IsState, :running do |env, b2|
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

Expand Down
4 changes: 4 additions & 0 deletions lib/vagrant-lxc/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def destroy
@cli.destroy
end

def supports_attach?
@cli.supports_attach?
end

def attach(*command)
@cli.attach(*command)
end
Expand Down
15 changes: 14 additions & 1 deletion lib/vagrant-lxc/driver/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def start(options = [])
end

def stop
attach '/sbin/halt'
attach '/sbin/halt' if supports_attach?
run :stop, '--name', @name
end

Expand Down Expand Up @@ -126,6 +126,19 @@ def transition_to(target_state, tries = 30, timeout = 1, &block)
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

def run(command, *args)
Expand Down

0 comments on commit 3fe6cc0

Please sign in to comment.