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.



35
36
37
38
39
40
41
42
43
44
# File 'lib/vagrant-lxc/config.rb', line 35

def initialize
  @customizations = []
  @backingstore = UNSET_VALUE
  @backingstore_options = []
  @container_name = UNSET_VALUE
  @tmpfs_mount_size = UNSET_VALUE
  @fetch_ip_tries = UNSET_VALUE
  @ssh_ip_addr = UNSET_VALUE
  @privileged = UNSET_VALUE
end

Instance Attribute Details

#backingstoreObject

A string that contains the backing store type used with lxc-create -B



10
11
12
# File 'lib/vagrant-lxc/config.rb', line 10

def backingstore
  @backingstore
end

#backingstore_optionsArray

Optional arguments for the backing store, such as –fssize, –fstype, …

Returns:

  • (Array)


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

def backingstore_options
  @backingstore_options
end

#container_nameObject

A string to explicitly set the container name. To use the vagrant machine name, set this to :machine



19
20
21
# File 'lib/vagrant-lxc/config.rb', line 19

def container_name
  @container_name
end

#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

#fetch_ip_triesObject

Returns the value of attribute fetch_ip_tries.



25
26
27
# File 'lib/vagrant-lxc/config.rb', line 25

def fetch_ip_tries
  @fetch_ip_tries
end

#privilegedObject

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.



33
34
35
# File 'lib/vagrant-lxc/config.rb', line 33

def privileged
  @privileged
end

#ssh_ip_addrObject

Returns the value of attribute ssh_ip_addr.



27
28
29
# File 'lib/vagrant-lxc/config.rb', line 27

def ssh_ip_addr
  @ssh_ip_addr
end

#tmpfs_mount_sizeObject

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’.



23
24
25
# File 'lib/vagrant-lxc/config.rb', line 23

def tmpfs_mount_size
  @tmpfs_mount_size
end

Instance Method Details

#backingstore_option(key, value) ⇒ Object

Stores options for backingstores like lvm, btrfs, etc



62
63
64
# File 'lib/vagrant-lxc/config.rb', line 62

def backingstore_option(key, value)
  @backingstore_options << [key, value]
end

#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



57
58
59
# File 'lib/vagrant-lxc/config.rb', line 57

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

#finalize!Object



66
67
68
69
70
71
72
73
74
# File 'lib/vagrant-lxc/config.rb', line 66

def finalize!
  @container_name = nil if @container_name == UNSET_VALUE
  @backingstore = nil if @backingstore == UNSET_VALUE
  @existing_container_name = nil if @existing_container_name == UNSET_VALUE
  @tmpfs_mount_size = '2G' if @tmpfs_mount_size == UNSET_VALUE
  @fetch_ip_tries = 10 if @fetch_ip_tries == UNSET_VALUE
  @ssh_ip_addr = nil if @ssh_ip_addr == UNSET_VALUE
  @privileged = true if @privileged == UNSET_VALUE
end