Skip to content

Commit

Permalink
Merge pull request #969 from yast/network-ng-lan_items_clean_up
Browse files Browse the repository at this point in the history
network-ng: LanItems module clean up
  • Loading branch information
imobachgs authored Sep 19, 2019
2 parents 242fd8e + 8b527b2 commit 0ba21fd
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 692 deletions.
4 changes: 2 additions & 2 deletions src/clients/lan_auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def main
elsif @func == "Packages"
@ret = Lan.AutoPackages
elsif @func == "SetModified"
@ret = LanItems.SetModified
@ret = Lan.SetModified
elsif @func == "GetModified"
@ret = LanItems.GetModified
@ret = Lan.Modified
elsif @func == "Export"
@settings2 = Lan.Export
Builtins.y2debug("settings: %1", @settings2)
Expand Down
2 changes: 1 addition & 1 deletion src/include/network/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def ManagedStore(_key, _event)
end

if NetworkService.Modified
LanItems.SetModified
Lan.SetModified

if Stage.normal && NetworkService.is_network_manager
Popup.AnyMessage(
Expand Down
2 changes: 2 additions & 0 deletions src/lib/y2network/interfaces_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

require "yast"
require "y2network/interface"
require "y2network/can_be_copied"
require "forwardable"

module Y2Network
Expand All @@ -41,6 +42,7 @@ module Y2Network
class InterfacesCollection
extend Forwardable
include Yast::Logger
include CanBeCopied

# @return [Array<Interface>] List of interfaces
attr_reader :interfaces
Expand Down
46 changes: 29 additions & 17 deletions src/modules/Lan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def main

@backend = nil

@modified = false

# Y2Network::Config objects
@configs = {}
end
Expand All @@ -111,7 +113,7 @@ def main
# Return a modification status
# @return true if data was modified
def Modified
return true if LanItems.GetModified
return true if @modified
return true unless system_config == yast_config
return true if NetworkConfig.Modified
return true if NetworkService.Modified
Expand All @@ -120,6 +122,11 @@ def Modified
false
end

def SetModified
@modified = true
nil
end

# function for use from autoinstallation (Fate #301032)
def isAnyInterfaceDown
down = false
Expand Down Expand Up @@ -265,10 +272,6 @@ def Read(cache)
return true
end

system_config = Y2Network::Config.from(:sysconfig)
add_config(:system, system_config)
add_config(:yast, system_config.copy)

# Read dialog caption
caption = _("Initializing Network Configuration")

Expand Down Expand Up @@ -334,7 +337,7 @@ def Read(cache)

return false if Abort()
ProgressNextStage(_("Reading device configuration...")) if @gui
LanItems.Read
read_config

Builtins.sleep(sl)

Expand Down Expand Up @@ -400,7 +403,7 @@ def SetIPv6(status)
if @ipv6 != status
@ipv6 = status
Popup.Warning(_("To apply this change, a reboot is needed."))
LanItems.SetModified
Lan.SetModified
end

nil
Expand Down Expand Up @@ -867,7 +870,7 @@ def ProposeVirtualized
builder.configure_as_slave
builder.save
LanItems.move_routes(builder.name, bridge_builder.name)
refresh_lan_items
refresh_interfaces
end

nil
Expand Down Expand Up @@ -1041,16 +1044,25 @@ def connected_and_bridgeable?(bridge_builder, interface)
true
end

def refresh_lan_items
LanItems.force_restart = true
# re-read configuration to see new items in UI
LanItems.Read
# Refreshes YaST network interfaces
#
# It refreshes system configuration and update the list of interfaces
# for the current YaST configuration. The rest of the configuration
# is not modified.
#
# TODO: consider adding an API to Y2Network::Config to do partial refreshes.
def refresh_interfaces
system_config = Y2Network::Config.from(:sysconfig)
yast_config.interfaces = system_config.interfaces.copy
end

# note: LanItems.Read resets modification flag
# the Read is used as a trick how to update LanItems' internal
# cache according NetworkInterfaces' one. As NetworkInterfaces'
# cache was edited directly, LanItems is not aware of changes.
LanItems.SetModified
# Reads system configuration
#
# It clears already read configuration.
def read_config
system_config = Y2Network::Config.from(:sysconfig)
Yast::Lan.add_config(:system, system_config)
Yast::Lan.add_config(:yast, system_config.copy)
end

# Returns the routing summary
Expand Down
Loading

0 comments on commit 0ba21fd

Please sign in to comment.