Module: Yast::NetworkRoutinesInclude
- Includes:
- I18n, Logger, Yast
- Defined in:
- src/include/network/routines.rb
Constant Summary
Constants included from Yast
DNS, Host, Lan, NetHwDetection, Routing
Instance Method Summary collapse
-
#Abort ⇒ Object
Abort function.
-
#add_pkgs_to_proposal(packages) ⇒ Object
Adds the packages to the software proposal to make sure they are available in the installed system.
-
#carrier?(dev_name) ⇒ boolean
Checks if given device has carrier.
-
#ControllerType(hwdevice) ⇒ Object
Simple convertor from subclass to controller type.
-
#dev_port(dev_name) ⇒ String
Dev port of the given interface from /sys/class/net/$dev_name/dev_port.
-
#DeviceName(hwdevice) ⇒ Object
Extract the device 'name'.
-
#disable_unconfigureable_items(items, show_popup) ⇒ Object
Disables all widgets which cannot be configured with current network service.
- #DistinguishedName(name, hwdevice) ⇒ Object
- #initialize_network_routines(_include_target) ⇒ Object
-
#IsEmpty(value) ⇒ Object
Checks if given value is emtpy.
-
#PackagesInstall(packages) ⇒ Object
Check if required packages are installed and install them if they're not.
-
#phy_connected?(dev_name) ⇒ boolean
Checks if device is physically connected to a network.
-
#physical_port_id(dev_name) ⇒ String
With NPAR and SR-IOV capabilities, one device could divide a ethernet port in various.
-
#physical_port_id?(dev_name) ⇒ boolean
True if the physical port id is not empty.
-
#PollAbort ⇒ Object
Check for pending Abort press.
-
#ProgressNextStage(title) ⇒ Object
Progress::NextStage and Progress::Title combined into one function.
-
#ReadHardware(hwtype) ⇒ Object
Read HW information.
-
#ReallyAbort ⇒ Object
If modified, ask for confirmation.
-
#ReallyAbortCond(modified) ⇒ Object
If modified, ask for confirmation.
-
#Run(command) ⇒ Object
Run an external command on the target machine and check if it was successful.
-
#SetLinkUp(dev_name) ⇒ Object
Wrapper to call 'ip link set up' with the given interface.
- #unconfigureable_service? ⇒ Boolean
Methods included from Yast
Instance Method Details
#Abort ⇒ Object
Abort function
58 59 60 61 62 |
# File 'src/include/network/routines.rb', line 58 def Abort return false if Mode.commandline UI.PollInput == :abort end |
#add_pkgs_to_proposal(packages) ⇒ Object
Adds the packages to the software proposal to make sure they are available in the installed system
96 97 98 99 100 |
# File 'src/include/network/routines.rb', line 96 def add_pkgs_to_proposal(packages) log.info "Adding network packages to proposal: #{packages}" PackagesProposal.AddResolvables("network", :package, packages) unless packages.empty? :next end |
#carrier?(dev_name) ⇒ boolean
Checks if given device has carrier
590 591 592 593 594 595 |
# File 'src/include/network/routines.rb', line 590 def carrier?(dev_name) SCR.Read( path(".target.string"), "/sys/class/net/#{dev_name}/carrier" ).to_i != 0 end |
#ControllerType(hwdevice) ⇒ Object
Simple convertor from subclass to controller type.
199 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 247 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 |
# File 'src/include/network/routines.rb', line 199 def ControllerType(hwdevice) hwdevice = deep_copy(hwdevice) return "modem" if Ops.get_string(hwdevice, "subclass", "") == "Modem" return "isdn" if Ops.get_string(hwdevice, "subclass", "") == "ISDN" return "dsl" if Ops.get_string(hwdevice, "subclass", "") == "DSL" subclass_id = Ops.get_integer(hwdevice, "sub_class_id", -1) # Network controller if Ops.get_integer(hwdevice, "class_id", -1) == 2 case subclass_id when 0 return "eth" when 1 return "tr" when 2 return "fddi" when 3 return "atm" when 4 return "isdn" when 6 ## Should be PICMG? return "ib" when 7 return "ib" when 129 return "myri" when 130 return "wlan" when 131 return "xp" when 134 return "qeth" when 135 return "hsi" when 136 return "ctc" when 137 return "lcs" when 142 return "ficon" when 143 return "escon" when 144 return "iucv" when 145 return "usb" # #22739 when 128 # Mellanox ConnectX-3 series badly uses the 128 sub class # Check for the specific known boards with bad subclass. # # Concerned devices are: # 15b3:1003 MT27500 Family [ConnectX-3] # 15b3:1004 MT27500/MT27520 Family [ConnectX-3/ConnectX-3 Pro Virtual Function] # 15b3:1007 MT27520 Family [ConnectX-3 Pro] if hwdevice["vendor_id"] == 71_091 return "ib" if [69_635, 69_636, 69_639].include?(hwdevice["device_id"]) end # Nothing was found Builtins.y2error("Unknown network controller type: %1", hwdevice) Builtins.y2error( "It's probably missing in hwinfo (NOT src/hd/hd.h:sc_net_if)" ) return "" else # Nothing was found Builtins.y2error("Unknown network controller type: %1", hwdevice) return "" end end # exception for infiniband device if Ops.get_integer(hwdevice, "class_id", -1) == 12 return "ib" if subclass_id == 6 end # Communication controller if Ops.get_integer(hwdevice, "class_id", -1) == 7 case subclass_id when 3 return "modem" when 128 # Nothing was found Builtins.y2error("Unknown network controller type: %1", hwdevice) Builtins.y2error( "It's probably missing in hwinfo (src/hd/hd.h:sc_net_if)" ) return "" else # Nothing was found Builtins.y2error("Unknown network controller type: %1", hwdevice) return "" end # Network Interface # check the CVS history and then kill this code! # 0x107 is the output of hwinfo --network # which lists the INTERFACES # but we are inteested in hwinfo --netcard # Just make sure that hwinfo or ag_probe # indeed does not pass this to us elsif Ops.get_integer(hwdevice, "class_id", -1) == 263 Builtins.y2milestone("CLASS 0x107") # this should happen rarely case subclass_id when 0 return "lo" when 1 return "eth" when 2 return "tr" when 3 return "fddi" when 4 return "ctc" when 5 return "iucv" when 6 return "hsi" when 7 return "qeth" when 8 return "escon" when 9 return "myri" when 10 return "wlan" when 11 return "xp" when 12 return "usb" when 128 # Nothing was found Builtins.y2error("Unknown network interface type: %1", hwdevice) Builtins.y2error( "It's probably missing in hwinfo (src/hd/hd.h:sc_net_if)" ) return "" when 129 return "sit" else # Nothing was found Builtins.y2error("Unknown network interface type: %1", hwdevice) return "" end elsif Ops.get_integer(hwdevice, "class_id", -1) == 258 return "modem" elsif Ops.get_integer(hwdevice, "class_id", -1) == 259 return "isdn" elsif Ops.get_integer(hwdevice, "class_id", -1) == 276 return "dsl" end # Nothing was found Builtins.y2error("Unknown controller type: %1", hwdevice) "" end |
#dev_port(dev_name) ⇒ String
Dev port of the given interface from /sys/class/net/$dev_name/dev_port
620 621 622 623 624 625 |
# File 'src/include/network/routines.rb', line 620 def dev_port(dev_name) SCR.Read( path(".target.string"), "/sys/class/net/#{dev_name}/dev_port" ).to_s.strip end |
#DeviceName(hwdevice) ⇒ Object
Extract the device 'name'
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'src/include/network/routines.rb', line 177 def DeviceName(hwdevice) device = hwdevice["device"] || "" return device if !device.empty? model = hwdevice["model"] || "" return model if !model.empty? vendor = hwdevice["sub_vendor"] || "" dev = hwdevice["sub_device"] || "" if vendor.empty? || dev.empty? vendor = hwdevice["vendor"] || "" dev = hwdevice["device"] || "" end "#{vendor} #{dev}".strip end |
#disable_unconfigureable_items(items, show_popup) ⇒ Object
Disables all widgets which cannot be configured with current network service
see bnc#433084 if listed any items, disable them, if show_popup, show warning popup
returns true if items were disabled
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
# File 'src/include/network/routines.rb', line 663 def disable_unconfigureable_items(items, show_popup) return false if !unconfigureable_service? items.each { |i| UI.ChangeWidget(Id(i), :Enabled, false) } if show_popup Popup.Warning( _( "Network is currently handled by NetworkManager\n" \ "or completely disabled. YaST is unable to configure some options." ) ) UI.FakeUserInput("ID" => "global") end true end |
#DistinguishedName(name, hwdevice) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 |
# File 'src/include/network/routines.rb', line 162 def DistinguishedName(name, hwdevice) hwdevice = deep_copy(hwdevice) if Ops.get_string(hwdevice, "sysfs_bus_id", "") != "" return Builtins.sformat( "%1 (%2)", name, Ops.get_string(hwdevice, "sysfs_bus_id", "") ) end name end |
#initialize_network_routines(_include_target) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'src/include/network/routines.rb', line 36 def initialize_network_routines(_include_target) Yast.import "UI" textdomain "network" Yast.import "Popup" Yast.import "Progress" Yast.import "String" Yast.import "Arch" Yast.import "Confirm" Yast.import "Map" Yast.import "Netmask" Yast.import "Mode" Yast.import "IP" Yast.import "TypeRepository" Yast.import "Stage" Yast.import "PackagesProposal" Yast.import "Report" end |
#IsEmpty(value) ⇒ Object
Checks if given value is emtpy.
157 158 159 160 |
# File 'src/include/network/routines.rb', line 157 def IsEmpty(value) value = deep_copy(value) TypeRepository.IsEmpty(value) end |
#PackagesInstall(packages) ⇒ Object
Check if required packages are installed and install them if they're not
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 146 147 148 149 150 151 152 153 154 |
# File 'src/include/network/routines.rb', line 105 def PackagesInstall(packages) packages = deep_copy(packages) return :next if packages == [] log.info "Checking packages: #{packages}" # bnc#888130 In inst-sys, there is no RPM database to check # If the required package is part of the inst-sys, it will work, # if not, package can't be installed anyway # # Ideas: # - check /.packages.* for presence of the required package # - use `extend` to load the required packages on-the-fly return :next if Stage.initial Yast.import "Package" return :next if Package.InstalledAll(packages) # Popup text text = _("These packages need to be installed:") + "<p>" Builtins.foreach(packages) do |l| text = Ops.add(text, Builtins.sformat("%1<br>", l)) end Builtins.y2debug("Installing packages: %1", text) ret = false loop do ret = Package.InstallAll(packages) break if ret == true if ret == false && Package.InstalledAll(packages) ret = true break end # Popup text if !Popup.YesNo( _( "The required packages are not installed.\n" \ "The configuration will be aborted.\n" \ "\n" \ "Try again?\n" ) + "\n" ) break end end (ret == true) ? :next : :abort end |
#phy_connected?(dev_name) ⇒ boolean
Checks if device is physically connected to a network
It does neccessary steps which might be needed for proper initialization of devices driver.
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
# File 'src/include/network/routines.rb', line 633 def phy_connected?(dev_name) return true if carrier?(dev_name) # SetLinkUp ensures that driver is loaded SetLinkUp(dev_name) # Wait for driver initialization if needed. bnc#876848 # 5 secs is minimum proposed by sysconfig guys for intel drivers. # # For a discussion regarding this see # https://github.com/yast/yast-network/pull/202 sleep(5) carrier?(dev_name) end |
#physical_port_id(dev_name) ⇒ String
With NPAR and SR-IOV capabilities, one device could divide a ethernet port in various. If the driver module support it, we can check the phys port id via sysfs reading the /sys/class/net/$dev_name/phys_port_id
603 604 605 606 607 608 |
# File 'src/include/network/routines.rb', line 603 def physical_port_id(dev_name) SCR.Read( path(".target.string"), "/sys/class/net/#{dev_name}/phys_port_id" ).to_s.strip end |
#physical_port_id?(dev_name) ⇒ boolean
Returns true if the physical port id is not empty.
612 613 614 |
# File 'src/include/network/routines.rb', line 612 def physical_port_id?(dev_name) !physical_port_id(dev_name).empty? end |
#PollAbort ⇒ Object
Check for pending Abort press
66 67 68 |
# File 'src/include/network/routines.rb', line 66 def PollAbort UI.PollInput == :abort end |
#ProgressNextStage(title) ⇒ Object
Progress::NextStage and Progress::Title combined into one function
85 86 87 88 89 90 |
# File 'src/include/network/routines.rb', line 85 def ProgressNextStage(title) Progress.NextStage Progress.Title(title) nil end |
#ReadHardware(hwtype) ⇒ Object
Read HW information
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 427 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 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'src/include/network/routines.rb', line 357 def ReadHardware(hwtype) hardware = [] Builtins.y2debug("hwtype=%1", hwtype) # Confirmation: label text (detecting hardware: xxx) return [] if !confirmed_detection(hwtype) # read the corresponding hardware allcards = [] if hwtypes[hwtype] allcards = Convert.to_list(SCR.Read(hwtypes[hwtype])) elsif hwtype == "all" || hwtype.nil? || hwtype.empty? Builtins.maplist( Convert.convert( Map.Values(hwtypes), from: "list", to: "list <path>" ) ) do |v| allcards = Builtins.merge(allcards, Convert.to_list(SCR.Read(v))) end else Builtins.y2error("unknown hwtype: %1", hwtype) return [] end if allcards.nil? Builtins.y2error("hardware detection failure") return [] end # #97540 bms = Convert.to_string(SCR.Read(path(".etc.install_inf.BrokenModules"))) bms = "" if bms.nil? broken_modules = Builtins.splitstring(bms, " ") # fill in the hardware data num = 0 Builtins.maplist( Convert.convert(allcards, from: "list", to: "list <map>") ) do |card| # common stuff resource = Ops.get_map(card, "resource", {}) controller = ControllerType(card) one = {} one["name"] = DeviceName(card) # Temporary solution for s390: #40587 one["name"] = DistinguishedName(one["name"], card) if Arch.s390 one["type"] = controller one["udi"] = card["udi"] || "" one["sysfs_id"] = card["sysfs_id"] || "" one["dev_name"] = card["dev_name"] || "" one["requires"] = card["requires"] || [] one["modalias"] = card["modalias"] || "" one["unique"] = card["unique_key"] || "" # driver option needs for (bnc#412248) one["driver"] = card["driver"] || "" # Each card remembers its position in the list of _all_ cards. # It is used when selecting the card from the list of _unconfigured_ # ones (which may be smaller). #102945. one["num"] = num case controller # modem when "modem" one["device_name"] = card["dev_name"] || "" one["drivers"] = card["drivers"] || [] speed = Ops.get_integer(resource, ["baud", 0, "speed"], 57_600) # :-) have to check .probe and libhd if this confusion is # really necessary. maybe a pppd bug too? #148893 speed = 57_600 if speed == 12_000_000 one["speed"] = speed one["init1"] = Ops.get_string(resource, ["init_strings", 0, "init1"], "") one["init2"] = Ops.get_string(resource, ["init_strings", 0, "init2"], "") one["pppd_options"] = Ops.get_string(resource, ["pppd_option", 0, "option"], "") # isdn card when "isdn" drivers = card["isdn"] || [] one["drivers"] = drivers one["sel_drv"] = 0 one["bus"] = card["bus"] || "" one["io"] = Ops.get_integer(resource, ["io", 0, "start"], 0) one["irq"] = Ops.get_integer(resource, ["irq", 0, "irq"], 0) # dsl card when "dsl" driver_info = Ops.get_map(card, ["dsl", 0], {}) translate_mode = { "capiadsl" => "capi-adsl", "pppoe" => "pppoe" } m = driver_info["mode"] || "" one["pppmode"] = translate_mode[m] || m # treat the rest as a network card else # drivers: # Although normally there is only one module # (one=$[active:, module:, options:,...]), the generic # situation is: one or more driver variants (exclusive), # each having one or more modules (one[drivers]) # only drivers that are not marked as broken (#97540) drivers = Builtins.filter(Ops.get_list(card, "drivers", [])) do |d| # ignoring more modules per driver... module0 = Ops.get_list(d, ["modules", 0], []) # [module, options] brk = broken_modules.include?(module0[0]) Builtins.y2milestone("In BrokenModules, skipping: %1", module0) if brk !brk end if drivers == [] Builtins.y2milestone("No good drivers found") else one["drivers"] = drivers driver = drivers[0] || {} one["active"] = driver["active"] || false module0 = Ops.get_list(driver, ["modules", 0], []) one["module"] = module0[0] || "" one["options"] = module0[1] || "" end # FIXME: this should be also done for modems and others # FIXME: #13571 hp = card["hotplug"] || "" case hp when "pcmcia", "cardbus" one["hotplug"] = "pcmcia" when "usb" one["hotplug"] = "usb" end # store the BUS type bus = card["bus_hwcfg"] || card["bus"] || "" if bus == "PCI" bus = "pci" elsif bus == "USB" bus = "usb" elsif bus == "Virtual IO" bus = "vio" end one["bus"] = bus one["busid"] = card["sysfs_bus_id"] || "" if one["busid"].start_with?("virtio") one["sub_device_busid"] = one["busid"] one["busid"] = one["sysfs_id"].split("/")[-2] end one["mac"] = Ops.get_string(resource, ["hwaddr", 0, "addr"], "") one["permanent_mac"] = Ops.get_string(resource, ["phwaddr", 0, "addr"], "") # is the cable plugged in? nil = don't know one["link"] = Ops.get(resource, ["link", 0, "state"]) # Wireless Card Features one["wl_channels"] = Ops.get(resource, ["wlan", 0, "channels"]) one["wl_bitrates"] = Ops.get(resource, ["wlan", 0, "bitrates"]) one["wl_auth_modes"] = Ops.get(resource, ["wlan", 0, "auth_modes"]) one["wl_enc_modes"] = Ops.get(resource, ["wlan", 0, "enc_modes"]) end if controller != "" && !filter_out(card, one["module"]) Builtins.y2debug("found device: %1", one) Ops.set(hardware, Builtins.size(hardware), one) num += 1 else Builtins.y2milestone("Filtering out: %1", card) end end # if there is wlan, put it to the front of the list # that's because we want it proposed and currently only one card # can be proposed found = false i = 0 Builtins.foreach(hardware) do |h| if h["type"] == "wlan" found = true raise Break end i += 1 end if found temp = hardware[0] || {} hardware[0] = hardware[i] hardware[i] = temp # adjust mapping: #98852, #102945 Ops.set(hardware, [0, "num"], 0) Ops.set(hardware, [i, "num"], i) end Builtins.y2debug("Hardware=%1", hardware) deep_copy(hardware) end |
#ReallyAbort ⇒ Object
If modified, ask for confirmation
72 73 74 |
# File 'src/include/network/routines.rb', line 72 def ReallyAbort Popup.ReallyAbort(true) end |
#ReallyAbortCond(modified) ⇒ Object
If modified, ask for confirmation
79 80 81 |
# File 'src/include/network/routines.rb', line 79 def ReallyAbortCond(modified) !modified || Popup.ReallyAbort(true) end |
#Run(command) ⇒ Object
Run an external command on the target machine and check if it was successful. Remember to always use a full path for the command and to quote the arguments. Using shellescape() is recommended.
567 568 569 570 571 572 573 574 575 576 |
# File 'src/include/network/routines.rb', line 567 def Run(command) if !command.lstrip.start_with?("/") log.warn("Command does not have an absolute path: #{command}") end ret = SCR.Execute(path(".target.bash"), command).zero? Builtins.y2error("Run <%1>: Command execution failed.", command) if !ret ret end |
#SetLinkUp(dev_name) ⇒ Object
Wrapper to call 'ip link set up' with the given interface
582 583 584 585 |
# File 'src/include/network/routines.rb', line 582 def SetLinkUp(dev_name) log.info("Setting link up for interface #{dev_name}") Run("/sbin/ip link set #{dev_name.shellescape} up") end |