Class: OsCtld::DistConfig::Network::SuseSysconfig

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

Overview

Configure SUSE style /etc/sysconfig for wicked

Instance Attribute Summary

Attributes inherited from Base

#configurator

Instance Method Summary collapse

Methods inherited from Base

#add_netif, #initialize

Methods included from Helpers::Common

#systemd_service_enabled?, #systemd_service_masked?, #writable?

Constructor Details

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

Instance Method Details

#configure(netifs) ⇒ Object



11
12
13
14
15
# File 'lib/osctld/dist_config/network/suse_sysconfig.rb', line 11

def configure(netifs)
  netifs.each do |netif|
    do_create_netif(netif)
  end
end

#do_create_netif(netif) ⇒ Object (protected)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/osctld/dist_config/network/suse_sysconfig.rb', line 29

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

  return unless writable?(ifcfg)

  OsCtld::ErbTemplate.render_to_if_changed(
    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_if_changed(
    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)



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/osctld/dist_config/network/suse_sysconfig.rb', line 58

def do_remove_netif(name)
  base = File.join(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

#remove_netif(netifs, netif) ⇒ Object

Cleanup old config files



18
19
20
# File 'lib/osctld/dist_config/network/suse_sysconfig.rb', line 18

def remove_netif(netifs, netif)
  do_remove_netif(netif.name)
end

#rename_netif(netifs, netif, old_name) ⇒ Object

Rename config files



23
24
25
26
# File 'lib/osctld/dist_config/network/suse_sysconfig.rb', line 23

def rename_netif(netifs, netif, old_name)
  do_remove_netif(old_name)
  do_create_netif(netif)
end

#usable?Boolean

Returns:

  • (Boolean)


6
7
8
9
# File 'lib/osctld/dist_config/network/suse_sysconfig.rb', line 6

def usable?
  Dir.exist?(File.join(rootfs, 'etc/sysconfig/network')) \
    && Dir.exist?(File.join(rootfs, 'etc/wicked'))
end