Skip to content

Commit

Permalink
Move method to connection config class
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Nov 6, 2024
1 parent 3fe7f5f commit bcd0458
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
12 changes: 12 additions & 0 deletions src/lib/y2network/connection_config/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 1 addition & 13 deletions src/lib/y2network/network_manager/config_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 1 addition & 13 deletions src/lib/y2network/wicked/connection_config_writers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit bcd0458

Please sign in to comment.