Class: OsCtld::DistConfig::Network::RedHatInitScripts
- Includes:
- Helpers::RedHat
- Defined in:
- lib/osctld/dist_config/network/redhat_initscripts.rb
Overview
Configure network using RH style sysconfig with initscripts
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #configure(netifs) ⇒ Object
- #do_create_netif(netif) ⇒ Object protected
- #do_remove_netif(name) ⇒ Object protected
-
#remove_netif(_netifs, netif) ⇒ Object
Cleanup old config files.
-
#rename_netif(_netifs, netif, old_name) ⇒ Object
Rename config files.
- #usable? ⇒ Boolean
Methods included from Helpers::RedHat
Methods inherited from Base
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
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/osctld/dist_config/network/redhat_initscripts.rb', line 14 def configure(netifs) set_params( File.join(rootfs, 'etc/sysconfig/network'), { 'NETWORKING' => 'yes' } ) netifs.each do |netif| do_create_netif(netif) end end |
#do_create_netif(netif) ⇒ Object (protected)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/osctld/dist_config/network/redhat_initscripts.rb', line 38 def do_create_netif(netif) tpl_base = File.join('dist_config/network/redhat_initscripts') ct_base = File.join(rootfs, 'etc', 'sysconfig') ifcfg = File.join(ct_base, 'network-scripts', "ifcfg-#{netif.name}") return unless writable?(ifcfg) OsCtld::ErbTemplate.render_to_if_changed( File.join(tpl_base, netif.type.to_s, 'ifcfg'), { netif: }, ifcfg ) return unless netif.type == :routed netif.active_ip_versions.each do |ip_v| OsCtld::ErbTemplate.render_to_if_changed( File.join(tpl_base, netif.type.to_s, "route_v#{ip_v}"), { netif: }, File.join( ct_base, 'network-scripts', "route#{ip_v == 6 ? '6' : ''}-#{netif.name}" ) ) end end |
#do_remove_netif(name) ⇒ Object (protected)
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/osctld/dist_config/network/redhat_initscripts.rb', line 66 def do_remove_netif(name) base = File.join(rootfs, 'etc', 'sysconfig', 'network-scripts') files = [ "ifcfg-#{name}", "route-#{name}", "route6-#{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
26 27 28 |
# File 'lib/osctld/dist_config/network/redhat_initscripts.rb', line 26 def remove_netif(_netifs, netif) do_remove_netif(netif.name) end |
#rename_netif(_netifs, netif, old_name) ⇒ Object
Rename config files
31 32 33 34 |
# File 'lib/osctld/dist_config/network/redhat_initscripts.rb', line 31 def rename_netif(_netifs, netif, old_name) do_remove_netif(old_name) do_create_netif(netif) end |
#usable? ⇒ Boolean
9 10 11 12 |
# File 'lib/osctld/dist_config/network/redhat_initscripts.rb', line 9 def usable? Dir.exist?(File.join(rootfs, 'etc/sysconfig/network-scripts')) \ && File.executable?(File.join(rootfs, 'etc/init.d/network')) end |