Module: OsCtld::Lxc

Defined in:
lib/osctld/lxc.rb

Constant Summary collapse

CONFIGS =
'/run/osctl/configs/lxc'.freeze

Class Method Summary collapse

Class Method Details

.dist_lxc_configs(dist, ver) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/osctld/lxc.rb', line 17

def self.dist_lxc_configs(dist, ver)
  name = dist_name(dist)

  [
    File.join(CONFIGS, 'common.conf'),
    File.join(CONFIGS, name, 'common.conf'),
    File.join(CONFIGS, name, "#{ver}.conf")
  ].select { |cfg| File.exist?(cfg) }
end

.dist_name(dist) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/osctld/lxc.rb', line 7

def self.dist_name(dist)
  case dist
  when 'suse'
    'opensuse'

  else
    dist
  end
end

.install_lxc_configs(dst) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/osctld/lxc.rb', line 27

def self.install_lxc_configs(dst)
  pid = Process.fork do
    abs_root = File.absolute_path(OsCtld.root)
    cfg_root = File.join(abs_root, 'configs', 'lxc')

    Dir.chdir(cfg_root)

    Dir.glob('**/*.conf').each do |cfg|
      link_path = File.join(dst, cfg)

      if File.symlink?(link_path) || File.exist?(link_path)
        File.unlink(link_path)
      end

      dir = File.join(dst, File.dirname(cfg))
      FileUtils.mkpath(dir)

      File.symlink(File.join(cfg_root, cfg), link_path)
    end
  end

  Process.wait(pid)
  raise 'unable to install lxc configs' if $?.exitstatus != 0
end