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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNetworkAutoYast

Returns a new instance of NetworkAutoYast.



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

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

Instance Attribute Details

#ay_networking_section=(value) ⇒ Hash

setter for networking section. Should be done during import.

Returns:

  • (Hash)

    networking section hash



142
143
144
# File 'src/lib/network/network_autoyast.rb', line 142

def ay_networking_section=(value)
  @ay_networking_section = value
end

Instance Method Details

#activate_s390_devices(section = nil) ⇒ Object

Takes care of activate s390 devices from the profile declaration



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'src/lib/network/network_autoyast.rb', line 99

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|
    builder = Y2Network::InterfaceConfigBuilder.for(conn.type, config: conn)
    activator = Y2Network::S390DeviceActivator.for(builder)
    if !activator.configured_interface.empty?
      log.info "Interface #{activator.configured_interface} is already active. " \
               "Skipping the activation."
      next
    end

    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.inspect}")
  end

  true
end

#configure_hostsObject

Initializates /etc/hosts according AY profile

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



127
128
129
# File 'src/lib/network/network_autoyast.rb', line 127

def configure_hosts
  Host.Write(gui: false)
end

#configure_lanBoolean

Writes the autoyast network configuration according to the already imported configuration

If the network was already written before the proposal it returns without touching it

Returns:

  • (Boolean)

    true when written



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'src/lib/network/network_autoyast.rb', line 83

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

  Yast::Lan.yast_config.backend = selected_backend

  # We need to ensure the config translation is written to the target
  # system
  return false if (selected_backend == :wicked) && Lan.autoinst.before_proposal

  # force a write only as it is run at the end of the installation and it
  # is already chrooted in the target system where restarting services or
  # refreshing udev rules does not make sense at all
  Lan.Write(apply_config: false)
end

#keep_net_config?Boolean

Checks if the profile asks for keeping installation network configuration

Returns:

  • (Boolean)


132
133
134
135
136
137
138
# File 'src/lib/network/network_autoyast.rb', line 132

def keep_net_config?
  ret = Lan.autoinst.keep_install_network

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

  ret
end

#merge_configs(conf) ⇒ Object

Merges existing config from system into given configuration map

Parameters:

  • conf (Hash, nil)

    configuration map

Returns:

  • updated configuration map



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'src/lib/network/network_autoyast.rb', line 53

def merge_configs(conf)
  # read settings from installation
  Lan.Read(:cache)
  # export settings into AY map
  from_system = Lan.Export
  return from_system if conf.nil? || conf.empty?

  dns = from_system["dns"] || {}
  routing = from_system["routing"] || {}

  # 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"])

  conf
end

#selected_backendObject



72
73
74
# File 'src/lib/network/network_autoyast.rb', line 72

def selected_backend
  Y2Network::ProposalSettings.instance.network_service
end