Class: LxcFileConfig
- Inherits:
-
Object
- Object
- LxcFileConfig
- Defined in:
- lib/vagabond/cookbooks/lxc/libraries/lxc_file_config.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ LxcFileConfig
constructor
A new instance of LxcFileConfig.
Constructor Details
#initialize(path) ⇒ LxcFileConfig
Returns a new instance of LxcFileConfig.
47 48 49 50 51 52 53 |
# File 'lib/vagabond/cookbooks/lxc/libraries/lxc_file_config.rb', line 47 def initialize(path) raise 'LXC config file not found' unless File.exists?(path) @path = path @network = [] @base = Mash.new parse! end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
4 5 6 |
# File 'lib/vagabond/cookbooks/lxc/libraries/lxc_file_config.rb', line 4 def base @base end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
3 4 5 |
# File 'lib/vagabond/cookbooks/lxc/libraries/lxc_file_config.rb', line 3 def network @network end |
Class Method Details
.generate_config(resource) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vagabond/cookbooks/lxc/libraries/lxc_file_config.rb', line 7 def generate_config(resource) config = [] config << "lxc.utsname = #{resource.utsname}" if(resource.aa_profile) config << "lxc.aa_profile = #{resource.aa_profile}" end [resource.network].flatten.each do |net_hash| nhsh = Mash.new(net_hash) flags = nhsh.delete(:flags) %w(type link).each do |k| config << "lxc.network.#{k} = #{nhsh.delete(k)}" if nhsh[k] end nhsh.each_pair do |k,v| config << "lxc.network.#{k} = #{v}" end if(flags) config << "lxc.network.flags = #{flags}" end end if(resource.cap_drop) config << "lxc.cap.drop = #{Array(resource.cap_drop).join(' ')}" end %w(pts tty arch devttydir mount mount_entry rootfs rootfs_mount pivotdir).each do |k| config << "lxc.#{k.sub('_', '.')} = #{resource.send(k)}" if resource.send(k) end prefix = 'lxc.cgroup' resource.cgroup.each_pair do |key, value| if(value.is_a?(Array)) value.each do |val| config << "#{prefix}.#{key} = #{val}" end else config << "#{prefix}.#{key} = #{value}" end end config.join("\n") + "\n" end |