linux-lxc 0.0.4 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b046b82ebb5b24db19f4e93d53ee8c7b932f44b
4
- data.tar.gz: 3fe3961749468474f2e673f45b283ab7e3db50ef
3
+ metadata.gz: c9ea4fb656b6d88f11202061ddf0177756b8e330
4
+ data.tar.gz: 801d1d04602c7ca47baaa87ae62bfdf8c7c7aa5e
5
5
  SHA512:
6
- metadata.gz: e0b848e1d55edd2edbe26290c0f0f325baab67a8551887a7afa5636480faa960059ffc25065bf0b2f06bd080c121cee10d0d8ee03526c12a9c1ac007e92622ff
7
- data.tar.gz: beb3d9773ef16949070c2816fc02be8714f1e4757e32d391944eabb9d2fae75d09effead7b7ec4df7f085ab0b0d35e9229e4aff36d2b126d0bcf31aea0e0dc1c
6
+ metadata.gz: ced9dd2ca6f1e5fa8d832981c2985a9d8cb7b50cbbef6ba9b2af30a39b255865ea20399692bc8710230153ebb4d43ec44444314caa97deb697bb0b16570f0dd2
7
+ data.tar.gz: 45b562050ef4c80f461b123531a25a5bd5a616780599abdf78ab46a94058e42fdf23508f7058922fd4c91e15504e01424fc6c8fb76b615dbb233209784e7201e
@@ -0,0 +1,53 @@
1
+ # def glob?
2
+ # @used_glob
3
+ # end
4
+
5
+ # def get_entries
6
+ # entries = []
7
+ # if ::File.directory?(file)
8
+ # @used_glob = true
9
+ # entries += ::Dir.glob(::File.join(file, "*")).select{|f| ::File.file?(f) }
10
+ # elsif ::File.file?(file)
11
+ # entries += [file]
12
+ # end
13
+ # entries
14
+ # end
15
+
16
+
17
+ module Linux
18
+ module Lxc
19
+ class Directory
20
+ attr_reader :entries, :index, :file
21
+ def initialize(fname, index)
22
+ @file = fname
23
+ @index = index
24
+ @entries = {}
25
+ end
26
+
27
+ def all_lines(&block)
28
+ @entries.values.each do |entry|
29
+ entry.all_lines(&block)
30
+ end
31
+ end
32
+
33
+ def to_s
34
+ @file
35
+ end
36
+
37
+ def get(key)
38
+ @index.get_key(key)
39
+ end
40
+
41
+ def add_file(fname)
42
+ @entries[fname] ||= @index.add_file(fname, self)
43
+ end
44
+
45
+ def write
46
+ FileUtils.mkdir_p file
47
+ @entries.values.each do |entry|
48
+ entry.write
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,116 @@
1
+
2
+ module Linux
3
+ module Lxc
4
+ class File
5
+ attr_reader :index, :lines, :file, :dir
6
+ attr_accessor :real_fname
7
+
8
+ def initialize(file, dir, index)
9
+ self.file = file
10
+ @dir = dir
11
+ @lines = Lines.new
12
+ @index = index
13
+ end
14
+
15
+ # file is more important than real_fname
16
+ def file=(a)
17
+ @file = a
18
+ @real_fname = a
19
+ end
20
+
21
+ def get(key)
22
+ @index.get_key(key)
23
+ end
24
+
25
+ def key_to_path(key, &block)
26
+ path = ''
27
+ dot = ''
28
+ key.split('.').each do |element|
29
+ path += dot + element
30
+ dot = '.'
31
+ # puts ">>>>#{path}"
32
+ block.call(path)
33
+ end
34
+ end
35
+
36
+ def remove_from_index(line)
37
+ key_to_path(line.key) do |path|
38
+ lines = @index.get_key(path)
39
+ lines.remove(line)
40
+ @index.delete_key(path)
41
+ end
42
+ end
43
+
44
+ def add(key, value = nil)
45
+ key = key.strip
46
+ value = value.strip if value && value.instance_of?(String)
47
+ line = Line.new(self, key, value)
48
+ add_to_index(line)
49
+ end
50
+
51
+ def add_to_index(line)
52
+ key_to_path(line.key) do |path|
53
+ @index.add_line(path, line)
54
+ end
55
+ end
56
+
57
+ def all_lines(&block)
58
+ @lines.each do |line|
59
+ block.call(line)
60
+ line.value.all_lines(&block) if line.value.respond_to?(:all_lines)
61
+ end
62
+ end
63
+
64
+ # def files
65
+ # ret = [Line.new(nil, 'lxc.include', self)]
66
+ # all_lines do |line|
67
+ # line.value.instance_of?(File) && (ret << line)
68
+ # end
69
+ # ret
70
+ # end
71
+
72
+ def entries
73
+ {file => self}
74
+ end
75
+
76
+ def write
77
+ FileUtils.mkdir_p ::File.dirname(real_fname)
78
+ ::File.open(real_fname, 'w') do |f|
79
+ @lines.each do |line|
80
+ if line.key == 'lxc.include'
81
+ line.value.write
82
+ f.write(line.to_s + "\n")
83
+ else
84
+ f.write(line.to_s + "\n")
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ def to_s
91
+ @file
92
+ end
93
+
94
+ def parse
95
+ IO.read(file).lines.each do |line|
96
+ line = line.chop
97
+ if line.match(/^\s*$/)
98
+ self.add(line, nil)
99
+ elsif line.match(/^\s*#.*$/)
100
+ self.add('#', line)
101
+ else
102
+ match = line.match(/^\s*([a-z_\.]+)\s*=\s*(.*)\s*$/)
103
+ throw "illegal line in #{@file}:#{@lines.length}" unless match
104
+ if match[1] == 'lxc.include'
105
+ self.add(match[1], Lxc.parse(match[2], index))
106
+ else
107
+ self.add(match[1], match[2])
108
+ end
109
+ end
110
+ end
111
+
112
+ self
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,35 @@
1
+ module Linux
2
+ module Lxc
3
+ class Index
4
+ attr_reader :files
5
+
6
+ def initialize
7
+ @key_index = {}
8
+ @dirs = {}
9
+ @files = {}
10
+ end
11
+
12
+ def add_line(key, line)
13
+ @key_index[key] ||= Lines.new
14
+ @key_index[key].add(line)
15
+ end
16
+
17
+ def get_key(key)
18
+ @key_index[key]
19
+ end
20
+
21
+ def delete_key(key)
22
+ return if @key_index[key].nil? || !@key_index[key].empty?
23
+ @key_index.delete(key)
24
+ end
25
+
26
+ def get_directory(fname)
27
+ @dirs[fname] ||= Directory.new(fname, self)
28
+ end
29
+
30
+ def add_file(fname, dir)
31
+ @files[fname] ||= File.new(fname, dir, self)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module Linux
2
+ module Lxc
3
+ class Line
4
+ attr_reader :lxc, :line, :key
5
+ attr_accessor :value
6
+ def initialize(lxc, key, value)
7
+ @lxc = lxc
8
+ @line = lxc && lxc.lines.add(self).length
9
+ @key = key
10
+ @value = value
11
+ end
12
+
13
+ def file
14
+ @lxc.file
15
+ end
16
+
17
+ def comment!
18
+ return if @key == '#'
19
+ # remove from index
20
+ lxc.remove_from_index(self)
21
+ @key = '#'
22
+ @value = '# ' + to_s
23
+ lxc.add_to_index(self)
24
+ end
25
+
26
+ def to_s
27
+ if value
28
+ "#{key} = #{value}"
29
+ else
30
+ key
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,46 @@
1
+ module Linux
2
+ module Lxc
3
+ class Lines
4
+ def initialize
5
+ @lines = []
6
+ end
7
+
8
+ def add(line)
9
+ @lines << line
10
+ @lines
11
+ end
12
+
13
+ def each(&block)
14
+ @lines.each { |line| block.call(line) }
15
+ end
16
+
17
+ def values
18
+ @lines.map(&:value)
19
+ end
20
+
21
+ def remove(line)
22
+ @lines = @lines.select { |i| i != line }
23
+ end
24
+
25
+ def [](idx)
26
+ @lines[idx]
27
+ end
28
+
29
+ def comment!
30
+ @lines.each(&:comment!)
31
+ end
32
+
33
+ def length
34
+ @lines.length
35
+ end
36
+
37
+ def empty?
38
+ @lines.empty?
39
+ end
40
+
41
+ def first
42
+ @lines.first
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  module Linux
2
- class Lxc
3
- VERSION = "0.0.4"
2
+ module Lxc
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
data/lib/linux/lxc.rb CHANGED
@@ -1,181 +1,32 @@
1
- require "linux/lxc/version"
1
+ require_relative 'lxc/version'
2
+ require_relative 'lxc/line'
3
+ require_relative 'lxc/lines'
4
+ require_relative 'lxc/file'
5
+ require_relative 'lxc/directory'
6
+ require_relative 'lxc/index'
2
7
 
3
8
  module Linux
4
- class Lxc
5
-
6
- class Line
7
- attr_reader :lxc, :line, :key
8
- attr_accessor :value
9
- def initialize(lxc, key, value)
10
- @lxc = lxc
11
- @line = lxc && lxc.lines.add(self).length
12
- @key = key
13
- @value = value
14
- end
15
- def file
16
- @lxc.file
17
- end
18
- def comment!
19
- return if @key == '#'
20
- # remove from index
21
- lxc.remove_from_index(self)
22
- @key = '#'
23
- @value = '# ' + self.to_s
24
- lxc.add_to_index(self)
25
- end
26
- def to_s
27
- if value
28
- "#{key} = #{value}"
29
- else
30
- key
31
- end
32
- end
33
- end
34
-
35
-
36
- class Lines
37
- def initialize
38
- @lines = []
39
- end
40
- def add(line)
41
- @lines << line
42
- @lines
43
- end
44
- def each(&block)
45
- @lines.each { |line| block.call(line) }
46
- end
47
- def values
48
- @lines.map{|i| i.value}
49
- end
50
-
51
- def remove(line)
52
- @lines = @lines.select{|i| i != line }
53
- end
54
-
55
- def [](idx)
56
- @lines[idx]
57
- end
58
-
59
- def comment!
60
- @lines.each{|i| i.comment! }
61
- end
62
-
63
- def length
64
- @lines.length
65
- end
66
-
67
- def empty?
68
- @lines.empty?
69
- end
70
-
71
- def first
72
- @lines.first
73
- end
74
- end
75
-
76
- attr_reader :index, :lines, :file
77
- attr_accessor :real_fname
78
-
79
- def initialize(file, index = {})
80
- self.file = file
81
- @lines = Lines.new
82
- @index = index
83
- end
84
-
85
- # file is more important than real_fname
86
- def file=(a)
87
- @file = a
88
- @real_fname = a
89
- end
90
-
91
- def get(key)
92
- @index[key]
93
- end
94
-
95
- def key_to_path(key, &block)
96
- path = ""
97
- dot = ""
98
- key.split('.').each do |element|
99
- path += dot + element
100
- dot = "."
101
- #puts ">>>>#{path}"
102
- block.call(path)
103
- end
104
- end
105
-
106
- def remove_from_index(line)
107
- key_to_path(line.key) do |path|
108
- get(path).remove(line)
109
- get(path).empty? && @index.delete(path)
110
- end
111
- end
112
-
113
- def add(key, value = nil)
114
- key = key.strip
115
- if value and value.instance_of?(String)
116
- value = value.strip
117
- end
118
- line = Line.new(self, key, value)
119
- add_to_index(line)
120
- end
121
-
122
- def add_to_index(line)
123
- key_to_path(line.key) do |path|
124
- @index[path] ||= Lines.new
125
- @index[path].add(line)
126
- end
127
- end
128
-
129
- def all_lines(&block)
130
- @lines.each do |line|
131
- block.call(line)
132
- if line.value.instance_of?(Lxc)
133
- line.value.all_lines(&block)
134
- end
135
- end
136
- end
137
-
138
- def files
139
- ret = [Line.new(nil, "lxc.include", self)]
140
- all_lines {|line| line.value.instance_of?(Lxc) && (ret << line) }
141
- ret
142
- end
143
-
144
- def write
145
- File.open(real_fname, 'w') do |f|
146
- @lines.each do |line|
147
- if line.key == "lxc.include"
148
- line.value.write
149
- end
150
- f.write(line.to_s + "\n")
151
- end
152
- end
153
- end
154
-
155
- def to_s
156
- @file
157
- end
9
+ module Lxc
10
+ def self.parse(file, index = Index.new)
11
+ if ::File.directory?(file)
12
+ fname = file
13
+ entries = ::Dir.glob(::File.join(file, '*')).select { |f| ::File.file?(f) }
14
+ dir = index.get_directory(fname)
15
+ entries.each do |entry|
16
+ dir.add_file(entry).parse
17
+ end
18
+ return dir
19
+ end
20
+ return Lxc.file(file, index).parse
21
+ end
158
22
 
159
- def self.parse(file, index = {})
160
- lxc = Lxc.new(file, index)
161
- IO.read(file).lines.each do |line|
162
- line = line.chop
163
- if line.match(/^\s*$/)
164
- lxc.add(line, nil)
165
- elsif line.match(/^\s*#.*$/)
166
- lxc.add('#', line)
167
- else
168
- match = line.match(/^\s*([a-z\.]+)\s*=\s*(.*)\s*$/)
169
- throw "illegal line in #{@file}:#{@lines.length}" unless match
170
- if match[1] == 'lxc.include'
171
- lxc.add(match[1], parse(match[2], index))
172
- else
173
- lxc.add(match[1], match[2])
174
- end
175
- end
176
- end
177
- lxc
178
- end
23
+ def self.file(fname, index = Index.new)
24
+ dir = index.get_directory(::File.dirname(fname))
25
+ dir.add_file(fname)
26
+ end
179
27
 
28
+ def self.directory(fname, index = Index.new)
29
+ index.get_directory(fname)
180
30
  end
31
+ end
181
32
  end
@@ -20,8 +20,8 @@ require 'linux/lxc'
20
20
 
21
21
  class LinuxLxcTest < Test::Unit::TestCase
22
22
  def setup
23
- @temp_dir = Dir.mktmpdir
24
- @lxc_config = File.join(@temp_dir, "lxc.config")
23
+ @temp_dir = Dir.mktmpdir
24
+ @lxc_config = File.join(@temp_dir, 'lxc.config')
25
25
  File.write(@lxc_config, <<SAMPLE)
26
26
  # Template used to create this container: /usr/share/lxc/templates/lxc-ubuntu
27
27
  # Parameters passed to the template:
@@ -42,7 +42,7 @@ lxc.network.flags = up
42
42
  lxc.network.link = lxcbr0
43
43
  lxc.network.hwaddr = 00:16:3e:67:03:4a
44
44
  SAMPLE
45
- @lxc_ubuntu_common_conf = File.join(@temp_dir, "ubuntu.common.conf")
45
+ @lxc_ubuntu_common_conf = File.join(@temp_dir, 'ubuntu.common.conf')
46
46
  File.write(@lxc_ubuntu_common_conf, <<SAMPLE)
47
47
  # Default pivot location
48
48
  lxc.pivotdir = lxc_putold
@@ -118,6 +118,15 @@ lxc.cgroup.devices.allow = c 10:232 rwm
118
118
  # Blacklist some syscalls which are not safe in privileged
119
119
  # containers
120
120
  lxc.seccomp = /usr/share/lxc/config/common.seccomp
121
+
122
+ lxc.include = #{File.join(@temp_dir, 'empty.conf.d')}
123
+ lxc.include = #{File.join(@temp_dir, 'common.conf.d')}
124
+ SAMPLE
125
+ FileUtils.mkdir_p File.join(@temp_dir, 'empty.conf.d')
126
+ FileUtils.mkdir_p File.join(@temp_dir, 'common.conf.d')
127
+ @lxc_common_conf_d_wildcard = File.join(@temp_dir, 'common.conf.d', 'wildcard')
128
+ File.write(@lxc_common_conf_d_wildcard, <<SAMPLE)
129
+ lxc.wildcard.loaded = true
121
130
  SAMPLE
122
131
  end
123
132
 
@@ -128,11 +137,15 @@ SAMPLE
128
137
  def test_reader
129
138
  lxc = Linux::Lxc.parse(@lxc_config)
130
139
 
131
- assert_equal lxc.get('lxc').length, 38
140
+ assert_equal lxc.get('lxc').length, 41
132
141
  assert_equal lxc.get('lxc.network').length, 4
133
142
  assert_equal lxc.get('lxc.network.hwaddr').length, 1
134
143
  assert_equal lxc.get('lxc.network.murks'), nil
135
144
 
145
+ assert_equal lxc.get('lxc.wildcard.loaded').values[0], 'true'
146
+ assert_equal lxc.get('lxc.wildcard.loaded')[0].file, @lxc_common_conf_d_wildcard
147
+ assert_equal lxc.get('lxc.wildcard.loaded')[0].line, 1
148
+
136
149
  assert_equal lxc.get('lxc.cgroup.devices.allow').values[4], 'c 5:0 rwm'
137
150
  assert_equal lxc.get('lxc.cgroup.devices.allow')[4].file, @lxc_ubuntu_common_conf
138
151
  assert_equal lxc.get('lxc.cgroup.devices.allow')[4].line, 48
@@ -142,19 +155,29 @@ SAMPLE
142
155
  assert_equal lxc.get('lxc.network.hwaddr').first.line, 18
143
156
  end
144
157
 
145
-
146
158
  def test_from_scratch
147
- lxc = Linux::Lxc.new(File.join(@temp_dir, "base"))
148
- lxc.add("# base meno")
149
- lxc.add("lxc.cgroup.devices.allow", "meno")
150
- incl = Linux::Lxc.new(File.join(@temp_dir, "incl"))
151
- lxc.add("lxc.include", incl)
152
- incl.add("# include meno")
153
- incl.add("lxc.network.hwaddr", '00:16:3e:67:03:4a')
159
+ lxc = Linux::Lxc.file(File.join(@temp_dir, 'base.f'))
160
+ lxc.add('# base meno')
161
+ lxc.add('lxc.cgroup.devices.allow', 'meno')
162
+ incl = Linux::Lxc.file(File.join(@temp_dir, 'incl.f'))
163
+ lxc.add('lxc.include', incl)
164
+ incl.add('# include meno')
165
+ incl.add('lxc.network.hwaddr', '00:16:3e:67:03:4a')
166
+
167
+ empty_d = Linux::Lxc.directory(File.join(@temp_dir, 'scratch.empty.d'))
168
+ lxc.add('lxc.include', empty_d)
169
+
170
+ scratch_d = Linux::Lxc.directory(File.join(@temp_dir, 'scratch.d'))
171
+ lxc.add('lxc.include', scratch_d)
172
+
173
+
174
+ scratch_file = scratch_d.add_file(File.join(@temp_dir, 'scratch.d', 'file.f'))
175
+ scratch_file.add('# include scratch')
176
+ scratch_file.add('lxc.scratch_file', 'it_is_scratch_file')
154
177
  lxc.write
155
178
 
156
179
  lxc_read = Linux::Lxc.parse(lxc.file)
157
- assert_equal lxc_read.get('#').length, 2
180
+ assert_equal lxc_read.get('#').length, 3
158
181
  assert_equal lxc_read.get('lxc.cgroup.devices.allow').values, ['meno']
159
182
  assert_equal lxc_read.get('lxc.cgroup.devices.allow').first.file, lxc.file
160
183
  assert_equal lxc_read.get('lxc.cgroup.devices.allow').first.line, 2
@@ -162,6 +185,13 @@ SAMPLE
162
185
  assert_equal lxc_read.get('lxc.network.hwaddr').values, ['00:16:3e:67:03:4a']
163
186
  assert_equal lxc_read.get('lxc.network.hwaddr').first.file, incl.file
164
187
  assert_equal lxc_read.get('lxc.network.hwaddr').first.line, 2
188
+
189
+ assert_equal lxc_read.get('lxc.scratch_file').values, ['it_is_scratch_file']
190
+ assert_equal lxc_read.get('lxc.scratch_file').first.file, scratch_file.file
191
+ assert_equal lxc_read.get('lxc.scratch_file').first.line, 2
192
+
193
+ assert_equal lxc_read.index.files.length, 3
194
+
165
195
  end
166
196
 
167
197
  def test_comment
@@ -174,61 +204,60 @@ SAMPLE
174
204
  lxc.get('lxc.network').comment!
175
205
  assert_equal lxc.get('#').length, 47
176
206
  assert_equal lxc.get('lxc.network'), nil
177
-
178
207
  end
179
208
 
180
209
  def test_real_fname
181
- lxc = Linux::Lxc.new(File.join(@temp_dir, "real_name"))
182
- lxc.add("# base meno")
183
- lxc.add("lxc.cgroup.devices.allow", "meno")
210
+ lxc = Linux::Lxc.file(File.join(@temp_dir, 'real_name'))
211
+ lxc.add('# base meno')
212
+ lxc.add('lxc.cgroup.devices.allow', 'meno')
184
213
  lxc.write
185
- lxc.real_fname = File.join(@temp_dir, "test_name")
186
- incl = Linux::Lxc.new(File.join(@temp_dir, "test_incl"))
187
- incl.real_fname = File.join(@temp_dir, "real_incl")
188
- lxc.add("lxc.include", incl)
189
- incl.add("# include meno")
190
- incl.add("lxc.network.hwaddr", '00:16:3e:67:03:4a')
214
+ lxc.real_fname = File.join(@temp_dir, 'test_name')
215
+ incl = Linux::Lxc.file(File.join(@temp_dir, 'test_incl'))
216
+ incl.real_fname = File.join(@temp_dir, 'real_incl')
217
+ lxc.add('lxc.include', incl)
218
+ incl.add('# include meno')
219
+ incl.add('lxc.network.hwaddr', '00:16:3e:67:03:4a')
191
220
  lxc.write
192
- assert_equal File.exists?(File.join(@temp_dir, "test_name")), true
193
- assert_equal File.exists?(File.join(@temp_dir, "real_name")), true
194
- assert_equal File.exists?(File.join(@temp_dir, "real_incl")), true
195
- assert_equal File.exists?(File.join(@temp_dir, "test_incl")), false
196
- # assert_raise do #Fails, no Exceptions are raised
221
+ assert_equal File.exist?(File.join(@temp_dir, 'test_name')), true
222
+ assert_equal File.exist?(File.join(@temp_dir, 'real_name')), true
223
+ assert_equal File.exist?(File.join(@temp_dir, 'real_incl')), true
224
+ assert_equal File.exist?(File.join(@temp_dir, 'test_incl')), false
225
+ # assert_raise do #Fails, no Exceptions are raised
197
226
  begin
198
- lxc = Linux::Lxc.parse(File.join(@temp_dir, "test_name"))
199
- assert_equal "Doof", "Darf nie passieren"
227
+ lxc = Linux::Lxc.parse(File.join(@temp_dir, 'test_name'))
228
+ assert_equal 'Doof', 'Darf nie passieren'
200
229
  rescue Exception => e
201
230
  assert_equal e.instance_of?(Errno::ENOENT), true
202
- assert_equal File.basename(e.message), "test_incl"
231
+ assert_equal File.basename(e.message), 'test_incl'
203
232
  end
204
- # end
233
+ # end
205
234
  end
206
235
 
207
236
  def test_lines
208
237
  lxc = Linux::Lxc.parse(@lxc_config)
209
238
  cnt = 0
210
- lxc.all_lines{|line| cnt+=1 }
211
- assert_equal cnt, 92
239
+ lxc.all_lines { |_line| cnt += 1 }
240
+ assert_equal cnt, 96
212
241
  end
213
242
 
214
243
  def test_files
215
244
  lxc = Linux::Lxc.parse(@lxc_config)
216
- assert_equal lxc.files[0].value.file, @lxc_config
217
- assert_equal File.basename(lxc.files[1].value.file), "ubuntu.common.conf"
218
- assert_equal lxc.files.length, 2
245
+ files = lxc.index.files.keys
246
+ assert_equal files[0], @lxc_config
247
+ assert_equal files[1], @lxc_ubuntu_common_conf
248
+ assert_equal files[2], @lxc_common_conf_d_wildcard
249
+ assert_equal files.length, 3
219
250
  end
220
251
 
221
252
  def test_write
222
253
  lxc = Linux::Lxc.parse(@lxc_config)
223
- lxc.file = "#{@lxc_config}.new"
224
254
  inc_file = "#{lxc.get('lxc.cgroup.devices.allow').first.lxc.file}.new"
225
255
  lxc.get('lxc.cgroup.devices.allow').first.lxc.file = inc_file
226
- lxc.get('lxc.cgroup.devices.allow')[5].value='meno'
256
+ lxc.get('lxc.cgroup.devices.allow')[5].value = 'meno'
227
257
  assert_equal lxc.get('lxc.cgroup.devices.allow').values[5], 'meno'
228
258
 
229
- lxc.get('lxc.network.hwaddr').first.value='construqt'
259
+ lxc.get('lxc.network.hwaddr').first.value = 'construqt'
230
260
  assert_equal lxc.get('lxc.network.hwaddr').values, ['construqt']
231
-
232
261
  lxc.write
233
262
 
234
263
  lxc_read = Linux::Lxc.parse(lxc.file)
@@ -239,9 +268,5 @@ SAMPLE
239
268
  assert_equal lxc_read.get('lxc.network.hwaddr').values, ['construqt']
240
269
  assert_equal lxc_read.get('lxc.network.hwaddr').first.file, lxc.file
241
270
  assert_equal lxc_read.get('lxc.network.hwaddr').first.line, 18
242
-
243
271
  end
244
-
245
-
246
272
  end
247
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux-lxc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meno Abels
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse the output of ip addr on a linux system
14
14
  email:
@@ -23,6 +23,11 @@ files:
23
23
  - README.md
24
24
  - Rakefile
25
25
  - lib/linux/lxc.rb
26
+ - lib/linux/lxc/directory.rb
27
+ - lib/linux/lxc/file.rb
28
+ - lib/linux/lxc/index.rb
29
+ - lib/linux/lxc/line.rb
30
+ - lib/linux/lxc/lines.rb
26
31
  - lib/linux/lxc/version.rb
27
32
  - linux-lxc.gemspec
28
33
  - test/linux_lxc_test.rb