Skip to content

Commit

Permalink
Merge pull request #807 from yast/more_cwm_objects
Browse files Browse the repository at this point in the history
more CWM
  • Loading branch information
jreidinger committed May 14, 2019
2 parents 437114c + 288d163 commit 86e0604
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 168 deletions.
63 changes: 15 additions & 48 deletions src/include/network/lan/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
require "y2network/widgets/bond_options"
require "y2network/widgets/bond_slave"
require "y2network/widgets/bridge_ports"
require "y2network/widgets/ifplugd_priority"
require "y2network/widgets/startmode"
require "y2network/widgets/mtu"

module Yast
Expand Down Expand Up @@ -99,6 +101,14 @@ def mtu_widget
@mtu_widget ||= Y2Network::Widgets::MTU.new(@settings)
end

def ifplugd_priority_widget
@ifplugd_priority_widget ||= Y2Network::Widgets::IfplugdPriority.new(@settings)
end

def startmode_widget
@startmode_widget ||= Y2Network::Widgets::Startmode.new(@settings, ifplugd_priority_widget)
end

def widget_descr_local
res = {
"AD_ADDRESSES" => {
Expand Down Expand Up @@ -370,10 +380,7 @@ def my2debug(class_, msg)
def InitAddrWidget(key)
value = Ops.get(@settings, key)
my2debug("AW", Builtins.sformat("init k: %1, v: %2", key, value))
# because IFPLUGD_PRIORITY is integer, not string
if key != "IFPLUGD_PRIORITY"
UI.ChangeWidget(Id(key), ValueProp(key), value)
end
UI.ChangeWidget(Id(key), ValueProp(key), value)

nil
end
Expand Down Expand Up @@ -797,22 +804,6 @@ def BuildTypesListCWM(types)
end
end

def initIfplugdPriority(_key)
UI.ChangeWidget(
Id("IFPLUGD_PRIORITY"),
:Value,
@settings["IFPLUGD_PRIORITY"].to_i
)

nil
end

# Stores content of IFPLUGD_PRIORITY widget into internal variables
def store_ifplugd_priority(_key, _event)
ifp_prio = UI.QueryWidget(Id("IFPLUGD_PRIORITY"), :Value).to_s
LanItems.ifplugd_priority = ifp_prio if !ifp_prio.empty?
end

def general_tab
type = LanItems.GetCurrentType

Expand All @@ -829,7 +820,7 @@ def general_tab
# TODO: "MANDATORY",
Frame(
_("Device Activation"),
HBox("STARTMODE", "IFPLUGD_PRIORITY", HStretch())
HBox(startmode_widget.widget_id, ifplugd_priority_widget.widget_id, HStretch())
),
VSpacing(0.4),
Frame(_("Firewall Zone"), HBox("FWZONE", HStretch())),
Expand Down Expand Up @@ -965,33 +956,8 @@ def AddressDialog
to: "map <string, map <string, any>>"
)

wd["STARTMODE"] = MakeStartmode(
["auto", "ifplugd", "hotplug", "manual", "off", "nfsroot"]
)

Ops.set(
wd,
"IFPLUGD_PRIORITY",
"widget" => :intfield,
"minimum" => 0,
"maximum" => 100,
# Combo box label - when to activate device (e.g. on boot, manually, never,..)
"label" => _(
"Ifplugd Priority"
),
"help" =>
# Device activation main help. The individual parts will be
# substituted as %1
_(
"<p><b><big>IFPLUGD PRIORITY</big></b></p> \n" \
"<p> All interfaces configured with <b>On Cable Connection</b> and with IFPLUGD_PRIORITY != 0 will be\n" \
" used mutually exclusive. If more then one of these interfaces is <b>On Cable Connection</b>\n" \
" then we need a way to decide which interface to take up. Therefore we have to\n" \
" set the priority of each interface. </p>\n"
),
"init" => fun_ref(method(:initIfplugdPriority), "void (string)"),
"store" => fun_ref(method(:store_ifplugd_priority), "void (string, map)")
)
wd[startmode_widget.widget_id] = startmode_widget.cwm_definition
wd[ifplugd_priority_widget.widget_id] = ifplugd_priority_widget.cwm_definition

Ops.set(wd, ["IFCFGTYPE", "items"], BuildTypesListCWM(NetworkInterfaces.GetDeviceTypes))
Ops.set(
Expand Down Expand Up @@ -1083,6 +1049,7 @@ def AddressDialog
LanItems.startmode = Ops.get_string(@settings, "STARTMODE", "")
LanItems.mtu = Ops.get_string(@settings, "MTU", "")
LanItems.firewall_zone = firewall_zone.store_permanent if firewalld.installed?
LanItems.ifplugd_priority = @settings["IFPLUGD_PRIORITY"]

# address tab
bootproto = @settings.fetch("BOOTPROTO", "")
Expand Down
120 changes: 0 additions & 120 deletions src/include/network/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,81 +64,6 @@ def initialize_network_widgets(include_target)
"help" => _("<p>H</p>")
}
}

# This is the data for widget_descr["STARTMODE"].
# It is separated because the list of items depends on the device type
# and will be substituted dynamically.
# Helps are rich text, but not paragraphs.
@startmode_items = {
# onboot, on and boot are aliases for auto
# See NetworkInterfaces::CanonicalizeStartmode
"auto" =>
# is a part of the static help text
{
# Combo box option for Device Activation
"label" => _(
"At Boot Time"
),
"help" => ""
},
"off" =>
# is a part of the static help text
{ "label" => _("Never"), "help" => "" },
"managed" => {
# Combo box option for Device Activation
# DO NOT TRANSLATE NetworkManager, it is a program name
"label" => _(
"By NetworkManager"
),
# help text for Device Activation
# DO NOT TRANSLATE NetworkManager, it is a program name
"help" => _(
"<b>By NetworkManager</b>: a desktop applet\ncontrols the interface. There is no need to set it up in YaST."
)
},
"manual" => {
# Combo box option for Device Activation
"label" => _("Manually"),
# help text for Device Activation
"help" => _(
"<p><b>Manually</b>: You control the interface manually\nvia 'ifup' or 'qinternet' (see 'User Controlled' below).</p>\n"
)
},
"ifplugd" => {
# Combo box option for Device Activation
"label" => _(
"On Cable Connection"
),
# help text for Device Activation
"help" => _(
"<b>On Cable Connection</b>:\n" \
"The interface is watched for whether there is a physical\n" \
"network connection. That means either the cable is connected or the\n" \
"wireless interface can connect to an access point.\n"
)
},
"hotplug" => {
# Combo box option for Device Activation
"label" => _("On Hotplug"),
# help text for Device Activation
"help" => _(
"With <b>On Hotplug</b>,\n" \
"the interface is set up as soon as it is available. This is\n" \
"nearly the same as 'At Boot Time', but does not result in an error at\n" \
"boot time if the interface is not present.\n"
)
},
"nfsroot" => {
# Combo box option for Device Activation
"label" => _("On NFSroot"),
# help text for Device Activation
"help" => _(
"Using <b>On NFSroot</b> is similar to <tt>auto</tt>. Interfaces with this startmode will never\n" \
"be shut down via <tt>rcnetwork stop</tt>. <tt>ifdown <iface></tt> is still available.\n" \
"Use this if you have an NFS or iSCSI root filesystem.\n"
)
}
}
end

# Validator for IP adresses, no_popup
Expand All @@ -151,51 +76,6 @@ def ValidateIP(key, _event)
true
end

def handleStartmode(_key, _event)
UI.ChangeWidget(
Id("IFPLUGD_PRIORITY"),
:Enabled,
UI.QueryWidget(Id("STARTMODE"), :Value) == "ifplugd"
)
nil
end

def MakeStartmode(ids)
ids = deep_copy(ids)
ret = {
"widget" => :combobox,
# Combo box label - when to activate device (e.g. on boot, manually, never,..)
"label" => _("Activate &Device"),
"opt" => [:notify],
"handle" => fun_ref(method(:handleStartmode), "symbol (string, map)"),
"help" =>
# Device activation main help. The individual parts will be
# substituted as %1
_(
"<p><b><big>Device Activation</big></b></p> \n" \
"<p>Choose when to bring up the network interface. <b>At Boot Time</b> activates it during system boot, \n" \
"<b>Never</b> does not start the device.\n" \
"%1</p>\n"
)
}
helps = ""
items = Builtins.maplist(ids) do |id|
helps = Ops.add(
Ops.add(helps, " "),
Ops.get(@startmode_items, [id, "help"], "")
)
[id, Ops.get(@startmode_items, [id, "label"], "")]
end

Ops.set(
ret,
"help",
Builtins.sformat(Ops.get_string(ret, "help", "%1"), helps)
)
Ops.set(ret, "items", items)
deep_copy(ret)
end

def init_ipoib_mode_widget(key)
ipoib_mode = LanItems.ipoib_mode || "default"

Expand Down
46 changes: 46 additions & 0 deletions src/lib/y2network/widgets/ifplugd_priority.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "cwm/common_widgets"

module Y2Network
module Widgets
class IfplugdPriority < CWM::IntField
def initialize(config)
textdomain "network"

@config = config
end

def label
_(
"Ifplugd Priority"
)
end

def help
# TRANSLATORS: help text for Ifplugd priority widget
_(
"<p><b><big>IFPLUGD PRIORITY</big></b></p> \n" \
"<p> All interfaces configured with <b>On Cable Connection</b> and with IFPLUGD_PRIORITY != 0 will be\n" \
" used mutually exclusive. If more then one of these interfaces is <b>On Cable Connection</b>\n" \
" then we need a way to decide which interface to take up. Therefore we have to\n" \
" set the priority of each interface. </p>\n"
)
end

def minimum
0
end

def maximum
100
end

def init
self.value = @config["IFPLUGD_PRIORITY"].to_i
end

def store
@config["IFPLUGD_PRIORITY"] = value.to_s
end
end
end
end
99 changes: 99 additions & 0 deletions src/lib/y2network/widgets/startmode.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
require "cwm/common_widgets"

module Y2Network
module Widgets
class Startmode < CWM::ComboBox
def initialize(config, plug_priority_widget)
textdomain "network"

@config = config
@plug_priority_widget = plug_priority_widget
end

def opt
[:notify]
end

def label
_("Activate &Device")
end

def init
self.value = @config["STARTMODE"]
handle
end

def store
@config["STARTMODE"] = value
end

def handle
value == "ifplugd" ? @plug_priority_widget.enable : @plug_priority_widget.disable

nil
end

def help
# tricky init only to not break long help text translations
items_help =
[
# TRANSLATORS: help text for Device Activation
_(
"<p><b>Manually</b>: You control the interface manually\n" \
"via 'ifup' or 'qinternet' (see 'User Controlled' below).</p>\n"
),
# TRANSLATORS: help text for Device Activation
_(
"<b>On Cable Connection</b>:\n" \
"The interface is watched for whether there is a physical\n" \
"network connection. That means either the cable is connected or the\n" \
"wireless interface can connect to an access point.\n"
),
# TRANSLATORS: help text for Device Activation
_(
"With <b>On Hotplug</b>,\n" \
"the interface is set up as soon as it is available. This is\n" \
"nearly the same as 'At Boot Time', but does not result in an error at\n" \
"boot time if the interface is not present.\n"
),
# TRANSLATORS: help text for Device Activation
_(
"Using <b>On NFSroot</b> is similar to <tt>auto</tt>. Interfaces with this startmode will never\n" \
"be shut down via <tt>rcnetwork stop</tt>. <tt>ifdown <iface></tt> is still available.\n" \
"Use this if you have an NFS or iSCSI root filesystem.\n"
)
]

# Device activation main help. The individual parts will be
# substituted as %1
Yast::Builtins.sformat(
_(
"<p><b><big>Device Activation</big></b></p> \n" \
"<p>Choose when to bring up the network interface. <b>At Boot Time</b> activates it during system boot, \n" \
"<b>Never</b> does not start the device.\n" \
"%1</p>\n"
),
items_help.join(" ")
)
end

def items
[
# onboot, on and boot are aliases for auto
# See NetworkInterfaces::CanonicalizeStartmode
# TRANSLATORS: Combo box option for Device Activation
["auto", _("At Boot Time")],
["off", _("Never")],
# TRANSLATORS: Combo box option for Device Activation
["manual", _("Manually")],
# TRANSLATORS: Combo box option for Device Activation
["ifplugd", _("On Cable Connection")],
# TRANSLATORS: Combo box option for Device Activation
["hotplug", _("On Hotplug")],
# TRANSLATORS: Combo box option for Device Activation
["nfsroot", _("On NFSroot")]
]
end
end
end
end
Loading

0 comments on commit 86e0604

Please sign in to comment.