From dd0379fb18e6f683133ea0d80e3e445ad3fbc8d3 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 17 Aug 2023 16:21:10 -0400 Subject: [PATCH 1/2] Remove unused methods remote_*_ipaddress/hostname --- app/models/miq_region.rb | 16 ++-------------- app/models/miq_server.rb | 38 ++++---------------------------------- 2 files changed, 6 insertions(+), 48 deletions(-) diff --git a/app/models/miq_region.rb b/app/models/miq_region.rb index b8828482c45..fcc7442e625 100644 --- a/app/models/miq_region.rb +++ b/app/models/miq_region.rb @@ -188,12 +188,8 @@ def remote_ui_miq_server MiqServer.in_region(region).recently_active.find_by(:has_active_userinterface => true) end - def remote_ui_ipaddress - remote_ui_miq_server&.ui_ipaddress - end - - def remote_ui_hostname - remote_ui_miq_server&.ui_hostname + def remote_ui_address + remote_ui_miq_server&.ui_address end def remote_ui_url(contact_with = :hostname) @@ -208,14 +204,6 @@ def remote_ws_address remote_ws_miq_server&.ws_address end - def remote_ws_ipaddress - remote_ws_miq_server&.ws_ipaddress - end - - def remote_ws_hostname - remote_ws_miq_server&.ws_hostname - end - def remote_ws_url remote_ws_miq_server&.ws_url end diff --git a/app/models/miq_server.rb b/app/models/miq_server.rb index e2201fff0e3..bee9e0954e0 100644 --- a/app/models/miq_server.rb +++ b/app/models/miq_server.rb @@ -404,27 +404,12 @@ def logon_status_details result.merge(:message => message) end - def ui_hostname - if MiqEnvironment::Command.is_podified? - ENV.fetch("APPLICATION_DOMAIN") - else - hostname || ipaddress - end - end - - def ui_ipaddress - if MiqEnvironment::Command.is_podified? - nil - else - ipaddress - end - end - def ui_address(contact_with = :hostname) if MiqEnvironment::Command.is_podified? ENV.fetch("APPLICATION_DOMAIN") else - contact_with == :hostname ? ui_hostname : ui_ipaddress + address = hostname if contact_with == :hostname + address || ipaddress end end @@ -438,27 +423,12 @@ def ui_url(contact_with = :hostname) URI::HTTPS.build(:host => host).to_s end - def ws_hostname - if MiqEnvironment::Command.is_podified? - ENV.fetch("APPLICATION_DOMAIN") - else - hostname || ipaddress - end - end - - def ws_ipaddress - if MiqEnvironment::Command.is_podified? - nil - else - ipaddress - end - end - def ws_address if MiqEnvironment::Command.is_podified? ENV.fetch("APPLICATION_DOMAIN") else - ::Settings.webservices.contactwith == 'hostname' ? ws_hostname : ws_ipaddress + address = hostname if ::Settings.webservices.contactwith == 'hostname' + address || ipaddress end end From a252d4ed35c6e9aaf8fee095a855ca077147cf54 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 17 Aug 2023 16:27:48 -0400 Subject: [PATCH 2/2] Move is_podified?/is_systemd? into MiqServer --- app/models/miq_server.rb | 24 +++++++++++++++++----- app/models/miq_server/worker_management.rb | 12 ++--------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/models/miq_server.rb b/app/models/miq_server.rb index bee9e0954e0..764a710afe8 100644 --- a/app/models/miq_server.rb +++ b/app/models/miq_server.rb @@ -340,6 +340,20 @@ def set_database_application_name ArApplicationName.name = database_application_name end + def self.podified? + return @podified unless @podified.nil? + + @podified = MiqEnvironment::Command.is_podified? + end + delegate :podified?, :to => :class + + def self.systemd? + return @systemd unless @systemd.nil? + + @systemd = MiqEnvironment::Command.supports_systemd? + end + delegate :systemd?, :to => :class + def is_local? guid == MiqServer.my_guid end @@ -353,7 +367,7 @@ def is_recently_active? end def is_deleteable? - return true if MiqEnvironment::Command.is_podified? + return true if podified? if self.is_local? message = N_("Cannot delete currently used %{log_message}") % {:log_message => format_short_log_msg} @@ -405,7 +419,7 @@ def logon_status_details end def ui_address(contact_with = :hostname) - if MiqEnvironment::Command.is_podified? + if podified? ENV.fetch("APPLICATION_DOMAIN") else address = hostname if contact_with == :hostname @@ -424,7 +438,7 @@ def ui_url(contact_with = :hostname) end def ws_address - if MiqEnvironment::Command.is_podified? + if podified? ENV.fetch("APPLICATION_DOMAIN") else address = hostname if ::Settings.webservices.contactwith == 'hostname' @@ -555,7 +569,7 @@ def self.display_name(number = 1) end def self.zone_is_modifiable? - return false if MiqEnvironment::Command.is_podified? + return false if podified? Zone.visible.in_my_region.count > 1 end @@ -584,7 +598,7 @@ def self.audit_managed_resources private def zone_unchanged_in_pods - return unless MiqEnvironment::Command.is_podified? + return unless podified? errors.add(:zone, N_('cannot be changed when running in containers')) if zone_id_changed? end diff --git a/app/models/miq_server/worker_management.rb b/app/models/miq_server/worker_management.rb index fadaec4a42f..950d13bea83 100644 --- a/app/models/miq_server/worker_management.rb +++ b/app/models/miq_server/worker_management.rb @@ -12,9 +12,9 @@ class MiqServer::WorkerManagement attr_reader :my_server def self.build(my_server) - klass = if podified? + klass = if my_server.podified? Kubernetes - elsif systemd? + elsif my_server.systemd? Systemd else Process @@ -23,14 +23,6 @@ def self.build(my_server) klass.new(my_server) end - def self.podified? - MiqEnvironment::Command.is_podified? - end - - def self.systemd? - MiqEnvironment::Command.supports_systemd? - end - def initialize(my_server) @my_server = my_server @workers_lock = Sync.new