Class: Yast::NetHwDetectionClass
- Inherits:
-
Module
- Object
- Module
- Yast::NetHwDetectionClass
- Defined in:
- ../../src/modules/NetHwDetection.rb
Instance Method Summary (collapse)
-
- (Object) DuplicateIP(ip)
Duplicate IP detection.
-
- (Object) LoadNetModules
Set up the first eth interface, if not already running WATCH OUT, this is the place where modules are loaded.
- - (Object) main
-
- (Object) ResolveIP(ip)
this function is moved here just to kee it out of the tangle of includes which will be torn apart in the next release.
-
- (Object) Start
Start the detection.
-
- (Object) Stop
Stop the detection.
Instance Method Details
- (Object) DuplicateIP(ip)
Duplicate IP detection
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File '../../src/modules/NetHwDetection.rb', line 195 def DuplicateIP(ip) # missing param for arping. Arping does nothing in such case only # floods logs. return false if ip.nil? || ip.empty? command = "LC_ALL=C ip link show|grep BROADCAST|grep -v NOARP|cut -d: -f2" exe = Convert.to_map(SCR.Execute(path(".target.bash_output"), command)) ifs = Ops.get_string(exe, "stdout", "") ifsl = Builtins.filter(Builtins.splitstring(ifs, " \t\n")) { |i| i != "" } # #45169: must only probe the interface being set up # but I don't know which one it is :-( # so pretend there are no dups if we have more interfaces return false if Ops.greater_than(Builtins.size(ifsl), 1) # find the interface that detects the dup ifc = Builtins.find(ifsl) do |ifname| # no need to be quiet, diagnostics is good command = Ops.add( Ops.add(Ops.add("arping -D -c2 -w3 -I", ifname), " "), ip ) # 0 no dup, 1 dup, 2 other error (eg. ifc not up, #182473) SCR.Execute(path(".target.bash"), command) == 1 end !ifc.nil? end |
- (Object) LoadNetModules
Set up the first eth interface, if not already running WATCH OUT, this is the place where modules are loaded
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File '../../src/modules/NetHwDetection.rb', line 98 def LoadNetModules Builtins.y2milestone("Network detection prepare") hardware = ReadHardware("netcard") Builtins.y2debug("Hardware=%1", hardware) return false if Ops.less_than(Builtins.size(hardware), 1) needed_modules = Builtins.listmap(hardware) do |h| # Formerly we simply modprobed the first module of the first # driver, if it was not already loaded. But if the user # configured the card to use the second driver and unloads it # and wants to load the first, it will not work because the # first driver is already loaded but not bound to the device # (the second one took it). N#59794#c31 # We will only load a driver if there's no driver for the card active. active_driver = Builtins.find(Ops.get_list(h, "drivers", [])) do |d| Ops.get_boolean(d, "active", false) end { Ops.get_string(h, "module", "") => active_driver.nil? } # TODO: list of todos # 1: choose which driver to load # 2: load all its modules: no cards use multiple modules # 3: either modprobe or insmod: ISA history end needed_modules = Builtins.filter(needed_modules) do |m, load| load && !m.nil? && m != "" && SCR.Execute( path(".target.bash"), Builtins.sformat("grep ^%1 /proc/modules", m) ) != 0 end @detection_modules = Builtins.maplist(needed_modules) { |m, _a| m } Package.InstallKernel(Builtins.maplist(@detection_modules) do |m| Ops.add(m, ".ko") end) Builtins.foreach(@detection_modules) do |mod| Builtins.y2milestone("Loading module: %1", mod) SCR.Execute( path(".target.bash"), Builtins.sformat("/sbin/modprobe --use-blacklist %1 2>&1", mod) ) end Builtins.y2milestone("Network detection prepare (end)") true end |
- (Object) main
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File '../../src/modules/NetHwDetection.rb', line 63 def main Yast.import "UI" textdomain "network" Yast.import "Directory" Yast.import "Package" Yast.import "String" # yuck, FIXME # this is here just because network/hardware.ycp references it # because of detection and module loading (StartEthInterface) # general stuff @description = "" @type = "" @unique = "" @hotplug = "" @Requires = [] Yast.include self, "network/hardware.rb" # Detection result # (in dhcpcd-<i>interface</i>.info format) @result = {} # True, if detection is running @running = false @tmpdir = Directory.tmpdir @detection_modules = [] end |
- (Object) ResolveIP(ip)
this function is moved here just to kee it out of the tangle of includes which will be torn apart in the next release. dependency hell. Resolve IP to hostname
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File '../../src/modules/NetHwDetection.rb', line 230 def ResolveIP(ip) # quick check to avoid timeout if Builtins.size(ip) == 0 || Convert.to_integer( SCR.Execute( path(".target.bash"), Builtins.sformat("grep -q %1 /etc/hosts", ip) ) ) != 0 return "" end command = "/usr/bin/getent hosts \"%1\" | sed \"s/^[0-9.: \t]\\+//g\"" getent = Convert.to_map( SCR.Execute(path(".target.bash_output"), Builtins.sformat(command, ip)) ) hnent = Ops.get_string(getent, "stdout", "") Builtins.y2debug("%1", hnent) hnent = String.FirstChunk(hnent, " \t\n") hnent = "" if hnent.nil? Builtins.y2debug("'%1'", hnent) String.CutBlanks(hnent) end |
- (Object) Start
Start the detection
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File '../../src/modules/NetHwDetection.rb', line 149 def Start if @running == true Builtins.y2error("Detection already running") return false end Builtins.y2milestone( "IFCONFIG1: %1", SCR.Execute(path(".target.bash_output"), "/sbin/ip addr show") ) ret = false if LoadNetModules() @running = true ret = true end Builtins.y2milestone( "IFCONFIG2: %1", SCR.Execute(path(".target.bash_output"), "/sbin/ip addr show") ) Builtins.y2milestone("Detection start result: %1", ret) ret end |
- (Object) Stop
Stop the detection
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File '../../src/modules/NetHwDetection.rb', line 175 def Stop if @running != true Builtins.y2error("Detection not running") return false end @running = false Builtins.y2milestone( "IFCONFIG3: %1", SCR.Execute(path(".target.bash_output"), "/sbin/ip addr show") ) Builtins.y2milestone("Detection stop ") true end |