Browse Source

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

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

12
pkg/zones/machine_scan.go

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

Loading…
Cancel
Save