Class: Y2Network::Presenters::InterfacesSummary

Inherits:
Object
  • Object
show all
Includes:
InterfaceStatus, Yast::I18n, Yast::Logger
Defined in:
src/lib/y2network/presenters/interfaces_summary.rb

Overview

This class is responsible of creating text summaries for the connections of the Y2Network::Config given

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InterfaceStatus

#status_info

Constructor Details

#initialize(config) ⇒ InterfacesSummary

Constructor

Parameters:



42
43
44
45
46
# File 'src/lib/y2network/presenters/interfaces_summary.rb', line 42

def initialize(config)
  textdomain "network"

  @config = config
end

Instance Attribute Details

#configConfig (readonly)

Returns:



37
38
39
# File 'src/lib/y2network/presenters/interfaces_summary.rb', line 37

def config
  @config
end

Instance Method Details

#bonding_summaryString

Return a summary of the configured bonding interfaces

Returns:

  • (String)

    bonding configured interfaces summary



146
147
148
149
150
151
152
# File 'src/lib/y2network/presenters/interfaces_summary.rb', line 146

def bonding_summary
  # TRANSLATORS: %s is the list of bonding interface names and included
  # devices like 'bond0 (br0, eth2)'
  _("Bonds: %s") % bonding_connections.map do |connection|
    "#{connection.name} (#{connection.ports.sort.join(", ")})"
  end
end

#bridge_summaryString

Return a summary of the configured bridge interfaces

Returns:

  • (String)

    bridge configured interfaces summary



135
136
137
138
139
140
141
# File 'src/lib/y2network/presenters/interfaces_summary.rb', line 135

def bridge_summary
  # TRANSLATORS: %s is a list of bridge interface names and their ports
  # like 'br0 (eth0, eth1)'
  _("Bridges: %s") % bridge_connections.map do |connection|
    "#{connection.name} (#{connection.ports.sort.join(", ")})"
  end
end

#dhcp_summaryString

Return a summary of the interfaces configured with DHCP

Returns:

  • (String)

    interfaces configured with DHCP summary



119
120
121
122
# File 'src/lib/y2network/presenters/interfaces_summary.rb', line 119

def dhcp_summary
  # TRANSLATORS: %s is the list of interfaces configured by DHCP
  _("Configured with DHCP: %s") % dhcp_ifaces.sort.join(", ")
end

#one_line_textString

Generates a one line text summary for the configured interfaces.

Examples:

with one configured interface

presenter.one_line_text
=> "DHCP / eth1"

with many configured interfaces

presenter.one_line_text
=> "Multiple Interfaces"

Returns:

  • (String)

    summary in just one line and in plain text



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'src/lib/y2network/presenters/interfaces_summary.rb', line 74

def one_line_text
  protocols = []
  output = []

  protocols << "DHCP" if config.connections.any?(&:dhcp?)
  protocols << "STATIC" if config.connections.any?(&:static?)

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

  case config.connections.size
  when 0
    return Yast::Summary.NotConfigured
  when 1
    output << config.connections.first.interface
  else
    output << _("Multiple Interfaces")
  end

  output.join(" / ")
end

#proposal_textString

Generates a summary in RichText format for the configured interfaces

Examples:

interfaces_summary.proposal_text
=> "<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:



105
106
107
108
109
110
111
112
113
114
# File 'src/lib/y2network/presenters/interfaces_summary.rb', line 105

def proposal_text
  items = []
  items << list_item_for(dhcp_summary) unless dhcp_ifaces.empty?
  items << list_item_for(static_summary) unless static_ifaces.empty?
  items << list_item_for(bridge_summary) unless bridge_connections.empty?
  items << list_item_for(bonding_summary) unless bonding_connections.empty?
  items << list_item_for(Yast::Summary.NotConfigured) if items.empty?

  Yast::Summary.DevicesList(items)
end

#static_summaryString

Return a summary of the interfaces configured statically

Returns:

  • (String)

    statically configured interfaces summary



127
128
129
130
# File 'src/lib/y2network/presenters/interfaces_summary.rb', line 127

def static_summary
  # TRANSLATORS: %s is the list of interfaces configured statically
  _("Statically configured: %s") % static_ifaces.sort.join(", ")
end

#textString

Interfaces configuration summary in RichText format

Returns:

  • (String)

    interfaces config summary in RichText format



51
52
53
54
55
56
57
58
59
60
61
# File 'src/lib/y2network/presenters/interfaces_summary.rb', line 51

def text
  overview = config.interfaces.map do |interface|
    connection = config.connections.by_name(interface.name)
    descr = interface.hardware ? interface.hardware.description : ""
    descr = interface.name if descr.empty?
    status = connection ? status_info(connection) : Yast::Summary.NotConfigured
    Yast::Summary.Device(descr, status)
  end

  Yast::Summary.DevicesList(overview)
end