Browse Source

zones: introduce Machine.PublicAddresses()

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head v0.0.1
Alejandro Mery 1 year ago
parent
commit
7e6c53c5f5
  1. 3
      pkg/zones/machine.go
  2. 26
      pkg/zones/machine_scan.go
  3. 4
      pkg/zones/scan.go

3
pkg/zones/machine.go

@ -1,6 +1,7 @@
package zones
import (
"net/netip"
"strconv"
"strings"
"sync"
@ -13,6 +14,8 @@ type Machine struct {
zone *Zone
id int
Name string
PublicAddresses []netip.Addr
}
func (m *Machine) String() string {

26
pkg/zones/machine_scan.go

@ -0,0 +1,26 @@
package zones
import (
"context"
"net/netip"
"time"
)
func (m *Machine) lookupNetIP() ([]netip.Addr, error) {
timeout := 2 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return m.zone.zones.resolver.LookupNetIP(ctx, "ip", m.FullName())
}
func (m *Machine) updatePublicAddresses() error {
addrs, err := m.lookupNetIP()
if err != nil {
return err
}
m.PublicAddresses = addrs
return nil
}

4
pkg/zones/scan.go

@ -43,6 +43,10 @@ func (z *Zone) scan() error {
Name: e.Name(),
}
if err := m.updatePublicAddresses(); err != nil {
return err
}
z.Machines = append(z.Machines, m)
}
}

Loading…
Cancel
Save