Class: Y2Network::AutoinstProfile::InterfaceSection

Inherits:
SectionWithAttributes 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 no 127.0.0.1 255.0.0.0 127.0.0.0 8 nfsroot no

See Also:

Constant Summary

Constants inherited from SectionWithAttributes

SectionWithAttributes::VALUES_TO_SKIP

Instance Attribute Summary collapse

Attributes inherited from SectionWithAttributes

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SectionWithAttributes

#attribute_key, #attribute_name, #attribute_scalar, #attribute_skip?, #attribute_value, #attributes, define_attr_accessors, #init_scalars_from_hash, new_from_hashes, #section_name, #to_hashes

Constructor Details

#initialize(*_args) ⇒ InterfaceSection

Returns a new instance of InterfaceSection.


258
259
260
261
262
263
264
265
266
267
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 258

def initialize(*_args)
  super

  self.class.attributes.each do |attr|
    # init everything to empty string
    public_send(:"#{attr[:name]}=", "")
  end

  self.aliases = {}
end

Instance Attribute Details

#aliasesObject

Returns aliases for interface.

Examples:

xml section for aliases from SLE15

<aliases>
  <alias0>
    <IPADDR>10.100.0.1</IPADDR>
    <LABEL>test</LABEL>
    <NETMASK>255.255.255.0</NETMASK>
    <PREFIXLEN>24</PREFIXLEN>
  </alias0>
  <alias1>
    <IPADDR>10.100.0.2</IPADDR>
    <LABEL>test2</LABEL>
    <NETMASK>255.255.255.0</NETMASK>
    <PREFIXLEN>24</PREFIXLEN>
  </alias1>
</aliases>

Returns:

  • (Object)

    aliases for interface


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

#bonding_masterString

Returns ???.

Returns:

  • (String)

    ???


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

#bonding_module_optsString

Returns bonding options.

Returns:

  • (String)

    bonding options


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

#bonding_slaveXString

Returns bonding slave on position X.

Returns:

  • (String)

    bonding slave on position X


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

#bootprotoString

Returns boot protocol.

Returns:

  • (String)

    boot protocol


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

#bridgeString

Returns "yes" if device is bridge.

Returns:

  • (String)

    "yes" if device is bridge


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

#bridge_forward_delayString

Returns time of delay.

Returns:

  • (String)

    time of delay


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

#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 212

#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 215

#broadcastString

Returns broadcast ip address.

Returns:

  • (String)

    broadcast ip address.


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

#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 121

#dhclient_set_default_routeString

Returns ???.

Returns:

  • (String)

    ???


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

Returns ???.

Returns:

  • (String)

    ???


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

#dhclient_set_hostnameString

Returns if dhcp sets hostname. It is plain text, values?.

Returns:

  • (String)

    if dhcp sets hostname. It is plain text, values?


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

#etherdeviceString

Returns parent device of vlan.

Returns:

  • (String)

    parent device of vlan


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

#ethtool_optionsString

Returns options for ethtool.

Returns:

  • (String)

    options for ethtool


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

#firewallString

Returns ???.

Returns:

  • (String)

    ???


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

#ifplugd_priorityString

Returns priority for ifplugd startmode.

Returns:

  • (String)

    priority for ifplugd startmode.


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

#ipaddrString

Returns ip address.

Returns:

  • (String)

    ip address.


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

#mtuString

Returns MTU for interface.

Returns:

  • (String)

    MTU for interface


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

#nameString

Returns device name.

Returns:

  • (String)

    device name.


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

#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 133

#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 136

#prefixlenString

Returns size of network prefix.

Returns:

  • (String)

    size of network prefix.


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

#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 130

#startmodeString

Returns when to start network.

Returns:

  • (String)

    when to start network.


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

#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 148

#vlan_idString

Returns id of vlan.

Returns:

  • (String)

    id of vlan


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

#wirelessString

Returns ???.

Returns:

  • (String)

    ???


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

#wireless_apObject


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

#wireless_auth_modeObject


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

#wireless_bitrateObject


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

#wireless_ca_certObject


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

#wireless_channelObject


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

#wireless_client_certObject


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

#wireless_client_keyObject


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

#wireless_client_key_passwordObject


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

#wireless_default_keyObject


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

#wireless_eap_authObject


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

#wireless_eap_modeObject


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

#wireless_essidObject


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

#wireless_frequencyObject


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

#wireless_keyObject


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

#wireless_key_lengthObject


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

#wireless_keyXString

Returns key on position X.

Returns:

  • (String)

    key on position X


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

#wireless_modeObject


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

#wireless_nickObject


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

#wireless_nwidObject


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

#wireless_peap_versionObject


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

#wireless_powerObject


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

#wireless_wpa_anonidObject


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

#wireless_wpa_identityObject


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

#wireless_wpa_passwordObject


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

#wireless_wpa_pskObject


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

#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 194

Class Method Details

.attributesObject


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

def self.attributes
  [
    { name: :bootproto },
    { name: :broadcast },
    { name: :device },
    { name: :name }, # has precedence over device
    { 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) ⇒ InterfacesSection

Clones a network interface into an AutoYaST interface section

Parameters:

Returns:


252
253
254
255
256
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 252

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

Instance Method Details

#bonding_slavesArray<String>

Helper to get bonding slaves as array

Returns:

  • (Array<String>)

339
340
341
342
343
344
345
346
347
348
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 339

def bonding_slaves
  slaves = []

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

  slaves
end

#init_from_config(config) ⇒ Boolean

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

Parameters:

Returns:

  • (Boolean)

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

def init_from_config(config)
  @bootproto = config.bootproto.name
  @name = config.name
  if config.bootproto == BootProtocol::STATIC && config.ip
    @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

  @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.each_with_index.each_with_object({}) do |(ip, index), res|
    res["alias#{index}"] = {
      "IPADDR"    => ip.address.address.to_s,
      "LABEL"     => ip.label || "",
      "PREFIXLEN" => ip.address.prefix.to_s
    }
  end

  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.slaves.each_with_index do |slave, index|
      public_send(:"bonding_slave#{index}=", slave)
    end
  when ConnectionConfig::Wireless
    init_from_wireless(config)
  end

  true
end

#init_from_hashes(hash) ⇒ Object

Overwrite base method to load also nested aliases


270
271
272
273
274
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 270

def init_from_hashes(hash)
  super

  self.aliases = hash["aliases"] if hash["aliases"]
end

#wireless_keysArray<String>

Helper to get wireless keys as array

Returns:

  • (Array<String>)

327
328
329
330
331
332
333
334
335
# File 'src/lib/y2network/autoinst_profile/interface_section.rb', line 327

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

  keys
end