GetGroupClusterResources retrieves cluster resources from all profiles in the group. This provides a unified view of all resources across all connected profiles. fresh flag bypasses caches when true.
(ctx context.Context, fresh bool)
| 272 | // This provides a unified view of all resources across all connected profiles. |
| 273 | // fresh flag bypasses caches when true. |
| 274 | func (m *GroupClientManager) GetGroupClusterResources(ctx context.Context, fresh bool) ([]*Node, []*VM, error) { |
| 275 | // Use goroutines to fetch nodes and VMs concurrently for better performance |
| 276 | type result struct { |
| 277 | nodes []*Node |
| 278 | vms []*VM |
| 279 | err error |
| 280 | } |
| 281 | |
| 282 | nodesChan := make(chan result, 1) |
| 283 | vmsChan := make(chan result, 1) |
| 284 | |
| 285 | // Fetch nodes |
| 286 | go func() { |
| 287 | if fresh { |
| 288 | // Selectively invalidate cluster-level cache keys per profile |
| 289 | // instead of wiping the entire cache (preserves node disks, updates, etc.) |
| 290 | for _, pc := range m.GetConnectedClients() { |
| 291 | if pc.Client != nil { |
| 292 | pc.Client.ClearClusterCache() |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | nodes, err := m.GetGroupNodes(ctx) |
| 297 | nodesChan <- result{nodes: nodes, err: err} |
| 298 | }() |
| 299 | |
| 300 | // Fetch VMs |
| 301 | go func() { |
| 302 | vms, err := m.GetGroupVMs(ctx) |
| 303 | vmsChan <- result{vms: vms, err: err} |
| 304 | }() |
| 305 | |
| 306 | // Wait for both operations to complete |
| 307 | nodesResult := <-nodesChan |
| 308 | vmsResult := <-vmsChan |
| 309 | |
| 310 | if nodesResult.err != nil { |
| 311 | return nil, nil, fmt.Errorf("failed to get group nodes: %w", nodesResult.err) |
| 312 | } |
| 313 | |
| 314 | if vmsResult.err != nil { |
| 315 | return nil, nil, fmt.Errorf("failed to get group VMs: %w", vmsResult.err) |
| 316 | } |
| 317 | |
| 318 | return nodesResult.nodes, vmsResult.vms, nil |
| 319 | } |
| 320 | |
| 321 | // GetNodeFromGroup retrieves a specific node from a specific profile. |
| 322 | // This is useful when you need to perform operations on a node and need to ensure |
no test coverage detected