Module: Yast::NetworkComplexInclude

Defined in:
src/include/network/complex.rb

Instance Method Summary collapse

Instance Method Details

#BuildDescription(devtype, devnum, devmap, hardware) ⇒ Object

Used for initializing the description variable (ifcfg[NAME]) The code is mostly moved from BuildSummaryDevs Take the NAME field from ifcfg If empty, identify the hardware and use its data


51
52
53
54
55
56
57
58
59
60
# File 'src/include/network/complex.rb', line 51

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

#CheckEmptyName(devtype, hwname) ⇒ Object


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
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
# File 'src/include/network/complex.rb', line 67

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")
  }

  return Ops.get_string(device_names, devtype, "") if Builtins.haskey(device_names, devtype)

  descr = NetworkInterfaces.GetDevTypeDescription(devtype, true)
  return descr if IsNotEmpty(descr)

  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

#DeviceProtocol(devmap) ⇒ Object

Return the device protocol or IP address in case of static config Or indicate that NetworkManager takes over.


273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'src/include/network/complex.rb', line 273

def DeviceProtocol(devmap)
  return _("Not configured") if devmap.nil? || devmap.empty?
  # Abbreviation for "The interface is Managed by NetworkManager"
  return _("Managed") if devmap["STARTMODE"] == "managed"

  bootproto = devmap["BOOTPROTO"] || "static"

  if bootproto.empty? || bootproto == "static"
    return "NONE" if devmap["IPADDR"] == "0.0.0.0"

    devmap["IPADDR"].to_s
  else
    bootproto.upcase
  end
end

#DeviceStatus(devtype, devname, devmap) ⇒ Object


172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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
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
# File 'src/include/network/complex.rb', line 172

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", ""))

    # Modem status (%1 is device)
    return Builtins.sformat(_("Configured as %1"), devname) if nam == "" || nam.nil?

    # Modem status (%1 is device, %2 is provider)
    return Builtins.sformat(
      _("Configured as %1 with provider %2"),
      devname,
      nam
    )
  # 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", "")
      return _("Configured without address (NONE)").dup if proto == "none"
      # Network card status
      return HTML.Colorize(_("Configured without an address"), "red") if IsEmpty(addr)
      if remip == "" || remip.nil?
        # Network card status (%1 is address)
        return Builtins.sformat(_("Configured with address %1"),
          Ops.add(addr, String.OptParens(host)))
      end

      # Network card status (%1 is address, %2 is address)
      return Builtins.sformat(
        _("Configured with address %1 (remote %2)"),
        addr,
        remip
      )
    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", "")
      # Network card status (%1 is device)
      return Builtins.sformat(_("Configured as %1"), devname) if addr == "" || addr.nil?

      if remip == "" || remip.nil?
        # Network card status (%1 is device, %2 is address)
        return Builtins.sformat(_("Configured as %1 with address %2"), devname, addr)
      end

      # 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

    # Network card status (%1 is device, %2 is protocol)
    return Builtins.sformat(
      _("Configured as %1 with %2"),
      devname,
      Builtins.toupper(proto)
    )
  end
end

#HardwareName(hardware, id) ⇒ Object


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
# File 'src/include/network/complex.rb', line 128

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

TODO: move to HTML.ycp


63
64
65
# File 'src/include/network/complex.rb', line 63

def Hyperlink(href, text)
  Builtins.sformat("<a href=\"%1\">%2</a>", href, text)
end

#initialize_network_complex(include_target) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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"
end

#ProviderName(provider) ⇒ Object

Get aprovider name from the provider map

Examples:

ProviderName("tonline") -> "T-Online"



161
162
163
164
165
166
167
168
169
170
# File 'src/include/network/complex.rb', line 161

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