-
Notifications
You must be signed in to change notification settings - Fork 34
/
bonding.rb
80 lines (63 loc) · 2.31 KB
/
bonding.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require "yast"
require "y2network/config"
require "y2network/interface_config_builder"
module Y2Network
module InterfaceConfigBuilders
class Bonding < InterfaceConfigBuilder
include Yast::Logger
def initialize
super(type: InterfaceType::BONDING)
# fill mandatory bond option
@config["BOND_SLAVES"] = []
end
# @return [Array<Interface>] list of interfaces usable for the bond device
def bondable_interfaces
interfaces.all.select { |i| bondable?(i) }
end
attr_writer :bond_options
def bond_options
return @bond_options if @bond_options
@bond_options = Yast::LanItems.bond_option
if @bond_options.nil? || @bond_options.empty?
@bond_options = @config["BONDING_MODULE_OPTS"]
end
@bond_options
end
def save
super
Yast::LanItems.bond_slaves = @config["BOND_SLAVES"]
Yast::LanItems.bond_option = bond_options
end
private
def interfaces
Config.find(:yast).interfaces
end
# Checks whether an interface can be enslaved in particular bond interface
#
# @param iface [Interface] an interface to be validated as bond_iface slave
# TODO: Check for valid configurations. E.g. bond device over vlan
# is nonsense and is not supported by netconfig.
# Also devices enslaved in a bridge should be excluded too.
def bondable?(iface)
Yast.import "Arch"
Yast.include self, "network/lan/s390.rb"
# check if the device is L2 capable on s390
if Yast::Arch.s390
s390_config = s390_ReadQethConfig(iface.name)
# only devices with L2 support can be enslaved in bond. See bnc#719881
return false unless s390_config["QETH_LAYER2"] == "yes"
end
if interfaces.bond_index[iface.name] && interfaces.bond_index[iface.name] != @name
log.debug("Excluding (#{iface.name}) - is already bonded")
return false
end
# cannot enslave itself
# FIXME: this can happen only bcs we silently use LanItems::Items which
# already contains partially configured bond when adding
return false if iface.name == @name
return true if !iface.configured
iface.bootproto == "none"
end
end
end
end