Browse Source

zones: export Machine.LookupNetIP() and Machine.UpdatePublicAddresses()

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/5/head
Alejandro Mery 10 months ago
parent
commit
94daf5ad59
  1. 12
      pkg/zones/machine_scan.go

12
pkg/zones/machine_scan.go

@ -7,8 +7,9 @@ import (
"time" "time"
) )
func (m *Machine) lookupNetIP() ([]netip.Addr, error) { // LookupNetIP uses the DNS Resolver to get the public addresses associated
timeout := 2 * time.Second // to a Machine
func (m *Machine) LookupNetIP(timeout time.Duration) ([]netip.Addr, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
@ -16,8 +17,9 @@ func (m *Machine) lookupNetIP() ([]netip.Addr, error) {
return m.zone.zones.resolver.LookupNetIP(ctx, "ip", m.FullName()) return m.zone.zones.resolver.LookupNetIP(ctx, "ip", m.FullName())
} }
func (m *Machine) updatePublicAddresses() error { // UpdatePublicAddresses uses the DNS Resolver to set Machine.PublicAddresses
addrs, err := m.lookupNetIP() func (m *Machine) UpdatePublicAddresses() error {
addrs, err := m.LookupNetIP(2 * time.Second)
if err != nil { if err != nil {
return err return err
} }
@ -60,7 +62,7 @@ func (m *Machine) scan(opts *ScanOptions) error {
} }
if !opts.DontResolvePublicAddresses { if !opts.DontResolvePublicAddresses {
return m.updatePublicAddresses() return m.UpdatePublicAddresses()
} }
return nil return nil

Loading…
Cancel
Save