Class: Y2Network::Hostname

Inherits:
Object
  • Object
show all
Includes:
Yast2::Equatable
Defined in:
src/lib/y2network/hostname.rb

Overview

Hostname configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Hostname

TODO:

receive an array instead all these arguments

Returns a new instance of Hostname.

Parameters:

  • opts (Hash) (defaults to: {})

    hostname configuration options

Options Hash (opts):

  • :static (String)
  • :transient (String)
  • :installer (String)
  • :dhcp_hostname (String, Symbol)


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_hostnameString, 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.

Returns:

  • (String, Symbol)

    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

#installerString?

Returns hostname as read from linuxrc (if set) or explicitly set in installer, nil otherwise.

Returns:

  • (String, nil)

    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

#staticString

Returns hostname as got from /etc/hostname.

Returns:

  • (String)

    hostname as got from /etc/hostname



32
33
34
# File 'src/lib/y2network/hostname.rb', line 32

def static
  @static
end

#transientString

Returns dynamically defined hostname (e.g. from DHCP), defaults to static.

Returns:

  • (String)

    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_staticString?

Reads the static hostname from /etc/hostname

Returns:

  • (String, nil)


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

#proposalString 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)

Returns:

  • (String)

    Hostname presented to user in different modes.



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]

Returns:

  • (Boolean)


87
88
89
# File 'src/lib/y2network/hostname.rb', line 87

def static_modified?
  @static != current_static.to_s
end