Skip to content

Commit

Permalink
Changes based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Dec 13, 2020
1 parent 2620971 commit 31c7154
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 222 deletions.
8 changes: 4 additions & 4 deletions src/include/network/services/dns.rb
Expand Up @@ -305,18 +305,18 @@ def current_hostname

def update_hostname_hosts(hostname)
return false if hostname == current_hostname
return false if current_hostname.to_s.empty?
return false if current_hostname.empty?

conn = config.connections.find { |c| c.hostnames.include?(current_hostname) }

update_hostname = conn && Popup.YesNo(
wrap_text(
format(_("The interface '%s' static IP address is mapped to the modified hostname.\n\n" \
"Would you like to adapt it now?"), conn.name)
format(_("The interface '%s' static IP address is mapped to the hostname '%s'.\n\n" \
"Would you like to adapt it now?"), conn.name, current_hostname)
)
)

Y2Network::Dialogs::UpdateHostnameHosts.new(hostname, conn).run if update_hostname
Y2Network::Dialogs::UpdateHostnameHosts.new(conn).run if update_hostname
end

# Stores actual hostname settings.
Expand Down
14 changes: 8 additions & 6 deletions src/lib/y2network/connection_config/base.rb
Expand Up @@ -204,21 +204,23 @@ def static?
bootproto ? bootproto.static? : true
end

# Return the first hostname associated with the primary IP address
# Return the first hostname associated with the primary IP address.
#
# @return [String, nil]
# @return [String, nil] returns the hostname associated with the primary
# IP address or nil
def hostname
hostnames&.first
end

# Convenience method in order to modify the canonical hostname mapped to
# the primary IP address.
#
# @param name [String] hostnamme mapped to the primary IP address
def hostname=(name)
short_name = name&.split(".")&.first
# @param name [String, nil] hostnamme mapped to the primary IP address
def hostname=(hname)
short_name = hname&.split(".")&.first

@hostnames = [name, short_name].uniq.compact
@hostnames = [hname, short_name].uniq.compact
log.info("Assigned hostnames #{@hostnames.inspect} to connection #{name}")
end

private
Expand Down
113 changes: 0 additions & 113 deletions src/lib/y2network/dialogs/popup.rb

This file was deleted.

29 changes: 18 additions & 11 deletions src/lib/y2network/dialogs/update_hostname_hosts.rb
Expand Up @@ -18,26 +18,30 @@
# find current contact information at www.suse.com.

require "cwm/popup"
require "y2network/dialogs/popup"
require "y2network/widgets/update_connection_hostname"
require "y2network/widgets/hostname"

module Y2Network
module Dialogs
class UpdateHostnameHosts < Popup
def initialize(hostname, connection)
# A popup dialog which permits to modify the hostname mapped to the given
# connection primary IP address
class UpdateHostnameHosts < CWM::Popup
def initialize(connection)
textdomain "network"

@hostname = hostname
@connection = connection
end

def title
format(_("Edit '%s' static IP address hostname"), @connection.name)
format(_("Edit '%s' hostname"), @connection.name)
end

def contents
VBox(
connection_hostname_widget
Left(Label(_("IP Address"))),
Left(Label(ip_address)),
VSpacing(0.5),
hostname_widget,
VSpacing(0.5)
)
end

Expand All @@ -46,18 +50,21 @@ def buttons
end

def ok_button_label
_("Modify")
Yast::Label.ModifyButton
end

def min_height
8
end

def ip_address
@connection&.ip&.address&.address&.to_s
end

private

def connection_hostname_widget
@connection_hostname_widget ||=
Widgets::UpdateConnectionHostname.new(@hostname, @connection)
def hostname_widget
@hostname_widget ||= Widgets::Hostname.new(@connection)
end
end
end
Expand Down
67 changes: 67 additions & 0 deletions src/lib/y2network/widgets/hostname.rb
@@ -0,0 +1,67 @@
# Copyright (c) [2020] 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 "cwm"

module Y2Network
module Widgets
# Widget that permits to modify the hostname of the given object
class Hostname < CWM::InputField
# Constructor
#
# @param settings [Object]
# @param empty_allowed [Boolean] whether an empty hostname should be
# valid or not
def initialize(settings, empty_allowed: true)
textdomain "network"

@settings = settings
@empty_allowed = empty_allowed
end

def init
self.value = @settings.hostname.to_s
end

def label
_("&Hostname")
end

def store
@settings.hostname = value
end

def validate
Yast.import "Hostname"
return true if empty_allowed? && value.to_s.empty?

Yast::Hostname.CheckFQ(value)
end

private

# Return whether an empty value is allowed or not
#
# @return [Boolean]
def empty_allowed?
@empty_allowed
end
end
end
end
88 changes: 0 additions & 88 deletions src/lib/y2network/widgets/update_connection_hostname.rb

This file was deleted.

0 comments on commit 31c7154

Please sign in to comment.