Class: OsCtld::Container::LxcConfig

Inherits:
Object
  • Object
show all
Includes:
Lockable
Defined in:
lib/osctld/container/lxc_config.rb

Overview

LXC configuration generator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Lockable

#exclusively, included, #inclusively, #init_lock, #lock, #unlock

Constructor Details

#initialize(ct) ⇒ LxcConfig

Returns a new instance of LxcConfig.



8
9
10
11
# File 'lib/osctld/container/lxc_config.rb', line 8

def initialize(ct)
  init_lock
  @ct = ct
end

Instance Attribute Details

#ctObject (readonly, protected)

Returns the value of attribute ct.



57
58
59
# File 'lib/osctld/container/lxc_config.rb', line 57

def ct
  @ct
end

Instance Method Details

#assets(add) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/osctld/container/lxc_config.rb', line 13

def assets(add)
  add.file(
    config_path,
    desc: 'LXC config',
    user: 0,
    group: 0,
    mode: 0o644
  )
end

#config_pathObject



44
45
46
# File 'lib/osctld/container/lxc_config.rb', line 44

def config_path
  File.join(ct.lxc_dir, 'config')
end

#configureObject Also known as: configure_base, configure_cgparams, configure_prlimits, configure_network, configure_mounts



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/osctld/container/lxc_config.rb', line 23

def configure
  exclusively do
    ErbTemplate.render_to('ct/config', {
      distribution: ct.get_run_conf.distribution,
      version: ct.get_run_conf.version,
      ct:,
      cgparams: ct.cgparams,
      prlimits: ct.prlimits,
      netifs: ct.netifs,
      mounts: ct.mounts.all_entries,
      raw: ct.raw_configs.lxc
    }, config_path)
  end
end

#dup(new_ct) ⇒ Object



48
49
50
51
52
53
# File 'lib/osctld/container/lxc_config.rb', line 48

def dup(new_ct)
  ret = super()
  ret.init_lock
  ret.instance_variable_set('@ct', new_ct)
  ret
end