Class: Yast::NetworkAutoconfiguration
- Inherits:
-
Object
- Object
- Yast::NetworkAutoconfiguration
- Includes:
- Logger, Singleton, Wicked
- Defined in:
- src/lib/network/network_autoconfiguration.rb
Overview
The class is responsible for generating / proposing automatic configuration during installation workflow
Constant Summary collapse
- BASH_PATH =
Path.new(".target.bash")
Constants included from Wicked
Wicked::BASH_OUTPUT_PATH, Wicked::IBFT_CMD, Wicked::WICKED_PATH
Instance Method Summary collapse
-
#any_iface_active? ⇒ Boolean
Checks if any of available interfaces is configured and active.
- #configure_dhcp ⇒ Object
-
#configure_dns ⇒ Object
Propose DNS and Hostname setup.
-
#configure_hosts ⇒ Object
Proposes updates for /etc/hosts.
- #configure_routing ⇒ Object
-
#configure_virtuals ⇒ Object
Propose configuration for virtual devices.
-
#dhcp_candidate?(interface) ⇒ Boolean
Return true if the given interface is connected but it is not configured by firmware or via an ifcfg file.
-
#initialize ⇒ NetworkAutoconfiguration
constructor
A new instance of NetworkAutoconfiguration.
-
#virtual_proposal_required? ⇒ Boolean
Decides if a proposal for virtualization host machine is required.
Methods included from Wicked
#firmware_configured_by?, #firmware_interfaces, #firmware_interfaces_by_extension, #ibft_interfaces, #parse_hostname, #parse_ntp_servers, #query_wicked, #reload_config
Constructor Details
#initialize ⇒ NetworkAutoconfiguration
Returns a new instance of NetworkAutoconfiguration.
36 37 38 39 40 41 42 43 44 |
# File 'src/lib/network/network_autoconfiguration.rb', line 36 def initialize Yast.import "Lan" Yast.import "Package" Yast.import "DNS" Yast.import "Arch" Yast.import "Host" Yast.include self, "network/routines.rb" # TODO: needed only for phy_connected end |
Instance Method Details
#any_iface_active? ⇒ Boolean
Checks if any of available interfaces is configured and active
returns [Boolean] true when at least one interface is active
49 50 51 52 53 54 55 56 |
# File 'src/lib/network/network_autoconfiguration.rb', line 49 def any_iface_active? Yast::Lan.Read(:cache) config.interfaces.any? do |interface| next false unless active_config?(interface.name) config.connections.by_name(interface.name) || firmware_interfaces.include?(interface.name) end end |
#configure_dhcp ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'src/lib/network/network_autoconfiguration.rb', line 71 def configure_dhcp Yast::Lan.Read(:cache) dhcp_cards = config.interfaces.select { |i| dhcp_candidate?(i) } log.info "Candidates for enabling DHCP: #{dhcp_cards.inspect}" return if dhcp_cards.empty? # TODO: time consuming, some progress would be nice dhcp_cards.each { |d| setup_dhcp(d) } activate_changes(dhcp_cards.map(&:name)) # drop devices without dhcp lease inactive_devices = dhcp_cards.reject { |c| active_config?(c.name) } log.info "Inactive devices: #{inactive_devices}" inactive_devices.each { |c| delete_config(c) } # setup route flag active_devices = dhcp_cards - inactive_devices if active_devices.size == 1 # just one dhcp device, nothing to care of set_default_route_flag(active_devices.first, "yes") else # try to find just one dhcp aware device for allowing default route # if there is more than one dhcp devices enabled for setting default # route (DHCLIENT_SET_DEFAULT_ROUTE = "yes"). bnc#868187 active_devices.find { |d| set_default_route_flag_if_wan_dev?(d.name) } end activate_changes(dhcp_cards.map(&:name)) # Force a read of the configuration just for reading the transient # hostname as it could be modified through dhcp since previous read. Lan.read_config(report: false) end |
#configure_dns ⇒ Object
Propose DNS and Hostname setup
145 146 147 148 149 |
# File 'src/lib/network/network_autoconfiguration.rb', line 145 def configure_dns DNS.Read # handles NetworkConfig too log.info("NetworkAutoconfiguration: proposing DNS / Hostname configuration") DNS.Write(netconfig_update: false) end |
#configure_hosts ⇒ Object
Proposes updates for /etc/hosts
Expected to be used for updating target system's config. Currently it only updates /etc/hosts with static IP if any.
155 156 157 158 159 |
# File 'src/lib/network/network_autoconfiguration.rb', line 155 def configure_hosts Host.Read Host.ResolveHostnameToStaticIPs Host.Write end |
#configure_routing ⇒ Object
161 162 163 164 165 |
# File 'src/lib/network/network_autoconfiguration.rb', line 161 def configure_routing return if config.routing == Lan.system_config.routing Lan.write_config(only: [:routing]) end |
#configure_virtuals ⇒ Object
Propose configuration for virtual devices
It checks if any of supported virtual machines were installed. If found, propose virtual device(s) configuration
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'src/lib/network/network_autoconfiguration.rb', line 129 def configure_virtuals return if !virtual_proposal_required? log.info("NetworkAutoconfiguration: proposing virtual devices") return unless Lan.ProposeVirtualized # avoid restarting network (installation can run via ssh, vnc, ...) # Moreover virtual devices are not needed during first stage. So, it can # wait for rebooting into just installed target return if Lan.yast_config == Lan.system_config Lan.write_config end |
#dhcp_candidate?(interface) ⇒ Boolean
Return true if the given interface is connected but it is not configured by firmware or via an ifcfg file.
Note: (it speeds up the initialization phase of installer - bnc#872319)
64 65 66 67 68 69 |
# File 'src/lib/network/network_autoconfiguration.rb', line 64 def dhcp_candidate?(interface) return false if config.connections.by_name(interface.name) return false if firmware_interfaces.include?(interface.name) phy_connected?(interface.name) end |
#virtual_proposal_required? ⇒ Boolean
Decides if a proposal for virtualization host machine is required.
114 115 116 117 118 119 120 121 122 123 |
# File 'src/lib/network/network_autoconfiguration.rb', line 114 def virtual_proposal_required? # S390 has special requirements. See bnc#817943 return false if Arch.s390 return true if Package.Installed("xen") && Arch.is_xen0 return true if Package.Installed("kvm") return true if Package.Installed("qemu") false end |