Merge 0.8.0

This commit is contained in:
Fabio Rehm 2014-02-26 21:55:35 -03:00
commit d391e840cc
13 changed files with 108 additions and 34 deletions

View file

@ -1,4 +1,14 @@
## [0.7.1](https://github.com/fgrehm/vagrant-lxc/compare/v0.7.0...master) (unreleased)
## [0.8.0](https://github.com/fgrehm/vagrant-lxc/compare/v0.7.0...v0.8.0) (Feb 26, 2014)
FEATURES:
- Support for naming containers from Vagrantfiles [#132](https://github.com/fgrehm/vagrant-lxc/issues/132)
IMPROVEMENTS:
- Use a safer random name for containers [#152](https://github.com/fgrehm/vagrant-lxc/issues/152)
- Improve Ubuntu 13.10 compatibility [#190](https://github.com/fgrehm/vagrant-lxc/pull/190) / [#197](https://github.com/fgrehm/vagrant-lxc/pull/197)
- Improved mac address detection from lxc configs [#226](https://github.com/fgrehm/vagrant-lxc/pull/226)
BUG FIXES:

View file

@ -25,7 +25,7 @@ GIT
PATH
remote: .
specs:
vagrant-lxc (0.7.1.dev)
vagrant-lxc (0.8.0)
GEM
remote: https://rubygems.org/

View file

@ -1,6 +1,6 @@
# 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)
[![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) [![Gittip](http://img.shields.io/gittip/fgrehm.svg)](https://www.gittip.com/fgrehm/)
[LXC](http://lxc.sourceforge.net/) provider for [Vagrant](http://www.vagrantup.com/) 1.1+
@ -95,11 +95,30 @@ prior to starting it.
For other configuration options, please check the [lxc.conf manpages](http://manpages.ubuntu.com/manpages/quantal/man5/lxc.conf.5.html).
### Container naming
By default vagrant-lxc will attempt to generate a unique container name
for you. However, if the container name is important to you, you may use the
`container_name` attribute to set it explicitly from the `provider` block:
```ruby
Vagrant.configure("2") do |config|
config.vm.box = "quantal64"
config.vm.define "db" do |node|
node.vm.provider :lxc do |lxc|
lxc.container_name = :machine # Sets the container name to 'db'
lxc.container_name = 'mysql' # Sets the container name to 'mysql'
end
end
end
```
### Avoiding `sudo` passwords
This plugin requires **a lot** of `sudo`ing since [user namespaces](https://wiki.ubuntu.com/UserNamespace)
are not supported on mainstream kernels. Have a look at the [Wiki](https://github.com/fgrehm/vagrant-lxc/wiki/Avoiding-'sudo'-passwords)
to find out how to work around that specially if you are running an OS with sudo
to find out how to work around that specially if you are running an OS with `sudo`
< 1.8.4 (like Ubuntu 12.04) as you might be affected by a bug.
### Base boxes
@ -123,14 +142,6 @@ list if you have a problem and feel free to use the [issue tracker](https://gith
propose new functionality and / or report bugs.
## Support
Support this project and [others by fgrehm](https://github.com/fgrehm)
via [gittip](https://www.gittip.com/fgrehm/).
[![Support via Gittip](https://rawgithub.com/twolfson/gittip-badge/0.1.0/dist/gittip.png)](https://www.gittip.com/fgrehm/)
## Contributing
1. Fork it
@ -138,5 +149,3 @@ via [gittip](https://www.gittip.com/fgrehm/).
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/fgrehm/vagrant-lxc/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

View file

@ -7,9 +7,20 @@ module Vagrant
end
def call(env)
container_name = env[:machine].provider_config.container_name
case container_name
when :machine
container_name = env[:machine].name.to_s
when String
# Nothing to do here, move along...
else
container_name = "#{env[:root_path].basename}_#{env[:machine].name}"
container_name.gsub!(/[^-a-z0-9_]/i, "")
container_name << "-#{Time.now.to_i}"
# milliseconds + random number suffix to allow for simultaneous
# `vagrant up` of the same box in different dirs
container_name << "_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}"
end
env[:machine].provider.driver.create(
container_name,

View file

@ -12,9 +12,14 @@ module Vagrant
# on /etc/sudoers
attr_accessor :sudo_wrapper
# A string to explicitly set the container name. To use the vagrant
# machine name, set this to :machine
attr_accessor :container_name
def initialize
@customizations = []
@sudo_wrapper = UNSET_VALUE
@container_name = UNSET_VALUE
end
# Customize the container by calling `lxc-start` with the given
@ -34,6 +39,7 @@ module Vagrant
def finalize!
@sudo_wrapper = nil if @sudo_wrapper == UNSET_VALUE
@container_name = nil if @container_name == UNSET_VALUE
end
def validate(machine)

View file

@ -40,7 +40,7 @@ module Vagrant
end
def mac_address
@mac_address ||= config_string.match(/^lxc\.network\.hwaddr\s+=\s+(.+)$/)[1]
@mac_address ||= config_string.match(/^lxc\.network\.hwaddr\s*+=\s*+(.+)$/)[1]
end
def config_string

View file

@ -38,7 +38,7 @@ module Vagrant
end
def state
if @name && run(:info, '--name', @name, retryable: true) =~ /^state:[^A-Z]+([A-Z]+)$/
if @name && run(:info, '--name', @name, retryable: true) =~ /^state:[^A-Z]+([A-Z]+)$/i
$1.downcase.to_sym
elsif @name
:unknown
@ -58,6 +58,12 @@ module Vagrant
'--name', @name,
*(config_opts),
*extra
rescue Errors::ExecuteError => e
if e.stderr =~ /already exists/i
raise Errors::ContainerAlreadyExists, name: @name
else
raise
end
end
def destroy
@ -69,6 +75,7 @@ module Vagrant
end
def stop
attach '/sbin/halt'
run :stop, '--name', @name
end

View file

@ -5,7 +5,16 @@ module Vagrant
module Errors
class ExecuteError < Vagrant::Errors::VagrantError
error_key(:lxc_execute_error)
attr_reader :stderr, :stdout
def initialize(message, *args)
super
if message.is_a?(Hash)
@stderr = message[:stderr]
@stdout = message[:stdout]
end
end
end
class NamespacesNotSupported < Vagrant::Errors::VagrantError
end
@ -13,6 +22,10 @@ module Vagrant
error_key(:lxc_not_installed)
end
class ContainerAlreadyExists < Vagrant::Errors::VagrantError
error_key(:lxc_container_already_exists)
end
# Box related errors
class TemplateFileMissing < Vagrant::Errors::VagrantError
error_key(:lxc_template_file_missing)

View file

@ -27,7 +27,7 @@ module Vagrant
def ensure_lxc_installed!
begin
sudo_wrapper.run("which", "lxc-version")
sudo_wrapper.run("which", "lxc-create")
rescue Vagrant::LXC::Errors::ExecuteError
raise Errors::LxcNotInstalled
end

View file

@ -51,7 +51,8 @@ module Vagrant
if @interrupted
@logger.info("Exit code != 0, but interrupted. Ignoring.")
else
raise LXC::Errors::ExecuteError, :command => command.inspect
raise LXC::Errors::ExecuteError,
command: command.inspect, stderr: r.stderr, stdout: r.stdout
end
end
end

View file

@ -1,5 +1,5 @@
module Vagrant
module LXC
VERSION = "0.7.1.dev"
VERSION = "0.8.0"
end
end

View file

@ -60,3 +60,8 @@ en:
lxc_redir_not_installed: |-
`redir` is not installed or is not accessible on the PATH.
lxc_container_already_exists: |-
There is container on your system with the same name you've specified
on your Vagrantfile (%{name}), please choose a different one or
run `lxc-destroy --name %{name}` and try again.

View file

@ -49,10 +49,10 @@ describe Vagrant::LXC::Driver::CLI do
before do
subject.stub(:run) { |*args| @run_args = args }
subject.create(template, config_file, template_args)
end
it 'issues a lxc-create with provided template, container name and hash of arguments' do
subject.create(template, config_file, template_args)
subject.should have_received(:run).with(
:create,
'--template', template,
@ -63,6 +63,13 @@ describe Vagrant::LXC::Driver::CLI do
'--other', 'value'
)
end
it 'wraps a low level error into something more meaningful in case the container already exists' do
subject.stub(:run) { raise Vagrant::LXC::Errors::ExecuteError, stderr: 'alreAdy Exists' }
expect {
subject.create(template, config_file, template_args)
}.to raise_error(Vagrant::LXC::Errors::ContainerAlreadyExists)
end
end
describe 'destroy' do
@ -134,6 +141,11 @@ describe Vagrant::LXC::Driver::CLI do
it 'maps the output of lxc-info status out to a symbol' do
subject.state.should == :stopped
end
it 'is not case sensitive' do
subject.stub(:run).and_return("StatE: STarTED\npid: 2")
subject.state.should == :started
end
end
describe 'attach' do