add consolidated methods, update cli

This commit is contained in:
2026-01-19 11:50:51 -05:00
parent b4f49be2c6
commit 63ef233357
3 changed files with 83 additions and 1 deletions

View File

@@ -203,3 +203,79 @@ func (c *Client) GetAllSystems(ctx context.Context) (map[string]*SystemConfig, e
wg.Wait()
return results, errs
}
// GetEdgeOS retrieves all information for a specific device,
// combining AuthInfo and Config.
func (c *Client) GetEdgeOS(ctx context.Context, host string) (*EdgeOS, error) {
_, err := c.getDeviceByHost(host)
if err != nil {
return nil, err
}
eos := &EdgeOS{}
var (
mu sync.Mutex
wg sync.WaitGroup
errs error
)
// Fetch auth info and config in parallel
wg.Go(func() {
res, err := c.GetAuthInfo(ctx, host)
mu.Lock()
defer mu.Unlock()
if err != nil {
errs = errors.Join(errs, err)
return
}
eos.AuthInfo = res
})
wg.Go(func() {
res, err := c.GetConfig(ctx, host)
mu.Lock()
defer mu.Unlock()
if err != nil {
errs = errors.Join(errs, err)
return
}
eos.Config = res
})
wg.Wait()
return eos, errs
}
// GetAllEdgeOS retrieves all information for all devices.
func (c *Client) GetAllEdgeOS(ctx context.Context) (map[string]*EdgeOS, error) {
results := make(map[string]*EdgeOS)
var (
mu sync.Mutex
wg sync.WaitGroup
errs error
)
c.mu.RLock()
hosts := make([]string, 0, len(c.devices))
for h := range c.devices {
hosts = append(hosts, h)
}
c.mu.RUnlock()
for _, host := range hosts {
wg.Go(func() {
res, err := c.GetEdgeOS(ctx, host)
if err != nil {
mu.Lock()
errs = errors.Join(errs, err)
mu.Unlock()
return
}
mu.Lock()
results[host] = res
mu.Unlock()
})
}
wg.Wait()
return results, errs
}