Class: Y2Network::Hostname
- Inherits:
-
Object
- Object
- Y2Network::Hostname
- Includes:
- Yast2::Equatable
- Defined in:
- src/lib/y2network/hostname.rb
Overview
Hostname configuration
Instance Attribute Summary collapse
-
#dhcp_hostname ⇒ String, Symbol
Whether to take the hostname from DHCP.
-
#installer ⇒ String?
Hostname as read from linuxrc (if set) or explicitly set in installer, nil otherwise.
-
#static ⇒ String
Hostname as got from /etc/hostname.
-
#transient ⇒ String
Dynamically defined hostname (e.g. from DHCP), defaults to static.
Instance Method Summary collapse
-
#current_static ⇒ String?
Reads the static hostname from /etc/hostname.
-
#initialize(opts = {}) ⇒ Hostname
constructor
A new instance of Hostname.
-
#proposal ⇒ String
(also: #hostname)
NOTE: we have different workflows where to query for the system hostname in running system or installation.
-
#static_modified? ⇒ Boolean
Returns whether the static hostname is different than the current one.
Constructor Details
#initialize(opts = {}) ⇒ Hostname
receive an array instead all these arguments
Returns a new instance of Hostname.
53 54 55 56 57 58 |
# File 'src/lib/y2network/hostname.rb', line 53 def initialize(opts = {}) @static = opts[:static] @transient = opts[:transient] || @static @installer = opts[:installer] @dhcp_hostname = opts[:dhcp_hostname] end |
Instance Attribute Details
#dhcp_hostname ⇒ String, Symbol
Returns Whether to take the hostname from DHCP. It can be an interface name (String), :any for any interface or :none from no taking the hostname from DHCP.
44 45 46 |
# File 'src/lib/y2network/hostname.rb', line 44 def dhcp_hostname @dhcp_hostname end |
#installer ⇒ String?
Returns hostname as read from linuxrc (if set) or explicitly set in installer, nil otherwise.
39 40 41 |
# File 'src/lib/y2network/hostname.rb', line 39 def installer @installer end |
#static ⇒ String
Returns hostname as got from /etc/hostname.
32 33 34 |
# File 'src/lib/y2network/hostname.rb', line 32 def static @static end |
#transient ⇒ String
Returns dynamically defined hostname (e.g. from DHCP), defaults to static.
35 36 37 |
# File 'src/lib/y2network/hostname.rb', line 35 def transient @transient end |
Instance Method Details
#current_static ⇒ String?
Reads the static hostname from /etc/hostname
79 80 81 82 |
# File 'src/lib/y2network/hostname.rb', line 79 def current_static name = Yast::SCR.Read(Yast::Path.new(".target.string"), "/etc/hostname").to_s.strip name.empty? ? nil : name end |
#proposal ⇒ String Also known as: hostname
NOTE: we have different workflows where to query for the system hostname in running system or installation. This presents result of the particular workflow (depending when the object was created)
64 65 66 67 68 69 70 |
# File 'src/lib/y2network/hostname.rb', line 64 def proposal if Yast::Stage.initial hostname_for_installer else hostname_for_running_system end end |
#static_modified? ⇒ Boolean
Returns whether the static hostname is different than the current one
@return [Boolean]
87 88 89 |
# File 'src/lib/y2network/hostname.rb', line 87 def static_modified? @static != current_static.to_s end |