Class: OsCtld::DistConfig::OpenSuse

Inherits:
Base
  • Object
show all
Defined in:
lib/osctld/dist_config/opensuse.rb

Instance Attribute Summary

Attributes inherited from Base

#ct, #distribution, #version

Instance Method Summary collapse

Methods inherited from Base

#add_netif, #bin_path, distribution, #dns_resolvers, #initialize, #passwd, #update_etc_hosts, #writable?

Methods included from Utils::SwitchUser

#ct_attach, #ct_syscmd

Constructor Details

This class inherits a constructor from OsCtld::DistConfig::Base

Instance Method Details

#do_create_netif(netif) ⇒ Object (protected)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/osctld/dist_config/opensuse.rb', line 47

def do_create_netif(netif)
  tpl_base = File.join('dist_config/network', 'opensuse')
  ct_base = File.join(ct.rootfs, 'etc', 'sysconfig')
  ifcfg = File.join(ct_base, 'network', "ifcfg-#{netif.name}")

  return unless writable?(ifcfg)

  OsCtld::ErbTemplate.render_to(
    File.join(tpl_base, netif.type.to_s, 'ifcfg'),
    {
      netif: netif,
      all_ips: netif.active_ip_versions.inject([]) do |acc, ip_v|
        acc.concat(netif.ips(ip_v))
      end,
    },
    ifcfg
  )

  OsCtld::ErbTemplate.render_to(
    File.join(tpl_base, netif.type.to_s, 'ifroute'),
    {netif: netif},
    File.join(
      ct_base,
      'network',
      "ifroute-#{netif.name}"
    )
  )
end

#do_remove_netif(name) ⇒ Object (protected)



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/osctld/dist_config/opensuse.rb', line 76

def do_remove_netif(name)
  base = File.join(ct.rootfs, 'etc', 'sysconfig', 'network')
  files = [
    "ifcfg-#{name}",
  ]

  files.each do |f|
    path = File.join(base, f)
    next if !File.exist?(path) || !writable?(path)

    File.unlink(path)
  end
end

#network(_opts) ⇒ Object



29
30
31
32
33
# File 'lib/osctld/dist_config/opensuse.rb', line 29

def network(_opts)
  ct.netifs.each do |netif|
    do_create_netif(netif)
  end
end

#remove_netif(opts) ⇒ Object

Cleanup old config files



36
37
38
# File 'lib/osctld/dist_config/opensuse.rb', line 36

def remove_netif(opts)
  do_remove_netif(opts[:netif].name)
end

#rename_netif(opts) ⇒ Object

Rename config files



41
42
43
44
# File 'lib/osctld/dist_config/opensuse.rb', line 41

def rename_netif(opts)
  do_remove_netif(opts[:original_name])
  do_create_netif(opts[:netif])
end

#set_hostname(opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/osctld/dist_config/opensuse.rb', line 7

def set_hostname(opts)
  # /etc/hostname
  writable?(File.join(ct.rootfs, 'etc', 'hostname')) do |path|
    regenerate_file(path, 0644) do |f|
      f.puts(ct.hostname.local)
    end
  end

  # Entry in /etc/hosts
  update_etc_hosts(opts[:original])

  # Apply hostname if the container is running
  if ct.running?
    begin
      ct_syscmd(ct, "hostname #{ct.hostname}")

    rescue SystemCommandFailed => e
      log(:warn, ct, "Unable to apply hostname: #{e.message}")
    end
  end
end