feat: suggest the host behind unknown DNS names
A name neither in NetBox nor in the cache is resolved through DNS, using dns.domains for short names. The hosts owning the address in NetBox or the cache are offered together with a direct connection; without a terminal the suggestions are part of the error. Afterwards netssh offers to save the name as a link. info, open and whois use the same lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5c41a5eb6f
commit
793f095e80
5 files changed
+531
-9
No files matched your search
+5
-2
@@ -276,13 +276,16 @@ func upsertResolved(c *cache.Cache, entry cache.Entry) (previous string) {
|
||||
// resolveTarget finds host in the cache (also by shortcut) or NetBox and
|
||||
// resolves its address. It exits on failure.
|
||||
func resolveTarget(cfg *config.Config, host string) resolvedHost {
|
||||
result, err := resolveTargetE(cfg, host, true)
|
||||
result, err := resolveOrSuggest(cfg, host, true)
|
||||
if err != nil {
|
||||
fatalf("%v", err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
func resolveTargetE(cfg *config.Config, host string, record bool) (resolvedHost, error) {
|
||||
if target, ok := cfg.Link(host); ok {
|
||||
host = target
|
||||
}
|
||||
c := newCache(cfg)
|
||||
_ = c.Load()
|
||||
if record {
|
||||
@@ -343,7 +346,7 @@ func resolveTargetE(cfg *config.Config, host string, record bool) (resolvedHost,
|
||||
}
|
||||
|
||||
if !cfg.HasNetBox() {
|
||||
return resolvedHost{}, fmt.Errorf("host %q is not in hosts: and no NetBox is configured (netssh configure)", host)
|
||||
return resolvedHost{}, fmt.Errorf("host %q is not in hosts: and no NetBox is configured (netssh configure): %w", host, netbox.ErrHostNotFound)
|
||||
}
|
||||
nbClient := newNetBoxClient(cfg)
|
||||
|
||||
|
||||
Reference in new issue
Block a user