Class: Y2Network::AutoinstProfile::UdevRuleSection

Inherits:
Installation::AutoinstProfile::SectionWithAttributes
  • Object
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#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 ATTR\{address\} 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 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

#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, parent = nil) ⇒ InterfacesSection?

Clones a network interface into an AutoYaST udev rule section

Parameters:

  • interface (Y2Network::Interface)
  • parent (SectionWithAttributes, nil) (defaults to: nil)

    Parent section

Returns:

  • (InterfacesSection, nil)

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



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_nameString

Returns the collection name

Returns:

  • (String)

    "udev_rules"



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

Parameters:



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

#mechanismSymbol

helper to get mechanism symbol from rule

Returns:



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_pathInstallation::AutoinstProfile::ElementPath?

Returns the section path

Returns:

  • (Installation::AutoinstProfile::ElementPath, nil)

    Section path or nil if the parent is not set



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