Class: Yast::NetworkAutoYast

Inherits:
Object
  • Object
show all
Includes:
Logger, Singleton
Defined in:
src/lib/network/network_autoyast.rb

Overview

Provides functionality for network AutoYaST client(s)

This currently shouldn't replace *::Import methods. In other words it is intended for functionality which cannot be handled in 2nd stage properly. Typically:

  • merging configuration provided by linuxrc means and AY profile together
  • target network service setup (to avoid need of restarting the service during 2nd stage) and all other stuff which could lead to the need of restarting the service (e.g. device renaming)

Instance Method Summary collapse

Constructor Details

#initializeNetworkAutoYast


41
42
43
44
45
46
47
48
49
# File 'src/lib/network/network_autoyast.rb', line 41

def initialize
  # import has to be done here, there are some collisions otherwise
  Yast.import "Arch"
  Yast.import "Lan"
  Yast.import "LanItems"
  Yast.import "Linuxrc"
  Yast.import "Host"
  Yast.import "AutoInstall"
end

Instance Method Details

#activate_s390_devices(section = nil) ⇒ Object

Takes care of activate s390 devices from the profile declaration


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'src/lib/network/network_autoyast.rb', line 121

def activate_s390_devices(section = nil)
  profile_devices = section || ay_networking_section["s390-devices"] || {}
  devices_section = Y2Network::AutoinstProfile::S390DevicesSection.new_from_hashes(profile_devices)
  connections = Y2Network::Autoinst::S390DevicesReader.new(devices_section).config
  connections.each do |conn|
    begin
      builder = Y2Network::InterfaceConfigBuilder.for(conn.type, config: conn)
      activator = Y2Network::S390DeviceActivator.for(builder)
      log.info "Created interface #{activator.configured_interface}" if activator.configure
    rescue RuntimeError => e
      log.error("An error ocurred when trying to activate the s390 device: #{conn.inspect}")
      log.error("Error: #{e.sinpect}")
    end
  end

  true
end

#configure_hosts(write: false) ⇒ Boolean

Initializates /etc/hosts according AY profile

If the installer is running in 1st stage mode only, then the configuration is also written


146
147
148
149
150
151
152
153
154
155
156
# File 'src/lib/network/network_autoyast.rb', line 146

def configure_hosts(write: false)
  log.info("NetworkAutoYast: Hosts configuration")

  hosts_config = (ay_host_section["hosts"] || {}).map do |host|
    # we need to guarantee order of the items here
    [host["host_address"] || "", host["names"] || []]
  end
  hosts_config = hosts_config.to_h.delete_if { |k, v| k.empty? || v.empty? }

  configure_submodule(Host, "hosts" => hosts_config, write: write)
end

#configure_lan(write: false) ⇒ Boolean

Initializates NICs setup according AY profile

If the installer is running in 1st stage mode only, then the configuration is also written


111
112
113
114
115
116
117
118
# File 'src/lib/network/network_autoyast.rb', line 111

def configure_lan(write: false)
  log.info("NetworkAutoYast: Lan configuration")

  ay_configuration = Lan.FromAY(ay_networking_section)
  ay_configuration = NetworkAutoYast.instance.merge_configs(ay_configuration) if keep_net_config?

  configure_submodule(Lan, ay_configuration, write: write)
end

#keep_net_config?Boolean

Checks if the profile asks for keeping installation network configuration


159
160
161
162
163
164
165
# File 'src/lib/network/network_autoyast.rb', line 159

def keep_net_config?
  ret = ay_networking_section.fetch("keep_install_network", true)

  log.info("NetworkAutoYast: keep installation network: #{ret}")

  ret
end

#merge_configs(conf) ⇒ Object

Merges existing config from system into given configuration map


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'src/lib/network/network_autoyast.rb', line 56

def merge_configs(conf)
  # read settings from installation
  Lan.Read(:cache)
  # export settings into AY map
  from_system = Lan.Export
  dns = from_system["dns"] || {}
  routing = from_system["routing"] || {}
  devices = from_system["devices"] || {}

  return from_system if conf.nil? || conf.empty?

  # copy the keys/values that are not existing in the XML
  # so we merge the inst-sys settings with the XML while XML
  # has higher priority
  conf["dns"] = merge_dns(dns, conf["dns"])
  conf["routing"] = merge_routing(routing, conf["routing"])
  # merge devices definitions obtained from inst-sys
  # and those which were read from AY profile. bnc#874259
  conf["devices"] = merge_devices(devices, conf["devices"])

  conf
end

#set_network_serviceObject

Sets network service for target


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'src/lib/network/network_autoyast.rb', line 80

def set_network_service
  return if !Mode.autoinst

  log.info("Setting network service according to AY profile")

  use_network_manager = ay_networking_section["managed"]
  use_network_manager = Lan.UseNetworkManager if use_network_manager.nil?

  nm_available = NetworkService.is_backend_available(:network_manager) if use_network_manager

  if use_network_manager && nm_available
    log.info("- using NetworkManager")

    NetworkService.use_network_manager
  else
    log.info("- using wicked")
    log.warn("- NetworkManager requested but not available") if use_network_manager

    NetworkService.use_wicked
  end

  NetworkService.EnableDisableNow
end