Class: Y2Network::AutoinstProfile::InterfaceSection

Inherits:
Installation::AutoinstProfile::SectionWithAttributes
  • Object
show all
Defined in:
src/lib/y2network/autoinst_profile/interface_section.rb

Overview

This class represents an AutoYaST section under

static 127.255.255.255 lo 02:02:02:02:02:02 no 127.0.0.1 255.0.0.0 127.0.0.0 8 nfsroot no

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ InterfaceSection

Returns a new instance of InterfaceSection.



251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 251

def initialize(*_args)
  super

  # TODO: Initializing all the attributes to an empty string makes
  # hard to know whether the value was defined or not at all. We probably
  # should ommit this initialization
  self.class.attributes.each do |attr|
    # init everything to empty string
    public_send(:"#{attr[:name]}=", "")
  end

  self.aliases = []
end

Instance Attribute Details

#aliasesArray<AliasSection>

Returns list of IP aliases.

Returns:



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 171

#bonding_masterString

Returns ???.

Returns:

  • (String)

    ???



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 162

#bonding_module_optsString

Returns bonding options.

Returns:

  • (String)

    bonding options



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 168

#bonding_slaveXString

Returns bonding port on position X.

Returns:

  • (String)

    bonding port on position X



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 165

#bootprotoString

Returns boot protocol.

Returns:

  • (String)

    boot protocol



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 119

#bridgeString

Returns "yes" if device is bridge.

Returns:

  • (String)

    "yes" if device is bridge



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 201

#bridge_forward_delayString

Returns time of delay.

Returns:

  • (String)

    time of delay



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 210

#bridge_portsString

Returns bridge ports separated by space.

Returns:

  • (String)

    bridge ports separated by space



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 204

#bridge_stpString

Returns "on" if stp is enabled.

Returns:

  • (String)

    "on" if stp is enabled



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 207

#broadcastString

Returns broadcast ip address.

Returns:

  • (String)

    broadcast ip address.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 122

#deviceString

Returns device name. Deprecated. name should be used instead.

Returns:

  • (String)

    device name. Deprecated. name should be used instead.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 125

#dhclient_set_default_routeString

Returns ???.

Returns:

  • (String)

    ???



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 192

Returns ???.

Returns:

  • (String)

    ???



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 189

#dhclient_set_hostnameString

Returns if dhcp sets hostname. "yes" if sets, "no" not set and nil not specified.

Returns:

  • (String)

    if dhcp sets hostname. "yes" if sets, "no" not set and nil not specified



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 159

#etherdeviceString

Returns parent device of vlan.

Returns:

  • (String)

    parent device of vlan



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 198

#ethtool_optionsString

Returns options for ethtool.

Returns:

  • (String)

    options for ethtool



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 177

#firewallString

Returns ???.

Returns:

  • (String)

    ???



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 183

#ifplugd_priorityString

Returns priority for ifplugd startmode.

Returns:

  • (String)

    priority for ifplugd startmode.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 153

#ipaddrString

Returns ip address.

Returns:

  • (String)

    ip address.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 134

#lladdrString

Returns ip address.

Returns:

  • (String)

    ip address.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 131

#mtuString

Returns MTU for interface.

Returns:

  • (String)

    MTU for interface



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 174

#nameString

Returns device name.

Returns:

  • (String)

    device name.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 128

#netmaskString

Returns network mask. Deprecated prefix should be used instead.

Returns:

  • (String)

    network mask. Deprecated prefix should be used instead.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 140

#networkString

Returns network ip after prefix applied. Deprecated as it can be computed from ipaddr and prefixlen.

Returns:

  • (String)

    network ip after prefix applied. Deprecated as it can be computed from ipaddr and prefixlen.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 143

#prefixlenString

Returns size of network prefix.

Returns:

  • (String)

    size of network prefix.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 147

#remote_ipaddrString

Returns remote ip address for ptp connections.

Returns:

  • (String)

    remote ip address for ptp connections.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 137

#startmodeString

Returns when to start network.

Returns:

  • (String)

    when to start network.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 150

#usercontrolString

Returns no clue what it means, but it is ignored now.

Returns:

  • (String)

    no clue what it means, but it is ignored now.



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 156

#vlan_idString

Returns id of vlan.

Returns:

  • (String)

    id of vlan



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 195

#wirelessString

Returns ???.

Returns:

  • (String)

    ???



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 180

#wireless_apObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_auth_modeObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_bitrateObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_ca_certObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_channelObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_client_certObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_client_keyObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_client_key_passwordObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_default_keyObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_eap_authObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_eap_modeObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_essidObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_frequencyObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_keyObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_key_lengthObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_keyXString

Returns key on position X.

Returns:

  • (String)

    key on position X



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_modeObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_nickObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_nwidObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_peap_versionObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_powerObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_wpa_anonidObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_wpa_identityObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_wpa_passwordObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#wireless_wpa_pskObject



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 213

#zoneString

Returns firewall zone to which interface belongs.

Returns:

  • (String)

    firewall zone to which interface belongs



# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 186

Class Method Details

.attributesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 43

def self.attributes
  [
    { name: :bootproto },
    { name: :broadcast },
    { name: :device },
    { name: :name }, # has precedence over device
    { name: :lladdr },
    { name: :description },
    { name: :ipaddr },
    { name: :remote_ipaddr },
    { name: :netmask },
    { name: :network }, # TODO: what it is? looks like ipaddr with applied prefix
    { name: :prefixlen }, # has precedence over netmask
    { name: :startmode },
    { name: :ifplugd_priority },
    { name: :usercontrol }, # no longer used, ignored
    { name: :dhclient_set_hostname },
    { name: :bonding_master },
    { name: :bonding_slave0 },
    { name: :bonding_slave1 },
    { name: :bonding_slave2 },
    { name: :bonding_slave3 },
    { name: :bonding_slave4 },
    { name: :bonding_slave5 },
    { name: :bonding_slave6 },
    { name: :bonding_slave7 },
    { name: :bonding_slave8 },
    { name: :bonding_slave9 },
    { name: :bonding_module_opts },
    { name: :aliases },
    { name: :mtu },
    { name: :ethtool_options },
    { name: :wireless }, # TODO: what it is?
    { name: :firewall }, # yes/no
    { name: :zone }, # firewall zone
    { name: :dhclient_set_down_link }, # TODO: what it do?
    { name: :dhclient_set_default_route }, # TODO: what it do?
    { name: :vlan_id },
    { name: :etherdevice },
    { name: :bridge }, # yes/no # why? bridge always have to be yes
    { name: :bridge_ports },
    { name: :bridge_stp }, # on/off
    { name: :bridge_forward_delay },
    { name: :wireless_ap },
    { name: :wireless_auth_mode },
    { name: :wireless_bitrate },
    { name: :wireless_ca_cert },
    { name: :wireless_channel },
    { name: :wireless_client_cert },
    { name: :wireless_client_key },
    { name: :wireless_client_key_password },
    { name: :wireless_default_key },
    { name: :wireless_eap_auth },
    { name: :wireless_eap_mode },
    { name: :wireless_essid },
    { name: :wireless_frequency },
    { name: :wireless_key }, # default wep key
    { name: :wireless_key0 },
    { name: :wireless_key1 },
    { name: :wireless_key2 },
    { name: :wireless_key3 },
    { name: :wireless_key_length },
    { name: :wireless_mode },
    { name: :wireless_nick },
    { name: :wireless_nwid },
    { name: :wireless_peap_version },
    { name: :wireless_power },
    { name: :wireless_wpa_anonid },
    { name: :wireless_wpa_identity },
    { name: :wireless_wpa_password },
    { name: :wireless_wpa_psk }
  ]
end

.new_from_network(connection_config, parent = nil) ⇒ InterfacesSection

Clones a network interface into an AutoYaST interface section

Parameters:

  • connection_config (Y2Network::ConnectionConfig)

    Network connection config

  • parent (SectionWithAttributes, nil) (defaults to: nil)

    Parent section

Returns:



245
246
247
248
249
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 245

def self.new_from_network(connection_config, parent = nil)
  result = new(parent)
  result.init_from_config(connection_config)
  result
end

Instance Method Details

#bonding_slavesArray<String>

Helper to get devices in the bonding as array

Returns:

  • (Array<String>)


360
361
362
363
364
365
366
367
368
369
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 360

def bonding_slaves
  ports = []

  (0..9).each do |i|
    port = public_send(:"bonding_slave#{i}")
    ports << port unless port.empty?
  end

  ports
end

#collection_nameString

Returns the collection name

Returns:

  • (String)

    "interfaces"



374
375
376
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 374

def collection_name
  "interfaces"
end

#init_from_config(config) ⇒ Boolean

Method used by new_from_network to populate the attributes when cloning a network interface

Parameters:

Returns:

  • (Boolean)


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
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 287

def init_from_config(config)
  # nil bootproto is valid use case (missing explicit setup) - wicked defaults to static then
  @bootproto = config.bootproto&.name
  @name = config.name
  @lladdr = config.lladdress
  if config.bootproto == BootProtocol::STATIC && config.ip
    # missing ip is valid scenario for wicked - so use empty string here
    @ipaddr = config.ip.address&.address.to_s
    @prefixlen = config.ip.address&.prefix.to_s
    @remote_ipaddr = config.ip.remote_address.address.to_s if config.ip.remote_address
    @broadcast = config.ip.broadcast.address.to_s if config.ip.broadcast
  end

  @dhclient_set_hostname = case config.dhclient_set_hostname
  when true then "yes"
  when false then "no"
  when nil then ""
  end
  @startmode = config.startmode.name
  @ifplugd_priority = config.startmode.priority.to_s if config.startmode.name == "ifplugd"
  @mtu = config.mtu.to_s if config.mtu
  @ethtool_options = config.ethtool_options if config.ethtool_options
  @zone = config.firewall_zone.to_s
  # see aliases for example output
  @aliases = config.ip_aliases.map { |ip| AliasSection.new_from_network(ip) }

  case config
  when ConnectionConfig::Vlan
    @vlan_id = config.vlan_id.to_s
    @etherdevice = config.parent_device
  when ConnectionConfig::Bridge
    @bridge = "yes"
    @bridge_ports = config.ports.join(" ")
    @bridge_stp = config.stp ? "on" : "off"
    @bridge_forward_delay = config.forward_delay.to_s
  when ConnectionConfig::Bonding
    @bonding_module_opts = config.options
    config.ports.each_with_index do |port, index|
      public_send(:"bonding_slave#{index}=", port)
    end
  when ConnectionConfig::Wireless
    init_from_wireless(config)
  end

  true
end

#init_from_hashes(hash) ⇒ Object

Overwrite base method to load also nested aliases



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 266

def init_from_hashes(hash)
  hash = rename_key(hash, "bridge_forwarddelay", "bridge_forward_delay")
  super(hash)

  # When the name and the device attributes are given then the pre network-ng behavior will be
  # adopted using the name as the description and the device as the name (bsc#1192270).
  unless hash.fetch("name", "").empty? || hash.fetch("device", "").empty?
    self.name = hash["device"]
    self.description = hash["name"]
  end

  return unless hash["aliases"].is_a?(Hash)

  self.aliases = hash["aliases"].values.map { |h| AliasSection.new_from_hashes(h) }
end

#section_pathInstallation::AutoinstProfile::ElementPath?

Returns the section path

Returns:

  • (Installation::AutoinstProfile::ElementPath, nil)

    Section path or nil if the parent is not set



382
383
384
385
386
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 382

def section_path
  return nil unless parent

  parent.section_path.join(index)
end

#to_hashesObject

See Also:

  • SectionWithAttributes#to_hashes


335
336
337
338
339
340
341
342
343
344
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 335

def to_hashes
  hash = super
  alias_sections = hash.delete("aliases")
  if alias_sections && !alias_sections.empty?
    hash["aliases"] = alias_sections.each_with_object({}).each_with_index do |(a, all), idx|
      all["alias#{idx}"] = a
    end
  end
  hash
end

#wireless_keysArray<String>

Helper to get wireless keys as array

Returns:

  • (Array<String>)


348
349
350
351
352
353
354
355
356
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 348

def wireless_keys
  keys = []
  (0..3).each do |i|
    key = public_send(:"wireless_key#{i}")
    keys << key unless key.empty?
  end

  keys
end