lxc-ruby 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/README.md +27 -10
- data/lib/lxc.rb +11 -2
- data/lib/lxc/container.rb +5 -2
- data/lib/lxc/shell.rb +5 -0
- data/lib/lxc/version.rb +1 -1
- data/spec/container_spec.rb +28 -0
- data/spec/lxc_spec.rb +18 -7
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3278c0b50a89c969fa21e9c1151fc614e325eff8
|
4
|
+
data.tar.gz: 38d8b3efd06f23d2dfd04fa8e770b16b779f8ab8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a61cb7a870e39a69b08e177e9eefafce41d61c8f682488655f558f501e47736fa5a2b8dc8b9e5b45aadfa74205eaefa94185a7f805fbf9d1026ff8ad160034c
|
7
|
+
data.tar.gz: b7d2a8468de82b3b79e237beb57000bc5346e091b716b94079192f0c430afa52d304cea74b1592d9b9adc113bf97b1111fc53e34ca011fdea43c1b9b86f1bd7f
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
-
#
|
1
|
+
# lxc-ruby
|
2
2
|
|
3
|
-
Ruby
|
3
|
+
Ruby wrapper for [Linux Containers](http://lxc.sourceforge.net/) tools.
|
4
|
+
|
5
|
+
[](http://travis-ci.org/sosedoff/lxc-ruby)
|
4
6
|
|
5
7
|
## Requirements
|
6
8
|
|
7
9
|
Supported LXC versions:
|
8
10
|
|
9
11
|
- 0.7.5
|
10
|
-
- 0.8.0
|
12
|
+
- 0.8.0
|
13
|
+
- 0.9.0
|
11
14
|
|
12
15
|
For testing purposes you can use [Vagrant](http://vagrantup.com/) with [VirtualBox](https://www.virtualbox.org/).
|
13
|
-
Most of the functionality was tested on 64-bit Ubuntu
|
16
|
+
Most of the functionality was tested on 64-bit Ubuntu 12.04.
|
14
17
|
Additional boxes could be found [here](http://www.vagrantbox.es/).
|
15
18
|
|
16
19
|
## Installation
|
@@ -131,7 +134,10 @@ LXC.use_sudo = true
|
|
131
134
|
|
132
135
|
**Using lxc-setcap**
|
133
136
|
|
134
|
-
If you want to make container usable by non-root users, run lxc-setcap as root,
|
137
|
+
If you want to make container usable by non-root users, run lxc-setcap as root,
|
138
|
+
and some capabilities will be set so that normal users will be able to use the
|
139
|
+
container utils. This is not done by default, though, and you have to
|
140
|
+
explicitly allow it.
|
135
141
|
|
136
142
|
## Testing
|
137
143
|
|
@@ -145,8 +151,19 @@ rake test
|
|
145
151
|
|
146
152
|
Copyright (c) 2012-2013 Dan Sosedoff.
|
147
153
|
|
148
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
154
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
155
|
+
this software and associated documentation files (the "Software"), to deal in
|
156
|
+
the Software without restriction, including without limitation the rights to
|
157
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
158
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
159
|
+
subject to the following conditions:
|
160
|
+
|
161
|
+
The above copyright notice and this permission notice shall be included in all
|
162
|
+
copies or substantial portions of the Software.
|
163
|
+
|
164
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
165
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
166
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
167
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
168
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
169
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/lxc.rb
CHANGED
@@ -53,9 +53,18 @@ module LXC
|
|
53
53
|
# @param [String] select containers that match string
|
54
54
|
# @return [Array] array of LXC::Containers
|
55
55
|
def self.containers(filter=nil)
|
56
|
-
names = LXC.run(
|
56
|
+
names = LXC.run("ls").split("\n").uniq
|
57
57
|
|
58
|
-
|
58
|
+
if filter
|
59
|
+
names = names.select do |name|
|
60
|
+
if filter.kind_of?(Regexp)
|
61
|
+
name =~ filter ? true : false
|
62
|
+
elsif filter.kind_of?(String)
|
63
|
+
name.include?(filter)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
59
68
|
names.map { |name| LXC::Container.new(name) }
|
60
69
|
end
|
61
70
|
|
data/lib/lxc/container.rb
CHANGED
@@ -172,8 +172,11 @@ module LXC
|
|
172
172
|
LXC.run('create', args)
|
173
173
|
exists?
|
174
174
|
else
|
175
|
-
|
176
|
-
|
175
|
+
unless File.exists?(path)
|
176
|
+
raise ArgumentError, "File #{path} does not exist."
|
177
|
+
end
|
178
|
+
|
179
|
+
LXC.run("create", "-n", name, "-f", path)
|
177
180
|
exists?
|
178
181
|
end
|
179
182
|
end
|
data/lib/lxc/shell.rb
CHANGED
@@ -88,6 +88,11 @@ module LXC
|
|
88
88
|
cmd << "#{command_name} #{args.join(' ')}".strip
|
89
89
|
cmd << " | #{yield}" if block_given?
|
90
90
|
|
91
|
+
# Debug if LXC_DEBUG env is set
|
92
|
+
if ENV["LXC_DEBUG"]
|
93
|
+
puts "Executing: #{cmd}"
|
94
|
+
end
|
95
|
+
|
91
96
|
child = POSIX::Spawn::Child.new(cmd.strip)
|
92
97
|
child.out
|
93
98
|
end
|
data/lib/lxc/version.rb
CHANGED
data/spec/container_spec.rb
CHANGED
@@ -42,6 +42,34 @@ describe LXC::Container do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe "#create" do
|
46
|
+
context "when container already exists" do
|
47
|
+
before do
|
48
|
+
stub_lxc("ls") { "app" }
|
49
|
+
end
|
50
|
+
|
51
|
+
it "raises error" do
|
52
|
+
expect { subject.create("path") }.
|
53
|
+
to raise_error LXC::ContainerError, "Container already exists."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "raises error if config path does not exist" do
|
58
|
+
stub_lxc("ls") { "" }
|
59
|
+
|
60
|
+
expect { subject.create("foobar") }.
|
61
|
+
to raise_error ArgumentError, "File foobar does not exist."
|
62
|
+
end
|
63
|
+
|
64
|
+
it "creates a new container" do
|
65
|
+
stub_lxc("ls") { "" }
|
66
|
+
stub_lxc("create", "-n", "app", "-f", "/tmp") { "" }
|
67
|
+
stub_lxc("ls") { "app" }
|
68
|
+
|
69
|
+
expect(subject.create("/tmp")).to eq true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
45
73
|
describe '#destroy' do
|
46
74
|
it 'raises error if container does not exist' do
|
47
75
|
stub_lxc('ls') { "app2" }
|
data/spec/lxc_spec.rb
CHANGED
@@ -70,8 +70,8 @@ describe LXC do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
describe
|
74
|
-
it
|
73
|
+
describe ".containers" do
|
74
|
+
it "returns all available containers" do
|
75
75
|
stub_lxc('ls') { "vm0\nvm1\nvm0" }
|
76
76
|
|
77
77
|
list = LXC.containers
|
@@ -81,12 +81,23 @@ describe LXC do
|
|
81
81
|
expect(list.first.name).to eq('vm0')
|
82
82
|
end
|
83
83
|
|
84
|
-
context
|
85
|
-
|
86
|
-
stub_lxc(
|
84
|
+
context "with string filter" do
|
85
|
+
before do
|
86
|
+
stub_lxc("ls") { "vm0\nvm1\nfoo\n"}
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns matched containers" do
|
90
|
+
expect(LXC.containers("vm").size).to eq 2
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "with regexp filter" do
|
95
|
+
before do
|
96
|
+
stub_lxc("ls") { "vm0\nvm1\nfoo\n"}
|
97
|
+
end
|
87
98
|
|
88
|
-
|
89
|
-
expect(
|
99
|
+
it "returns matched container" do
|
100
|
+
expect(LXC.containers(/vm/).size).to eq 2
|
90
101
|
end
|
91
102
|
end
|
92
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lxc-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Sosedoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: posix-spawn
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.0.
|
121
|
+
rubygems_version: 2.0.3
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Ruby wrapper to LXC
|
@@ -134,4 +134,3 @@ test_files:
|
|
134
134
|
- spec/lxc_spec.rb
|
135
135
|
- spec/spec_helper.rb
|
136
136
|
- spec/status_spec.rb
|
137
|
-
has_rdoc:
|