Class: Vagrant::LXC::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-lxc/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



15
16
17
18
# File 'lib/vagrant-lxc/config.rb', line 15

def initialize
  @customizations = []
  @sudo_wrapper   = UNSET_VALUE
end

Instance Attribute Details

#customizationsArray (readonly)

An array of container’s configuration overrides to be provided to ‘lxc-start`.

Returns:

  • (Array)


7
8
9
# File 'lib/vagrant-lxc/config.rb', line 7

def customizations
  @customizations
end

#sudo_wrapperObject

A String that points to a file that acts as a wrapper for sudo commands.

This allows us to have a single entry when whitelisting NOPASSWD commands on /etc/sudoers



13
14
15
# File 'lib/vagrant-lxc/config.rb', line 13

def sudo_wrapper
  @sudo_wrapper
end

Instance Method Details

#customize(key, value) ⇒ Object

Customize the container by calling ‘lxc-start` with the given configuration overrides.

For example, if you want to set the memory limit, you can use it like: config.customize ‘cgroup.memory.limit_in_bytes’, ‘400M’

When ‘lxc-start`ing the container, vagrant-lxc will pass in “-s lxc.cgroup.memory.limit_in_bytes=400M” to it.

Parameters:

  • key (String)

    Configuration key to override

  • value (String)

    Configuration value to override



31
32
33
# File 'lib/vagrant-lxc/config.rb', line 31

def customize(key, value)
  @customizations << [key, value]
end

#finalize!Object



35
36
37
# File 'lib/vagrant-lxc/config.rb', line 35

def finalize!
  @sudo_wrapper = nil if @sudo_wrapper == UNSET_VALUE
end

#validate(machine) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vagrant-lxc/config.rb', line 39

def validate(machine)
  errors = []

  if @sudo_wrapper
    hostpath = Pathname.new(@sudo_wrapper).expand_path(machine.env.root_path)
    if ! hostpath.file?
      errors << I18n.t('vagrant_lxc.sudo_wrapper_not_found', path: hostpath.to_s)
    elsif ! hostpath.executable?
      errors << I18n.t('vagrant_lxc.sudo_wrapper_not_executable', path: hostpath.to_s)
    end
  end

  { "lxc provider" => errors }
end