Module: Yast::NetworkComplexInclude
- Defined in:
- ../../src/include/network/complex.rb
Instance Method Summary (collapse)
-
- (Object) BuildDescription(devtype, devnum, devmap, hardware)
Used for initializing the description variable (ifcfg) The code is mostly moved from BuildSummaryDevs Take the NAME field from ifcfg If empty, identify the hardware and use its data.
-
- (configured, unconfigured) BuildSummary(devregex, hardware, split, link)
Build textual summary.
-
- (configured, unconfigured) BuildSummaryDevs(devs, hardware, split, link)
Build textual summary.
- - (Object) CheckEmptyName(devtype, hwname)
-
- (Object) DeviceProtocol(devmap)
Return the device protocol or IP address in case of static config Or indicate that NetworkManager takes over.
- - (Object) DeviceStatus(devtype, devname, devmap)
- - (Object) HardwareName(hardware, id)
-
- (Object) Hyperlink(href, text)
TODO: move to HTML.ycp.
- - (Object) initialize_network_complex(include_target)
-
- (Object) ProviderName(provider)
Get aprovider name from the provider map.
Instance Method Details
- (Object) BuildDescription(devtype, devnum, devmap, hardware)
Used for initializing the description variable (ifcfg) The code is mostly moved from BuildSummaryDevs Take the NAME field from ifcfg If empty, identify the hardware and use its data
52 53 54 55 56 57 58 59 60 61 |
# File '../../src/include/network/complex.rb', line 52 def BuildDescription(devtype, devnum, devmap, hardware) descr = devmap["NAME"] || "" return descr if descr != "" descr = HardwareName(hardware, devnum) return descr if descr != "" descr = HardwareName(hardware, devmap["UNIQUE"] || "") return descr if descr != "" CheckEmptyName(devtype, descr) end |
- (configured, unconfigured) BuildSummary(devregex, hardware, split, link)
Build textual summary
190 191 192 193 194 195 |
# File '../../src/include/network/complex.rb', line 190 def BuildSummary(devregex, hardware, split, link) hardware = deep_copy(hardware) devs = NetworkInterfaces.FilterDevices(devregex) ret = BuildSummaryDevs(devs, hardware, split, link) deep_copy(ret) end |
- (configured, unconfigured) BuildSummaryDevs(devs, hardware, split, link)
Build textual summary
72 73 74 75 76 77 78 79 80 81 82 83 84 85 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 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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File '../../src/include/network/complex.rb', line 72 def BuildSummaryDevs(devs, hardware, split, link) devs = deep_copy(devs) hardware = deep_copy(hardware) Builtins.y2milestone("Devs=%1", NetworkInterfaces.ConcealSecrets(devs)) Builtins.y2milestone("Hardware=%1", hardware) Builtins.y2debug("split=%1", split) uniques = [] uniques_old = [] configured = [] unconfigured = [] links = [] # build a list of configured devices Builtins.maplist(devs) do |devtype, devsmap| Builtins.maplist( Convert.convert(devsmap, from: "map", to: "map <string, map>") ) do |devname, devmap| # main device summary descr = BuildDescription(devtype, devname, devmap, hardware) unq = Ops.get_string(devmap, "UNIQUE", "") status = DeviceStatus(devtype, devname, devmap) if link if devtype == "wlan" && Ops.get_string(devmap, "WIRELESS_AUTH_MODE", "") == "open" && Ops.get_string(devmap, "WIRELESS_KEY_0", "") == "" href = Ops.add("lan--wifi-encryption-", devname) # interface summary: WiFi without encryption warning = HTML.Colorize( _("Warning: no encryption is used."), "red" ) status = Ops.add( Ops.add(Ops.add(Ops.add(status, " "), warning), " "), # Hyperlink: Change the configuration of an interface Hyperlink(href, _("Change.")) ) links = Builtins.add(links, href) end end configured = Builtins.add(configured, Summary.Device(descr, status)) uniques = Builtins.add(uniques, devname) uniques_old = Builtins.add(uniques_old, unq) # aliases summary aliasee = Ops.get_map(devmap, "_aliases", {}) Builtins.maplist(aliasee) do |_aid, amap| # Table item # this is what used to be Virtual Interface # (eth0:1) descr = _("Additional Address") status = DeviceStatus(devtype, devname, amap) configured = Builtins.add(configured, Summary.Device(descr, status)) end if aliasee != {} end end Builtins.y2debug("uniques(%1)", uniques) Builtins.y2debug("uniques_old(%1)", uniques_old) # build a list of unconfigured devices id = 0 Builtins.maplist(hardware) do |h| unq = Ops.get_string(h, "unique", "") busid = Ops.add( Ops.add(Ops.add("bus-", Ops.get_string(h, "bus", "")), "-"), Ops.get_string(h, "busid", "") ) mac = Ops.add("id-", Ops.get_string(h, "mac", "")) hwtype = Ops.get_string(h, "type", "") hwname = CheckEmptyName(hwtype, Ops.get_string(h, "name", "")) Builtins.y2debug("busid=%1, mac=%2", busid, mac) if !Builtins.contains(uniques, busid) && !Builtins.contains(uniques, mac) && !Builtins.contains(uniques_old, unq) if split && !Builtins.contains(uniques_old, unq) Ops.set(h, "id", id) unconfigured = Builtins.add(unconfigured, h) else configured = Builtins.add( configured, Summary.Device(hwname, Summary.NotConfigured) ) end end id = Ops.add(id, 1) end Builtins.y2debug("configured=%1", configured) Builtins.y2debug("unconfigured=%1", unconfigured) # create a summary text summary = Summary.DevicesList(configured) # if not split -> summary is finished return [summary, links] if !split # add headers if Ops.greater_than(Builtins.size(configured), 0) # Summary text summary = Ops.add( Summary.AddHeader("", _("Already Configured Devices:")), summary ) else # Summary text summary = Summary.AddHeader("", _("Nothing is configured")) end # FIXME: OtherDevices(devs, type); Builtins.y2debug("summary=%1", summary) [summary, unconfigured] end |
- (Object) CheckEmptyName(devtype, hwname)
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 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 |
# File '../../src/include/network/complex.rb', line 197 def CheckEmptyName(devtype, hwname) return hwname if !hwname.nil? && hwname != "" device_names = { # Device type label "contr-pcmcia" => _("PCMCIA ISDN Card"), # Device type label "contr-usb" => _("USB ISDN Card"), # Device type label "eth-pcmcia" => _("PCMCIA Ethernet Network Card"), # Device type label "eth-usb" => _("USB Ethernet Network Card"), # Device type label "fddi-pcmcia" => _("PCMCIA FDDI Network Card"), # Device type label "fddi-usb" => _("USB FDDI Network Card"), # Device type label "ippp-pcmcia" => _("PCMCIA ISDN Connection"), # Device type label "ippp-usb" => _("USB ISDN Connection"), # Device type label "isdn-pcmcia" => _("PCMCIA ISDN Connection"), # Device type label "isdn-usb" => _("USB ISDN Connection"), # Device type label "modem-pcmcia" => _("PCMCIA Modem"), # Device type label "modem-usb" => _("USB Modem"), # Device type label "ppp-pcmcia" => _("PCMCIA Modem"), # Device type label "ppp-usb" => _("USB Modem"), # Device type label "tr-pcmcia" => _( "PCMCIA Token Ring Network Card" ), # Device type label "tr-usb" => _("USB Token Ring Network Card"), # Device type label "usb-usb" => _("USB Network Device"), # Device type label "wlan-pcmcia" => _("PCMCIA Wireless Network Card"), # Device type label "wlan-usb" => _("USB Wireless Network Card") } if Builtins.haskey(device_names, devtype) return Ops.get_string(device_names, devtype, "") else descr = NetworkInterfaces.GetDevTypeDescription(devtype, true) return descr if IsNotEmpty(descr) end if Builtins.haskey(device_names, Ops.add(devtype, "-")) Builtins.y2warning("- device found: %1, %2", devtype, hwname) return Ops.get_string(device_names, Ops.add(devtype, "-"), "") end Builtins.y2error("Unknown type: %1", devtype) # Device type label _("Unknown Network Device") end |
- (Object) DeviceProtocol(devmap)
Return the device protocol or IP address in case of static config Or indicate that NetworkManager takes over.
415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File '../../src/include/network/complex.rb', line 415 def DeviceProtocol(devmap) devmap = deep_copy(devmap) if Ops.get_string(devmap, "STARTMODE", "") == "managed" # Abbreviation for "The interface is Managed by NetworkManager" return _("Managed") end ip = Ops.get_string(devmap, "BOOTPROTO", "static") if ip.nil? || ip == "" || ip == "static" ip = Ops.get_string(devmap, "IPADDR", "") else ip = Builtins.toupper(ip) end ip end |
- (Object) DeviceStatus(devtype, devname, devmap)
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 |
# File '../../src/include/network/complex.rb', line 304 def DeviceStatus(devtype, devname, devmap) devmap = deep_copy(devmap) # Modem and DSL if devtype == "ppp" || devtype == "modem" || devtype == "dsl" nam = ProviderName(Ops.get_string(devmap, "PROVIDER", "")) if nam == "" || nam.nil? # Modem status (%1 is device) return Builtins.sformat(_("Configured as %1"), devname) else # Modem status (%1 is device, %2 is provider) return Builtins.sformat( _("Configured as %1 with provider %2"), devname, nam ) end # ISDN card elsif devtype == "isdn" || devtype == "contr" # ISDN device status (%1 is device) return Builtins.sformat(_("Configured as %1"), devname) # ISDN stuff elsif devtype == "net" nam = ProviderName(Ops.get_string(devmap, "PROVIDER", "")) # Connection protocol (syncppp|rawip) proto = Ops.get_string(devmap, "PROTOCOL", "") # ISDN status (%1 is device, %2 is provider, %3 protocol) return Builtins.sformat( _("Configured as %1 with provider %2 (protocol %3)"), devname, nam, proto ) else proto = Ops.get_string(devmap, "BOOTPROTO", "static") if proto == "" || proto == "static" || proto == "none" || proto.nil? addr = Ops.get_string(devmap, "IPADDR", "") host = NetHwDetection.ResolveIP(addr) remip = Ops.get_string(devmap, "REMOTE_IPADDR", "") if proto == "none" return _("Configured without address (NONE)").dup elsif IsEmpty(addr) # Network card status return HTML.Colorize(_("Configured without an address"), "red") elsif remip == "" || remip.nil? # Network card status (%1 is address) return Builtins.sformat( _("Configured with address %1"), Ops.add(addr, String.OptParens(host)) ) else # Network card status (%1 is address, %2 is address) return Builtins.sformat( _("Configured with address %1 (remote %2)"), addr, remip ) end else # Network card status (%1 is protocol) return Builtins.sformat( _("Configured with %1"), Builtins.toupper(proto) ) end # This is the old version of the above code, including the # configuration name. But the name is long and cryptic so wen # don't use it. # FIXME: dropped interface name if proto == "" || proto == "static" || proto == "none" || proto.nil? addr = Ops.get_string(devmap, "IPADDR", "") remip = Ops.get_string(devmap, "REMOTE_IPADDR", "") if addr == "" || addr.nil? # Network card status (%1 is device) return Builtins.sformat(_("Configured as %1"), devname) elsif remip == "" || remip.nil? # Network card status (%1 is device, %2 is address) return Builtins.sformat( _("Configured as %1 with address %2"), devname, addr ) else # Network card status (%1 is device, %2 is address, %3 is address) return Builtins.sformat( _("Configured as %1 with address %2 (remote %3)"), devname, addr, remip ) end else # Network card status (%1 is device, %2 is protocol) return Builtins.sformat( _("Configured as %1 with %2"), devname, Builtins.toupper(proto) ) end end end |
- (Object) HardwareName(hardware, id)
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 |
# File '../../src/include/network/complex.rb', line 260 def HardwareName(hardware, id) return "" if id.nil? || id.empty? return "" if hardware.nil? || hardware.empty? # filter out a list of hwinfos which correspond to the given id res_list = hardware.select do |h| have = [ "id-" + (h["mac"] || ""), "bus-" + (h["bus"] || "") + "-" + (h["busid"] || ""), h["udi"] || "", h["dev_name"] || "" ] have.include?(id) end # take first item from the list - there should be just one if res_list.empty? Builtins.y2warning("HardwareName: no matching hardware for id=#{id}") return "" else hwname = res_list.first["name"] || "" Builtins.y2milestone("HardwareName: hwname=#{hwname} for id=#{id}") return hwname end end |
- (Object) Hyperlink(href, text)
TODO: move to HTML.ycp
64 65 66 |
# File '../../src/include/network/complex.rb', line 64 def Hyperlink(href, text) Builtins.sformat("<a href=\"%1\">%2</a>", href, text) end |
- (Object) initialize_network_complex(include_target)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File '../../src/include/network/complex.rb', line 32 def initialize_network_complex(include_target) Yast.import "UI" textdomain "network" Yast.import "NetHwDetection" Yast.import "HTML" Yast.import "NetworkInterfaces" Yast.import "Popup" Yast.import "String" Yast.import "Summary" Yast.include include_target, "network/routines.rb" Yast.include include_target, "network/summary.rb" end |
- (Object) ProviderName(provider)
Get aprovider name from the provider map
293 294 295 296 297 298 299 300 301 302 |
# File '../../src/include/network/complex.rb', line 293 def ProviderName(provider) Yast.import "Provider" return "" if provider.nil? || provider == "" Provider.Select(provider) nam = Ops.get_string(Provider.Current, "PROVIDER", provider) return provider if nam.nil? || nam == "" nam end |