From bcd0458adff408cdf88a0df1840e4facf5a9732d Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Wed, 6 Nov 2024 14:01:09 +0000 Subject: [PATCH] Move method to connection config class --- src/lib/y2network/connection_config/base.rb | 12 ++++++++++++ src/lib/y2network/network_manager/config_writer.rb | 14 +------------- .../wicked/connection_config_writers/base.rb | 14 +------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/lib/y2network/connection_config/base.rb b/src/lib/y2network/connection_config/base.rb index 938e0b34e..3076bc875 100644 --- a/src/lib/y2network/connection_config/base.rb +++ b/src/lib/y2network/connection_config/base.rb @@ -192,6 +192,18 @@ def static? bootproto ? bootproto.static? : true end + # Convenience method to check whether a connection is configured using + # the static bootproto and a valid IP address. + # + # @param conn [Y2Network::ConnectionConfig::Base] Connection to take settings from + # @return [Boolean] whether the connection is configured with a valid + # static IP address or not + def static_valid_ip? + return false unless bootproto.static? + + ip && ip.address.to_s != "0.0.0.0" + end + # Return the first hostname associated with the primary IP address. # # @return [String, nil] returns the hostname associated with the primary diff --git a/src/lib/y2network/network_manager/config_writer.rb b/src/lib/y2network/network_manager/config_writer.rb index facfc0a43..16c8b7715 100644 --- a/src/lib/y2network/network_manager/config_writer.rb +++ b/src/lib/y2network/network_manager/config_writer.rb @@ -87,7 +87,7 @@ def routes_for(conn, routes) explicit = routes.select { |r| r.interface&.name == conn.name } - return explicit if !static_valid_ip?(conn) + return explicit if !conn.static_valid_ip? # select the routes without an specific interface and which gateway belongs to the # same network @@ -100,18 +100,6 @@ def routes_for(conn, routes) explicit + global end - # Convenience method to check whether a connection is configured using - # the static bootproto and a valid IP address. - # - # @param conn [Y2Network::ConnectionConfig::Base] Connection to take settings from - # @return [Boolean] whether the connection is configured with a valid - # static IP address or not - def static_valid_ip?(conn) - return false unless conn.bootproto.static? - - conn.ip && conn.ip.address.to_s != "0.0.0.0" - end - # Add the DNS settings to the nmconnection file corresponding to the give conn # # @param conn [Connectionconfig::Base] Connection configuration diff --git a/src/lib/y2network/wicked/connection_config_writers/base.rb b/src/lib/y2network/wicked/connection_config_writers/base.rb index 030b01534..d41fc64fa 100644 --- a/src/lib/y2network/wicked/connection_config_writers/base.rb +++ b/src/lib/y2network/wicked/connection_config_writers/base.rb @@ -81,7 +81,7 @@ def dhclient_set_hostname(conn) def add_ips(conn) file.ipaddrs.clear ips_to_add = conn.ip_aliases.clone - ips_to_add << conn.ip if static_valid_ip?(conn) + ips_to_add << conn.ip if conn.static_valid_ip? ips_to_add.each { |i| add_ip(i) } end @@ -105,18 +105,6 @@ def add_hostname(conn) Yast::Host.Update("", conn.hostname, conn.ip.address.address.to_s) end - # Convenience method to check whether a connection is configured using - # the static bootproto and a valid IP address. - # - # @param conn [Y2Network::ConnectionConfig::Base] Connection to take settings from - # @return [Boolean] whether the connection is configured with a valid - # static IP address or not - def static_valid_ip?(conn) - return false unless conn.bootproto.static? - - conn.ip && conn.ip.address.address.to_s != "0.0.0.0" - end - # Converts the value into a string (or nil if empty) # # @param [String] value