Class: Y2Network::Presenters::InterfaceSummary

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

Overview

This class converts a connection config configuration object into a string to be used in an AutoYaST summary or in a table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InterfaceStatus

#status_info

Constructor Details

#initialize(name, config) ⇒ InterfaceSummary

Constructor


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

def initialize(name, config)
  textdomain "network"
  @name = name
  @config = config
end

Instance Attribute Details

#nameString (readonly)


35
36
37
# File 'src/lib/y2network/presenters/interface_summary.rb', line 35

def name
  @name
end

Instance Method Details

#textObject


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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'src/lib/y2network/presenters/interface_summary.rb', line 47

def text
  interface = @config.interfaces.by_name(@name)
  hardware = interface ? interface.hardware : nil
  descr = hardware ? hardware.description : ""

  connection = @config.connections.by_name(@name)
  bullets = []
  rich = ""

  if connection
    descr = connection.name if descr.empty?

    status = status_info(connection)

    bullets << _("Device Name: %s") % connection.name
    bullets << status
    bullets << connection.startmode.long_description
    bullets += aliases_info(connection)

    if connection.type.bonding?
      # TRANSLATORS: text label before list of slaves
      label = _("Bonding Slaves")
      bullets << "#{label}: #{connection.slaves.join(" ")}"
    elsif connection.type.bridge?
      # TRANSLATORS: text label before list of ports
      label = _("Bridge Ports")
      bullets << "#{label}: #{connection.ports.join(" ")}"
    end

    master = connection.find_master(@config.connections)
    if master
      master_desc = if master.type.bonding?
        # TRANSLATORS: text label before device which is master for this device
        _("Bonding master")
      else
        # TRANSLATORS: text label before device which is bridge for this device
        _("Bridge")
      end
      bullets << format("%s: %s", master_desc, master.name)
    end
  end

  if hardware.nil? || !hardware.exists?
    rich << "<b>(" << _("No hardware information") << ")</b><br>"
  else
    rich << "<b>(" << _("Not connected") << ")</b><br>" if !hardware.link
    rich << "<b>MAC : </b>" << hardware.mac << "<br>" if hardware.mac
    rich << "<b>BusID : </b>" << hardware.busid << "<br>" if hardware.busid
    # TODO: physical port id. Probably in hardware?
  end

  rich = Yast::HTML.Bold(descr) + "<br>" + rich
  if connection
    rich << Yast::HTML.List(bullets)
  else
    if hardware && hardware.name && !hardware.name.empty?
      dev_name = _("Device Name: %s") % hardware.name
      rich << Yast::HTML.Bold(dev_name) << "<br>"
    end

    rich << "<p>"
    rich << _("The device is not configured. Press <b>Edit</b>\nto configure.\n")
    rich << "</p>"
  end
  rich
end