Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Mar 29, 2019
1 parent 5e36587 commit 07543dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src/lib/y2network/config_reader/sysconfig.rb
Expand Up @@ -32,15 +32,9 @@ class Sysconfig
# @return [Y2Network::Config] Network configuration
def config
interfaces = find_interfaces
# load /etc/sysconfig/network/routes
routes = SysconfigRoutesReader.new.config
# load /etc/sysconfig/network/ifroute-*
dev_routes = interfaces.map do |iface|
SysconfigRoutesReader.new(routes_file: "/etc/sysconfig/network/ifroute-#{iface.name}").config
end
routing = dev_routes.inject(routes) { |memo, r| memo.concat(r.routes) }.uniq
routing = Routing.new(tables: [load_routes])

Config.new(interfaces: interfaces, routing: Routing.new(tables: [routing]), source: :sysconfig)
Config.new(interfaces: interfaces, routing: routing, source: :sysconfig)
end

private
Expand All @@ -58,6 +52,23 @@ def find_interfaces
Y2Network::Interface.new(name)
end
end

# Reads routes
#
# Merges routes from /etc/sysconfig/network/routes and /etc/sysconfig/network/ifroute-*
# TODO: currently it implicitly loads main/default routing table
#
# return [RoutingTable] an object with routes
def load_routes
# load /etc/sysconfig/network/routes
routes = SysconfigRoutesReader.new.config
# load /etc/sysconfig/network/ifroute-*
dev_routes = find_interfaces.map do |iface|
SysconfigRoutesReader.new(routes_file: "/etc/sysconfig/network/ifroute-#{iface.name}").config
end

dev_routes.inject(routes) { |memo, r| memo.concat(r.routes) }.uniq
end
end
end
end
2 changes: 1 addition & 1 deletion src/lib/y2network/config_reader/sysconfig_routes_reader.rb
Expand Up @@ -179,7 +179,7 @@ def ifroute_term(path)
# @raise [RuntimeError] if it fails
def register_ifroute_agent_for_path(path)
# /etc/sysconfig/network/ifroute-eth0 define .ifroute-eth0 agent
# collisions not handled
# TODO: collisions not handled
scr_path = Yast::Path.new(".#{File.basename(path)}")
Yast::SCR.RegisterAgent(scr_path, ifroute_term(path)) ||
raise("Cannot register agent (#{scr_path})")
Expand Down

0 comments on commit 07543dd

Please sign in to comment.