Class: Yast::HostnameClass
- Inherits:
-
Module
- Object
- Module
- Yast::HostnameClass
- Defined in:
- ../../src/modules/Hostname.rb
Instance Method Summary (collapse)
-
- (Object) Check(host)
Check syntax of hostname entry (that is a domain name component, unqualified, without dots).
-
- (Object) CheckDomain(domain)
Check syntax of domain entry.
-
- (Object) CheckFQ(host)
Check syntax of fully qualified hostname.
-
- (Object) CurrentDomain
Retrieve currently set domain name.
-
- (Object) CurrentFQ
Retrieve currently set fully qualified hostname (uses hostname –fqdn).
-
- (Object) CurrentHostname
Retrieve currently set (short) hostname.
- - (Object) main
-
- (Object) MergeFQ(hostname, domain)
Merge short hostname and domain to full-qualified host name.
-
- (Array) SplitFQ(fqhostname)
Split FQ hostname to hostname and domain name.
-
- (Object) ValidDomain
describe a valid domain name.
-
- (Object) ValidFQ
describe a valid FQ host name.
-
- (Object) ValidHost
describe a valid host name.
Instance Method Details
- (Object) Check(host)
Check syntax of hostname entry (that is a domain name component, unqualified, without dots)
83 84 85 86 87 88 |
# File '../../src/modules/Hostname.rb', line 83 def Check(host) if host.nil? || host == "" || Ops.greater_than(Builtins.size(host), 63) return false end Builtins.regexpmatch(host, "^[[:alnum:]]([[:alnum:]-]*[[:alnum:]])?$") end |
- (Object) CheckDomain(domain)
Check syntax of domain entry
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File '../../src/modules/Hostname.rb', line 93 def CheckDomain(domain) return false if domain.nil? || domain == "" # if "domain" contains "." character as last character remove it before validation (but it's valid) if Ops.greater_than(Builtins.size(domain), 1) if Builtins.substring(domain, Ops.subtract(Builtins.size(domain), 1), 1) == "." domain = Builtins.substring( domain, 0, Ops.subtract(Builtins.size(domain), 1) ) end end l = Builtins.splitstring(domain, ".") return false if Builtins.contains(Builtins.maplist(l) { |h| Check(h) }, false) !Builtins.regexpmatch(domain, "\\.[[:digit:]][^.]*$") end |
- (Object) CheckFQ(host)
Check syntax of fully qualified hostname
113 114 115 |
# File '../../src/modules/Hostname.rb', line 113 def CheckFQ(host) CheckDomain(host) end |
- (Object) CurrentDomain
Retrieve currently set domain name
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File '../../src/modules/Hostname.rb', line 207 def CurrentDomain domain = "" fqhostname = CurrentFQ() # the same as above, if FQDN is IP address # let's claim domainname as empty (#415109) if !IP.Check(fqhostname) data = SplitFQ(fqhostname) if data != [] && Ops.greater_than(Builtins.size(data), 1) domain = Ops.get(data, 1, "") end end Builtins.y2debug("Current domainname: %1", domain) domain end |
- (Object) CurrentFQ
Retrieve currently set fully qualified hostname (uses hostname –fqdn)
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File '../../src/modules/Hostname.rb', line 157 def CurrentFQ fqhostname = "" hostname_data = Convert.to_map( SCR.Execute(path(".target.bash_output"), "hostname --fqdn") ) if hostname_data.nil? || hostname_data["exit"] != 0 || invalid_hostname?(hostname_data["stdout"].to_s.strip) fqhostname = if FileUtils.Exists("/etc/hostname") SCR.Read(path(".target.string"), "/etc/hostname") else "" end if fqhostname == "" || fqhostname.nil? # last resort (#429792) fqhostname = "linux.#{@DefaultDomain}" end Builtins.y2warning("Using fallback hostname %1", fqhostname) else fqhostname = Ops.get_string(hostname_data, "stdout", "") end fqhostname = String.FirstChunk(fqhostname, "\n") Builtins.y2debug("Current FQDN: %1", fqhostname) fqhostname end |
- (Object) CurrentHostname
Retrieve currently set (short) hostname
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File '../../src/modules/Hostname.rb', line 187 def CurrentHostname hostname = "" fqhostname = CurrentFQ() # current FQDN is IP address - it happens, esp. in inst-sys :) # so let's not cut it into pieces (#415109) if IP.Check(fqhostname) hostname = fqhostname else data = SplitFQ(fqhostname) hostname = Ops.get(data, 0, "") if data != [] Builtins.y2debug("Current hostname: %1", hostname) end hostname end |
- (Object) main
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File '../../src/modules/Hostname.rb', line 35 def main textdomain "base" Yast.import "IP" Yast.import "String" Yast.import "FileUtils" Yast.import "Mode" # i18n characters in domain names are still not allowed # # @note This is an unstable API function and may change in the future @ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-" @ValidCharsDomain = Ops.add(@ValidChars, ".") @ValidCharsFQ = @ValidCharsDomain @DefaultDomain = "" end |
- (Object) MergeFQ(hostname, domain)
Merge short hostname and domain to full-qualified host name
149 150 151 152 |
# File '../../src/modules/Hostname.rb', line 149 def MergeFQ(hostname, domain) return hostname if domain == "" || domain.nil? Ops.add(Ops.add(hostname, "."), domain) end |
- (Array) SplitFQ(fqhostname)
Split FQ hostname to hostname and domain name
If domain is not defined, returns empty string.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File '../../src/modules/Hostname.rb', line 125 def SplitFQ(fqhostname) if fqhostname == "" || fqhostname.nil? Builtins.y2error("Bad FQ hostname: %1", fqhostname) return [] end hn = "" dn = "" dot = Builtins.findfirstof(fqhostname, ".") if !dot.nil? hn = Builtins.substring(fqhostname, 0, dot) dn = Builtins.substring(fqhostname, Ops.add(dot, 1)) else hn = fqhostname end [hn, dn] end |
- (Object) ValidDomain
describe a valid domain name
54 55 56 57 58 59 60 61 |
# File '../../src/modules/Hostname.rb', line 54 def ValidDomain # Translators: dot: ".", hyphen: "-" _( "A valid domain name consists of components separated by dots.\n" \ "Each component contains letters, digits, and hyphens. A hyphen may not\n" \ "start or end a component and the last component may not begin with a digit." ) end |
- (Object) ValidFQ
describe a valid FQ host name
74 75 76 |
# File '../../src/modules/Hostname.rb', line 74 def ValidFQ ValidDomain() end |
- (Object) ValidHost
describe a valid host name
65 66 67 68 69 70 |
# File '../../src/modules/Hostname.rb', line 65 def ValidHost # Translators: hyphen: "-" _( "A valid host name consists of letters, digits, and hyphens.\nA host name may not begin or end with a hyphen.\n" ) end |