Class: Yast::LanUdevAutoClass
- Inherits:
-
Module
- Object
- Module
- Yast::LanUdevAutoClass
- Includes:
- Logger
- Defined in:
- ../../src/modules/LanUdevAuto.rb
Instance Method Summary (collapse)
-
- (Object) AllowUdevModify
FATE#311332.
-
- (Object) createUdevFromIfaceName(interfaces)
internal function: for old-slyle create udev rules and rename interface names to new-style.
- - (Object) Export(devices)
-
- (Object) getDeviceName(oldname)
It finds a new style device name for device name in old fashioned format.
- - (Object) GetDevnameByMAC(mac)
- - (Object) Import(settings)
-
- (Object) InstallationParameter(name)
Installation parameter or nil.
-
- (Object) InstallInfParameter(name)
Parameter from /etc/install.inf or nil.
-
- (Object) KernelCmdlineParameter(name)
Parameter from the kernel(boot) command line or nil.
- - (Object) main
-
- (Object) oldStyle(ay)
internal function: check if old-style (ifcfg-eth-id-…, ifcfg-eth-bus-… is used) or new-style (ifcfg-eth0).
- - (Object) Write
Instance Method Details
- (Object) AllowUdevModify
FATE#311332
76 77 78 |
# File '../../src/modules/LanUdevAuto.rb', line 76 def AllowUdevModify InstallationParameter("biosdevname") != "1" end |
- (Object) createUdevFromIfaceName(interfaces)
internal function: for old-slyle create udev rules and rename interface names to new-style
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File '../../src/modules/LanUdevAuto.rb', line 136 def createUdevFromIfaceName(interfaces) interfaces = deep_copy(interfaces) Builtins.y2milestone( "old-style names for interfaces found - convert into new-style" ) Builtins.y2milestone("interfaces %1", interfaces) tmp_interfaces = [] Builtins.foreach(interfaces) do |interface| if Builtins.issubstring(Ops.get_string(interface, "device", ""), "-id-") || Builtins.issubstring( Ops.get_string(interface, "device", ""), "-bus-" ) value = Ops.get( Builtins.splitstring(Ops.get_string(interface, "device", ""), "-"), 2, "" ) rule = "ATTR{address}" if Ops.get( Builtins.splitstring(Ops.get_string(interface, "device", ""), "-"), 1, "" ) == "bus" rule = "KERNELS" end @udev_rules = Builtins.add( @udev_rules, { "rule" => rule, "value" => value, "name" => getDeviceName(Ops.get_string(interface, "device", "")) } ) tmp_interfaces = Builtins.add(tmp_interfaces, interface) end end Builtins.y2milestone("converted interfaces: %1", tmp_interfaces) deep_copy(tmp_interfaces) end |
- (Object) Export(devices)
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File '../../src/modules/LanUdevAuto.rb', line 248 def Export(devices) devices = deep_copy(devices) _AY = { "s390-devices" => {}, "net-udev" => {} } if Arch.s390 devs = [] Builtins.foreach( Convert.convert(devices, :from => "map", :to => "map <string, any>") ) do |type, value| devs = Convert.convert( Builtins.union(devs, Map.Keys(Convert.to_map(value))), :from => "list", :to => "list <string>" ) end Builtins.foreach(devs) do |device| driver = Convert.convert( SCR.Execute( path(".target.bash_output"), Builtins.sformat( "driver=$(ls -l /sys/class/net/%1/device/driver);echo ${driver##*/}|tr -d '\n'", device ) ), :from => "any", :to => "map <string, any>" ) device_type = "" chanids = "" portname = "" protocol = "" if Ops.get_integer(driver, "exit", -1) == 0 case Ops.get_string(driver, "stdout", "") when "qeth" device_type = Ops.get_string(driver, "stdout", "") when "ctcm" device_type = "ctc" when "netiucv" device_type = "iucv" else Builtins.y2error( "unknown driver type :%1", Ops.get_string(driver, "stdout", "") ) end else Builtins.y2error("%1", driver) next end chan_ids = Convert.convert( SCR.Execute( path(".target.bash_output"), Builtins.sformat( "for i in $(seq 0 2);do chanid=$(ls -l /sys/class/net/%1/device/cdev$i);echo ${chanid##*/};done|tr '\n' ' '", device ) ), :from => "any", :to => "map <string, any>" ) if Ops.greater_than( Builtins.size(Ops.get_string(chan_ids, "stdout", "")), 0 ) chanids = String.CutBlanks(Ops.get_string(chan_ids, "stdout", "")) end port_name = Convert.convert( SCR.Execute( path(".target.bash_output"), Builtins.sformat( "cat /sys/class/net/%1/device/portname|tr -d '\n'", device ) ), :from => "any", :to => "map <string, any>" ) if Ops.greater_than( Builtins.size(Ops.get_string(port_name, "stdout", "")), 0 ) portname = String.CutBlanks(Ops.get_string(port_name, "stdout", "")) end proto = Convert.convert( SCR.Execute( path(".target.bash_output"), Builtins.sformat( "cat /sys/class/net/%1/device/protocol|tr -d '\n'", device ) ), :from => "any", :to => "map <string, any>" ) if Ops.greater_than( Builtins.size(Ops.get_string(proto, "stdout", "")), 0 ) protocol = String.CutBlanks(Ops.get_string(proto, "stdout", "")) end layer2 = Convert.to_integer( SCR.Execute( path(".target.bash"), Builtins.sformat( "grep -q 1 /sys/class/net/%1/device/layer2", device ) ) ) == 0 ? true : false Ops.set(_AY, ["s390-devices", device], { "type" => device_type }) if Ops.greater_than(Builtins.size(chanids), 0) Ops.set(_AY, ["s390-devices", device, "chanids"], chanids) end if Ops.greater_than(Builtins.size(portname), 0) Ops.set(_AY, ["s390-devices", device, "portname"], portname) end if Ops.greater_than(Builtins.size(protocol), 0) Ops.set(_AY, ["s390-devices", device, "protocol"], protocol) end Ops.set(_AY, ["s390-devices", device, "layer2"], true) if layer2 port0 = Convert.convert( SCR.Execute( path(".target.bash_output"), Builtins.sformat( "port0=$(ls -l /sys/class/net/%1/device/cdev0);echo ${port0##*/}|tr -d '\n'", device ) ), :from => "any", :to => "map <string, any>" ) Builtins.y2milestone("port0 %1", port0) if Ops.greater_than( Builtins.size(Ops.get_string(port0, "stdout", "")), 0 ) value = Ops.get_string(port0, "stdout", "") Ops.set( _AY, ["net-udev", device], { "rule" => "KERNELS", "name" => device, "value" => value } ) end end else Builtins.foreach( Convert.convert( LanItems.Items, :from => "map <integer, any>", :to => "map <integer, map <string, any>>" ) ) do |id, row| LanItems.current = id if Ops.greater_than( Builtins.size(Ops.get_string(row, "ifcfg", "")), 0 ) name = LanItems.GetItemUdev("NAME") mac_rule = LanItems.GetItemUdev("ATTR{address}") bus_rule = LanItems.GetItemUdev("KERNELS") if Builtins.size(mac_rule) == 0 && Builtins.size(bus_rule) == 0 Builtins.y2error("No MAC or BusID rule %1", row) next end Ops.set( _AY, ["net-udev", name], { "rule" => Ops.greater_than(Builtins.size(mac_rule), 0) ? "ATTR{address}" : "KERNELS", "name" => name, "value" => Ops.greater_than(Builtins.size(mac_rule), 0) ? mac_rule : bus_rule } ) end end end Builtins.y2milestone("AY profile %1", _AY) deep_copy(_AY) end |
- (Object) getDeviceName(oldname)
It finds a new style device name for device name in old fashioned format
It goes through currently present devices and tries to mach it to given old fashioned name
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File '../../src/modules/LanUdevAuto.rb', line 86 def getDeviceName(oldname) # TODO: # raise an exception when old name could not be matched to existing cfg. newname = oldname @hardware = ReadHardware("netcard") if @hardware == nil @hardware.each do |hw| hw_dev_name = hw["dev_name"] || "" hw_dev_mac = hw["mac"] || "" hw_dev_busid = hw["busid"] || "" case oldname when /.*-id-#{hw_dev_mac}/i Builtins.y2milestone("device by ID found: #{oldname}") newname = hw_dev_name when /.*-bus-#{hw_dev_busid}/i Builtins.y2milestone("device by BUS found #{oldname}") newname = hw_dev_name end end log = "nothing changed, #{newname} is old style dev_name" Builtins.y2milestone( log) if oldname == newname newname end |
- (Object) GetDevnameByMAC(mac)
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File '../../src/modules/LanUdevAuto.rb', line 428 def GetDevnameByMAC(mac) devname = "" if Ops.greater_than(Builtins.size(mac), 0) Builtins.y2milestone("MAC address from 1st stage: %1", mac) Builtins.foreach(@udev_rules) do |rule| if Ops.get_string(rule, "rule", "") == "ATTR{address}" if mac == Ops.get_string(rule, "value", "") devname = Ops.get_string(rule, "name", "") Builtins.y2milestone( "MAC address matched with device:%1", Ops.get_string(rule, "name", "") ) raise Break end elsif Ops.get_string(rule, "rule", "") == "KERNELS" Builtins.y2milestone("rule: %1", rule) # input parameter is MAC address, output is BusID of matched device cmd = Convert.to_map( SCR.Execute( path(".target.bash_output"), Builtins.sformat( "DEVICE=$(grep '%1' /sys/class/net/*/address);KERNELS=$(ls -l \"$(echo ${DEVICE%%/*})/device\");echo ${KERNELS##*/}|tr -d '\n'", mac ) ) ) if Ops.get_integer(cmd, "exit", -1) == 0 Builtins.y2milestone( "cmd output:%1", Ops.get_string(cmd, "stdout", "") ) if Ops.get_string(cmd, "stdout", "") == Ops.get_string(rule, "value", "") Builtins.y2internal("match!") devname = Ops.get_string(rule, "name", "") end end else Builtins.y2error("Unknown rule for:%1", rule) end end else Builtins.y2warning("No MAC address to compare.") end devname end |
- (Object) Import(settings)
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File '../../src/modules/LanUdevAuto.rb', line 177 def Import(settings) settings = deep_copy(settings) Builtins.y2milestone("importing %1", settings) if oldStyle(settings) Ops.set( settings, "interfaces", createUdevFromIfaceName(Ops.get_list(settings, "interfaces", [])) ) else @udev_rules = Ops.get_list(settings, "net-udev", []) end # if (Arch::s390()) @s390_devices = Ops.get_list(settings, "s390-devices", []) Builtins.y2milestone( "interfaces: %1", Ops.get_list(settings, "interfaces", []) ) Builtins.y2milestone("net-udev rules:%1", @udev_rules) Builtins.y2milestone("s390-devices rules:%1", @s390_devices) true end |
- (Object) InstallationParameter(name)
Returns installation parameter or nil
69 70 71 72 73 |
# File '../../src/modules/LanUdevAuto.rb', line 69 def InstallationParameter(name) value = InstallInfParameter(name) value = KernelCmdlineParameter(name) if value == nil value end |
- (Object) InstallInfParameter(name)
Returns parameter from /etc/install.inf or nil
54 55 56 57 |
# File '../../src/modules/LanUdevAuto.rb', line 54 def InstallInfParameter(name) p = Builtins.add(path(".etc.install_inf"), name) Convert.to_string(SCR.Read(p)) end |
- (Object) KernelCmdlineParameter(name)
Returns parameter from the kernel(boot) command line or nil
61 62 63 64 65 |
# File '../../src/modules/LanUdevAuto.rb', line 61 def KernelCmdlineParameter(name) cmdline = InstallInfParameter("Cmdline") cmdmap = Map.FromString(cmdline) # handles nil too Ops.get_string(cmdmap, name) end |
- (Object) main
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File '../../src/modules/LanUdevAuto.rb', line 38 def main Yast.import "UI" Yast.import "LanItems" Yast.import "Map" Yast.include self, "network/routines.rb" Yast.include self, "network/lan/udev.rb" textdomain "network" @udev_rules = [] @s390_devices = [] @hardware = nil end |
- (Object) oldStyle(ay)
internal function: check if old-style (ifcfg-eth-id-…, ifcfg-eth-bus-… is used) or new-style (ifcfg-eth0)
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File '../../src/modules/LanUdevAuto.rb', line 116 def oldStyle(ay) ay = deep_copy(ay) old_style_found = false Builtins.foreach(Ops.get_list(ay, "interfaces", [])) do |interface| if Builtins.issubstring(Ops.get_string(interface, "device", ""), "-id-") old_style_found = true end if Builtins.issubstring( Ops.get_string(interface, "device", ""), "-bus-" ) old_style_found = true end end Builtins.y2milestone("old-style found:%1", old_style_found) old_style_found end |
- (Object) Write
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File '../../src/modules/LanUdevAuto.rb', line 200 def Write template = "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", %s==\"%s\", NAME=\"%s\"" rules = @udev_rules.map do |rule| opt = rule["rule"] || "" value = rule["value"] || "" devname = rule["name"] || "" template % [opt, value.downcase, devname] end if !rules.empty? && AllowUdevModify() SetAllLinksDown() log.info("Writing AY udev rules for network") write_update_udevd(rules) SCR.Execute(path(".target.bash"), "udevadm settle") else log.info("No udev rules created by AY") end # FIXME: In fact, this has nothing to do with udev. At least no # directly. It creates linux emulation for s390 devices. if Arch.s390 @s390_devices.each do |rule| LanItems.Select("") LanItems.type = Ops.get_string(rule, "type", "") LanItems.qeth_chanids = Ops.get_string(rule, "chanids", "") LanItems.qeth_layer2 = Ops.get_boolean(rule, "layer2", false) LanItems.qeth_portname = Ops.get_string(rule, "portname", "") LanItems.chan_mode = Ops.get_string(rule, "protocol", "") LanItems.iucv_user = Ops.get_string(rule, "router", "") Builtins.y2milestone("rule:%1", rule) Builtins.y2milestone("type:%1", LanItems.type) Builtins.y2milestone("chanids:%1", LanItems.qeth_chanids) Builtins.y2milestone("layer2:%1", LanItems.qeth_layer2) Builtins.y2milestone("portname:%1", LanItems.qeth_portname) LanItems.createS390Device Builtins.y2milestone("rule %1", rule) end log.info("Writing s390 rules #{@s390_devices}") end true end |