Class: Y2Network::Wicked::HostnameReader
- Inherits:
-
Object
- Object
- Y2Network::Wicked::HostnameReader
- Includes:
- Yast::Logger, Yast::Wicked
- Defined in:
- src/lib/y2network/wicked/hostname_reader.rb
Overview
This class is responsible for reading the hostname
Depending on different circunstamces, the hostname can be read from different places (from a
simple call to /usr/bin/hostname
to the /etc/install.inf
during installation).
Constant Summary
Constants included from Yast::Wicked
Yast::Wicked::BASH_OUTPUT_PATH, Yast::Wicked::BASH_PATH, Yast::Wicked::IBFT_CMD, Yast::Wicked::WICKED_PATH
Instance Method Summary collapse
-
#config ⇒ Y2Network::Hostname
Return configuration from sysconfig files.
-
#dhcp_hostname ⇒ String, ...
Returns whether the hostname should be taken from DHCP.
-
#hostname_from_dhcp ⇒ String?
Queries for hostname obtained as part of dhcp configuration.
-
#hostname_from_install_inf ⇒ String?
Reads the hostname from the /etc/install.inf file.
-
#hostname_from_resolver ⇒ String?
Reads the (transient) hostname known to the resolver.
-
#hostname_from_system ⇒ String?
Reads the transient hostname or system (local) hostname.
-
#static_hostname ⇒ String?
Reads the static hostname from /etc/hostname.
Methods included from Yast::Wicked
#firmware_configured_by?, #firmware_interfaces, #firmware_interfaces_by_extension, #ibft_interfaces, #parse_hostname, #parse_ntp_servers, #query_wicked, #reload_config
Instance Method Details
#config ⇒ Y2Network::Hostname
Return configuration from sysconfig files
46 47 48 49 50 51 52 53 |
# File 'src/lib/y2network/wicked/hostname_reader.rb', line 46 def config Y2Network::Hostname.new( installer: hostname_from_install_inf, static: static_hostname, transient: hostname_from_system, dhcp_hostname: dhcp_hostname ) end |
#dhcp_hostname ⇒ String, ...
Returns whether the hostname should be taken from DHCP
59 60 61 62 63 64 65 66 67 68 69 |
# File 'src/lib/y2network/wicked/hostname_reader.rb', line 59 def dhcp_hostname value = Yast::SCR.Read(Yast::Path.new(".sysconfig.network.dhcp.DHCLIENT_SET_HOSTNAME")) return :any if value == "yes" files = CFA::InterfaceFile.all file = files.find do |f| f.load f.dhclient_set_hostname == "yes" end file ? file.interface : :none end |
#hostname_from_dhcp ⇒ String?
Queries for hostname obtained as part of dhcp configuration
123 124 125 126 127 128 129 130 131 132 133 |
# File 'src/lib/y2network/wicked/hostname_reader.rb', line 123 def hostname_from_dhcp # We currently cannot use connections for getting only dhcp aware configurations here # bcs this can be called during Y2Network::Config initialization and this is # acceptable replacement for this case. ifaces = CFA::InterfaceFile.all.map(&:interface) dhcp_hostname = ifaces.map { |i| parse_hostname(i) }.compact.first log.info("Hostname obtained from DHCP: #{dhcp_hostname}") dhcp_hostname end |
#hostname_from_install_inf ⇒ String?
Reads the hostname from the /etc/install.inf file
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'src/lib/y2network/wicked/hostname_reader.rb', line 74 def hostname_from_install_inf install_inf_hostname = Yast::SCR.Read(Yast::Path.new(".etc.install_inf.Hostname")) || "" log.info("Got #{install_inf_hostname} from install.inf") return nil if install_inf_hostname.empty? # if the name is actually IP, try to resolve it (bnc#556613, bnc#435649) if Yast::IP.Check(install_inf_hostname) fqdn = Yast::NetHwDetection.ResolveIP(install_inf_hostname) log.info("Got #{fqdn} after resolving IP from install.inf") else fqdn = install_inf_hostname end host, _domain = *Yast::Hostname.SplitFQ(fqdn) return nil if host.nil? || host.empty? host end |
#hostname_from_resolver ⇒ String?
Reads the (transient) hostname known to the resolver
97 98 99 100 101 |
# File 'src/lib/y2network/wicked/hostname_reader.rb', line 97 def hostname_from_resolver Yast::Execute.on_target!("/usr/bin/hostname", "--fqdn", stdout: :capture).strip rescue Cheetah::ExecutionFailed nil end |
#hostname_from_system ⇒ String?
Reads the transient hostname or system (local) hostname
106 107 108 109 110 |
# File 'src/lib/y2network/wicked/hostname_reader.rb', line 106 def hostname_from_system Yast::Execute.on_target!("/usr/bin/hostname", stdout: :capture).strip rescue Cheetah::ExecutionFailed static_hostname end |