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


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>

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


#bonding_masterString


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


#bonding_module_optsString


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


#bonding_slaveXString


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


#bootprotoString


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


#bridgeString


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


#bridge_forward_delayString


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


#bridge_portsString


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


#bridge_stpString


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


#broadcastString


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


#deviceString


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


#dhclient_set_default_routeString


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



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


#dhclient_set_hostnameString


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


#etherdeviceString


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


#ethtool_optionsString


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


#firewallString


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


#ifplugd_priorityString


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


#ipaddrString


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


#mtuString


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


#nameString


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


#netmaskString


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


#networkString


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


#prefixlenString


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


#remote_ipaddrString


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


#startmodeString


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


#usercontrolString


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


#vlan_idString


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


#wirelessString


# 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


# 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


# 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


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


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


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


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