Support alternative lxcpath in sudo wrapper
The previously hardcoded lxc path prevented the sudo wrapper from working in environment with alternative `lxcpath`. I had to move `sudo_wrapper` from `provider` to `LXC` because the concept of "provider" is tied to a machine when a command sush as `sudoers` is not. Fixes #413 and #399
This commit is contained in:
parent
2ce460bc30
commit
10c53c54d7
4 changed files with 14 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
require "vagrant-lxc/version"
|
require "vagrant-lxc/version"
|
||||||
require "vagrant-lxc/plugin"
|
require "vagrant-lxc/plugin"
|
||||||
|
require "vagrant-lxc/sudo_wrapper"
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
|
@ -10,5 +11,12 @@ module Vagrant
|
||||||
def self.sudo_wrapper_path
|
def self.sudo_wrapper_path
|
||||||
"/usr/local/bin/vagrant-lxc-wrapper"
|
"/usr/local/bin/vagrant-lxc-wrapper"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.sudo_wrapper
|
||||||
|
wrapper = Pathname.new(sudo_wrapper_path).exist? &&
|
||||||
|
sudo_wrapper_path || nil
|
||||||
|
SudoWrapper.new(wrapper)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
|
|
||||||
|
require "vagrant-lxc/driver"
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
module Command
|
module Command
|
||||||
|
@ -43,11 +45,13 @@ module Vagrant
|
||||||
|
|
||||||
# This requires vagrant 1.5.2+ https://github.com/mitchellh/vagrant/commit/3371c3716278071680af9b526ba19235c79c64cb
|
# This requires vagrant 1.5.2+ https://github.com/mitchellh/vagrant/commit/3371c3716278071680af9b526ba19235c79c64cb
|
||||||
def create_wrapper!
|
def create_wrapper!
|
||||||
|
lxc_base_path = Driver.new(0, LXC.sudo_wrapper).containers_path
|
||||||
wrapper = Tempfile.new('lxc-wrapper').tap do |file|
|
wrapper = Tempfile.new('lxc-wrapper').tap do |file|
|
||||||
template = Vagrant::Util::TemplateRenderer.new(
|
template = Vagrant::Util::TemplateRenderer.new(
|
||||||
'sudoers.rb',
|
'sudoers.rb',
|
||||||
:template_root => Vagrant::LXC.source_root.join('templates').to_s,
|
:template_root => Vagrant::LXC.source_root.join('templates').to_s,
|
||||||
:cmd_paths => build_cmd_paths_hash,
|
:cmd_paths => build_cmd_paths_hash,
|
||||||
|
:lxc_base_path => lxc_base_path,
|
||||||
:pipework_regex => "#{ENV['HOME']}/\.vagrant\.d/gems/(?:\\d+?\\.\\d+?\\.\\d+?/)?gems/vagrant-lxc.+/scripts/pipework"
|
:pipework_regex => "#{ENV['HOME']}/\.vagrant\.d/gems/(?:\\d+?\\.\\d+?\\.\\d+?/)?gems/vagrant-lxc.+/scripts/pipework"
|
||||||
)
|
)
|
||||||
file.puts template.render
|
file.puts template.render
|
||||||
|
|
|
@ -2,7 +2,6 @@ require "log4r"
|
||||||
|
|
||||||
require "vagrant-lxc/action"
|
require "vagrant-lxc/action"
|
||||||
require "vagrant-lxc/driver"
|
require "vagrant-lxc/driver"
|
||||||
require "vagrant-lxc/sudo_wrapper"
|
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
|
@ -26,12 +25,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def sudo_wrapper
|
def sudo_wrapper
|
||||||
@shell ||= begin
|
@shell ||= LXC.sudo_wrapper
|
||||||
wrapper = Pathname.new(LXC.sudo_wrapper_path).exist? &&
|
|
||||||
LXC.sudo_wrapper_path || nil
|
|
||||||
@logger.debug("Found sudo wrapper : #{wrapper}") if wrapper
|
|
||||||
SudoWrapper.new(wrapper)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_lxc_installed!
|
def ensure_lxc_installed!
|
||||||
|
|
|
@ -78,7 +78,7 @@ class Whitelist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
base = "/var/lib/lxc"
|
base = "<%= lxc_base_path %>"
|
||||||
base_path = %r{\A#{base}/.*\z}
|
base_path = %r{\A#{base}/.*\z}
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
Loading…
Reference in a new issue