Class: Y2Network::Interface
- Inherits:
-
Object
- Object
- Y2Network::Interface
- Includes:
- Yast::Logger
- Defined in:
- src/lib/y2network/interface.rb
Overview
Network interface.
It represents network interfaces, no matter whether they are physical or virtual ones. This class (including its subclasses) are basically responsible for holding the hardware configuration (see Hwinfo), including naming and driver information.
Logical configuration, like TCP/IP or WIFI settings, are handled through ConnectionConfig::Base classes. Actually, relationships with other interfaces are kept in those configuration objects too.
Direct Known Subclasses
Instance Attribute Summary collapse
- #firmware_configured_by ⇒ Symbol?
- #hardware ⇒ HwInfo readonly
-
#name ⇒ String
Device name ('eth0', 'wlan0', etc.).
- #old_name ⇒ String? readonly
-
#renaming_mechanism ⇒ Symbol
Mechanism to rename the interface (:none -no rename-, :bus_id or :mac).
-
#type ⇒ InterfaceType
Interface type.
- #udev_rule ⇒ UdevRule
Class Method Summary collapse
-
.from_connection(conn) ⇒ Object
Builds an interface based on a connection.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Determines whether two interfaces are equal.
-
#config ⇒ Hash<String, String>
Complete configuration of the interface.
-
#connected? ⇒ Boolean
Whether the interface is connected or not based on hardware information.
-
#drivers ⇒ Array<Driver>
Returns the list of kernel modules.
-
#firmware_configured? ⇒ Boolean
Whether the interface is firmware configured or not.
-
#hash ⇒ Object
Used by Array or Hash in order to compare equality of elements (bsc#1186082).
-
#hotplug? ⇒ Boolean
True if the interface is hotplug.
-
#initialize(name, type: InterfaceType::ETHERNET) ⇒ Interface
constructor
Constructor.
-
#rename(new_name, mechanism) ⇒ Object
Renames the interface.
-
#update_udev_rule ⇒ UdevRule
Updates or creates the associated udev rule depending on the renaming mechanism selected.
Constructor Details
#initialize(name, type: InterfaceType::ETHERNET) ⇒ Interface
Constructor
73 74 75 76 77 78 |
# File 'src/lib/y2network/interface.rb', line 73 def initialize(name, type: InterfaceType::ETHERNET) @name = name.freeze @type = type # TODO: move renaming logic to physical interfaces only @renaming_mechanism = :none end |
Instance Attribute Details
#firmware_configured_by ⇒ Symbol?
53 54 55 |
# File 'src/lib/y2network/interface.rb', line 53 def firmware_configured_by @firmware_configured_by end |
#hardware ⇒ HwInfo (readonly)
45 46 47 |
# File 'src/lib/y2network/interface.rb', line 45 def hardware @hardware end |
#name ⇒ String
Returns Device name ('eth0', 'wlan0', etc.).
41 42 43 |
# File 'src/lib/y2network/interface.rb', line 41 def name @name end |
#old_name ⇒ String? (readonly)
51 52 53 |
# File 'src/lib/y2network/interface.rb', line 51 def old_name @old_name end |
#renaming_mechanism ⇒ Symbol
Returns Mechanism to rename the interface (:none -no rename-, :bus_id or :mac).
49 50 51 |
# File 'src/lib/y2network/interface.rb', line 49 def renaming_mechanism @renaming_mechanism end |
#type ⇒ InterfaceType
Returns Interface type.
43 44 45 |
# File 'src/lib/y2network/interface.rb', line 43 def type @type end |
#udev_rule ⇒ UdevRule
47 48 49 |
# File 'src/lib/y2network/interface.rb', line 47 def udev_rule @udev_rule end |
Class Method Details
.from_connection(conn) ⇒ Object
Builds an interface based on a connection
59 60 61 62 63 64 65 66 |
# File 'src/lib/y2network/interface.rb', line 59 def from_connection(conn) # require here to avoid circular dependency require "y2network/physical_interface" require "y2network/virtual_interface" interface_class = conn.virtual? ? VirtualInterface : PhysicalInterface interface_class.new(conn.interface || conn.name, type: conn.type) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
although it is preferable to use Yast2::Equatable it uses the class hash for comparing objects and it will fail when comparing with subclasses objects (bsc#1188908)
Determines whether two interfaces are equal
103 104 105 106 107 |
# File 'src/lib/y2network/interface.rb', line 103 def ==(other) return false unless other.is_a?(Interface) name == other.name end |
#config ⇒ Hash<String, String>
Complete configuration of the interface
121 122 123 |
# File 'src/lib/y2network/interface.rb', line 121 def config system_config(name) end |
#connected? ⇒ Boolean
Whether the interface is connected or not based on hardware information
84 85 86 |
# File 'src/lib/y2network/interface.rb', line 84 def connected? !!hardware&.connected? end |
#drivers ⇒ Array<Driver>
Returns the list of kernel modules
92 93 94 |
# File 'src/lib/y2network/interface.rb', line 92 def drivers hardware&.drivers || [] end |
#firmware_configured? ⇒ Boolean
Returns whether the interface is firmware configured or not.
164 165 166 |
# File 'src/lib/y2network/interface.rb', line 164 def firmware_configured? !!firmware_configured_by end |
#hash ⇒ Object
Used by Array or Hash in order to compare equality of elements (bsc#1186082)
114 115 116 |
# File 'src/lib/y2network/interface.rb', line 114 def hash name.hash end |
#hotplug? ⇒ Boolean
Returns true if the interface is hotplug.
157 158 159 160 161 |
# File 'src/lib/y2network/interface.rb', line 157 def hotplug? return false unless hardware ["usb", "pcmcia"].include?(hardware.hotplug) end |
#rename(new_name, mechanism) ⇒ Object
Renames the interface
129 130 131 132 133 134 |
# File 'src/lib/y2network/interface.rb', line 129 def rename(new_name, mechanism) log.info "Rename interface '#{name}' to '#{new_name}' using the '#{mechanism}'" @old_name = name if name != new_name # same name, just set different mechanism @name = new_name.freeze @renaming_mechanism = mechanism end |
#update_udev_rule ⇒ UdevRule
Updates or creates the associated udev rule depending on the renaming mechanism selected
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'src/lib/y2network/interface.rb', line 140 def update_udev_rule log.info("Updating udev rule for #{name} based on: #{renaming_mechanism.inspect}") case renaming_mechanism when :mac udev_rule&.rename_by_mac(name, hardware.mac) @udev_rule ||= Y2Network::UdevRule.new_mac_based_rename(name, hardware.mac) when :bus_id udev_rule&.rename_by_bus_id(name, hardware.busid, hardware.dev_port) @udev_rule ||= Y2Network::UdevRule.new_bus_id_based_rename(name, hardware.busid, hardware.dev_port) end end |