Compare commits
No commits in common. "master" and "v1.4.2" have entirely different histories.
11 changed files with 108 additions and 34 deletions
7
Gemfile
7
Gemfile
|
@ -1,7 +1,7 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
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-rspec'
|
||||
gem 'rb-inotify'
|
||||
|
@ -9,9 +9,10 @@ end
|
|||
|
||||
group :development, :test do
|
||||
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 '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
|
||||
|
||||
group :plugins do
|
||||
|
|
15
README.md
15
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
|
||||
|
||||
[](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
|
||||
as an alternative to the built in VirtualBox provider for Linux hosts. Check out
|
||||
|
@ -21,8 +17,8 @@ to see it in action.
|
|||
|
||||
## Requirements
|
||||
|
||||
* [Vagrant 1.9+](http://www.vagrantup.com/downloads.html)
|
||||
* lxc >=2.1
|
||||
* [Vagrant 1.8+](http://www.vagrantup.com/downloads.html)
|
||||
* lxc >=1.0
|
||||
* `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`)
|
||||
|
||||
|
@ -55,9 +51,8 @@ _More information about skipping the `--provider` argument can be found at the
|
|||
|
||||
## Base boxes
|
||||
|
||||
Base boxes provided on Atlas haven't been refreshed for a good while and shouldn't be relied on.
|
||||
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).
|
||||
Base boxes can be found on [Atlas](https://atlas.hashicorp.com/boxes/search?provider=lxc)
|
||||
and some scripts to build your own are available at [fgrehm/vagrant-lxc-base-boxes](https://github.com/fgrehm/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)
|
||||
for more information.
|
||||
|
|
|
@ -21,7 +21,6 @@ module Vagrant
|
|||
fetch_ip_tries = config.fetch_ip_tries
|
||||
driver = env[:machine].provider.driver
|
||||
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
|
||||
unless ip = get_container_ip_from_ip_addr(driver)
|
||||
# retry
|
||||
|
|
|
@ -108,7 +108,7 @@ module Vagrant
|
|||
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 = stdout || stderr
|
||||
version.split('.')[0].to_i
|
||||
end
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ module Vagrant
|
|||
|
||||
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
|
||||
|
@ -39,7 +37,6 @@ module Vagrant
|
|||
@container_name = UNSET_VALUE
|
||||
@tmpfs_mount_size = UNSET_VALUE
|
||||
@fetch_ip_tries = UNSET_VALUE
|
||||
@ssh_ip_addr = UNSET_VALUE
|
||||
@privileged = UNSET_VALUE
|
||||
end
|
||||
|
||||
|
@ -69,7 +66,6 @@ module Vagrant
|
|||
@existing_container_name = nil if @existing_container_name == UNSET_VALUE
|
||||
@tmpfs_mount_size = '2G' if @tmpfs_mount_size == 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
|
||||
|
|
|
@ -50,20 +50,20 @@ module Vagrant
|
|||
end
|
||||
|
||||
def rootfs_path
|
||||
pathtype, path = config_string.match(/^lxc\.rootfs(?:\.path)?\s+=\s+(.+:)?(.+)$/)[1..2]
|
||||
case pathtype
|
||||
when 'overlayfs:'
|
||||
config_entry = config_string.match(/^lxc\.rootfs\s+=\s+(.+)$/)[1]
|
||||
case config_entry
|
||||
when /^overlayfs:/
|
||||
# Split on colon (:), ignoring any colon escaped by an escape character ( \ )
|
||||
# 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
|
||||
Pathname.new(overlay_path)
|
||||
else
|
||||
# Malformed: fall back to prior behaviour
|
||||
Pathname.new(path)
|
||||
Pathname.new(config_entry)
|
||||
end
|
||||
else
|
||||
Pathname.new(path)
|
||||
Pathname.new(config_entry)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -122,6 +122,10 @@ module Vagrant
|
|||
@cli.destroy
|
||||
end
|
||||
|
||||
def supports_attach?
|
||||
@cli.supports_attach?
|
||||
end
|
||||
|
||||
def attach(*command)
|
||||
@cli.attach(*command)
|
||||
end
|
||||
|
|
|
@ -89,13 +89,14 @@ module Vagrant
|
|||
# Man Page:
|
||||
# 2 The specified container exists but was not running.
|
||||
def stop
|
||||
attach '/sbin/halt' if supports_attach?
|
||||
begin
|
||||
run :stop, '--name', @name
|
||||
rescue LXC::Errors::ExecuteError => e
|
||||
if e.exitcode == 2
|
||||
@logger.debug "Machine already stopped, lxc-stop returned 2"
|
||||
@logger.debug "Machine already stopped, lxc-stop returned 2"
|
||||
else
|
||||
raise e
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -141,6 +142,19 @@ module Vagrant
|
|||
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
|
||||
|
||||
def run(command, *args)
|
||||
|
|
|
@ -10,7 +10,7 @@ module Vagrant
|
|||
EOF
|
||||
|
||||
provider(:lxc, parallel: true, priority: 7) do
|
||||
require_relative 'provider'
|
||||
require File.expand_path("../provider", __FILE__)
|
||||
init!
|
||||
Provider
|
||||
end
|
||||
|
@ -22,13 +22,13 @@ module Vagrant
|
|||
end
|
||||
|
||||
config(:lxc, :provider) do
|
||||
require_relative 'config'
|
||||
require File.expand_path("../config", __FILE__)
|
||||
init!
|
||||
Config
|
||||
end
|
||||
|
||||
synced_folder(:lxc) do
|
||||
require_relative 'synced_folder'
|
||||
require File.expand_path("../synced_folder", __FILE__)
|
||||
SyncedFolder
|
||||
end
|
||||
|
||||
|
|
|
@ -390,7 +390,7 @@ else
|
|||
;;
|
||||
"")
|
||||
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"
|
||||
else
|
||||
ip netns exec "$NSPID" ip addr add "$IPADDR" dev "$CONTAINER_IFNAME"
|
||||
|
|
|
@ -134,11 +134,36 @@ describe Vagrant::LXC::Driver::CLI do
|
|||
|
||||
before do
|
||||
allow(subject).to receive(:run)
|
||||
subject.stop
|
||||
end
|
||||
|
||||
it 'issues a lxc-stop with provided container name' do
|
||||
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
||||
context 'lxc-attach is supported' do
|
||||
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
|
||||
|
||||
|
@ -206,4 +231,33 @@ describe Vagrant::LXC::Driver::CLI do
|
|||
|
||||
skip 'waits for the expected container state'
|
||||
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
|
||||
|
|
|
@ -75,6 +75,17 @@ describe Vagrant::LXC::Driver do
|
|||
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
|
||||
let(:customizations) { [['a', '1'], ['b', '2']] }
|
||||
let(:internal_customization) { ['internal', 'customization'] }
|
||||
|
|
Loading…
Add table
Reference in a new issue