vagrant-lxc 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/lib/vagrant-lxc/action.rb +4 -9
- data/lib/vagrant-lxc/driver/cli.rb +22 -2
- data/lib/vagrant-lxc/driver.rb +8 -3
- data/lib/vagrant-lxc/errors.rb +4 -0
- data/lib/vagrant-lxc/provider.rb +4 -4
- data/lib/vagrant-lxc/version.rb +1 -1
- data/locales/en.yml +4 -0
- data/spec/unit/driver/cli_spec.rb +41 -3
- data/spec/unit/driver_spec.rb +26 -1
- data/templates/sudoers.rb.erb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1dddc38d13d5bbf1413f5cfbe0a668416096636
|
4
|
+
data.tar.gz: 646adccd342594104746e82741a0661a3c8a87d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aec9d4adc32aa37d0c3371e412698057fda1e05701c0f50ac7fe31bc3b72fd89a1a98b68947a92cb828c539ebf09c53d5a428ebf2e31c18c7423e3b5eb83554
|
7
|
+
data.tar.gz: 0a0593325da1a0b775d79251099647580583955d52cc6eda41b7c1bdad1f62680b24c0e867b010e238960861ce124996568a8436968fc33eb80f84ec06e5f787
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## [1.0.1](https://github.com/fgrehm/vagrant-lxc/compare/v1.0.0...v1.0.1) (Oct 15, 2014)
|
2
|
+
|
3
|
+
IMPROVEMENTS:
|
4
|
+
|
5
|
+
- Avoid lock race condition when fetching container's IP [[GH-318]] and SSH execution [[GH-321]]
|
6
|
+
- Support for custom containers storage path by reading `lxc.lxcpath` [[GH-317]]
|
7
|
+
|
8
|
+
|
9
|
+
[GH-317]: https://github.com/fgrehm/vagrant-lxc/pull/317
|
10
|
+
[GH-318]: https://github.com/fgrehm/vagrant-lxc/pull/318
|
11
|
+
[GH-321]: https://github.com/fgrehm/vagrant-lxc/issues/321
|
12
|
+
|
1
13
|
## [1.0.0](https://github.com/fgrehm/vagrant-lxc/compare/v1.0.0.alpha.3...v1.0.0) (Sep 23, 2014)
|
2
14
|
|
3
15
|
DEPRECATIONS:
|
data/Gemfile.lock
CHANGED
data/lib/vagrant-lxc/action.rb
CHANGED
@@ -195,16 +195,11 @@ module Vagrant
|
|
195
195
|
|
196
196
|
# This action is called to read the IP of the container. The IP found
|
197
197
|
# is expected to be put into the `:machine_ip` key.
|
198
|
-
def self.
|
198
|
+
def self.action_ssh_ip
|
199
199
|
Builder.new.tap do |b|
|
200
|
-
b.use Builtin::ConfigValidate
|
201
|
-
|
202
|
-
|
203
|
-
b2.use FetchIpWithLxcAttach if env[:machine].provider.driver.supports_attach?
|
204
|
-
b2.use FetchIpFromDnsmasqLeases
|
205
|
-
else
|
206
|
-
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running")
|
207
|
-
end
|
200
|
+
b.use Builtin::Call, Builtin::ConfigValidate do |env, b2|
|
201
|
+
b2.use FetchIpWithLxcAttach if env[:machine].provider.driver.supports_attach?
|
202
|
+
b2.use FetchIpFromDnsmasqLeases
|
208
203
|
end
|
209
204
|
end
|
210
205
|
end
|
@@ -28,14 +28,24 @@ module Vagrant
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def version
|
31
|
-
|
32
|
-
|
31
|
+
return @version if @version
|
32
|
+
@version = support_version_command? ? run(:version) : run(:create, '--version')
|
33
|
+
if @version =~ /(lxc version:\s+|)(.+)\s*$/
|
34
|
+
@version = $2.downcase
|
33
35
|
else
|
34
36
|
# TODO: Raise an user friendly error
|
35
37
|
raise 'Unable to parse lxc version!'
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
41
|
+
def config(param)
|
42
|
+
if support_config_command?
|
43
|
+
run(:config, param).gsub("\n", '')
|
44
|
+
else
|
45
|
+
raise Errors::CommandNotSupported, name: 'config', available_version: '> 1.x.x', version: version
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
39
49
|
def state
|
40
50
|
if @name && run(:info, '--name', @name, retryable: true) =~ /^state:[^A-Z]+([A-Z]+)$/i
|
41
51
|
$1.downcase.to_sym
|
@@ -134,6 +144,16 @@ module Vagrant
|
|
134
144
|
return @supports_attach
|
135
145
|
end
|
136
146
|
|
147
|
+
def support_config_command?
|
148
|
+
version[0].to_i >= 1
|
149
|
+
end
|
150
|
+
|
151
|
+
def support_version_command?
|
152
|
+
@sudo_wrapper.run('which', 'lxc-version').strip.chomp != ''
|
153
|
+
rescue Vagrant::LXC::Errors::ExecuteError
|
154
|
+
return false
|
155
|
+
end
|
156
|
+
|
137
157
|
private
|
138
158
|
|
139
159
|
def run(command, *args)
|
data/lib/vagrant-lxc/driver.rb
CHANGED
@@ -13,8 +13,8 @@ module Vagrant
|
|
13
13
|
# a name.
|
14
14
|
class ContainerNotFound < StandardError; end
|
15
15
|
|
16
|
-
#
|
17
|
-
|
16
|
+
# Default root folder where container configs are stored
|
17
|
+
DEFAULT_CONTAINERS_PATH = '/var/lib/lxc'
|
18
18
|
|
19
19
|
attr_reader :container_name,
|
20
20
|
:customizations
|
@@ -31,12 +31,17 @@ module Vagrant
|
|
31
31
|
raise ContainerNotFound if @container_name && ! @cli.list.include?(@container_name)
|
32
32
|
end
|
33
33
|
|
34
|
+
# Root folder where container configs are stored
|
35
|
+
def containers_path
|
36
|
+
@containers_path ||= @cli.support_config_command? ? @cli.config('lxc.lxcpath') : DEFAULT_CONTAINERS_PATH
|
37
|
+
end
|
38
|
+
|
34
39
|
def all_containers
|
35
40
|
@cli.list
|
36
41
|
end
|
37
42
|
|
38
43
|
def base_path
|
39
|
-
Pathname.new("#{
|
44
|
+
Pathname.new("#{containers_path}/#{@container_name}")
|
40
45
|
end
|
41
46
|
|
42
47
|
def rootfs_path
|
data/lib/vagrant-lxc/errors.rb
CHANGED
@@ -26,6 +26,10 @@ module Vagrant
|
|
26
26
|
error_key(:lxc_container_already_exists)
|
27
27
|
end
|
28
28
|
|
29
|
+
class CommandNotSupported < Vagrant::Errors::VagrantError
|
30
|
+
error_key(:lxc_command_not_supported)
|
31
|
+
end
|
32
|
+
|
29
33
|
# Box related errors
|
30
34
|
class TemplateFileMissing < Vagrant::Errors::VagrantError
|
31
35
|
error_key(:lxc_template_file_missing)
|
data/lib/vagrant-lxc/provider.rb
CHANGED
@@ -64,13 +64,13 @@ module Vagrant
|
|
64
64
|
|
65
65
|
# Returns the SSH info for accessing the Container.
|
66
66
|
def ssh_info
|
67
|
-
# If the Container is not
|
67
|
+
# If the Container is not running then we cannot possibly SSH into it, so
|
68
68
|
# we return nil.
|
69
|
-
return nil if state
|
69
|
+
return nil if state.id != :running
|
70
70
|
|
71
|
-
# Run a custom action called "
|
71
|
+
# Run a custom action called "ssh_ip" which does what it says and puts
|
72
72
|
# the IP found into the `:machine_ip` key in the environment.
|
73
|
-
env = @machine.action("
|
73
|
+
env = @machine.action("ssh_ip")
|
74
74
|
|
75
75
|
# If we were not able to identify the container's IP, we return nil
|
76
76
|
# here and we let Vagrant core deal with it ;)
|
data/lib/vagrant-lxc/version.rb
CHANGED
data/locales/en.yml
CHANGED
@@ -66,3 +66,7 @@ en:
|
|
66
66
|
There is container on your system with the same name you've specified
|
67
67
|
on your Vagrantfile (%{name}), please choose a different one or
|
68
68
|
run `lxc-destroy --name %{name}` and try again.
|
69
|
+
|
70
|
+
lxc_command_not_supported: |-
|
71
|
+
Command (lxc-%{command}) not supported in version %{version}.
|
72
|
+
This command is available with version %{available_version}.
|
@@ -29,14 +29,52 @@ describe Vagrant::LXC::Driver::CLI do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe 'version' do
|
32
|
-
|
32
|
+
before do
|
33
|
+
allow(subject).to receive(:run).with(:version).and_return(lxc_version_out)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'lxc version before 1.x.x' do
|
37
|
+
let(:lxc_version_out) { "lxc version: 0.x.y-rc1\n" }
|
38
|
+
|
39
|
+
it 'parses the version from the output' do
|
40
|
+
expect(subject.version).to eq('0.x.y-rc1')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'lxc version after 1.x.x' do
|
45
|
+
let(:lxc_version_out) { "1.0.0\n" }
|
46
|
+
|
47
|
+
it 'parses the version from the output' do
|
48
|
+
expect(subject.version).to eq('1.0.0')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
33
52
|
|
53
|
+
describe 'config' do
|
34
54
|
before do
|
55
|
+
allow(subject).to receive(:run).with(:config, 'lxc.lxcpath').and_return(lxc_config_out)
|
35
56
|
allow(subject).to receive(:run).with(:version).and_return(lxc_version_out)
|
57
|
+
allow(subject).to receive(:run).with(:create, '--version').and_return(lxc_version_out)
|
36
58
|
end
|
37
59
|
|
38
|
-
|
39
|
-
|
60
|
+
describe 'lxc version before 1.x.x' do
|
61
|
+
let(:support_version_command?) { true }
|
62
|
+
let(:lxc_config_out) { "/var/lib/lxc\n" }
|
63
|
+
let(:lxc_version_out) { "lxc version: 0.x.y-rc1\n" }
|
64
|
+
|
65
|
+
it 'not supported' do
|
66
|
+
expect{subject.config('lxc.lxcpath')}.to raise_error(Vagrant::LXC::Errors::CommandNotSupported)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'lxc version before after 1.x.x'do
|
71
|
+
let(:support_version_command?) { false }
|
72
|
+
let(:lxc_config_out) { "/var/lib/lxc\n" }
|
73
|
+
let(:lxc_version_out) { "1.0.0\n" }
|
74
|
+
|
75
|
+
it 'parser the lxc.lxcpath value' do
|
76
|
+
expect(subject.config('lxc.lxcpath')).not_to end_with("\n")
|
77
|
+
end
|
40
78
|
end
|
41
79
|
end
|
42
80
|
|
data/spec/unit/driver_spec.rb
CHANGED
@@ -89,7 +89,7 @@ describe Vagrant::LXC::Driver do
|
|
89
89
|
describe 'start' do
|
90
90
|
let(:customizations) { [['a', '1'], ['b', '2']] }
|
91
91
|
let(:internal_customization) { ['internal', 'customization'] }
|
92
|
-
let(:cli) { double(Vagrant::LXC::Driver::CLI, start: true) }
|
92
|
+
let(:cli) { double(Vagrant::LXC::Driver::CLI, start: true, support_config_command?: false) }
|
93
93
|
let(:sudo) { double(Vagrant::LXC::SudoWrapper) }
|
94
94
|
|
95
95
|
subject { described_class.new('name', sudo, cli) }
|
@@ -99,6 +99,7 @@ describe Vagrant::LXC::Driver do
|
|
99
99
|
and_return('# CONFIGURATION')
|
100
100
|
sudo.should_receive(:run).twice.with('cp', '-f', %r{/tmp/.*}, '/var/lib/lxc/name/config')
|
101
101
|
sudo.should_receive(:run).twice.with('chown', 'root:root', '/var/lib/lxc/name/config')
|
102
|
+
|
102
103
|
subject.customizations << internal_customization
|
103
104
|
subject.start(customizations)
|
104
105
|
end
|
@@ -150,6 +151,30 @@ describe Vagrant::LXC::Driver do
|
|
150
151
|
end
|
151
152
|
end
|
152
153
|
|
154
|
+
describe 'containers_path' do
|
155
|
+
let(:cli) { double(Vagrant::LXC::Driver::CLI, config: cli_config_value, support_config_command?: cli_support_config_command_value) }
|
156
|
+
|
157
|
+
subject { described_class.new('name', nil, cli) }
|
158
|
+
|
159
|
+
describe 'lxc version before 1.x.x' do
|
160
|
+
let(:cli_support_config_command_value) { false }
|
161
|
+
let(:cli_config_value) { '/var/lib/lxc' }
|
162
|
+
|
163
|
+
it 'delegates to cli' do
|
164
|
+
expect(subject.containers_path).to eq(cli_config_value)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe 'lxc version after 1.x.x' do
|
169
|
+
let(:cli_support_config_command_value) { true }
|
170
|
+
let(:cli_config_value) { '/etc/lxc' }
|
171
|
+
|
172
|
+
it 'delegates to cli' do
|
173
|
+
expect(subject.containers_path).to eq(cli_config_value)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
153
178
|
describe 'folder sharing' do
|
154
179
|
let(:shared_folder) { {guestpath: '/vagrant', hostpath: '/path/to/host/dir'} }
|
155
180
|
let(:ro_rw_folder) { {guestpath: '/vagrant/ro_rw', hostpath: '/path/to/host/dir', mount_options: ['ro', 'rw']} }
|
data/templates/sudoers.rb.erb
CHANGED
@@ -95,12 +95,14 @@ Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-version'
|
|
95
95
|
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-ls'
|
96
96
|
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-info', '--name', /.*/
|
97
97
|
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-create', '-B', /.*/, '--template', /.*/, '--name', /.*/, '**'
|
98
|
+
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-create', '--version'
|
98
99
|
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-destroy', '--name', /.*/
|
99
100
|
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-start', '-d', '--name', /.*/, '**'
|
100
101
|
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-stop', '--name', /.*/
|
101
102
|
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-shutdown', '--name', /.*/
|
102
103
|
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-attach', '--name', /.*/, '**'
|
103
104
|
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-attach', '-h'
|
105
|
+
Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-config', 'lxc.lxcpath'
|
104
106
|
|
105
107
|
##
|
106
108
|
# Commands from driver/action/remove_temporary_files.rb
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-lxc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Rehm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux Containers provider for Vagrant
|
14
14
|
email:
|