lxc-ruby 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/lib/lxc/container.rb +6 -0
- data/lib/lxc/version.rb +1 -1
- data/spec/container_spec.rb +51 -14
- metadata +4 -3
data/README.md
CHANGED
data/lib/lxc/container.rb
CHANGED
@@ -45,6 +45,12 @@ module LXC
|
|
45
45
|
status[:state] == 'FROZEN'
|
46
46
|
end
|
47
47
|
|
48
|
+
# Check if container is stopped?
|
49
|
+
# @return [Boolean]
|
50
|
+
def stopped?
|
51
|
+
exists? && status[:state] == 'STOPPED'
|
52
|
+
end
|
53
|
+
|
48
54
|
# Start container
|
49
55
|
# @return [Hash] container status hash
|
50
56
|
def start
|
data/lib/lxc/version.rb
CHANGED
data/spec/container_spec.rb
CHANGED
@@ -13,15 +13,23 @@ describe LXC::Container do
|
|
13
13
|
subject.pid.should be_nil
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
describe '#exists?' do
|
17
|
+
context 'for existing container' do
|
18
|
+
it 'returns true' do
|
19
|
+
stub_lxc('ls') { "app\napp2" }
|
20
|
+
subject.exists?.should be_true
|
21
|
+
end
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
context 'for non-existing container' do
|
25
|
+
it 'returns false' do
|
26
|
+
stub_lxc('ls') { "app2\napp3" }
|
27
|
+
subject.exists?.should be_false
|
28
|
+
end
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
|
-
|
32
|
+
describe '#status' do
|
25
33
|
it 'returns STOPPED' do
|
26
34
|
stub_lxc('info', '-n', 'app') { fixture('lxc-info-stopped.txt') }
|
27
35
|
subject.status.should eq({:state => 'STOPPED', :pid => '-1'})
|
@@ -33,7 +41,7 @@ describe LXC::Container do
|
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
36
|
-
|
44
|
+
describe '#destroy' do
|
37
45
|
it 'raises error if container does not exist' do
|
38
46
|
stub_lxc('ls') { "app2" }
|
39
47
|
proc { subject.destroy }.
|
@@ -48,17 +56,21 @@ describe LXC::Container do
|
|
48
56
|
end
|
49
57
|
end
|
50
58
|
|
51
|
-
|
52
|
-
|
53
|
-
|
59
|
+
describe '#memory_usage' do
|
60
|
+
it 'returns the amount of used memory' do
|
61
|
+
stub_lxc('cgroup', '-n', 'app', 'memory.usage_in_bytes') { "3280896\n" }
|
62
|
+
subject.memory_usage.should eq(3280896)
|
63
|
+
end
|
54
64
|
end
|
55
65
|
|
56
|
-
|
57
|
-
|
58
|
-
|
66
|
+
describe '#memory_limit' do
|
67
|
+
it 'returns the memory limit' do
|
68
|
+
stub_lxc('cgroup', '-n', 'app', 'memory.limit_in_bytes') { "268435456\n" }
|
69
|
+
subject.memory_limit.should eq(268435456)
|
70
|
+
end
|
59
71
|
end
|
60
72
|
|
61
|
-
|
73
|
+
describe '#processes' do
|
62
74
|
it 'raises error if container is not running' do
|
63
75
|
stub_lxc('info', '-n', 'app') { fixture('lxc-info-stopped.txt') }
|
64
76
|
|
@@ -83,4 +95,29 @@ describe LXC::Container do
|
|
83
95
|
p.should have_key('args')
|
84
96
|
end
|
85
97
|
end
|
98
|
+
|
99
|
+
describe '#stopped?' do
|
100
|
+
context 'when container does not exist' do
|
101
|
+
it 'returns false' do
|
102
|
+
stub_lxc('ls') { "foo-app" }
|
103
|
+
subject.stopped?.should be_false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when container exists' do
|
108
|
+
it 'returns true if stopped' do
|
109
|
+
stub_lxc('ls') { 'app' }
|
110
|
+
stub_lxc('info', '-n', 'app') { fixture('lxc-info-stopped.txt') }
|
111
|
+
|
112
|
+
subject.stopped?.should be_true
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'returns false if running' do
|
116
|
+
stub_lxc('ls') { 'app' }
|
117
|
+
stub_lxc('info', '-n', 'app') { fixture('lxc-info-running.txt') }
|
118
|
+
|
119
|
+
subject.stopped?.should be_false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
86
123
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lxc-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.8.
|
113
|
+
rubygems_version: 1.8.24
|
114
114
|
signing_key:
|
115
115
|
specification_version: 3
|
116
116
|
summary: Ruby wrapper to LXC
|
@@ -125,3 +125,4 @@ test_files:
|
|
125
125
|
- spec/fixtures/lxc-version.txt
|
126
126
|
- spec/lxc_spec.rb
|
127
127
|
- spec/spec_helper.rb
|
128
|
+
has_rdoc:
|