vagrant-lxc-ng/lib/vagrant-lxc/config.rb

78 lines
2.8 KiB
Ruby
Raw Permalink Normal View History

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`.
#
# @return [Array]
2013-04-06 01:08:02 +00:00
attr_reader :customizations
2014-02-18 09:52:54 +00:00
# A string that contains the backing store type used with lxc-create -B
attr_accessor :backingstore
# Optional arguments for the backing store, such as --fssize, --fstype, ...
#
# @return [Array]
2014-02-18 09:52:54 +00:00
attr_accessor :backingstore_options
# 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
# Size (as a string like '400M') of the tmpfs to mount at /tmp on boot.
# Set to false or nil to disable the tmpfs mount altogether. Defaults to '2G'.
attr_accessor :tmpfs_mount_size
attr_accessor :fetch_ip_tries
2018-07-21 12:52:26 +00:00
attr_accessor :ssh_ip_addr
# Whether the container needs to be privileged. Defaults to true (unprivileged containers
# is a very new feature in vagrant-lxc). If false, will try creating an unprivileged
# container. If it can't, will revert to the old "sudo wrapper" method to create a privileged
# container.
attr_accessor :privileged
def initialize
2013-04-06 01:08:02 +00:00
@customizations = []
2014-02-18 09:52:54 +00:00
@backingstore = UNSET_VALUE
@backingstore_options = []
2014-01-31 17:01:27 +00:00
@container_name = UNSET_VALUE
@tmpfs_mount_size = UNSET_VALUE
2016-11-11 08:34:42 +00:00
@fetch_ip_tries = UNSET_VALUE
2018-07-21 12:52:26 +00:00
@ssh_ip_addr = UNSET_VALUE
@privileged = UNSET_VALUE
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
2014-02-18 09:52:54 +00:00
# Stores options for backingstores like lvm, btrfs, etc
def backingstore_option(key, value)
@backingstore_options << [key, value]
end
def finalize!
2014-01-31 17:01:27 +00:00
@container_name = nil if @container_name == UNSET_VALUE
@backingstore = nil if @backingstore == UNSET_VALUE
2014-02-18 09:52:54 +00:00
@existing_container_name = nil if @existing_container_name == UNSET_VALUE
@tmpfs_mount_size = '2G' if @tmpfs_mount_size == UNSET_VALUE
2016-11-11 08:34:42 +00:00
@fetch_ip_tries = 10 if @fetch_ip_tries == UNSET_VALUE
2018-07-21 12:52:26 +00:00
@ssh_ip_addr = nil if @ssh_ip_addr == UNSET_VALUE
@privileged = true if @privileged == UNSET_VALUE
end
end
end
end