Compare commits
32 commits
Author | SHA1 | Date | |
---|---|---|---|
a47660a1e5 | |||
3575d65ffb | |||
|
938a29ed96 | ||
|
ff58ecd5f2 | ||
|
df6b78c4ed | ||
|
4d53acb9fb | ||
|
b88d50fb68 | ||
4e3306ed74 | |||
|
c167ac7f83 | ||
|
a112b072aa | ||
|
f750bf406c | ||
|
2a5510b34c | ||
|
a1aa60ded5 | ||
|
61c921ac6f | ||
|
437b5e7a2e | ||
|
2c2630a788 | ||
|
5a1f6ab2cb | ||
|
f71de429a1 | ||
|
50cbe5a0d6 | ||
|
44eefd81fb | ||
|
a84f8b59bf | ||
|
c1dd7baf2a | ||
|
8a1e1863a7 | ||
|
b812a6934a | ||
|
8cfe577b17 | ||
|
dd24cdc3d6 | ||
|
208edd49e5 | ||
|
484b868100 | ||
|
b5f2a9006c | ||
|
2e20f96fec | ||
|
d3409ace2a | ||
|
530a899467 |
21 changed files with 188 additions and 160 deletions
|
@ -3,6 +3,7 @@ rvm:
|
||||||
- 2.2
|
- 2.2
|
||||||
- 2.3
|
- 2.3
|
||||||
- 2.4
|
- 2.4
|
||||||
|
- 2.5
|
||||||
install:
|
install:
|
||||||
- gem install -v 1.12.5 bundler
|
- gem install -v 1.12.5 bundler
|
||||||
- bundle _1.12.5_ install --jobs=3 --retry=3
|
- bundle _1.12.5_ install --jobs=3 --retry=3
|
||||||
|
|
20
CHANGELOG.md
20
CHANGELOG.md
|
@ -1,3 +1,23 @@
|
||||||
|
## [1.4.2](https://github.com/fgrehm/vagrant-lxc/compare/v1.4.1...v1.4.2) (Jul 17, 2018)
|
||||||
|
|
||||||
|
FIXES:
|
||||||
|
- Fix problems with `redir` 3.x command line. [[GH-467]]
|
||||||
|
|
||||||
|
## [1.4.1](https://github.com/fgrehm/vagrant-lxc/compare/v1.4.0...v1.4.1) (Apr 30, 2018)
|
||||||
|
|
||||||
|
FEATURES:
|
||||||
|
- Add support for LXC v3.0
|
||||||
|
- Add support for `redir` 3.x command line. [[GH-460]]
|
||||||
|
|
||||||
|
[GH-460]: https://github.com/fgrehm/vagrant-lxc/issues/460
|
||||||
|
|
||||||
|
## [1.4.0](https://github.com/fgrehm/vagrant-lxc/compare/v1.3.1...v1.4.0) (Mar 04, 2018)
|
||||||
|
|
||||||
|
FEATURES:
|
||||||
|
- Add support for unprivileged containers. [[GH-312]]
|
||||||
|
|
||||||
|
[GH-312]: https://github.com/fgrehm/vagrant-lxc/issues/312
|
||||||
|
|
||||||
## [1.3.1](https://github.com/fgrehm/vagrant-lxc/compare/v1.3.0...v1.3.1) (Fev 06, 2018)
|
## [1.3.1](https://github.com/fgrehm/vagrant-lxc/compare/v1.3.0...v1.3.1) (Fev 06, 2018)
|
||||||
|
|
||||||
FIXES:
|
FIXES:
|
||||||
|
|
7
Gemfile
7
Gemfile
|
@ -1,7 +1,7 @@
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v1.8.7'
|
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
|
||||||
gem 'guard'
|
gem 'guard'
|
||||||
gem 'guard-rspec'
|
gem 'guard-rspec'
|
||||||
gem 'rb-inotify'
|
gem 'rb-inotify'
|
||||||
|
@ -9,10 +9,9 @@ end
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'rake', '~> 10.4.2'
|
gem 'rake', '~> 10.4.2'
|
||||||
gem 'rspec', '~> 2.99.0'
|
gem 'rspec', '~> 3.5.0'
|
||||||
gem 'coveralls', '~> 0.7.2', require: (ENV['COVERAGE'] == 'true')
|
gem 'coveralls', '~> 0.7.2', require: (ENV['COVERAGE'] == 'true')
|
||||||
# The is the ref *just* before we switch to childprocess 0.6, which conflicts with vagrant 1.8 deps.
|
gem 'vagrant-spec', git: 'https://github.com/mitchellh/vagrant-spec.git'
|
||||||
gem 'vagrant-spec', git: 'https://github.com/mitchellh/vagrant-spec.git', ref: '5006bc73cd8796465ca09307d4774f8ec8375aa0'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
group :plugins do
|
group :plugins do
|
||||||
|
|
41
README.md
41
README.md
|
@ -1,8 +1,12 @@
|
||||||
|
🟢 We plan to support and maintain vagrant-lxc, as well as clean it up.<br/>
|
||||||
|
🟢 Please feel free to contribute Issues and pull requests.<br/>
|
||||||
|
🟢 P.S: Thanks [Fabio Rehm](https://fabiorehm.com) for the amazing initial project.
|
||||||
|
|
||||||
# vagrant-lxc
|
# vagrant-lxc
|
||||||
|
|
||||||
[](https://travis-ci.org/fgrehm/vagrant-lxc) [](http://badge.fury.io/rb/vagrant-lxc) [](https://codeclimate.com/github/fgrehm/vagrant-lxc) [](https://coveralls.io/r/fgrehm/vagrant-lxc) [](https://gitter.im/fgrehm/vagrant-lxc)
|
[](https://travis-ci.org/fgrehm/vagrant-lxc) [](http://badge.fury.io/rb/vagrant-lxc) [](https://codeclimate.com/github/fgrehm/vagrant-lxc) [](https://coveralls.io/r/fgrehm/vagrant-lxc) [](https://gitter.im/fgrehm/vagrant-lxc)
|
||||||
|
|
||||||
[LXC](http://lxc.sourceforge.net/) provider for [Vagrant](http://www.vagrantup.com/) 1.8+
|
[LXC](http://lxc.sourceforge.net/) provider for [Vagrant](http://www.vagrantup.com/) 1.9+
|
||||||
|
|
||||||
This is a Vagrant plugin that allows it to control and provision Linux Containers
|
This is a Vagrant plugin that allows it to control and provision Linux Containers
|
||||||
as an alternative to the built in VirtualBox provider for Linux hosts. Check out
|
as an alternative to the built in VirtualBox provider for Linux hosts. Check out
|
||||||
|
@ -12,13 +16,13 @@ to see it in action.
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
* Provides the same workflow as the Vagrant VirtualBox provider
|
* Provides the same workflow as the Vagrant VirtualBox provider
|
||||||
* Port forwarding via [`redir`](http://linux.die.net/man/1/redir)
|
* Port forwarding via [`redir`](https://github.com/troglobit/redir)
|
||||||
* Private networking via [`pipework`](https://github.com/jpetazzo/pipework)
|
* Private networking via [`pipework`](https://github.com/jpetazzo/pipework)
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* [Vagrant 1.8+](http://www.vagrantup.com/downloads.html)
|
* [Vagrant 1.9+](http://www.vagrantup.com/downloads.html)
|
||||||
* lxc >=1.0
|
* lxc >=2.1
|
||||||
* `redir` (if you are planning to use port forwarding)
|
* `redir` (if you are planning to use port forwarding)
|
||||||
* `brctl` (if you are planning to use private networks, on Ubuntu this means `apt-get install bridge-utils`)
|
* `brctl` (if you are planning to use private networks, on Ubuntu this means `apt-get install bridge-utils`)
|
||||||
|
|
||||||
|
@ -51,8 +55,9 @@ _More information about skipping the `--provider` argument can be found at the
|
||||||
|
|
||||||
## Base boxes
|
## Base boxes
|
||||||
|
|
||||||
Base boxes can be found on [Atlas](https://atlas.hashicorp.com/boxes/search?provider=lxc)
|
Base boxes provided on Atlas haven't been refreshed for a good while and shouldn't be relied on.
|
||||||
and some scripts to build your own are available at [fgrehm/vagrant-lxc-base-boxes](https://github.com/fgrehm/vagrant-lxc-base-boxes).
|
Your best best is to build your boxes yourself. Some scripts to build your own are available at
|
||||||
|
[hsoft/vagrant-lxc-base-boxes](https://github.com/hsoft/vagrant-lxc-base-boxes).
|
||||||
|
|
||||||
If you want to build your own boxes, please have a look at [`BOXES.md`](https://github.com/fgrehm/vagrant-lxc/tree/master/BOXES.md)
|
If you want to build your own boxes, please have a look at [`BOXES.md`](https://github.com/fgrehm/vagrant-lxc/tree/master/BOXES.md)
|
||||||
for more information.
|
for more information.
|
||||||
|
@ -78,7 +83,7 @@ prior to starting it.
|
||||||
|
|
||||||
For other configuration options, please check the [lxc.conf manpages](http://manpages.ubuntu.com/manpages/precise/man5/lxc.conf.5.html).
|
For other configuration options, please check the [lxc.conf manpages](http://manpages.ubuntu.com/manpages/precise/man5/lxc.conf.5.html).
|
||||||
|
|
||||||
### Private Networks [EXPERIMENTAL]
|
### Private Networks
|
||||||
|
|
||||||
Starting with vagrant-lxc 1.1.0, there is some rudimentary support for configuring
|
Starting with vagrant-lxc 1.1.0, there is some rudimentary support for configuring
|
||||||
[Private Networks](https://docs.vagrantup.com/v2/networking/private_network.html)
|
[Private Networks](https://docs.vagrantup.com/v2/networking/private_network.html)
|
||||||
|
@ -137,25 +142,29 @@ Vagrant.configure("2") do |config|
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
For old versions of lxc (like 0.7.5 shipped with Ubuntu 12.04 by default) that
|
## Unprivileged containers support
|
||||||
does not support `best` for the backingstore option, changing it to `none` is
|
|
||||||
required and a default for all Vagrant environments can be set from your
|
Since v1.4.0, `vagrant-lxc` gained support for unprivileged containers. For now, since it's a new
|
||||||
`~/.vagrant.d/Vagrantfile` using the same `provider` block:
|
feature, privileged containers are still the default, but you can have your `Vagrantfile` use
|
||||||
|
unprivileged containers with the `privileged` flag (which defaults to `true`). Example:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
config.vm.provider :lxc do |lxc|
|
config.vm.provider :lxc do |lxc|
|
||||||
lxc.backingstore = 'none'
|
lxc.privileged = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For unprivileged containers to work with `vagrant-lxc`, you need a properly configured system. On
|
||||||
|
some distros, it can be somewhat of a challenge. Your journey to configuring your system can start
|
||||||
|
with [Stéphane Graber's blog post about it](https://stgraber.org/2014/01/17/lxc-1-0-unprivileged-containers/).
|
||||||
|
|
||||||
## Avoiding `sudo` passwords
|
## Avoiding `sudo` passwords
|
||||||
|
|
||||||
This plugin requires **a lot** of `sudo`ing since [unprivileged containers](https://github.com/fgrehm/vagrant-lxc/issues/312)
|
If you're not using unprivileged containers, this plugin requires **a lot** of `sudo`ing To work
|
||||||
are not supported yet. To work around that, you can use the `vagrant lxc sudoers`
|
around that, you can use the `vagrant lxc sudoers` command which will create a file under
|
||||||
command which will create a file under `/etc/sudoers.d/vagrant-lxc` whitelisting
|
`/etc/sudoers.d/vagrant-lxc` whitelisting all commands required by `vagrant-lxc` to run.
|
||||||
all commands required by `vagrant-lxc` to run.
|
|
||||||
|
|
||||||
If you are interested on what will be generated by that command, please check
|
If you are interested on what will be generated by that command, please check
|
||||||
[this code](lib/vagrant-lxc/command/sudoers.rb).
|
[this code](lib/vagrant-lxc/command/sudoers.rb).
|
||||||
|
|
|
@ -8,11 +8,15 @@ module Vagrant
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
@env = env
|
@env = env
|
||||||
|
driver = env[:machine].provider.driver
|
||||||
config = env[:machine].provider_config
|
config = env[:machine].provider_config
|
||||||
|
|
||||||
utsname = env[:machine].config.vm.hostname || env[:machine].id
|
utsname = env[:machine].config.vm.hostname || env[:machine].id
|
||||||
config.customize 'utsname', utsname
|
if driver.supports_new_config_format
|
||||||
|
config.customize 'uts.name', utsname
|
||||||
|
else
|
||||||
|
config.customize 'utsname', utsname
|
||||||
|
end
|
||||||
|
|
||||||
# Fix apparmor issues when starting Ubuntu 14.04 containers
|
# Fix apparmor issues when starting Ubuntu 14.04 containers
|
||||||
# See https://github.com/fgrehm/vagrant-lxc/issues/278 for more information
|
# See https://github.com/fgrehm/vagrant-lxc/issues/278 for more information
|
||||||
|
@ -32,7 +36,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
env[:ui].info I18n.t("vagrant_lxc.messages.starting")
|
env[:ui].info I18n.t("vagrant_lxc.messages.starting")
|
||||||
env[:machine].provider.driver.start(config.customizations)
|
driver.start(config.customizations)
|
||||||
|
|
||||||
@app.call env
|
@app.call env
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,14 +19,26 @@ module Vagrant
|
||||||
container_name = generate_container_name(env)
|
container_name = generate_container_name(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
backingstore = config.backingstore
|
||||||
|
if backingstore.nil?
|
||||||
|
backingstore = config.privileged ? "best" : "dir"
|
||||||
|
end
|
||||||
driver = env[:machine].provider.driver
|
driver = env[:machine].provider.driver
|
||||||
|
template_options = env[:lxc_template_opts]
|
||||||
|
if driver.supports_new_config_format
|
||||||
|
if env[:lxc_box_config]
|
||||||
|
driver.update_config_keys(env[:lxc_box_config])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
template_options['--oldconfig'] = ''
|
||||||
|
end
|
||||||
driver.create(
|
driver.create(
|
||||||
container_name,
|
container_name,
|
||||||
config.backingstore,
|
backingstore,
|
||||||
config.backingstore_options,
|
config.backingstore_options,
|
||||||
env[:lxc_template_src],
|
env[:lxc_template_src],
|
||||||
env[:lxc_template_config],
|
env[:lxc_template_config],
|
||||||
env[:lxc_template_opts]
|
template_options
|
||||||
)
|
)
|
||||||
driver.update_config_keys
|
driver.update_config_keys
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ module Vagrant
|
||||||
fetch_ip_tries = config.fetch_ip_tries
|
fetch_ip_tries = config.fetch_ip_tries
|
||||||
driver = env[:machine].provider.driver
|
driver = env[:machine].provider.driver
|
||||||
ip = ''
|
ip = ''
|
||||||
|
return config.ssh_ip_addr if not config.ssh_ip_addr.nil?
|
||||||
retryable(:on => LXC::Errors::ExecuteError, :tries => fetch_ip_tries, :sleep => 3) do
|
retryable(:on => LXC::Errors::ExecuteError, :tries => fetch_ip_tries, :sleep => 3) do
|
||||||
unless ip = get_container_ip_from_ip_addr(driver)
|
unless ip = get_container_ip_from_ip_addr(driver)
|
||||||
# retry
|
# retry
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'open3'
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
module Action
|
module Action
|
||||||
|
@ -78,8 +80,12 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_port(host_ip, host_port, guest_ip, guest_port)
|
def redirect_port(host_ip, host_port, guest_ip, guest_port)
|
||||||
params = %W( --lport=#{host_port} --caddr=#{guest_ip} --cport=#{guest_port} )
|
if redir_version >= 3
|
||||||
params.unshift "--laddr=#{host_ip}" if host_ip
|
params = %W( -n #{host_ip}:#{host_port} #{guest_ip}:#{guest_port} )
|
||||||
|
else
|
||||||
|
params = %W( --lport=#{host_port} --caddr=#{guest_ip} --cport=#{guest_port} )
|
||||||
|
params.unshift "--laddr=#{host_ip}" if host_ip
|
||||||
|
end
|
||||||
params << '--syslog' if ENV['REDIR_LOG']
|
params << '--syslog' if ENV['REDIR_LOG']
|
||||||
if host_port < 1024
|
if host_port < 1024
|
||||||
redir_cmd = "sudo redir #{params.join(' ')} 2>/dev/null"
|
redir_cmd = "sudo redir #{params.join(' ')} 2>/dev/null"
|
||||||
|
@ -99,6 +105,13 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redir_version
|
||||||
|
stdout, stderr, _ = Open3.capture3 "redir --version"
|
||||||
|
# For some weird reason redir printed version information in STDERR prior to 3.2
|
||||||
|
version = stdout.empty? ? stderr : stdout
|
||||||
|
version.split('.')[0].to_i
|
||||||
|
end
|
||||||
|
|
||||||
def redir_installed?
|
def redir_installed?
|
||||||
system "which redir > /dev/null"
|
system "which redir > /dev/null"
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,8 +33,10 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
if template_config_file.exist?
|
if template_config_file.exist?
|
||||||
|
@env[:lxc_box_config] = template_config_file.to_s
|
||||||
@env[:lxc_template_opts].merge!('--config' => template_config_file.to_s)
|
@env[:lxc_template_opts].merge!('--config' => template_config_file.to_s)
|
||||||
elsif old_template_config_file.exist?
|
elsif old_template_config_file.exist?
|
||||||
|
@env[:lxc_box_config] = old_template_config_file.to_s
|
||||||
@env[:lxc_template_config] = old_template_config_file.to_s
|
@env[:lxc_template_config] = old_template_config_file.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,14 @@ module Vagrant
|
||||||
|
|
||||||
attr_accessor :fetch_ip_tries
|
attr_accessor :fetch_ip_tries
|
||||||
|
|
||||||
|
attr_accessor :ssh_ip_addr
|
||||||
|
|
||||||
|
# Whether the container needs to be privileged. Defaults to true (unprivileged containers
|
||||||
|
# is a very new feature in vagrant-lxc). If false, will try creating an unprivileged
|
||||||
|
# container. If it can't, will revert to the old "sudo wrapper" method to create a privileged
|
||||||
|
# container.
|
||||||
|
attr_accessor :privileged
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@customizations = []
|
@customizations = []
|
||||||
@backingstore = UNSET_VALUE
|
@backingstore = UNSET_VALUE
|
||||||
|
@ -31,6 +39,8 @@ module Vagrant
|
||||||
@container_name = UNSET_VALUE
|
@container_name = UNSET_VALUE
|
||||||
@tmpfs_mount_size = UNSET_VALUE
|
@tmpfs_mount_size = UNSET_VALUE
|
||||||
@fetch_ip_tries = UNSET_VALUE
|
@fetch_ip_tries = UNSET_VALUE
|
||||||
|
@ssh_ip_addr = UNSET_VALUE
|
||||||
|
@privileged = UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
# Customize the container by calling `lxc-start` with the given
|
# Customize the container by calling `lxc-start` with the given
|
||||||
|
@ -55,10 +65,12 @@ module Vagrant
|
||||||
|
|
||||||
def finalize!
|
def finalize!
|
||||||
@container_name = nil if @container_name == UNSET_VALUE
|
@container_name = nil if @container_name == UNSET_VALUE
|
||||||
@backingstore = "best" if @backingstore == UNSET_VALUE
|
@backingstore = nil if @backingstore == UNSET_VALUE
|
||||||
@existing_container_name = nil if @existing_container_name == UNSET_VALUE
|
@existing_container_name = nil if @existing_container_name == UNSET_VALUE
|
||||||
@tmpfs_mount_size = '2G' if @tmpfs_mount_size == UNSET_VALUE
|
@tmpfs_mount_size = '2G' if @tmpfs_mount_size == UNSET_VALUE
|
||||||
@fetch_ip_tries = 10 if @fetch_ip_tries == UNSET_VALUE
|
@fetch_ip_tries = 10 if @fetch_ip_tries == UNSET_VALUE
|
||||||
|
@ssh_ip_addr = nil if @ssh_ip_addr == UNSET_VALUE
|
||||||
|
@privileged = true if @privileged == UNSET_VALUE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,9 +20,9 @@ module Vagrant
|
||||||
attr_reader :container_name,
|
attr_reader :container_name,
|
||||||
:customizations
|
:customizations
|
||||||
|
|
||||||
def initialize(container_name, sudo_wrapper = nil, cli = nil)
|
def initialize(container_name, sudo_wrapper = nil, cli = nil, privileged: true)
|
||||||
@container_name = container_name
|
@container_name = container_name
|
||||||
@sudo_wrapper = sudo_wrapper || SudoWrapper.new()
|
@sudo_wrapper = sudo_wrapper || SudoWrapper.new(privileged: privileged)
|
||||||
@cli = cli || CLI.new(@sudo_wrapper, container_name)
|
@cli = cli || CLI.new(@sudo_wrapper, container_name)
|
||||||
@logger = Log4r::Logger.new("vagrant::provider::lxc::driver")
|
@logger = Log4r::Logger.new("vagrant::provider::lxc::driver")
|
||||||
@customizations = []
|
@customizations = []
|
||||||
|
@ -50,20 +50,20 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def rootfs_path
|
def rootfs_path
|
||||||
config_entry = config_string.match(/^lxc\.rootfs\s+=\s+(.+)$/)[1]
|
pathtype, path = config_string.match(/^lxc\.rootfs(?:\.path)?\s+=\s+(.+:)?(.+)$/)[1..2]
|
||||||
case config_entry
|
case pathtype
|
||||||
when /^overlayfs:/
|
when 'overlayfs:'
|
||||||
# Split on colon (:), ignoring any colon escaped by an escape character ( \ )
|
# Split on colon (:), ignoring any colon escaped by an escape character ( \ )
|
||||||
# Pays attention to when the escape character is itself escaped.
|
# Pays attention to when the escape character is itself escaped.
|
||||||
fs_type, master_path, overlay_path = config_entry.split(/(?<!\\)(?:\\\\)*:/)
|
_, overlay_path = config_entry.split(/(?<!\\)(?:\\\\)*:/)
|
||||||
if overlay_path
|
if overlay_path
|
||||||
Pathname.new(overlay_path)
|
Pathname.new(overlay_path)
|
||||||
else
|
else
|
||||||
# Malformed: fall back to prior behaviour
|
# Malformed: fall back to prior behaviour
|
||||||
Pathname.new(config_entry)
|
Pathname.new(path)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Pathname.new(config_entry)
|
Pathname.new(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ module Vagrant
|
||||||
@cli.name = @container_name = name
|
@cli.name = @container_name = name
|
||||||
|
|
||||||
@logger.debug "Creating container..."
|
@logger.debug "Creating container..."
|
||||||
|
|
||||||
@cli.create template_path, backingstore, backingstore_options, config_file, template_options
|
@cli.create template_path, backingstore, backingstore_options, config_file, template_options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -121,10 +122,6 @@ 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
|
||||||
|
@ -214,6 +211,10 @@ module Vagrant
|
||||||
@version ||= @cli.version
|
@version ||= @cli.version
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def supports_new_config_format
|
||||||
|
Gem::Version.new(version) >= Gem::Version.new('2.1.0')
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: This needs to be reviewed and specs needs to be written
|
# TODO: This needs to be reviewed and specs needs to be written
|
||||||
def compress_rootfs
|
def compress_rootfs
|
||||||
# TODO: Pass in tmpdir so we can clean up from outside
|
# TODO: Pass in tmpdir so we can clean up from outside
|
||||||
|
@ -244,8 +245,9 @@ module Vagrant
|
||||||
write_config(contents)
|
write_config(contents)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_config_keys
|
def update_config_keys(path = nil)
|
||||||
@cli.update_config(config_path)
|
path = path || config_path
|
||||||
|
@cli.update_config(path)
|
||||||
rescue Errors::ExecuteError
|
rescue Errors::ExecuteError
|
||||||
# not on LXC 2.1+. Doesn't matter, ignore.
|
# not on LXC 2.1+. Doesn't matter, ignore.
|
||||||
end
|
end
|
||||||
|
@ -266,12 +268,21 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_config(contents)
|
def write_config(contents)
|
||||||
Tempfile.new('lxc-config').tap do |file|
|
confpath = base_path.join('config').to_s
|
||||||
file.chmod 0644
|
begin
|
||||||
file.write contents
|
File.open(confpath, File::RDWR) do |file|
|
||||||
file.close
|
file.write contents
|
||||||
@sudo_wrapper.run 'cp', '-f', file.path, config_path
|
end
|
||||||
@sudo_wrapper.run 'chown', 'root:root', config_path
|
rescue
|
||||||
|
# We don't have permissions to write in the conf file. That's probably because it's a
|
||||||
|
# privileged container. Work around that through sudo_wrapper.
|
||||||
|
Tempfile.new('lxc-config').tap do |file|
|
||||||
|
file.chmod 0644
|
||||||
|
file.write contents
|
||||||
|
file.close
|
||||||
|
@sudo_wrapper.run 'cp', '-f', file.path, confpath
|
||||||
|
@sudo_wrapper.run 'chown', 'root:root', confpath
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ module Vagrant
|
||||||
config_opts = ['-f', config_file]
|
config_opts = ['-f', config_file]
|
||||||
end
|
end
|
||||||
|
|
||||||
extra = template_opts.to_a.flatten
|
extra = template_opts.to_a.flatten.reject { |elem| elem.empty? }
|
||||||
extra.unshift '--' unless extra.empty?
|
extra.unshift '--' unless extra.empty?
|
||||||
|
|
||||||
run :create,
|
run :create,
|
||||||
|
@ -89,14 +89,13 @@ module Vagrant
|
||||||
# Man Page:
|
# Man Page:
|
||||||
# 2 The specified container exists but was not running.
|
# 2 The specified container exists but was not running.
|
||||||
def stop
|
def stop
|
||||||
attach '/sbin/halt' if supports_attach?
|
|
||||||
begin
|
begin
|
||||||
run :stop, '--name', @name
|
run :stop, '--name', @name
|
||||||
rescue LXC::Errors::ExecuteError => e
|
rescue LXC::Errors::ExecuteError => e
|
||||||
if e.exitcode == 2
|
if e.exitcode == 2
|
||||||
@logger.debug "Machine already stopped, lxc-stop returned 2"
|
@logger.debug "Machine already stopped, lxc-stop returned 2"
|
||||||
else
|
else
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -142,19 +141,6 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_attach?
|
|
||||||
unless defined?(@supports_attach)
|
|
||||||
begin
|
|
||||||
@supports_attach = true
|
|
||||||
run(:attach, '--name', @name, '--', '/bin/true')
|
|
||||||
rescue LXC::Errors::ExecuteError
|
|
||||||
@supports_attach = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return @supports_attach
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def run(command, *args)
|
def run(command, *args)
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Vagrant
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
provider(:lxc, parallel: true, priority: 7) do
|
provider(:lxc, parallel: true, priority: 7) do
|
||||||
require File.expand_path("../provider", __FILE__)
|
require_relative 'provider'
|
||||||
init!
|
init!
|
||||||
Provider
|
Provider
|
||||||
end
|
end
|
||||||
|
@ -22,13 +22,13 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
config(:lxc, :provider) do
|
config(:lxc, :provider) do
|
||||||
require File.expand_path("../config", __FILE__)
|
require_relative 'config'
|
||||||
init!
|
init!
|
||||||
Config
|
Config
|
||||||
end
|
end
|
||||||
|
|
||||||
synced_folder(:lxc) do
|
synced_folder(:lxc) do
|
||||||
require File.expand_path("../synced_folder", __FILE__)
|
require_relative 'synced_folder'
|
||||||
SyncedFolder
|
SyncedFolder
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
@ -27,7 +26,7 @@ module Vagrant
|
||||||
|
|
||||||
def ensure_lxc_installed!
|
def ensure_lxc_installed!
|
||||||
begin
|
begin
|
||||||
SudoWrapper.new().run("which", "lxc-create")
|
SudoWrapper.new(privileged: @machine.provider_config.privileged).run("which", "lxc-create")
|
||||||
rescue Vagrant::LXC::Errors::ExecuteError
|
rescue Vagrant::LXC::Errors::ExecuteError
|
||||||
raise Errors::LxcNotInstalled
|
raise Errors::LxcNotInstalled
|
||||||
end
|
end
|
||||||
|
@ -40,7 +39,7 @@ module Vagrant
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@logger.debug("Instantiating the container for: #{id.inspect}")
|
@logger.debug("Instantiating the container for: #{id.inspect}")
|
||||||
@driver = Driver.new(id)
|
@driver = Driver.new(id, privileged: @machine.provider_config.privileged)
|
||||||
@driver.validate!
|
@driver.validate!
|
||||||
rescue Driver::ContainerNotFound
|
rescue Driver::ContainerNotFound
|
||||||
# The container doesn't exist, so we probably have a stale
|
# The container doesn't exist, so we probably have a stale
|
||||||
|
|
|
@ -10,8 +10,9 @@ module Vagrant
|
||||||
"/usr/local/bin/vagrant-lxc-wrapper"
|
"/usr/local/bin/vagrant-lxc-wrapper"
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize()
|
def initialize(privileged: true)
|
||||||
@wrapper_path = Pathname.new(SudoWrapper.dest_path).exist? && SudoWrapper.dest_path || nil
|
@wrapper_path = Pathname.new(SudoWrapper.dest_path).exist? && SudoWrapper.dest_path || nil
|
||||||
|
@privileged = privileged
|
||||||
@logger = Log4r::Logger.new("vagrant::lxc::sudo_wrapper")
|
@logger = Log4r::Logger.new("vagrant::lxc::sudo_wrapper")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,11 +28,15 @@ module Vagrant
|
||||||
File.umask(old_mask & 022) # allow all `r` and `x` bits
|
File.umask(old_mask & 022) # allow all `r` and `x` bits
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if @wrapper_path && !options[:no_wrapper]
|
if @privileged
|
||||||
command.unshift @wrapper_path
|
if @wrapper_path && !options[:no_wrapper]
|
||||||
execute *(['sudo'] + command)
|
command.unshift @wrapper_path
|
||||||
|
execute *(['sudo'] + command)
|
||||||
|
else
|
||||||
|
execute *(['sudo', '/usr/bin/env'] + command)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
execute *(['sudo', '/usr/bin/env'] + command)
|
execute *(['/usr/bin/env'] + command)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
File.umask(old_mask)
|
File.umask(old_mask)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
VERSION = "1.3.1"
|
VERSION = "1.4.2"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,8 +33,10 @@ LXC_PATH=
|
||||||
LXC_ROOTFS=
|
LXC_ROOTFS=
|
||||||
LXC_TARBALL=
|
LXC_TARBALL=
|
||||||
LXC_CONFIG=
|
LXC_CONFIG=
|
||||||
|
LXC_USE_OLDCONFIG=
|
||||||
LXC_STRIP_COMPONENTS=2
|
LXC_STRIP_COMPONENTS=2
|
||||||
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
vagrant-lxc default template
|
vagrant-lxc default template
|
||||||
|
@ -44,6 +46,7 @@ Required arguments:
|
||||||
|
|
||||||
Optional arguments:
|
Optional arguments:
|
||||||
[ --config ]: Configuration file to be used when building the container
|
[ --config ]: Configuration file to be used when building the container
|
||||||
|
[ --oldconfig ]: Use pre LXC 2.1 config format
|
||||||
[ -h | --help ]: This help message
|
[ -h | --help ]: This help message
|
||||||
|
|
||||||
LXC internal arguments (do not pass manually!):
|
LXC internal arguments (do not pass manually!):
|
||||||
|
@ -57,7 +60,7 @@ EOF
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
options=$(getopt -o h -l tarball:,config:,help:,name:,path:,rootfs:,mapped-uid:,mapped-gid:,strip-components: -- "$@")SS
|
options=$(getopt -o h -l tarball:,config:,oldconfig,help:,name:,path:,rootfs:,mapped-uid:,mapped-gid:,strip-components: -- "$@")SS
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
usage $(basename $0)
|
usage $(basename $0)
|
||||||
|
@ -70,6 +73,7 @@ do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--help) usage $0 && exit 0;;
|
-h|--help) usage $0 && exit 0;;
|
||||||
--config) LXC_CONFIG=$2; shift 2;;
|
--config) LXC_CONFIG=$2; shift 2;;
|
||||||
|
--oldconfig) LXC_USE_OLDCONFIG=1; shift 1;;
|
||||||
--tarball) LXC_TARBALL=$2; shift 2;;
|
--tarball) LXC_TARBALL=$2; shift 2;;
|
||||||
--name) LXC_NAME=$2; shift 2;;
|
--name) LXC_NAME=$2; shift 2;;
|
||||||
--path) LXC_PATH=$2; shift 2;;
|
--path) LXC_PATH=$2; shift 2;;
|
||||||
|
@ -144,7 +148,12 @@ if [ -e "${LXC_PATH}/config-auto" ]; then
|
||||||
cat ${LXC_PATH}/config-auto >> ${LXC_PATH}/config
|
cat ${LXC_PATH}/config-auto >> ${LXC_PATH}/config
|
||||||
rm ${LXC_PATH}/config-auto
|
rm ${LXC_PATH}/config-auto
|
||||||
fi
|
fi
|
||||||
echo "lxc.utsname = ${LXC_NAME}" >> ${LXC_PATH}/config
|
|
||||||
|
if [ $LXC_USE_OLDCONFIG ]; then
|
||||||
|
echo "lxc.utsname = ${LXC_NAME}" >> ${LXC_PATH}/config
|
||||||
|
else
|
||||||
|
echo "lxc.uts.name = ${LXC_NAME}" >> ${LXC_PATH}/config
|
||||||
|
fi
|
||||||
|
|
||||||
## Re-add the previously removed network config
|
## Re-add the previously removed network config
|
||||||
if [ -e "${LXC_PATH}/config-network" ]; then
|
if [ -e "${LXC_PATH}/config-network" ]; then
|
||||||
|
|
|
@ -390,7 +390,7 @@ else
|
||||||
;;
|
;;
|
||||||
"")
|
"")
|
||||||
if installed ipcalc; then
|
if installed ipcalc; then
|
||||||
eval $(ipcalc -b $IPADDR)
|
eval "$(ipcalc -b $IPADDR)"
|
||||||
ip netns exec "$NSPID" ip addr add "$IPADDR" brd "$BROADCAST" dev "$CONTAINER_IFNAME"
|
ip netns exec "$NSPID" ip addr add "$IPADDR" brd "$BROADCAST" dev "$CONTAINER_IFNAME"
|
||||||
else
|
else
|
||||||
ip netns exec "$NSPID" ip addr add "$IPADDR" dev "$CONTAINER_IFNAME"
|
ip netns exec "$NSPID" ip addr add "$IPADDR" dev "$CONTAINER_IFNAME"
|
||||||
|
|
|
@ -24,6 +24,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
machine.stub_chain(:config, :vm, :networks).and_return(networks)
|
machine.stub_chain(:config, :vm, :networks).and_return(networks)
|
||||||
machine.stub(provider: provider, data_dir: data_dir)
|
machine.stub(provider: provider, data_dir: data_dir)
|
||||||
|
|
||||||
|
subject.stub(redir_version: 3)
|
||||||
subject.stub(exec: true)
|
subject.stub(exec: true)
|
||||||
subject.stub(spawn: pid)
|
subject.stub(spawn: pid)
|
||||||
end
|
end
|
||||||
|
@ -34,7 +35,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
subject.stub(system: true)
|
subject.stub(system: true)
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
expect(subject).to have_received(:spawn).with(
|
expect(subject).to have_received(:spawn).with(
|
||||||
"redir --laddr=#{host_ip} --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
"redir -n #{host_ip}:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
subject.stub(system: true)
|
subject.stub(system: true)
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
expect(subject).to have_received(:spawn).with(
|
expect(subject).to have_received(:spawn).with(
|
||||||
"redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
"redir -n 127.0.0.1:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
subject.stub(system: true)
|
subject.stub(system: true)
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
expect(subject).to have_received(:spawn).with(
|
expect(subject).to have_received(:spawn).with(
|
||||||
"redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
"redir -n 127.0.0.1:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,6 +71,15 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
expect(subject).not_to have_received(:spawn)
|
expect(subject).not_to have_received(:spawn)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'uses redir 2.x command line interface' do
|
||||||
|
subject.stub(system: true)
|
||||||
|
subject.stub(redir_version: 2)
|
||||||
|
subject.call(env)
|
||||||
|
expect(subject).to have_received(:spawn).with(
|
||||||
|
"redir --laddr=#{host_ip} --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
it 'raises RedirNotInstalled error if `redir` is not installed' do
|
it 'raises RedirNotInstalled error if `redir` is not installed' do
|
||||||
subject.stub(system: false)
|
subject.stub(system: false)
|
||||||
expect { subject.call(env) }.to raise_error(Vagrant::LXC::Errors::RedirNotInstalled)
|
expect { subject.call(env) }.to raise_error(Vagrant::LXC::Errors::RedirNotInstalled)
|
||||||
|
@ -82,7 +92,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
subject.stub(system: true)
|
subject.stub(system: true)
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
expect(subject).to have_received(:spawn).with(
|
expect(subject).to have_received(:spawn).with(
|
||||||
"sudo redir --laddr=#{host_ip} --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
"sudo redir -n #{host_ip}:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -91,7 +101,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
subject.stub(system: true)
|
subject.stub(system: true)
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
expect(subject).to have_received(:spawn).with(
|
expect(subject).to have_received(:spawn).with(
|
||||||
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
"sudo redir -n 127.0.0.1:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -100,7 +110,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
subject.stub(system: true)
|
subject.stub(system: true)
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
expect(subject).to have_received(:spawn).with(
|
expect(subject).to have_received(:spawn).with(
|
||||||
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
"sudo redir -n 127.0.0.1:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -134,36 +134,11 @@ describe Vagrant::LXC::Driver::CLI do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(subject).to receive(:run)
|
allow(subject).to receive(:run)
|
||||||
|
subject.stop
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'lxc-attach is supported' do
|
it 'issues a lxc-stop with provided container name' do
|
||||||
before do
|
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
||||||
subject.stub(attach: true, supports_attach?: true)
|
|
||||||
subject.stop
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'runs a /sbin/halt within the container' do
|
|
||||||
expect(subject).to have_received(:attach).with('/sbin/halt')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'issues a lxc-stop with provided container name' do
|
|
||||||
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'lxc-attach is not supported' do
|
|
||||||
before do
|
|
||||||
subject.stub(attach: false, supports_attach?: false)
|
|
||||||
subject.stop
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'runs a /sbin/halt within the container' do
|
|
||||||
expect(subject).to_not have_received(:attach)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'issues a lxc-stop with provided container name' do
|
|
||||||
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -231,33 +206,4 @@ describe Vagrant::LXC::Driver::CLI do
|
||||||
|
|
||||||
skip 'waits for the expected container state'
|
skip 'waits for the expected container state'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'check for whether lxc-attach is supported' do
|
|
||||||
let(:name) { 'a-running-container' }
|
|
||||||
subject { described_class.new(sudo_wrapper, name) }
|
|
||||||
|
|
||||||
context 'lxc-attach is present on system' do
|
|
||||||
before { subject.stub(run: true) }
|
|
||||||
|
|
||||||
it 'returns true if `lxc-attach --name CNAME -- /bin/true` works' do
|
|
||||||
expect(subject.supports_attach?).to be_truthy
|
|
||||||
expect(subject).to have_received(:run).with(
|
|
||||||
:attach, '--name', name, '--', '/bin/true'
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'lxc-attach is not present on system' do
|
|
||||||
before do
|
|
||||||
allow(subject).to receive(:run).and_raise(Vagrant::LXC::Errors::ExecuteError.new('msg'))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns true if `lxc-attach --name CNAME -- /bin/true` works' do
|
|
||||||
expect(subject.supports_attach?).to be_falsy
|
|
||||||
expect(subject).to have_received(:run).with(
|
|
||||||
:attach, '--name', name, '--', '/bin/true'
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,17 +75,6 @@ describe Vagrant::LXC::Driver do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'supports_attach?' do
|
|
||||||
let(:cli) { double(Vagrant::LXC::Driver::CLI, supports_attach?: true) }
|
|
||||||
|
|
||||||
subject { described_class.new('name', nil, cli) }
|
|
||||||
|
|
||||||
it 'delegates to cli object' do
|
|
||||||
expect(subject.supports_attach?).to be_truthy
|
|
||||||
expect(cli).to have_received(:supports_attach?)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'start' do
|
describe 'start' do
|
||||||
let(:customizations) { [['a', '1'], ['b', '2']] }
|
let(:customizations) { [['a', '1'], ['b', '2']] }
|
||||||
let(:internal_customization) { ['internal', 'customization'] }
|
let(:internal_customization) { ['internal', 'customization'] }
|
||||||
|
@ -211,9 +200,9 @@ describe Vagrant::LXC::Driver do
|
||||||
# Blah blah comment
|
# Blah blah comment
|
||||||
lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
|
lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
|
||||||
lxc.mount.entry = sysfs sys sysfs defaults 0 0
|
lxc.mount.entry = sysfs sys sysfs defaults 0 0
|
||||||
lxc.tty = 4
|
lxc.tty.max = 4
|
||||||
lxc.pts = 1024
|
lxc.pty.max = 1024
|
||||||
lxc.rootfs = #{rootfs_path}
|
lxc.rootfs.path = #{rootfs_path}
|
||||||
# VAGRANT-BEGIN
|
# VAGRANT-BEGIN
|
||||||
lxc.network.type=veth
|
lxc.network.type=veth
|
||||||
lxc.network.name=eth1
|
lxc.network.name=eth1
|
||||||
|
@ -241,9 +230,9 @@ describe Vagrant::LXC::Driver do
|
||||||
# Blah blah comment
|
# Blah blah comment
|
||||||
lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
|
lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
|
||||||
lxc.mount.entry = sysfs sys sysfs defaults 0 0
|
lxc.mount.entry = sysfs sys sysfs defaults 0 0
|
||||||
lxc.tty = 4
|
lxc.tty.max = 4
|
||||||
lxc.pts = 1024
|
lxc.pty.max = 1024
|
||||||
lxc.rootfs = overlayfs:/path/to/master/directory:#{rootfs_path}
|
lxc.rootfs.path = overlayfs:/path/to/master/directory:#{rootfs_path}
|
||||||
# VAGRANT-BEGIN
|
# VAGRANT-BEGIN
|
||||||
lxc.network.type=veth
|
lxc.network.type=veth
|
||||||
lxc.network.name=eth1
|
lxc.network.name=eth1
|
||||||
|
|
Loading…
Add table
Reference in a new issue