Class: Y2Network::Hwinfo
- Inherits:
-
Object
- Object
- Y2Network::Hwinfo
- Includes:
- Yast2::Equatable
- Defined in:
- src/lib/y2network/hwinfo.rb
Overview
Stores useful (from networking POV) items of hwinfo for an interface. FIXME: decide whether it should read hwinfo (on demand or at once) for a network device and store only necessary info or just parse provided hash
Instance Attribute Summary collapse
-
#hwinfo ⇒ Hash
readonly
TODO: this method should be private.
Class Method Summary collapse
-
.for(name) ⇒ Hwinfo
Creates a new instance containing hardware information for a given interface.
-
.netcards ⇒ Array<Hwinfo>
Returns the network devices hardware information.
-
.reset ⇒ Object
Resets the hardware information.
Instance Method Summary collapse
- #busid(readvalueofhwinfo["busid"]) ⇒ String
-
#connected? ⇒ Boolean
Return whether the interface has link.
-
#description ⇒ Object
Device type description FIXME: collision with alias for dev_name.
- #dev_name(readvalueofhwinfo["dev_name"]) ⇒ String (also: #name)
- #driver(readvalueofhwinfo["driver"]) ⇒ String
-
#drivers ⇒ Array<Driver>
Returns the list of kernel modules.
- #eql_hash ⇒ Object
- #exists? ⇒ Boolean
- #hotplug(readvalueofhwinfo["hotplug"]) ⇒ String
-
#initialize(hwinfo = {}) ⇒ Hwinfo
constructor
Constructor.
- #link(readvalueofhwinfo["link"]) ⇒ Boolean
-
#mac ⇒ String?
Returns the MAC adress.
-
#merge!(other) ⇒ Object
Merges data from another Hwinfo object.
- #module(readvalueofhwinfo["module"]) ⇒ String
-
#present? ⇒ Boolean
Determines whether the hardware is available (plugged).
- #requires(readvalueofhwinfo["requires"]) ⇒ Array<String>
-
#used_mac ⇒ String?
MAC address which is being used by the device.
- #wl_auth_modes(readvalueofhwinfo["wl_auth_modes"]) ⇒ String
- #wl_bitrates(readvalueofhwinfo["wl_bitrates"]) ⇒ String?
- #wl_channels(readvalueofhwinfo["wl_channels"]) ⇒ Array<String>?
- #wl_enc_modes(readvalueofhwinfo["wl_enc_modes"]) ⇒ Array<String>?
Constructor Details
#initialize(hwinfo = {}) ⇒ Hwinfo
Constructor
142 143 144 145 |
# File 'src/lib/y2network/hwinfo.rb', line 142 def initialize(hwinfo = {}) # FIXME: store only what's needed. @hwinfo = hwinfo.transform_keys(&:to_s) end |
Instance Attribute Details
#hwinfo ⇒ Hash (readonly)
TODO: this method should be private
68 69 70 |
# File 'src/lib/y2network/hwinfo.rb', line 68 def hwinfo @hwinfo end |
Class Method Details
.for(name) ⇒ Hwinfo
Probably, this logic should be moved to a separate class.
Creates a new instance containing hardware information for a given interface
It retrieves the information from existing udev rules.
81 82 83 |
# File 'src/lib/y2network/hwinfo.rb', line 81 def for(name) hwinfo_from_hardware(name) || hwinfo_from_udev(name) || Hwinfo.new end |
.netcards ⇒ Array<Hwinfo>
Returns the network devices hardware information
88 89 90 |
# File 'src/lib/y2network/hwinfo.rb', line 88 def netcards hardware_wrapper.netcards end |
.reset ⇒ Object
Resets the hardware information
It will be re-read the next time is needed.
95 96 97 |
# File 'src/lib/y2network/hwinfo.rb', line 95 def reset @hardware_wrapper = nil end |
Instance Method Details
#busid(readvalueofhwinfo["busid"]) ⇒ String
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#connected? ⇒ Boolean
Return whether the interface has link
254 255 256 |
# File 'src/lib/y2network/hwinfo.rb', line 254 def connected? present? && !!link end |
#description ⇒ Object
Device type description FIXME: collision with alias for dev_name
211 212 213 |
# File 'src/lib/y2network/hwinfo.rb', line 211 def description @hwinfo ? @hwinfo.fetch("name", "") : "" end |
#dev_name(readvalueofhwinfo["dev_name"]) ⇒ String Also known as: name
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#driver(readvalueofhwinfo["driver"]) ⇒ String
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#drivers ⇒ Array<Driver>
Returns the list of kernel modules
The list of modules is internally represented as:
[[mod1name, mod1args], [mod2name, mod2args]]
This method only returns the names, omitting the arguments.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#eql_hash ⇒ Object
278 279 280 |
# File 'src/lib/y2network/hwinfo.rb', line 278 def eql_hash hwinfo.compact end |
#exists? ⇒ Boolean
205 206 207 |
# File 'src/lib/y2network/hwinfo.rb', line 205 def exists? !@hwinfo.empty? end |
#hotplug(readvalueofhwinfo["hotplug"]) ⇒ String
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#link(readvalueofhwinfo["link"]) ⇒ Boolean
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#mac ⇒ String?
Returns the MAC adress
It usually returns the permanent MAC address (defined in the firmware). However, when missing, it will use the current MAC. See bsc#1136929 and bsc#1149234 for the reasons behind preferring the permanent MAC address.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#merge!(other) ⇒ Object
Merges data from another Hwinfo object
218 219 220 221 |
# File 'src/lib/y2network/hwinfo.rb', line 218 def merge!(other) @hwinfo.merge!(other.hwinfo) self end |
#module(readvalueofhwinfo["module"]) ⇒ String
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#present? ⇒ Boolean
Determines whether the hardware is available (plugged)
If the hardware layer was able to get its type, it consider the hardware to be connected. Bear in mind that it is not possible to just rely in #exists? because it could include some info from udev rules.
247 248 249 |
# File 'src/lib/y2network/hwinfo.rb', line 247 def present? !!type end |
#requires(readvalueofhwinfo["requires"]) ⇒ Array<String>
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#used_mac ⇒ String?
MAC address which is being used by the device
274 275 276 |
# File 'src/lib/y2network/hwinfo.rb', line 274 def used_mac @hwinfo["mac"] end |
#wl_auth_modes(readvalueofhwinfo["wl_auth_modes"]) ⇒ String
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#wl_bitrates(readvalueofhwinfo["wl_bitrates"]) ⇒ String?
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#wl_channels(readvalueofhwinfo["wl_channels"]) ⇒ Array<String>?
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |
#wl_enc_modes(readvalueofhwinfo["wl_enc_modes"]) ⇒ Array<String>?
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'src/lib/y2network/hwinfo.rb', line 179 [ { name: "dev_name", default: "" }, { name: "permanent_mac", default: nil }, { name: "busid", default: nil }, { name: "link", default: false }, { name: "driver", default: "" }, { name: "module", default: nil }, { name: "requires", default: [] }, { name: "hotplug", default: "" }, { name: "wl_auth_modes", default: "" }, { name: "wl_enc_modes", default: nil }, { name: "wl_channels", default: nil }, { name: "wl_bitrates", default: nil }, { name: "dev_port", default: nil }, { name: "type", default: nil }, { name: "name", default: "" }, { name: "modalias", default: nil } ].each do |hwinfo_item| define_method hwinfo_item[:name].downcase do @hwinfo ? @hwinfo.fetch(hwinfo_item[:name], hwinfo_item[:default]) : hwinfo_item[:default] end end |