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 section under

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

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_from_hashes, #init_scalars_from_hash, new_from_hashes, #section_name, #to_hashes

Constructor Details

#initialize(*_args) ⇒ 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


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


#ruleString


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


#valueString


# 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


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


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


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