2013-02-28 03:20:54 +00:00
|
|
|
module Vagrant
|
|
|
|
module LXC
|
|
|
|
class Config < Vagrant.plugin("2", :config)
|
2013-04-06 01:08:02 +00:00
|
|
|
# An array of container's configuration overrides to be provided to `lxc-start`.
|
2013-03-03 07:37:07 +00:00
|
|
|
#
|
|
|
|
# @return [Array]
|
2013-04-06 01:08:02 +00:00
|
|
|
attr_reader :customizations
|
2013-03-03 07:37:07 +00:00
|
|
|
|
2013-07-28 05:17:05 +00:00
|
|
|
# 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
|
|
|
|
attr_accessor :sudo_wrapper
|
|
|
|
|
2014-02-18 08:05:14 +00:00
|
|
|
# A string to explicitly set the container name. To use the vagrant
|
|
|
|
# machine name, set this to :machine
|
2014-01-31 17:01:27 +00:00
|
|
|
attr_accessor :container_name
|
2014-01-01 21:54:27 +00:00
|
|
|
|
2013-03-03 07:37:07 +00:00
|
|
|
def initialize
|
2013-04-06 01:08:02 +00:00
|
|
|
@customizations = []
|
2013-07-28 05:17:05 +00:00
|
|
|
@sudo_wrapper = UNSET_VALUE
|
2014-01-31 17:01:27 +00:00
|
|
|
@container_name = UNSET_VALUE
|
2013-03-03 07:37:07 +00:00
|
|
|
end
|
2013-04-06 01:08:02 +00:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# @param [String] key Configuration key to override
|
|
|
|
# @param [String] value Configuration value to override
|
|
|
|
def customize(key, value)
|
|
|
|
@customizations << [key, value]
|
|
|
|
end
|
|
|
|
|
2013-07-28 05:17:05 +00:00
|
|
|
def finalize!
|
|
|
|
@sudo_wrapper = nil if @sudo_wrapper == UNSET_VALUE
|
2014-01-31 17:01:27 +00:00
|
|
|
@container_name = nil if @container_name == UNSET_VALUE
|
2013-07-28 05:17:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2013-02-28 03:20:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|