Skip to content

Commit

Permalink
Merge 96d462e into 0da94fa
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed May 5, 2019
2 parents 0da94fa + 96d462e commit 850b5c7
Show file tree
Hide file tree
Showing 28 changed files with 263 additions and 486 deletions.
1 change: 0 additions & 1 deletion src/clients/dns.rb
Expand Up @@ -49,7 +49,6 @@ def main
Yast.import "CommandLine"
Yast.import "RichText"

Yast.include self, "network/runtime.rb"
Yast.include self, "network/services/dns.rb"

@HOSTNAME = "hostname"
Expand Down
112 changes: 0 additions & 112 deletions src/clients/dns_auto.rb

This file was deleted.

15 changes: 7 additions & 8 deletions src/include/network/services/dns.rb
Expand Up @@ -252,9 +252,9 @@ def InitSettings
searchstring = Ops.get_string(settings, "DOMAIN", "")
end
Ops.set(settings, "SEARCHLIST_S", searchstring)
Ops.set(settings, "NAMESERVER_1", Ops.get(DNS.nameservers, 0, ""))
Ops.set(settings, "NAMESERVER_2", Ops.get(DNS.nameservers, 1, ""))
Ops.set(settings, "NAMESERVER_3", Ops.get(DNS.nameservers, 2, ""))
Ops.set(settings, "NAMESERVER_1", DNS.nameservers[0].to_s)
Ops.set(settings, "NAMESERVER_2", DNS.nameservers[1].to_s)
Ops.set(settings, "NAMESERVER_3", DNS.nameservers[2].to_s)

@settings_orig = deep_copy(settings)

Expand All @@ -275,14 +275,13 @@ def StoreSettings(settings)
)

DNS.hostname = Ops.get_string(settings, "HOSTNAME", "")
DNS.nameservers = NonEmpty(nameservers)
valid_nameservers = NonEmpty(nameservers).each_with_object([]) do |ip_str, all|
all << IPAddr.new(ip_str) if IP.Check(ip_str)
end
DNS.nameservers = valid_nameservers
DNS.searchlist = NonEmpty(searchlist)
DNS.resolv_conf_policy = settings["PLAIN_POLICY"]

# update modified flag
DNS.modified = DNS.modified || settings != @settings_orig
Builtins.y2milestone("Modified DNS: %1", DNS.modified)

nil
end

Expand Down
16 changes: 3 additions & 13 deletions src/lib/network/clients/save_network.rb
Expand Up @@ -232,16 +232,6 @@ def copy_files_to_target(files, path)
true
end

# Creates target's default DNS configuration
#
# It proposes a predefined default values in common installation, exits
# in AY mode.
def configure_dns
return if Mode.autoinst

NetworkAutoconfiguration.instance.configure_dns
end

# Creates target's /etc/hosts configuration
#
# It uses hosts' configuration as defined in AY profile (if any) or
Expand All @@ -259,10 +249,10 @@ def configure_hosts
def configure_lan
NetworkAutoconfiguration.instance.configure_virtuals

if !Mode.autoinst
configure_dns
else
if Mode.autoinst
NetworkAutoYast.instance.configure_lan
else
NetworkAutoconfiguration.instance.configure_dns
end

# this depends on DNS configuration
Expand Down
9 changes: 1 addition & 8 deletions src/lib/network/network_autoconfiguration.rb
Expand Up @@ -90,15 +90,8 @@ def configure_virtuals
# Propose DNS and Hostname setup
def configure_dns
DNS.Read # handles NetworkConfig too
DNS.ProposeHostname # generate random hostname, if none known so far

# get default value, from control.xml
DNS.write_hostname = DNS.DefaultWriteHostname

DNS.propose_hostname
log.info("NetworkAutoconfiguration: proposing DNS / Hostname configuration")
log.info("dhcp hostname: #{DNS.dhcp_hostname}")
log.info("write hostname: #{DNS.write_hostname}")

DNS.Write
end

Expand Down
4 changes: 2 additions & 2 deletions src/lib/y2network/autoinst_profile/dns_section.rb
Expand Up @@ -90,7 +90,7 @@ def initialize(*_args)
def init_from_hashes(hash)
super
@nameservers = hash["nameservers"] || []
@searchlist = hash["search_domains"] || []
@searchlist = hash["searchlist"] || []
end

# Method used by {.new_from_network} to populate the attributes when cloning DNS options
Expand All @@ -102,7 +102,7 @@ def init_from_network(dns)
@hostname = dns.hostname
@nameservers = dns.nameservers.map(&:to_s)
@resolv_conf_policy = dns.resolv_conf_policy
@searchlist = dns.search_domains
@searchlist = dns.searchlist
true
end
end
Expand Down
3 changes: 2 additions & 1 deletion src/lib/y2network/config.rb
Expand Up @@ -19,6 +19,7 @@
require "y2network/interface"
require "y2network/config_writer"
require "y2network/config_reader"
require "y2network/routing"
require "y2network/dns"

module Y2Network
Expand Down Expand Up @@ -115,7 +116,7 @@ def copy
def ==(other)
source == other.source &&
((interfaces - other.interfaces) | (other.interfaces - interfaces)).empty? &&
routing == other.routing
routing == other.routing && dns == other.dns
end

alias_method :eql?, :==
Expand Down
9 changes: 6 additions & 3 deletions src/lib/y2network/config_reader/autoinst.rb
Expand Up @@ -21,6 +21,7 @@
require "y2network/interface"
require "y2network/config"
require "y2network/config_reader/autoinst_routing"
require "y2network/config_reader/autoinst_dns"
require "y2network/autoinst_profile/networking_section"

Yast.import "Lan"
Expand All @@ -41,9 +42,11 @@ def initialize(section)

# @return [Y2Network::Config] Network configuration
def config
interfaces = find_interfaces
routing = section.routing ? AutoinstRouting.new(section.routing).config : nil
Y2Network::Config.new(interfaces: interfaces, routing: routing, source: :sysconfig)
attrs = { source: :sysconfig }
attrs[:interfaces] = find_interfaces
attrs[:routing] = AutoinstRouting.new(section.routing).config if section.routing
attrs[:dns] = AutoinstDNS.new(section.dns).config if section.dns
Y2Network::Config.new(attrs)
end

private
Expand Down
27 changes: 22 additions & 5 deletions src/lib/y2network/config_reader/autoinst_dns.rb
Expand Up @@ -19,6 +19,8 @@

require "yast"
require "y2network/dns"
require "ipaddr"
Yast.import "IP"

module Y2Network
module ConfigReader
Expand All @@ -36,12 +38,27 @@ def initialize(section)
#
# @return [DNS] the imported {DNS} config
def config
options = section.class.attributes.each_with_object({}) do |attr_entry, result|
value = section.public_send(attr_entry[:name])
result[attr_entry[:name]] = value unless value.nil?
end
Y2Network::DNS.new(
dhcp_hostname: section.dhcp_hostname,
hostname: section.hostname,
nameservers: valid_ips(section.nameservers),
resolv_conf_policy: section.resolv_conf_policy,
searchlist: section.searchlist
)
end

private

Y2Network::DNS.new(options)
# Given a list of IPs in string form, builds a list of valid IPAddr objects
#
# Invalid IPs are filtered out.
#
# @param ips [Array<String>]
# @return [Array<IPAddr>]
def valid_ips(ips)
ips.each_with_object([]) do |ip_str, all|
all << IPAddr.new(ip_str) if Yast::IP.Check(ip_str)
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/lib/y2network/config_reader/sysconfig_dns.rb
Expand Up @@ -38,7 +38,7 @@ def config
Y2Network::DNS.new(
nameservers: nameservers,
hostname: hostname,
search_domains: search_domains,
searchlist: searchlist,
resolv_conf_policy: resolv_conf_policy,
dhcp_hostname: dhcp_hostname
)
Expand Down Expand Up @@ -118,7 +118,7 @@ def hostname_from_system
# Return the list of search domains
#
# @return [Array<String>]
def search_domains
def searchlist
Yast::SCR.Read(
Yast::Path.new(".sysconfig.network.config.NETCONFIG_DNS_STATIC_SEARCHLIST")
).to_s.split
Expand Down
9 changes: 5 additions & 4 deletions src/lib/y2network/config_writer/sysconfig.rb
Expand Up @@ -139,11 +139,12 @@ def routes_file_for(iface)

# Updates the DNS configuration
#
# @param dns [Y2Network::DNS] Current DNS configuration
# @param old_dns [Y2Network::DNS] Old DNS configuration; nil if it is unknown
def write_dns_settings(dns, old_dns)
# @param config [Y2Network::Config] Current DNS configuration
# @param old_config [Y2Network::Config,nil] Old DNS configuration; nil if it is unknown
def write_dns_settings(config, old_config)
old_dns = old_config.dns if old_config
writer = Y2Network::ConfigWriter::SysconfigDNS.new
writer.write(dns, old_dns)
writer.write(config.dns, old_dns)
end
end
end
Expand Down
15 changes: 8 additions & 7 deletions src/lib/y2network/config_writer/sysconfig_dns.rb
Expand Up @@ -30,9 +30,9 @@ class SysconfigDNS
# @param dns [Y2Network::DNS] DNS configuration
# @param old_dns [Y2Network::DNS] Old DNS configuration
def write(dns, old_dns)
return if dns == old_dns
return if old_dns && dns == old_dns
update_sysconfig_dhcp(dns, old_dns)
update_hostname(dns.hostname)
update_hostname(dns)
update_mta_config
update_sysconfig_config(dns)
end
Expand Down Expand Up @@ -61,10 +61,11 @@ def update_sysconfig_dhcp(config, old_config)

# Sets the hostname
#
# @param hostname [String] Hostname (FQDN)
def update_hostname(hostname)
Yast::Execute.on_target!("/bin/hostname", hostname.split(".")[0])
Yast::SCR.Write(Yast::Path.new(".target.string"), HOSTNAME_PATH, "#{hostname}\n")
# @param dns [Y2Network::DNS] DNS configuration
def update_hostname(dns)
dns.ensure_hostname!
Yast::Execute.on_target!("/bin/hostname", dns.hostname.split(".")[0])
Yast::SCR.Write(Yast::Path.new(".target.string"), HOSTNAME_PATH, "#{dns.hostname}\n")
end

# Updates the MTA configuration
Expand All @@ -86,7 +87,7 @@ def update_sysconfig_config(dns)
)
Yast::SCR.Write(
Yast::Path.new(".sysconfig.network.config.NETCONFIG_DNS_STATIC_SEARCHLIST"),
dns.search_domains.join(" ")
dns.searchlist.join(" ")
)
Yast::SCR.Write(
Yast::Path.new(".sysconfig.network.config.NETCONFIG_DNS_STATIC_SERVERS"),
Expand Down

0 comments on commit 850b5c7

Please sign in to comment.