Class: Y2Network::AutoinstProfile::UdevRuleSection
- Inherits:
-
Installation::AutoinstProfile::SectionWithAttributes
- Object
- Installation::AutoinstProfile::SectionWithAttributes
- Y2Network::AutoinstProfile::UdevRuleSection
- Includes:
- Yast::Logger
- Defined in:
- src/lib/y2network/autoinst_profile/udev_rule_section.rb
Overview
This class represents an AutoYaST
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
-
#name ⇒ String
Device name that should be used.
-
#rule ⇒ String
Type of rule.
-
#value ⇒ String
Mac or bus id value.
Class Method Summary collapse
- .attributes ⇒ Object
-
.new_from_network(interface, parent = nil) ⇒ InterfacesSection?
Clones a network interface into an AutoYaST udev rule section.
Instance Method Summary collapse
-
#collection_name ⇒ String
Returns the collection name.
-
#init_from_config(interface) ⇒ Object
Method used by UdevRuleSection.new_from_network to populate the attributes when cloning a udev rule.
-
#initialize(*_args) ⇒ UdevRuleSection
constructor
A new instance of UdevRuleSection.
-
#mechanism ⇒ Symbol
helper to get mechanism symbol from rule.
-
#section_path ⇒ Installation::AutoinstProfile::ElementPath?
Returns the section path.
Constructor Details
#initialize(*_args) ⇒ UdevRuleSection
Returns a new instance of UdevRuleSection.
70 71 72 73 74 75 76 77 |
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 70 def initialize(*_args) super self.class.attributes.each do |attr| # init everything to empty string public_send(:"#{attr[:name]}=", "") end end |
Instance Attribute Details
#name ⇒ String
Returns device name that should be used.
|
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 54
|
#rule ⇒ String
Returns type of rule. Supported now is ATTR\{address\}
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
|
#value ⇒ String
Returns mac or bus id value.
|
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 51
|
Class Method Details
.attributes ⇒ Object
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, parent = nil) ⇒ InterfacesSection?
Clones a network interface into an AutoYaST udev rule section
63 64 65 66 67 68 |
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 63 def self.new_from_network(interface, parent = nil) return if interface.renaming_mechanism == :none return unless interface.hardware new(parent).tap { |r| r.init_from_config(interface) } end |
Instance Method Details
#collection_name ⇒ String
Returns the collection name
110 111 112 |
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 110 def collection_name "udev_rules" end |
#init_from_config(interface) ⇒ Object
Method used by new_from_network to populate the attributes when cloning a udev rule
94 95 96 97 98 99 |
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 94 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 |
#mechanism ⇒ Symbol
helper to get mechanism symbol from rule
103 104 105 |
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 103 def mechanism RULE_MAPPING.each_pair { |k, v| return k if v == rule } end |
#section_path ⇒ Installation::AutoinstProfile::ElementPath?
Returns the section path
118 119 120 121 122 |
# File 'src/lib/y2network/autoinst_profile/udev_rule_section.rb', line 118 def section_path return nil unless parent parent.section_path.join(index) end |