Class: Y2Network::AutoinstProfile::UdevRuleSection

Inherits:
SectionWithAttributes show all
Includes:
Yast::Logger
Defined in:
src/lib/y2network/autoinst_profile/udev_rule_section.rb

Overview

This class represents an AutoYaST <rule> section under <net-udev>

Examples:

xml content

<rule>
  <name>eth0</name>
  <rule>ATTR\{address\}</rule>
  <value>00:30:6E:08:EC:80</value>
</rule>

See Also:

Constant Summary collapse

RULE_MAPPING =

mapping of renaming_mechanism to rule string

{
  mac:    "ATTR{address}",
  bus_id: "KERNELS"
}.freeze
VALUE_MAPPING =

mapping of renaming_mechanism to method to obtain value

{
  mac:    :mac,
  bus_id: :busid
}.freeze

Instance Attribute Summary collapse

Attributes inherited from SectionWithAttributes

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SectionWithAttributes

#init_from_hashes, new_from_hashes, #section_name, #to_hashes

Constructor Details

#initialize(*_args) ⇒ UdevRuleSection

Returns a new instance of UdevRuleSection.


68
69
70
71
72
73
74
75
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 68

def initialize(*_args)
  super

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

Instance Attribute Details

#nameString

Returns device name that should be used.

Returns:

  • (String)

    device name that should be used.


# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 54

#ruleString

Returns type of rule. Supported now is `ATTRaddress` and `KERNELS`. The first one is for MAC based rules and second for bus id based ones.

Returns:

  • (String)

    type of rule. Supported now is `ATTRaddress` and `KERNELS`. The first one is for MAC based rules and second for bus id based ones.


# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 47

#valueString

Returns mac or bus id value.

Returns:

  • (String)

    mac or bus id value


# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 51

Class Method Details

.attributesObject


37
38
39
40
41
42
43
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 37

def self.attributes
  [
    { name: :rule },
    { name: :value },
    { name: :name }
  ]
end

.new_from_network(interface) ⇒ InterfacesSection?

Clones a network interface into an AutoYaST udev rule section

Parameters:

Returns:

  • (InterfacesSection, nil)

    Udev rule section or nil if udev naming is not implemented for interface


61
62
63
64
65
66
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 61

def self.new_from_network(interface)
  return if interface.renaming_mechanism == :none
  return unless interface.hardware

  new.tap { |r| r.init_from_config(interface) }
end

Instance Method Details

#init_from_config(interface) ⇒ Object

Method used by new_from_network to populate the attributes when cloning a udev rule

Parameters:


92
93
94
95
96
97
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 92

def init_from_config(interface)
  @name = interface.name
  @rule = RULE_MAPPING[interface.renaming_mechanism] or
    raise("invalid renaming mechanism #{interface.renaming_mechanism}")
  @value = interface.hardware.public_send(VALUE_MAPPING[interface.renaming_mechanism])
end

#mechanismSymbol

helper to get mechanism symbol from rule

Returns:


101
102
103
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 101

def mechanism
  RULE_MAPPING.each_pair { |k, v| return k if v == rule }
end