Class: Y2Network::Hwinfo

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hwinfo = {}) ⇒ Hwinfo

Constructor


147
148
149
150
# File 'src/lib/y2network/hwinfo.rb', line 147

def initialize(hwinfo = {})
  # FIXME: store only what's needed.
  @hwinfo = Hash[hwinfo.map { |k, v| [k.to_s, v] }]
end

Instance Attribute Details

#hwinfoHash (readonly)

TODO: this method should be private


73
74
75
# File 'src/lib/y2network/hwinfo.rb', line 73

def hwinfo
  @hwinfo
end

Class Method Details

.for(name) ⇒ Hwinfo

TODO:

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 two sources:

  • hardware (through Yast::LanItems for the time being),
  • from existing udev rules.

87
88
89
# File 'src/lib/y2network/hwinfo.rb', line 87

def for(name)
  hwinfo_from_hardware(name) || hwinfo_from_udev(name) || Hwinfo.new
end

.netcardsArray<Hwinfo>

Returns the network devices hardware information


94
95
96
# File 'src/lib/y2network/hwinfo.rb', line 94

def netcards
  hardware_wrapper.netcards
end

.resetObject

Resets the hardware information

It will be re-read the next time is needed.


101
102
103
# File 'src/lib/y2network/hwinfo.rb', line 101

def reset
  @hardware_wrapper = nil
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Determines whether two objects are equivalent

Ignores any element having a nil value.


280
281
282
# File 'src/lib/y2network/hwinfo.rb', line 280

def ==(other)
  hwinfo.compact == other.hwinfo.compact
end

#busid(readvalueofhwinfo["busid"]) ⇒ String


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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

#descriptionObject

Device type description FIXME: collision with alias for dev_name


216
217
218
# File 'src/lib/y2network/hwinfo.rb', line 216

def description
  @hwinfo ? @hwinfo.fetch("name", "") : ""
end

#dev_name(readvalueofhwinfo["dev_name"]) ⇒ String Also known as: name


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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

#driversArray<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.


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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

#exists?Boolean


210
211
212
# File 'src/lib/y2network/hwinfo.rb', line 210

def exists?
  !@hwinfo.empty?
end

#hotplug(readvalueofhwinfo["hotplug"]) ⇒ Boolean


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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

#macString?

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.


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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


223
224
225
226
# File 'src/lib/y2network/hwinfo.rb', line 223

def merge!(other)
  @hwinfo.merge!(other.hwinfo)
  self
end

#module(readvalueofhwinfo["module"]) ⇒ String


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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.


251
252
253
# File 'src/lib/y2network/hwinfo.rb', line 251

def present?
  !!type
end

#requires(readvalueofhwinfo["requires"]) ⇒ Array<String>


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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_macString?

MAC address which is being used by the device


270
271
272
# File 'src/lib/y2network/hwinfo.rb', line 270

def used_mac
  @hwinfo["mac"]
end

#wl_auth_modes(readvalueofhwinfo["wl_auth_modes"]) ⇒ String


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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?


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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>?


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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>?


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/lib/y2network/hwinfo.rb', line 184

[
  { 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: false },
  { 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