GetFastFreshClusterStatus retrieves fresh cluster status (cache-busting) and returns basic data immediately. VM enrichment runs in the background and the provided callback is called when enrichment completes (with any error that occurred). This gives the UI instant node/VM names while detailed guest
(onEnrichmentComplete func(error))
| 354 | // is called when enrichment completes (with any error that occurred). |
| 355 | // This gives the UI instant node/VM names while detailed guest agent data loads asynchronously. |
| 356 | func (c *Client) GetFastFreshClusterStatus(onEnrichmentComplete func(error)) (*Cluster, error) { |
| 357 | // Clear cluster-level cache so we get truly fresh data |
| 358 | c.ClearClusterCache() |
| 359 | |
| 360 | cluster := &Cluster{ |
| 361 | Nodes: make([]*Node, 0), |
| 362 | StorageManager: NewStorageManager(), |
| 363 | lastUpdate: time.Now(), |
| 364 | } |
| 365 | |
| 366 | // 1. Get basic cluster status (node names, online/offline) |
| 367 | if err := c.getClusterBasicStatus(cluster); err != nil { |
| 368 | return nil, err |
| 369 | } |
| 370 | |
| 371 | // 2. Get cluster resources fresh (TTL=0) — gives us node stats + VM names/status |
| 372 | if err := c.processClusterResourcesWithCache(cluster, 0); err != nil { |
| 373 | return nil, err |
| 374 | } |
| 375 | |
| 376 | // 3. Calculate cluster-wide totals from the basic data |
| 377 | c.calculateClusterTotals(cluster) |
| 378 | |
| 379 | c.Cluster = cluster |
| 380 | |
| 381 | // 4. Run VM enrichment in background — guest agent IPs, filesystems, configs |
| 382 | go func() { |
| 383 | c.logger.Debug("[FAST-FRESH] Starting background VM enrichment for %d nodes", len(cluster.Nodes)) |
| 384 | |
| 385 | // Reset guestAgentChecked before enrichment (same as startup path) |
| 386 | for _, node := range cluster.Nodes { |
| 387 | if node.Online && node.VMs != nil { |
| 388 | for _, vm := range node.VMs { |
| 389 | vm.guestAgentChecked = false |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | var enrichErr error |
| 395 | if err := c.EnrichVMs(cluster); err != nil { |
| 396 | c.logger.Debug("[FAST-FRESH] Error enriching VM data: %v", err) |
| 397 | enrichErr = err |
| 398 | } |
| 399 | |
| 400 | // Retry QEMU VMs with missing guest agent data (same as startup path) |
| 401 | time.Sleep(3 * time.Second) |
| 402 | for _, node := range cluster.Nodes { |
| 403 | if !node.Online || node.VMs == nil { |
| 404 | continue |
| 405 | } |
| 406 | for _, vm := range node.VMs { |
| 407 | if vm.Status == VMStatusRunning && vm.Type == VMTypeQemu && vm.AgentEnabled && (!vm.AgentRunning || len(vm.NetInterfaces) == 0) { |
| 408 | if err := c.GetVmStatus(vm); err != nil { |
| 409 | if strings.Contains(err.Error(), "guest agent is not running") { |
| 410 | // Expected: agent not yet ready; not a reportable error. |
| 411 | continue |
| 412 | } |
| 413 | // Unexpected retry error: aggregate into enrichErr so the caller |
no test coverage detected