Compare commits
No commits in common. "master" and "v1.4.0" have entirely different histories.
19 changed files with 132 additions and 124 deletions
|
@ -3,7 +3,6 @@ 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
|
||||||
|
|
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -1,16 +1,3 @@
|
||||||
## [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:
|
||||||
|
|
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'
|
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v1.8.7'
|
||||||
gem 'guard'
|
gem 'guard'
|
||||||
gem 'guard-rspec'
|
gem 'guard-rspec'
|
||||||
gem 'rb-inotify'
|
gem 'rb-inotify'
|
||||||
|
@ -9,9 +9,10 @@ end
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'rake', '~> 10.4.2'
|
gem 'rake', '~> 10.4.2'
|
||||||
gem 'rspec', '~> 3.5.0'
|
gem 'rspec', '~> 2.99.0'
|
||||||
gem 'coveralls', '~> 0.7.2', require: (ENV['COVERAGE'] == 'true')
|
gem 'coveralls', '~> 0.7.2', require: (ENV['COVERAGE'] == 'true')
|
||||||
gem 'vagrant-spec', git: 'https://github.com/mitchellh/vagrant-spec.git'
|
# 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', ref: '5006bc73cd8796465ca09307d4774f8ec8375aa0'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :plugins do
|
group :plugins do
|
||||||
|
|
17
README.md
17
README.md
|
@ -1,12 +1,8 @@
|
||||||
🟢 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.9+
|
[LXC](http://lxc.sourceforge.net/) provider for [Vagrant](http://www.vagrantup.com/) 1.8+
|
||||||
|
|
||||||
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
|
||||||
|
@ -16,13 +12,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`](https://github.com/troglobit/redir)
|
* Port forwarding via [`redir`](http://linux.die.net/man/1/redir)
|
||||||
* Private networking via [`pipework`](https://github.com/jpetazzo/pipework)
|
* Private networking via [`pipework`](https://github.com/jpetazzo/pipework)
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* [Vagrant 1.9+](http://www.vagrantup.com/downloads.html)
|
* [Vagrant 1.8+](http://www.vagrantup.com/downloads.html)
|
||||||
* lxc >=2.1
|
* lxc >=1.0
|
||||||
* `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`)
|
||||||
|
|
||||||
|
@ -55,9 +51,8 @@ _More information about skipping the `--provider` argument can be found at the
|
||||||
|
|
||||||
## Base boxes
|
## Base boxes
|
||||||
|
|
||||||
Base boxes provided on Atlas haven't been refreshed for a good while and shouldn't be relied on.
|
Base boxes can be found on [Atlas](https://atlas.hashicorp.com/boxes/search?provider=lxc)
|
||||||
Your best best is to build your boxes yourself. Some scripts to build your own are available at
|
and some scripts to build your own are available at [fgrehm/vagrant-lxc-base-boxes](https://github.com/fgrehm/vagrant-lxc-base-boxes).
|
||||||
[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.
|
||||||
|
|
|
@ -8,15 +8,11 @@ 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
|
||||||
if driver.supports_new_config_format
|
config.customize 'utsname', utsname
|
||||||
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
|
||||||
|
@ -36,7 +32,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
env[:ui].info I18n.t("vagrant_lxc.messages.starting")
|
env[:ui].info I18n.t("vagrant_lxc.messages.starting")
|
||||||
driver.start(config.customizations)
|
env[:machine].provider.driver.start(config.customizations)
|
||||||
|
|
||||||
@app.call env
|
@app.call env
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,21 +24,13 @@ 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],
|
||||||
template_options
|
env[:lxc_template_opts]
|
||||||
)
|
)
|
||||||
driver.update_config_keys
|
driver.update_config_keys
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ 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,5 +1,3 @@
|
||||||
require 'open3'
|
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
module Action
|
module Action
|
||||||
|
@ -80,12 +78,8 @@ 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)
|
||||||
if redir_version >= 3
|
params = %W( --lport=#{host_port} --caddr=#{guest_ip} --cport=#{guest_port} )
|
||||||
params = %W( -n #{host_ip}:#{host_port} #{guest_ip}:#{guest_port} )
|
params.unshift "--laddr=#{host_ip}" if host_ip
|
||||||
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"
|
||||||
|
@ -105,13 +99,6 @@ 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,10 +33,8 @@ 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,8 +24,6 @@ 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
|
||||||
|
@ -39,7 +37,6 @@ 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
|
||||||
|
|
||||||
|
@ -69,7 +66,6 @@ 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
|
||||||
|
|
|
@ -50,20 +50,20 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def rootfs_path
|
def rootfs_path
|
||||||
pathtype, path = config_string.match(/^lxc\.rootfs(?:\.path)?\s+=\s+(.+:)?(.+)$/)[1..2]
|
config_entry = config_string.match(/^lxc\.rootfs\s+=\s+(.+)$/)[1]
|
||||||
case pathtype
|
case config_entry
|
||||||
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.
|
||||||
_, overlay_path = config_entry.split(/(?<!\\)(?:\\\\)*:/)
|
fs_type, master_path, 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(path)
|
Pathname.new(config_entry)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Pathname.new(path)
|
Pathname.new(config_entry)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,7 +83,6 @@ 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
|
||||||
|
|
||||||
|
@ -122,6 +121,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
|
||||||
|
@ -211,10 +214,6 @@ 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
|
||||||
|
@ -245,9 +244,8 @@ module Vagrant
|
||||||
write_config(contents)
|
write_config(contents)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_config_keys(path = nil)
|
def update_config_keys
|
||||||
path = path || config_path
|
@cli.update_config(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
|
||||||
|
|
|
@ -59,7 +59,7 @@ module Vagrant
|
||||||
config_opts = ['-f', config_file]
|
config_opts = ['-f', config_file]
|
||||||
end
|
end
|
||||||
|
|
||||||
extra = template_opts.to_a.flatten.reject { |elem| elem.empty? }
|
extra = template_opts.to_a.flatten
|
||||||
extra.unshift '--' unless extra.empty?
|
extra.unshift '--' unless extra.empty?
|
||||||
|
|
||||||
run :create,
|
run :create,
|
||||||
|
@ -89,13 +89,14 @@ 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
|
||||||
|
@ -141,6 +142,19 @@ 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_relative 'provider'
|
require File.expand_path("../provider", __FILE__)
|
||||||
init!
|
init!
|
||||||
Provider
|
Provider
|
||||||
end
|
end
|
||||||
|
@ -22,13 +22,13 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
config(:lxc, :provider) do
|
config(:lxc, :provider) do
|
||||||
require_relative 'config'
|
require File.expand_path("../config", __FILE__)
|
||||||
init!
|
init!
|
||||||
Config
|
Config
|
||||||
end
|
end
|
||||||
|
|
||||||
synced_folder(:lxc) do
|
synced_folder(:lxc) do
|
||||||
require_relative 'synced_folder'
|
require File.expand_path("../synced_folder", __FILE__)
|
||||||
SyncedFolder
|
SyncedFolder
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
VERSION = "1.4.2"
|
VERSION = "1.4.0"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,10 +33,8 @@ 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
|
||||||
|
@ -46,7 +44,6 @@ 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!):
|
||||||
|
@ -60,7 +57,7 @@ EOF
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
options=$(getopt -o h -l tarball:,config:,oldconfig,help:,name:,path:,rootfs:,mapped-uid:,mapped-gid:,strip-components: -- "$@")SS
|
options=$(getopt -o h -l tarball:,config:,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)
|
||||||
|
@ -73,7 +70,6 @@ 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;;
|
||||||
|
@ -148,12 +144,7 @@ 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,7 +24,6 @@ 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
|
||||||
|
@ -35,7 +34,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 -n #{host_ip}:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
"redir --laddr=#{host_ip} --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,7 +43,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 -n 127.0.0.1:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
"redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,7 +52,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 -n 127.0.0.1:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
"redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,15 +70,6 @@ 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)
|
||||||
|
@ -92,7 +82,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 -n #{host_ip}:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
"sudo redir --laddr=#{host_ip} --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -101,7 +91,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 -n 127.0.0.1:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -110,7 +100,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 -n 127.0.0.1:#{host_port} #{container_ip}:#{guest_port} 2>/dev/null"
|
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -134,11 +134,36 @@ describe Vagrant::LXC::Driver::CLI do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(subject).to receive(:run)
|
allow(subject).to receive(:run)
|
||||||
subject.stop
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'issues a lxc-stop with provided container name' do
|
context 'lxc-attach is supported' do
|
||||||
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
before do
|
||||||
|
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
|
||||||
|
|
||||||
|
@ -206,4 +231,33 @@ 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,6 +75,17 @@ 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'] }
|
||||||
|
@ -200,9 +211,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.max = 4
|
lxc.tty = 4
|
||||||
lxc.pty.max = 1024
|
lxc.pts = 1024
|
||||||
lxc.rootfs.path = #{rootfs_path}
|
lxc.rootfs = #{rootfs_path}
|
||||||
# VAGRANT-BEGIN
|
# VAGRANT-BEGIN
|
||||||
lxc.network.type=veth
|
lxc.network.type=veth
|
||||||
lxc.network.name=eth1
|
lxc.network.name=eth1
|
||||||
|
@ -230,9 +241,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.max = 4
|
lxc.tty = 4
|
||||||
lxc.pty.max = 1024
|
lxc.pts = 1024
|
||||||
lxc.rootfs.path = overlayfs:/path/to/master/directory:#{rootfs_path}
|
lxc.rootfs = 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