Compare commits

...

30 commits

Author SHA1 Message Date
a47660a1e5 Update 'README.md' 2023-02-03 19:28:15 +00:00
3575d65ffb Update 'README.md' 2023-02-03 19:08:48 +00:00
Glenn Y. Rolland
938a29ed96
Merge branch 'fgrehm:master' into master 2023-02-03 19:56:32 +01:00
Fabio
ff58ecd5f2
Update README.md 2022-11-24 20:41:12 -03:00
Fabio
df6b78c4ed
Update README.md 2022-11-24 20:40:54 -03:00
Fabio
4d53acb9fb
Update README.md 2022-11-24 20:40:34 -03:00
Fabio
b88d50fb68
Update README.md 2022-11-16 22:39:19 -03:00
4e3306ed74 Fix the 'eval: Address:: not found' error that may appear 2022-09-28 15:01:04 +02:00
Fabio Rehm
c167ac7f83
Make it clear that project is looking for maintainers
Ref https://github.com/fgrehm/vagrant-lxc/issues/492
2021-01-12 11:15:50 -03:00
Virgil Dupras
a112b072aa
Merge pull request #473 from ebobby/fix-redir3
Fix redir version fetching.
2018-09-26 19:53:14 -04:00
Francisco Soto
f750bf406c Fix redir version fetching.
"" || "something" doesn't really work. Have to check for the actual string
length to determine if got something or not out of the pipe.
2018-09-24 18:43:03 -07:00
Virgil Dupras
2a5510b34c Fix "vargant package" for LXC 2.1+ config format
New config format would be under `lxc.rootfs.path` and be prefixed by
`dir:`.
2018-07-24 12:23:25 -04:00
Virgil Dupras
a1aa60ded5 Remove supports_attach? and call to /sbin/halt
Hosts without support for lxc-attach are ancien and can always use old
versions of vagrant-lxc. To be able to move forward more easily, we
should be able to assume a functional `lxc-attach`.

As for `/sbin/halt`, I'm really not sure it's needed anymore. Let's see
if its removal causes problems.
2018-07-24 11:21:09 -04:00
Virgil Dupras
61c921ac6f Use require_relative everywhere in plugin entry point 2018-07-24 10:25:08 -04:00
Virgil Dupras
437b5e7a2e README: base boxes status update 2018-07-24 10:08:07 -04:00
Virgil Dupras
2c2630a788 Bump minimum requirements for next vagrant-lxc release (v1.5)
We now depend on vagrant 1.9+ and LXC 2.0+, following bundled version in
debian stretch.

Also, update Gemfile to target latest vagrant/vagrant-spec. It's too
complicated to test against old vagrant versions. Vagrant 1.8.x didn't
specify an upper bound for supported versions but vagrant 1.9 does
(<2.4). This breaks out CI testing matrix which tests against 2.3, 2.4
and 2.5.

So let's make our live easier and just test against the latest vagrant
version and try not to mistakenly drop support for our lowest supported
vagrant version...
2018-07-24 09:37:34 -04:00
Virgil Dupras
5a1f6ab2cb
Merge pull request #469 from worxli/feature-add-ssh-ip
Add config for container SSH IP
2018-07-23 06:27:50 -04:00
Lukas Bischofberger
f71de429a1 Add config for container ssh IP 2018-07-21 14:52:26 +02:00
Virgil Dupras
50cbe5a0d6 v1.4.2 2018-07-17 14:37:18 -04:00
Virgil Dupras
44eefd81fb Merge tag 'v1.4.1' 2018-07-17 14:34:58 -04:00
Virgil Dupras
a84f8b59bf redir: adjust failing tests 2018-07-04 15:00:46 -04:00
Virgil Dupras
c1dd7baf2a redir: start in foreground mode under v3.x
ref #467
2018-07-04 14:34:26 -04:00
Virgil Dupras
8a1e1863a7 redir: fix version parsing
At some point in v 3.x, it outputted version in stderr, then went back
to stdout...
2018-07-04 14:33:51 -04:00
Virgil Dupras
b812a6934a v1.4.1 2018-04-30 21:32:33 -04:00
Virgil Dupras
8cfe577b17 Fix LXC 3.0 compatibility with old boxes
Creating a new vagrant machine with a box created with an old LXC config
format would fail with LXC 3.0. We now update the LXC config of the box
itself before calling `lxc-create`.
2018-04-30 20:45:25 -04:00
Virgil Dupras
dd24cdc3d6 Fix incompatibility with LXC 3.0
LXC 3.0, unlike 2.1, doesn't support old configuration formats at all
and because our previous approach to handling old format was incomplete,
running `vagrant up` on a system with LXC 3.0 would fail, even if the
base box itself was made with modernized config.

This commit fixes this problem: is the box has a modern config, it's
going to be properly created and booted under LXC 3.0. It does so
without breaking the support for LXC < 2.1
2018-04-29 22:57:31 -04:00
Virgil Dupras
208edd49e5
Merge pull request #461 from nicolasleger/patch-1
[CI] Test against Ruby 2.5
2018-03-18 16:41:55 -04:00
Virgil Dupras
484b868100
Merge pull request #460 from lucaskanashiro/support_redir-3.x
Support the new redir 3.x command line interface
2018-03-18 16:41:18 -04:00
Nicolas Leger
b5f2a9006c
[CI] Test against Ruby 2.5 2018-03-15 14:52:34 +01:00
Lucas Kanashiro
2e20f96fec Support the new redir 3.x command line interface
Since redir 2.x upstream is not evolving it, Joachim Nilsson adopted it
and have started to work on it and publish a new command line interface
(check out https://github.com/troglobit/redir). The redir 3.1 is already
available in Debian and Ubuntu in their stable releases.
2018-03-12 13:09:06 -03:00
19 changed files with 124 additions and 132 deletions

View file

@ -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

View file

@ -1,3 +1,16 @@
## [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) ## [1.4.0](https://github.com/fgrehm/vagrant-lxc/compare/v1.3.1...v1.4.0) (Mar 04, 2018)
FEATURES: FEATURES:

View file

@ -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

View file

@ -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
[![Build Status](https://travis-ci.org/fgrehm/vagrant-lxc.png?branch=master)](https://travis-ci.org/fgrehm/vagrant-lxc) [![Gem Version](https://badge.fury.io/rb/vagrant-lxc.png)](http://badge.fury.io/rb/vagrant-lxc) [![Code Climate](https://codeclimate.com/github/fgrehm/vagrant-lxc.png)](https://codeclimate.com/github/fgrehm/vagrant-lxc) [![Coverage Status](https://coveralls.io/repos/fgrehm/vagrant-lxc/badge.png?branch=master)](https://coveralls.io/r/fgrehm/vagrant-lxc) [![Gitter chat](https://badges.gitter.im/fgrehm/vagrant-lxc.png)](https://gitter.im/fgrehm/vagrant-lxc) [![Build Status](https://travis-ci.org/fgrehm/vagrant-lxc.png?branch=master)](https://travis-ci.org/fgrehm/vagrant-lxc) [![Gem Version](https://badge.fury.io/rb/vagrant-lxc.png)](http://badge.fury.io/rb/vagrant-lxc) [![Code Climate](https://codeclimate.com/github/fgrehm/vagrant-lxc.png)](https://codeclimate.com/github/fgrehm/vagrant-lxc) [![Coverage Status](https://coveralls.io/repos/fgrehm/vagrant-lxc/badge.png?branch=master)](https://coveralls.io/r/fgrehm/vagrant-lxc) [![Gitter chat](https://badges.gitter.im/fgrehm/vagrant-lxc.png)](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.

View file

@ -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

View file

@ -24,13 +24,21 @@ module Vagrant
backingstore = config.privileged ? "best" : "dir" backingstore = config.privileged ? "best" : "dir"
end 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,
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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -24,6 +24,8 @@ 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 # 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 # 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. If it can't, will revert to the old "sudo wrapper" method to create a privileged
@ -37,6 +39,7 @@ 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 @privileged = UNSET_VALUE
end end
@ -66,6 +69,7 @@ module Vagrant
@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 @privileged = true if @privileged == UNSET_VALUE
end end
end end

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -1,5 +1,5 @@
module Vagrant module Vagrant
module LXC module LXC
VERSION = "1.4.0" VERSION = "1.4.2"
end end
end end

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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