Class: Yast::LanItemsSummary

Inherits:
Object
  • Object
show all
Includes:
I18n
Defined in:
src/lib/network/lan_items_summary.rb

Overview

This class creates a summary of the configured lan items supporting different types of summaries.

Instance Method Summary collapse

Constructor Details

#initializeLanItemsSummary

Returns a new instance of LanItemsSummary.


30
31
32
33
34
# File 'src/lib/network/lan_items_summary.rb', line 30

def initialize
  textdomain "network"
  Yast.import "LanItems"
  Yast.import "Summary"
end

Instance Method Details

#one_lineString

Generates a one line text summary for the configured interfaces.

Examples:

with one configured interface

LanItemsSummary.new.one_line
=> "DHCP / eth1"

with many configured interfaces

LanItemsSummary.new.one_line
=> "Multiple Interfaces"

Returns:

  • (String)

    summary in just one line and in plain text


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'src/lib/network/lan_items_summary.rb', line 71

def one_line
  protocols  = []
  configured = []
  output     = []

  Yast::LanItems.Items.each do |item, conf|
    next if !LanItems.IsItemConfigured(item)

    ifcfg = LanItems.GetDeviceMap(item) || {}
    protocols << ifcfg_protocol(ifcfg)

    configured << conf["ifcfg"]
  end

  output << protocols.first if protocols.uniq.size == 1

  case configured.size
  when 0
    return Summary.NotConfigured
  when 1
    output << configured.join(", ")
  else
    # TRANSLATORS: informs that multiple interfaces are configured
    output << _("Multiple Interfaces")
  end

  output.join(" / ")
end

#proposalString

Generates a summary in RichText format for the configured interfaces

Examples:

LanItemsSummary.new.proposal
=> "<ul><li><p>Configured with DHCP: eth0, eth1<br></p></li>" \
   "<li><p>br0 (Bridge)<br>IP address: 192.168.122.60/24" \
   "<br>Bridge Ports: eth2 eth3</p></li></ul>"

Returns:

  • (String)

    summary in RichText

See Also:

  • Summary

46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'src/lib/network/lan_items_summary.rb', line 46

def proposal
  items = []
  config = Y2Network::Config.find(:yast)

  items << "<li>#{dhcp_summary}</li>" unless LanItems.find_dhcp_ifaces.empty?
  items << "<li>#{static_summary}</li>" unless LanItems.find_static_ifaces.empty?
  items << "<li>#{bridge_summary}</li>" unless config.interfaces.by_type(Y2Network::InterfaceType::BRIDGE).to_a.empty?
  items << "<li>#{bonding_summary}</li>" unless config.interfaces.by_type(Y2Network::InterfaceType::BONDING).to_a.empty?

  return Summary.NotConfigured if items.empty?

  Summary.DevicesList(items)
end