add consolidated methods, update cli
This commit is contained in:
@@ -44,5 +44,5 @@ func fetchEdgeOSDevice(ctx context.Context, clientConf *config.ClientConfig) (an
|
|||||||
return nil, fmt.Errorf("login failed: %w", err)
|
return nil, fmt.Errorf("login failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.GetConfig(ctx, clientConf.Host)
|
return client.GetEdgeOS(ctx, clientConf.Host)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,3 +203,79 @@ func (c *Client) GetAllSystems(ctx context.Context) (map[string]*SystemConfig, e
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
return results, errs
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package edgeos
|
package edgeos
|
||||||
|
|
||||||
|
// EdgeOS combines all device information into one response.
|
||||||
|
type EdgeOS struct {
|
||||||
|
AuthInfo *AuthResponse `json:"authInfo,omitempty"`
|
||||||
|
Config *ConfigData `json:"config,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// AuthResponse represents the authentication response from login2 endpoint.
|
// AuthResponse represents the authentication response from login2 endpoint.
|
||||||
type AuthResponse struct {
|
type AuthResponse struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
|
|||||||
Reference in New Issue
Block a user