Module: Yast::NetworkRoutinesInclude
- Includes:
- I18n, Logger, Yast
- Defined in:
- ../../src/include/network/routines.rb
Constant Summary
Constant Summary
Constants included from Yast
DNS, Host, InternetDevices, Lan, LanItems, LanUdevAuto, NetHwDetection, Network, NetworkStorage, Remote, Routing, SuSEFirewall4Network
Instance Method Summary (collapse)
-
- (Object) Abort
Abort function.
-
- (Object) BusyPopup(message)
Show busy popup (for proposal).
-
- (Object) BusyPopupClose
Close busy popup.
-
- (Object) ChangedComment(modul)
Create comment for changed file.
-
- (Object) ChangeWidgetIfExists(id, param, value)
Change UI widget only if it exists.
-
- (Object) ControllerType(hwdevice)
Simple convertor from subclass to controller type.
- - (Object) dev_name_to_sysfs_id(dev_name, hardware)
-
- (Object) DeviceName(hwdevice)
Extract the device 'name'.
-
- (Object) disable_unconfigureable_items(items, show_popup)
Disables all widgets which cannot be configured with current network service.
- - (Object) DistinguishedName(name, hwdevice)
-
- (Object) DriverType(type)
For s390 hwinfo gives us a multitude of types but some are handled the same, mostly acording to the driver which is used.
-
- (Object) FinishPopup(modified, head, text, run, params)
Display the finished popup and possibly run another module.
-
- (Array) GetAllInterfaces
Return list of all interfaces present in the system (not only configured ones as NetworkInterfaces::List does).
-
- (Object) getHardware(sysfs_id, hw)
map getcfg(string options, string device){ map cfg=$[]; map output = (map )SCR::Execute(.target.bash_output, sformat(“getcfg %1 %2”, options, device)); foreach(string row, splitstring(output:“”, “n”), { row=deletechars(row, “\”;“); list keyval=splitstring(row, ”=“); if (size(keyval)>1) cfg[keyval:”“]=keyval:”“; }); y2milestone(”%1 %2n%3“, options, device, cfg); return cfg; }.
-
- (boolean) has_carrier?(dev_name)
Checks if given device has carrier.
-
- (Object) hwlist2items(l, selected)
Create a list of items for UI from the given hardware list.
- - (Object) initialize_network_routines(_include_target)
-
- (Object) IsEmpty(value)
Checks if given value is emtpy.
-
- (Object) IsNotEmpty(value)
Checks if given value is non emtpy.
-
- (Object) list2items(l, selected)
Create a list of items for UI from the given list.
- - (Object) needHwcfg(hw)
-
- (Object) PackagesInstall(packages)
Check if required packages are installed and install them if they're not.
-
- (boolean) phy_connected?(dev_name)
Checks if device is physically connected to a network.
-
- (Object) PollAbort
Check for pending Abort press.
-
- (Object) ProgressNextStage(title)
Progress::NextStage and Progress::Title combined into one function.
-
- (Object) QueryWidgetIfExists(id, param, value)
Query UI widget only if it exists.
-
- (Object) ReadHardware(hwtype)
Read HW information.
-
- (Object) ReallyAbort
If modified, ask for confirmation.
-
- (Object) ReallyAbortCond(modified)
If modified, ask for confirmation.
-
- (Object) Run(command)
Whether command execution succeeds.
-
- (Object) RunAndRead(command)
Hash in form $[ “exit”: , “output”: [ , , … ] ].
- - (Object) s390_device_needs_persistent_mac(sysfs_id, hardware)
-
- (boolean) SetAllLinksDown
Tries to set all available interfaces down.
-
- (boolean) SetAllLinksUp
Tries to set all available interfaces up.
- - (Object) SetLinkDown(dev_name)
- - (Object) SetLinkUp(dev_name)
- - (Object) sysfs_card_type(sysfs_id, _hardware)
- - (Boolean) unconfigureable_service?
-
- (Object) UsedNicName(name)
Checks if device with the given name is configured already.
-
- (Object) ValidNicName(name)
Validates given name for use as a nic name in sysconfig.
- - (Object) validPrefixOrNetmask(ip, mask)
Instance Method Details
- (Object) Abort
Abort function
59 60 61 62 63 |
# File '../../src/include/network/routines.rb', line 59 def Abort return false if Mode.commandline UI.PollInput == :abort end |
- (Object) BusyPopup(message)
Show busy popup (for proposal)
195 196 197 198 199 200 |
# File '../../src/include/network/routines.rb', line 195 def BusyPopup() UI.BusyCursor UI.OpenDialog(VBox(Label())) nil end |
- (Object) BusyPopupClose
Close busy popup
204 205 206 207 208 |
# File '../../src/include/network/routines.rb', line 204 def BusyPopupClose UI.CloseDialog nil end |
- (Object) ChangedComment(modul)
Create comment for changed file
180 181 182 183 184 185 186 187 188 189 190 191 |
# File '../../src/include/network/routines.rb', line 180 def ChangedComment(modul) ret = "\n# Changed by YaST2" if !modul.nil? && modul != "" ret = Ops.add(Ops.add(ret, " module "), modul) end out = Convert.to_map( SCR.Execute(path(".target.bash_output"), "/bin/date '+%x'") ) date = Ops.get_string(out, "stdout", "") ret = Ops.add(Ops.add(ret, " "), date) if date != "" ret end |
- (Object) ChangeWidgetIfExists(id, param, value)
Change UI widget only if it exists
97 98 99 100 101 102 103 104 105 106 107 |
# File '../../src/include/network/routines.rb', line 97 def ChangeWidgetIfExists(id, param, value) id = deep_copy(id) value = deep_copy(value) if UI.WidgetExists(id) UI.ChangeWidget(id, param, value) else Builtins.y2debug("Not changing: %1", id) end nil end |
- (Object) ControllerType(hwdevice)
Simple convertor from subclass to controller type.
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 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
# File '../../src/include/network/routines.rb', line 506 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 if subclass_id == 0 return "eth" elsif subclass_id == 1 return "tr" elsif subclass_id == 2 return "fddi" elsif subclass_id == 3 return "atm" elsif subclass_id == 4 return "isdn" elsif subclass_id == 6 return "ib" elsif subclass_id == 129 return "myri" elsif subclass_id == 130 return "wlan" elsif subclass_id == 131 return "xp" elsif subclass_id == 134 return "qeth" elsif subclass_id == 135 return "hsi" elsif subclass_id == 136 return "ctc" elsif subclass_id == 137 return "lcs" elsif subclass_id == 142 return "ficon" elsif subclass_id == 143 return "escon" elsif subclass_id == 144 return "iucv" elsif subclass_id == 145 return "usb" # #22739 elsif subclass_id == 128 # 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 if subclass_id == 3 return "modem" elsif subclass_id == 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 if subclass_id == 0 return "lo" elsif subclass_id == 1 return "eth" elsif subclass_id == 2 return "tr" elsif subclass_id == 3 return "fddi" elsif subclass_id == 4 return "ctc" elsif subclass_id == 5 return "iucv" elsif subclass_id == 6 return "hsi" elsif subclass_id == 7 return "qeth" elsif subclass_id == 8 return "escon" elsif subclass_id == 9 return "myri" elsif subclass_id == 10 return "wlan" elsif subclass_id == 11 return "xp" elsif subclass_id == 12 return "usb" elsif subclass_id == 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 "" elsif subclass_id == 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 |
- (Object) dev_name_to_sysfs_id(dev_name, hardware)
386 387 388 389 390 391 392 393 |
# File '../../src/include/network/routines.rb', line 386 def dev_name_to_sysfs_id(dev_name, hardware) hardware = deep_copy(hardware) # hardware is cached list of netcards hw_item = Builtins.find(hardware) do |i| Ops.get_string(i, "dev_name", "") == dev_name end Ops.get_string(hw_item, "sysfs_id", "") end |
- (Object) DeviceName(hwdevice)
Extract the device 'name'
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 |
# File '../../src/include/network/routines.rb', line 463 def DeviceName(hwdevice) hwdevice = deep_copy(hwdevice) delimiter = " " # "\n"; #FIXME: constant if IsNotEmpty(Ops.get_string(hwdevice, "device", "")) return Ops.get_string(hwdevice, "device", "") end model = Ops.get_string(hwdevice, "model", "") return model if model != "" && !model.nil? vendor = Ops.get_string(hwdevice, "sub_vendor", "") dev = Ops.get_string(hwdevice, "sub_device", "") if vendor == "" || dev == "" vendor = Ops.get_string(hwdevice, "vendor", "") dev = Ops.get_string(hwdevice, "device", "") end if vendor != "" return Ops.add(Ops.add(vendor, delimiter), dev) else return dev end end |
- (Object) disable_unconfigureable_items(items, show_popup)
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
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 |
# File '../../src/include/network/routines.rb', line 997 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 |
- (Object) DistinguishedName(name, hwdevice)
448 449 450 451 452 453 454 455 456 457 458 |
# File '../../src/include/network/routines.rb', line 448 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 |
- (Object) DriverType(type)
For s390 hwinfo gives us a multitude of types but some are handled the same, mostly acording to the driver which is used. So let's group them under the name Driver Type.
345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File '../../src/include/network/routines.rb', line 345 def DriverType(type) drvtype = type # handle HSI like qeth, S#40692#c15 if type == "hsi" drvtype = "qeth" # Should eth occur on s390? elsif type == "tr" || type == "eth" drvtype = "lcs" # N#82891 elsif type == "escon" || type == "ficon" drvtype = "ctc" end drvtype end |
- (Object) FinishPopup(modified, head, text, run, params)
Display the finished popup and possibly run another module. If not modified, don't do anything.
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 |
# File '../../src/include/network/routines.rb', line 272 def FinishPopup(modified, head, text, run, params) params = deep_copy(params) return :next if !modified h = head if h.nil? || h == "" # Popup headline h = _("Configuration Successfully Saved") end heads = { # Popup headline "dns" => _("DNS Configuration Successfully Saved"), # Popup headline "dsl" => _("DSL Configuration Successfully Saved"), # Popup headline "host" => _( "Hosts Configuration Successfully Saved" ), # Popup headline "isdn" => _( "ISDN Configuration Successfully Saved" ), # Popup headline "lan" => _( "Network Card Configuration Successfully Saved" ), # Popup headline "modem" => _( "Modem Configuration Successfully Saved" ), # Popup headline "proxy" => _( "Proxy Configuration Successfully Saved" ), # Popup headline "provider" => _( "Provider Configuration Successfully Saved" ), # Popup headline "routing" => _( "Routing Configuration Successfully Saved" ) } h = Ops.get_string(heads, head, h) t = text texts = { # Popup text "mail" => _("Configure mail now?") } t = Ops.get_string(texts, run, text) if t == "" if t == "" # Popup text t = Builtins.sformat(_("Run configuration of %1?"), run) end if run != "" ret = Popup.YesNoHeadline(h, t) # FIXME: check for the module presence Call.Function(run, params) if ret == true else Popup.AnyMessage(h, t) end :next end |
- (Array) GetAllInterfaces
Return list of all interfaces present in the system (not only configured ones as NetworkInterfaces::List does).
894 895 896 897 898 899 900 901 902 |
# File '../../src/include/network/routines.rb', line 894 def GetAllInterfaces result = RunAndRead("ls /sys/class/net") if Ops.get_boolean(result, "exit", false) Ops.get_list(result, "output", []) else [] end end |
- (Object) getHardware(sysfs_id, hw)
map<string, any> getcfg(string options, string device){ map <string, any> cfg=$[]; map <string, any> output = (map <string, any>)SCR::Execute(.target.bash_output, sformat(“getcfg %1 %2”, options, device)); foreach(string row, splitstring(output:“”, “n”), { row=deletechars(row, “\”;“); list<string> keyval=splitstring(row, ”=“); if (size(keyval)>1) cfg[keyval:”“]=keyval:”“;
}); y2milestone(“%1 %2n%3”, options, device, cfg); return cfg; }
437 438 439 440 441 442 443 444 445 446 |
# File '../../src/include/network/routines.rb', line 437 def getHardware(sysfs_id, hw) hardware = {} Builtins.foreach(hw) do |hw_temp| if sysfs_id == Builtins.sformat("/sys%1", Ops.get_string(hw_temp, "sysfs_id", "")) hardware = deep_copy(hw_temp) end end deep_copy(hardware) end |
- (boolean) has_carrier?(dev_name)
Checks if given device has carrier
939 940 941 942 943 944 |
# File '../../src/include/network/routines.rb', line 939 def has_carrier?(dev_name) SCR.Read( path(".target.string"), "/sys/class/net/#{dev_name}/carrier" ).to_i != 0 end |
- (Object) hwlist2items(l, selected)
Create a list of items for UI from the given hardware list.
This list is used when selecting <ol> <li> detected unconfigured cards, there we want to see the link status </li> <li> undetected cards manually. there is no link status there and it won't be displayed. all is ok. </li> </ol>
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File '../../src/include/network/routines.rb', line 249 def hwlist2items(l, selected) l = deep_copy(l) items = [] n = 0 Builtins.foreach(l) do |i| # Table field (Unknown device) hwname = Ops.get_locale(i, "name", _("Unknown")) num = Ops.get_integer(i, "num", n) # num for detected, n for manual items = Builtins.add(items, Item(Id(num), hwname, num == selected)) n = Ops.add(n, 1) end deep_copy(items) # return list2items(maplist(map h, l, { return h["name"]:_("Unknown Device"); }), selected); end |
- (Object) initialize_network_routines(_include_target)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File '../../src/include/network/routines.rb', line 35 def initialize_network_routines(_include_target) Yast.import "UI" textdomain "network" Yast.import "Call" Yast.import "Popup" Yast.import "Progress" Yast.import "String" Yast.import "NetworkService" Yast.import "PackageSystem" Yast.import "NetworkInterfaces" Yast.import "Arch" Yast.import "Confirm" Yast.import "Map" Yast.import "Netmask" Yast.import "Mode" Yast.import "IP" Yast.import "TypeRepository" Yast.import "Stage" end |
- (Object) IsEmpty(value)
Checks if given value is emtpy.
211 212 213 214 |
# File '../../src/include/network/routines.rb', line 211 def IsEmpty(value) value = deep_copy(value) TypeRepository.IsEmpty(value) end |
- (Object) IsNotEmpty(value)
Checks if given value is non emtpy.
217 218 219 220 |
# File '../../src/include/network/routines.rb', line 217 def IsNotEmpty(value) value = deep_copy(value) !IsEmpty(value) end |
- (Object) list2items(l, selected)
Create a list of items for UI from the given list
227 228 229 230 231 232 233 234 235 236 |
# File '../../src/include/network/routines.rb', line 227 def list2items(l, selected) l = deep_copy(l) items = [] n = 0 Builtins.foreach(l) do |i| items = Builtins.add(items, Item(Id(n), i, n == selected)) n = Ops.add(n, 1) end deep_copy(items) end |
- (Object) needHwcfg(hw)
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 |
# File '../../src/include/network/routines.rb', line 360 def needHwcfg(hw) hw = deep_copy(hw) need = true # if kernel will autoload module for device if IsNotEmpty(Ops.get_string(hw, "modalias", "")) if Ops.greater_than(Builtins.size(Ops.get_list(hw, "drivers", [])), 1) Builtins.y2milestone( "there are more modules available for device, hwcfg is needed" ) else Builtins.y2milestone( "Just one autoloadable module available.No need to write hwcfg" ) need = false end # not autoload because of built-in driver (compiled in kernel) elsif IsEmpty(Ops.get_string(hw, "driver_module", "")) Builtins.y2milestone( "built-in driver %1", Ops.get_string(hw, "driver", "") ) need = false end need end |
- (Object) PackagesInstall(packages)
Check if required packages are installed and install them if they're not
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File '../../src/include/network/routines.rb', line 125 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 |
- (boolean) phy_connected?(dev_name)
Checks if device is physically connected to a network
It does neccessary steps which might be needed for proper initialization of devices driver.
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 |
# File '../../src/include/network/routines.rb', line 952 def phy_connected?(dev_name) return true if has_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) has_carrier?(dev_name) end |
- (Object) PollAbort
Check for pending Abort press
67 68 69 |
# File '../../src/include/network/routines.rb', line 67 def PollAbort UI.PollInput == :abort end |
- (Object) ProgressNextStage(title)
Progress::NextStage and Progress::Title combined into one function
86 87 88 89 90 91 |
# File '../../src/include/network/routines.rb', line 86 def ProgressNextStage(title) Progress.NextStage Progress.Title(title) nil end |
- (Object) QueryWidgetIfExists(id, param, value)
Query UI widget only if it exists
114 115 116 117 118 119 120 |
# File '../../src/include/network/routines.rb', line 114 def QueryWidgetIfExists(id, param, value) id = deep_copy(id) value = deep_copy(value) return UI.QueryWidget(id, param) if UI.WidgetExists(id) Builtins.y2debug("Not changing: %1", id) deep_copy(value) end |
- (Object) ReadHardware(hwtype)
Read HW information
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 |
# File '../../src/include/network/routines.rb', line 649 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]) if brk Builtins.y2milestone("In BrokenModules, skipping: %1", module0) end !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"] || "" if hp == "pcmcia" || hp == "cardbus" one["hotplug"] = "pcmcia" elsif hp == "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"] || "" one["mac"] = Ops.get_string(resource, ["hwaddr", 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 |
- (Object) ReallyAbort
If modified, ask for confirmation
73 74 75 |
# File '../../src/include/network/routines.rb', line 73 def ReallyAbort Popup.ReallyAbort(true) end |
- (Object) ReallyAbortCond(modified)
If modified, ask for confirmation
80 81 82 |
# File '../../src/include/network/routines.rb', line 80 def ReallyAbortCond(modified) !modified || Popup.ReallyAbort(true) end |
- (Object) Run(command)
Returns whether command execution succeeds
882 883 884 885 886 887 888 |
# File '../../src/include/network/routines.rb', line 882 def Run(command) ret = SCR.Execute(path(".target.bash"), command) == 0 Builtins.y2error("Run <%1>: Command execution failed.", command) if !ret ret end |
- (Object) RunAndRead(command)
Returns Hash in form $[ “exit”: <command-exit-status>, “output”: [ <1st line>, <2nd line>, … ] ]
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
# File '../../src/include/network/routines.rb', line 852 def RunAndRead(command) ret = { "exit" => false, "output" => [] } result = Convert.to_map(SCR.Execute(path(".target.bash_output"), command)) output = Ops.get_string(result, "stdout", "") if Builtins.regexpmatch(output, ".*\n$") output = Builtins.substring( output, 0, Ops.subtract(Builtins.size(output), 1) ) end Ops.set(ret, "output", Builtins.splitstring(output, "\n")) Ops.set(ret, "exit", Ops.get_integer(result, "exit", 1) == 0) if Ops.get_boolean(ret, "exit", false) == false || IsEmpty(Ops.get_string(result, "stderr", "")) == false Builtins.y2error( "RunAndRead <%1>: Command execution failed.\n%2", command, Ops.get_string(result, "stderr", "") ) end deep_copy(ret) end |
- (Object) s390_device_needs_persistent_mac(sysfs_id, hardware)
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File '../../src/include/network/routines.rb', line 402 def s390_device_needs_persistent_mac(sysfs_id, hardware) hardware = deep_copy(hardware) card_type = sysfs_card_type(sysfs_id, hardware) types_needing_persistent = [ "OSD_100", "OSD_1000", "OSD_10GIG", "OSD_FE_LANE", "OSD_GbE_LANE", "OSD_Express" ] needs_persistent = Builtins.contains(types_needing_persistent, card_type) Builtins.y2milestone( "Sysfs Device: %1, card type: %2, needs persistent MAC: %3", sysfs_id, card_type, needs_persistent ) needs_persistent end |
- (boolean) SetAllLinksDown
Tries to set all available interfaces down
928 929 930 931 932 933 934 |
# File '../../src/include/network/routines.rb', line 928 def SetAllLinksDown interfaces = GetAllInterfaces() return false if interfaces.empty? interfaces.all? { |i| SetLinkDown(i) } end |
- (boolean) SetAllLinksUp
Tries to set all available interfaces up
917 918 919 920 921 922 923 |
# File '../../src/include/network/routines.rb', line 917 def SetAllLinksUp interfaces = GetAllInterfaces() return false if interfaces.empty? interfaces.all? { |i| SetLinkUp(i) } end |
- (Object) SetLinkDown(dev_name)
909 910 911 912 |
# File '../../src/include/network/routines.rb', line 909 def SetLinkDown(dev_name) log.info("Setting link down for interface #{dev_name}") Run("ip link set #{dev_name} down") end |
- (Object) SetLinkUp(dev_name)
904 905 906 907 |
# File '../../src/include/network/routines.rb', line 904 def SetLinkUp(dev_name) log.info("Setting link up for interface #{dev_name}") Run("ip link set #{dev_name} up") end |
- (Object) sysfs_card_type(sysfs_id, _hardware)
395 396 397 398 399 400 |
# File '../../src/include/network/routines.rb', line 395 def sysfs_card_type(sysfs_id, _hardware) return "none" if sysfs_id == "" filename = Ops.add(Ops.add("/sys", sysfs_id), "/card_type") card_type = Convert.to_string(SCR.Read(path(".target.string"), filename)) String.FirstChunk(card_type, "\n") end |
- (Boolean) unconfigureable_service?
984 985 986 987 988 989 |
# File '../../src/include/network/routines.rb', line 984 def unconfigureable_service? return true if Mode.normal && NetworkService.is_network_manager return true if NetworkService.is_disabled false end |
- (Object) UsedNicName(name)
Checks if device with the given name is configured already.
498 499 500 |
# File '../../src/include/network/routines.rb', line 498 def UsedNicName(name) Builtins.contains(NetworkInterfaces.List(""), name) end |
- (Object) ValidNicName(name)
Validates given name for use as a nic name in sysconfig. See bnc#784952
490 491 492 493 494 495 |
# File '../../src/include/network/routines.rb', line 490 def ValidNicName(name) # 16 is the kernel limit on interface name size (IFNAMSIZ) return false if !Builtins.regexpmatch(name, "^[[:alnum:]._:-]{1,15}$") true end |
- (Object) validPrefixOrNetmask(ip, mask)
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
# File '../../src/include/network/routines.rb', line 968 def validPrefixOrNetmask(ip, mask) valid_mask = false if Builtins.substring(mask, 0, 1) == "/" mask = Builtins.substring(mask, 1) end if IP.Check4(ip) && (Netmask.Check4(mask) || Netmask.CheckPrefix4(mask)) valid_mask = true elsif IP.Check6(ip) && Netmask.Check6(mask) valid_mask = true else Builtins.y2warning("IP address %1 is not valid", ip) end valid_mask end |