Class: Vagrant::LXC::Config
- Inherits:
-
Object
- Object
- Vagrant::LXC::Config
- Defined in:
- lib/vagrant-lxc/config.rb
Instance Attribute Summary collapse
-
#container_name ⇒ Object
A string to explicitly set the container name.
-
#customizations ⇒ Array
readonly
An array of container’s configuration overrides to be provided to ‘lxc-start`.
-
#sudo_wrapper ⇒ Object
A String that points to a file that acts as a wrapper for sudo commands.
Instance Method Summary collapse
-
#customize(key, value) ⇒ Object
Customize the container by calling ‘lxc-start` with the given configuration overrides.
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
19 20 21 22 23 |
# File 'lib/vagrant-lxc/config.rb', line 19 def initialize @customizations = [] @sudo_wrapper = UNSET_VALUE @container_name = UNSET_VALUE end |
Instance Attribute Details
#container_name ⇒ Object
A string to explicitly set the container name. To use the vagrant machine name, set this to :machine
17 18 19 |
# File 'lib/vagrant-lxc/config.rb', line 17 def container_name @container_name end |
#customizations ⇒ Array (readonly)
An array of container’s configuration overrides to be provided to ‘lxc-start`.
7 8 9 |
# File 'lib/vagrant-lxc/config.rb', line 7 def customizations @customizations end |
#sudo_wrapper ⇒ Object
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.
36 37 38 |
# File 'lib/vagrant-lxc/config.rb', line 36 def customize(key, value) @customizations << [key, value] end |
#finalize! ⇒ Object
40 41 42 43 |
# File 'lib/vagrant-lxc/config.rb', line 40 def finalize! @sudo_wrapper = nil if @sudo_wrapper == UNSET_VALUE @container_name = nil if @container_name == UNSET_VALUE end |
#validate(machine) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vagrant-lxc/config.rb', line 45 def validate(machine) errors = [] if @sudo_wrapper hostpath = Pathname.new(@sudo_wrapper).(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 |