Permalink
Browse files

Validate configuration attributes

  • Loading branch information...
1 parent 6dc6c7d commit 1b7362a7c4f8ef1a1b15035af8936f405c99716c @sosedoff committed May 29, 2012
Showing with 33 additions and 0 deletions.
  1. +1 −0 lib/lxc.rb
  2. +5 −0 lib/lxc/configuration.rb
  3. +27 −0 lib/lxc/configuration_options.rb
View
@@ -1,6 +1,7 @@
require 'lxc/version'
require 'lxc/errors'
require 'lxc/shell'
+require 'lxc/configuration_options'
require 'lxc/configuration'
require 'lxc/container'
View
@@ -1,5 +1,7 @@
module LXC
class Configuration
+ include LXC::ConfigurationOptions
+
attr_reader :content
# Initialize a new LXC::Configuration instance
@@ -61,6 +63,9 @@ def parse(data)
lines = data.split("\n").map(&:strip).select { |l| !l.empty? && l[0,1] != '#' }
lines.each do |l|
key,value = l.split('=').map(&:strip)
+ if !valid_option?(key)
+ raise ConfigurationError, "Invalid config attribute: #{key}."
+ end
key.gsub!(/^lxc\./, '').gsub!('.', '_')
hash[key] = [] if !hash.key?(key)
hash[key] << value
@@ -0,0 +1,27 @@
+module LXC
+ module ConfigurationOptions
+ VALID_OPTIONS = [
+ 'lxc.utsname',
+ 'lxc.network.type',
+ 'lxc.network.flags',
+ 'lxc.network.link',
+ 'lxc.network.name',
+ 'lxc.network.hwaddr',
+ 'lxc.network.ipv4',
+ 'lxc.network.ipv6',
+ 'lxc.pts',
+ 'lxc.tty',
+ 'lxc.mount',
+ 'lxc.mount.entry',
+ 'lxc.rootfs',
+ 'lxc.cgroup',
+ 'lxc.cap.drop'
+ ]
+
+ protected
+
+ def valid_option?(name)
+ VALID_OPTIONS.include?(name) || name =~ /^lxc.cgroup/
+ end
+ end
+end

0 comments on commit 1b7362a

Please sign in to comment.