Module: Y2Network::Widgets::PortItems

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

Overview

Mixin to help create a port device (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

Parameters:

  • dev_name (String)

    device name to check

Returns:

  • (String)

    physical port id if supported or a empty string if not



88
89
90
91
92
93
# File 'src/lib/y2network/widgets/port_items.rb', line 88

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

Returns:

  • (boolean)

    true if the physical port id is not empty

See Also:



98
99
100
# File 'src/lib/y2network/widgets/port_items.rb', line 98

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

#port_items_from(add_ifaces, included_ifaces, config) ⇒ Object

Builds content for port configuration dialog (used e.g. when configuring devices included in a bond)

Parameters:

  • add_ifaces (Array<String>)

    list of device names

  • included_ifaces (Array<String>)

    list of device names already included in a main device (bond, bridge, ...)

  • config (ConnectionConfig)

    where port devices live

Raises:

  • (ArgumentError)


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
74
75
76
77
78
79
# File 'src/lib/y2network/widgets/port_items.rb', line 38

def port_items_from(add_ifaces, included_ifaces, config)
  raise ArgumentError, "list of devices for adding cannot be nil" if add_ifaces.nil?
  raise ArgumentError, "some interfaces must be selected" if included_ifaces.nil?

  if add_ifaces.empty? && !included_ifaces.empty?
    raise ArgumentError, "list of devices cannot be empty"
  end

  textdomain "network"

  log.debug "creating list of devices to be added from #{add_ifaces.inspect}"

  add_ifaces.each_with_object([]) do |add_iface, result|
    interface = config.interfaces.by_name(add_iface)

    next unless interface

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

      # this conditions origin from bridge configuration
      # if including 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 = included_ifaces.include?(interface.name)
    if physical_port_id?(interface.name)
      description += " (Port ID: #{physical_port_id(interface.name)})"
    end

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