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



116
117
118
# File 'lib/osctld/container/lxc_config.rb', line 116

def ct
  @ct
end

Instance Method Details

#assets(add) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/osctld/container/lxc_config.rb', line 13

def assets(add)
  add.file(
    config_path,
    desc: 'LXC base config',
    user: 0,
    group: 0,
    mode: 0644
  )
  add.file(
    config_path('network'),
    desc: 'LXC network config',
    user: 0,
    group: 0,
    mode: 0644
  )
  add.file(
    config_path('cgparams'),
    desc: 'LXC cgroup parameters',
    user: 0,
    group: 0,
    mode: 0644
  )
  add.file(
    config_path('prlimits'),
    desc: 'LXC resource limits',
    user: 0,
    group: 0,
    mode: 0644
  )
  add.file(
    config_path('mounts'),
    desc: 'LXC mounts',
    user: 0,
    group: 0,
    mode: 0644
  )
end

#config_path(cfg = 'config') ⇒ Object



104
105
106
# File 'lib/osctld/container/lxc_config.rb', line 104

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

#configureObject



51
52
53
54
55
56
57
58
59
# File 'lib/osctld/container/lxc_config.rb', line 51

def configure
  exclusively do
    configure_base
    configure_cgparams
    configure_prlimits
    configure_network
    configure_mounts
  end
end

#configure_baseObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/osctld/container/lxc_config.rb', line 61

def configure_base
  exclusively do
    ErbTemplate.render_to('ct/config', {
      distribution: ct.distribution,
      version: ct.version,
      ct: ct,
      config_path: method(:config_path),
    }, config_path)
  end
end

#configure_cgparamsObject



72
73
74
75
76
77
78
# File 'lib/osctld/container/lxc_config.rb', line 72

def configure_cgparams
  exclusively do
    ErbTemplate.render_to('ct/cgparams', {
      cgparams: ct.cgparams,
    }, config_path('cgparams'))
  end
end

#configure_mountsObject



96
97
98
99
100
101
102
# File 'lib/osctld/container/lxc_config.rb', line 96

def configure_mounts
  exclusively do
    ErbTemplate.render_to('ct/mounts', {
      mounts: ct.mounts.all_entries,
    }, config_path('mounts'))
  end
end

#configure_networkObject



88
89
90
91
92
93
94
# File 'lib/osctld/container/lxc_config.rb', line 88

def configure_network
  exclusively do
    ErbTemplate.render_to('ct/network', {
      netifs: ct.netifs,
    }, config_path('network'))
  end
end

#configure_prlimitsObject



80
81
82
83
84
85
86
# File 'lib/osctld/container/lxc_config.rb', line 80

def configure_prlimits
  exclusively do
    ErbTemplate.render_to('ct/prlimits', {
      prlimits: ct.prlimits,
    }, config_path('prlimits'))
  end
end

#dup(new_ct) ⇒ Object



108
109
110
111
112
113
# File 'lib/osctld/container/lxc_config.rb', line 108

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