Skip to content

Commit

Permalink
Merge 5b6a717 into 3458e90
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Sep 11, 2019
2 parents 3458e90 + 5b6a717 commit 26c7156
Show file tree
Hide file tree
Showing 17 changed files with 468 additions and 29 deletions.
15 changes: 15 additions & 0 deletions src/lib/y2network/connection_config/base.rb
Expand Up @@ -126,6 +126,21 @@ def all_ips
([ip] + ip_aliases).compact
end

# find master from given collection of configs
# @param configs [ConnectionConfigsCollection]
# @return [ConnectionConfig::Bonding, ConnectionConfig::Bridge, nil] gets bridge, bonding or
# nil in which this device in enslaved
def find_master(configs)
configs.find do |config|
# TODO: what about VLAN?
if config.type.bonding?
config.slaves.include?(name)
elsif config.type.bridge?
config.ports.include?(name)
end
end
end

private

def replace_ifplugd?
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2network/connection_configs_collection.rb
Expand Up @@ -36,7 +36,7 @@ class ConnectionConfigsCollection
attr_reader :connection_configs
alias_method :to_a, :connection_configs

def_delegators :@connection_configs, :each, :push, :<<, :reject!, :map, :flat_map, :any?, :size
def_delegators :@connection_configs, :each, :find, :push, :<<, :reject!, :map, :flat_map, :any?, :size

# Constructor
#
Expand Down
62 changes: 62 additions & 0 deletions src/lib/y2network/presenters/interface_status.rb
@@ -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
123 changes: 123 additions & 0 deletions src/lib/y2network/presenters/interface_summary.rb
@@ -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
55 changes: 55 additions & 0 deletions src/lib/y2network/presenters/interfaces_summary.rb
@@ -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
1 change: 1 addition & 0 deletions src/lib/y2network/startmode.rb
Expand Up @@ -35,6 +35,7 @@ def initialize(name)

# gets new instance of startmode for given type and its params
def self.create(name)
name = "auto" if name == "onboot" # onboot is alias for auto
# avoid circular dependencies
require "y2network/startmodes"
Startmodes.const_get(name.capitalize).new
Expand Down
6 changes: 6 additions & 0 deletions src/lib/y2network/startmodes/auto.rb
Expand Up @@ -40,6 +40,12 @@ def initialize
def to_human_string
_("At Boot Time")
end

def long_description
_(
"Started automatically at boot"
)
end
end
end
end
6 changes: 6 additions & 0 deletions src/lib/y2network/startmodes/hotplug.rb
Expand Up @@ -37,6 +37,12 @@ def initialize
def to_human_string
_("On Hotplug")
end

def long_description
_(
"Started automatically when attached"
)
end
end
end
end
6 changes: 6 additions & 0 deletions src/lib/y2network/startmodes/ifplugd.rb
Expand Up @@ -48,6 +48,12 @@ def to_human_string
def ==(other)
name == other.name && priority == other.priority
end

def long_description
_(
"Started automatically on cable connection"
)
end
end
end
end
6 changes: 6 additions & 0 deletions src/lib/y2network/startmodes/manual.rb
Expand Up @@ -36,6 +36,12 @@ def initialize
def to_human_string
_("Manually")
end

def long_description
_(
"Started manually"
)
end
end
end
end
6 changes: 6 additions & 0 deletions src/lib/y2network/startmodes/nfsroot.rb
Expand Up @@ -39,6 +39,12 @@ def initialize
def to_human_string
_("On NFSroot")
end

def long_description
_(
"Started automatically at boot (mandatory)"
)
end
end
end
end
6 changes: 6 additions & 0 deletions src/lib/y2network/startmodes/off.rb
Expand Up @@ -36,6 +36,12 @@ def initialize
def to_human_string
_("Never")
end

def long_description
_(
"Will not be started at all"
)
end
end
end
end

0 comments on commit 26c7156

Please sign in to comment.