Skip to content

Commit

Permalink
[RFC] Initialize with defaults when no exist. (cache problems)
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Apr 12, 2019
1 parent 85b5219 commit d10adf8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/clients/lan_auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ def main
@ret = Lan.Summary("summary")
elsif @func == "Reset"
Lan.Import({})
Yast::Lan.clear_configs
@ret = {}
elsif @func == "Change"
unless Yast::Lan.yast_config
Yast::Lan.add_config(:yast, Y2Network::Config.from(:defaults))
end
@ret = LanAutoSequence("")
elsif @func == "Import"
@new = Lan.FromAY(@param)
Expand Down
8 changes: 4 additions & 4 deletions src/include/network/services/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ def RoutingMainDialog

def config
# TODO: get it from some config holder
@routing_config ||= Yast::Lan.yast_config
@routing_config = Yast::Lan.yast_config
end

def routing_table
@routing_table_widget ||= Y2Network::Widgets::RoutingTable.new(config.routing.tables.first)
@routing_table_widget = Y2Network::Widgets::RoutingTable.new(config.routing.tables.first)
end

def ip4_forwarding
@ip4_forwarding_widget ||= Y2Network::Widgets::IP4Forwarding.new(config)
@ip4_forwarding_widget = Y2Network::Widgets::IP4Forwarding.new(config)
end

def ip6_forwarding
@ip6_forwarding_widget ||= Y2Network::Widgets::IP6Forwarding.new(config)
@ip6_forwarding_widget = Y2Network::Widgets::IP6Forwarding.new(config)
end

def add_button
Expand Down
58 changes: 58 additions & 0 deletions src/lib/y2network/config_reader/defaults.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"
require "y2network/interface"
require "y2network/config"
require "y2network/routing"
require "y2network/routing_table"

Yast.import "Lan"

module Y2Network
module ConfigReader
# This class is responsible of initializing the default configuration
class Defaults
def initialize(_options)
end

def config
interfaces = find_interfaces
routing = Y2Network::Routing.new(tables: [Y2Network::RoutingTable.new])
Y2Network::Config.new(interfaces: interfaces, routing: routing, source: :sysconfig)
end

private

# Find configured network interfaces
#
# Configured interfaces have a configuration (ifcfg file) assigned.
#
# @return [Array<Interface>] Detected interfaces
# @see Yast::NetworkInterfaces.Read
def find_interfaces
Yast::NetworkInterfaces.Read
# TODO: for the time being, we are just relying in the underlying stuff.
Yast::NetworkInterfaces.List("").map do |name|
Y2Network::Interface.new(name)
end
end
end
end
end

0 comments on commit d10adf8

Please sign in to comment.