Module: Y2Network::Widgets::SlaveItems

Includes:
Yast::I18n, Yast::Logger
Included in:
BondSlave, BridgePorts
Defined in:
src/lib/y2network/widgets/slave_items.rb

Overview

Mixin to help create slave (of any kind) list

Instance Method Summary collapse

Instance Method Details

#physical_port_id(dev_name) ⇒ String

With NPAR and SR-IOV capabilities, one device could divide a ethernet port in various. If the driver module support it, we can check the phys port id via sysfs reading the /sys/class/net/$dev_name/phys_port_id TODO: backend method


82
83
84
85
86
87
# File 'src/lib/y2network/widgets/slave_items.rb', line 82

def physical_port_id(dev_name)
  Yast::SCR.Read(
    Yast::Path.new(".target.string"),
    "/sys/class/net/#{dev_name}/phys_port_id"
  ).to_s.strip
end

#physical_port_id?(dev_name) ⇒ boolean

TODO: backend method

See Also:


92
93
94
# File 'src/lib/y2network/widgets/slave_items.rb', line 92

def physical_port_id?(dev_name)
  !physical_port_id(dev_name).empty?
end

#slave_items_from(slaves, enslaved_ifaces, config) ⇒ Object

Builds content for slave configuration dialog (used e.g. when configuring bond slaves) according the given list of item_ids (see LanItems::Items)

Raises:

  • (ArgumentError)

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'src/lib/y2network/widgets/slave_items.rb', line 37

def slave_items_from(slaves, enslaved_ifaces, config)
  raise ArgumentError, "slaves cannot be nil" if slaves.nil?
  raise ArgumentError, "enslaved interfaces cannot be nil" if enslaved_ifaces.nil?
  raise ArgumentError, "slaves cannot be empty" if slaves.empty? && !enslaved_ifaces.empty?

  textdomain "network"

  log.debug "creating list of slaves from #{slaves.inspect}"

  slaves.each_with_object([]) do |slave, result|
    interface = config.interfaces.by_name(slave)

    next unless interface

    if interface.type.tun? || interface.type.tap?
      description = Yast::NetworkInterfaces.GetDevTypeDescription(interface.type.short_name, true)
    else
      description = interface.name

      # this conditions origin from bridge configuration
      # if enslaving a configured device then its configuration is rewritten
      # to "0.0.0.0/32"
      #
      # translators: a note that listed device is already configured
      description += " " + _("configured") if config.connections.by_name(interface.name)
    end

    selected = enslaved_ifaces.include?(interface.name)

    description << " (Port ID: #{physical_port_id(interface.name)})" if physical_port_id?(interface.name)

    result << Yast::Term.new(:item,
      Yast::Term.new(:id, interface.name),
      "#{interface.name} - #{description}",
      selected)
  end
end