Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
468 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright (c) [2019] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "yast" | ||
Yast.import "HTML" | ||
Yast.import "NetHwDetection" | ||
|
||
module Y2Network | ||
module Presenters | ||
# Mixin that provide status info about interface `status_info(config)` | ||
module InterfaceStatus | ||
include Yast::I18n | ||
# @param config [ConnectionConfig::Base] | ||
# @return [String] status information | ||
def status_info(config) | ||
textdomain "network" | ||
|
||
case config.bootproto | ||
when BootProtocol::STATIC | ||
return Yast::HTML.Colorize(_("Configured without an address"), "red") if !config.ip | ||
|
||
ip = config.ip.address.to_s | ||
host = Yast::NetHwDetection.ResolveIP(config.ip.address.address.to_s) | ||
addr = ip | ||
addr << "(#{host})" if host && !host.empty? | ||
if config.ip.remote_address | ||
# TRANSLATORS %{local} is local address and %{remote} is remote address | ||
format( | ||
_("Configured with address %{local} (remote %{remote})"), | ||
local: addr, | ||
remote: config.remote_address.to_s | ||
) | ||
else | ||
# TRANSLATORS %s is address | ||
format(_("Configured with address %s"), addr) | ||
end | ||
when BootProtocol::NONE | ||
_("Do not assign (e.g. bond or bridge slaves)") | ||
else | ||
# TODO: maybe human name for boot protocols? | ||
format(_("Configured with %s"), config.bootproto.name) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# Copyright (c) [2019] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "yast" | ||
require "y2network/presenters/interface_status" | ||
|
||
Yast.import "Summary" | ||
Yast.import "HTML" | ||
|
||
module Y2Network | ||
module Presenters | ||
# This class converts a connection config configuration object into a string to be used | ||
# in an AutoYaST summary or in a table. | ||
class InterfaceSummary | ||
include Yast::I18n | ||
include InterfaceStatus | ||
|
||
# @return [String] | ||
attr_reader :name | ||
|
||
# Constructor | ||
# | ||
# @param name [String] name of device to describe | ||
# @param config [Y2Network::Config] | ||
def initialize(name, config) | ||
textdomain "network" | ||
@name = name | ||
@config = config | ||
end | ||
|
||
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 | ||
|
||
private | ||
|
||
def aliases_info(config) | ||
config.ip_aliases.map do |alias_| | ||
"#{alias_.address} (#{alias_.label})" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (c) [2019] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "yast" | ||
require "y2network/presenters/interface_status" | ||
|
||
Yast.import "Summary" | ||
Yast.import "HTML" | ||
|
||
module Y2Network | ||
module Presenters | ||
# This class converts a connection config configurations into a string to be used | ||
# in an AutoYaST summary. | ||
class InterfacesSummary | ||
include Yast::I18n | ||
include Yast::Logger | ||
include InterfaceStatus | ||
|
||
# @return [Config] | ||
attr_reader :config | ||
|
||
def initialize(config) | ||
@config = config | ||
end | ||
|
||
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 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.