FastGetClusterStatus retrieves only essential cluster status without VM enrichment for fast application startup. VM details will be loaded in the background. The onEnrichmentComplete callback is called when background VM enrichment finishes.
(onEnrichmentComplete func())
| 83 | // for fast application startup. VM details will be loaded in the background. |
| 84 | // The onEnrichmentComplete callback is called when background VM enrichment finishes. |
| 85 | func (c *Client) FastGetClusterStatus(onEnrichmentComplete func()) (*Cluster, error) { |
| 86 | cluster := &Cluster{ |
| 87 | Nodes: make([]*Node, 0), |
| 88 | StorageManager: NewStorageManager(), |
| 89 | lastUpdate: time.Now(), |
| 90 | } |
| 91 | |
| 92 | // 1. Get basic cluster status and node list |
| 93 | if err := c.getClusterBasicStatus(cluster); err != nil { |
| 94 | return nil, err |
| 95 | } |
| 96 | |
| 97 | // 2. Get cluster resources and populate all nodes, VMs, and storage |
| 98 | if err := c.processClusterResources(cluster); err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | // 3. Selectively enrich nodes with missing details (Version, KernelVersion, CPUInfo, LoadAvg) |
| 103 | if err := c.enrichMissingNodeDetails(cluster); err != nil { |
| 104 | return nil, err |
| 105 | } |
| 106 | |
| 107 | // 4. Calculate cluster-wide totals |
| 108 | c.calculateClusterTotals(cluster) |
| 109 | |
| 110 | // 5. Store the cluster in the client |
| 111 | c.Cluster = cluster |
| 112 | |
| 113 | // 6. Start background VM enrichment |
| 114 | go func() { |
| 115 | c.logger.Debug("[BACKGROUND] Starting VM enrichment for %d nodes", len(cluster.Nodes)) |
| 116 | |
| 117 | // Count VMs that will be enriched |
| 118 | var runningVMCount int |
| 119 | |
| 120 | for _, node := range cluster.Nodes { |
| 121 | if node.Online && node.VMs != nil { |
| 122 | for _, vm := range node.VMs { |
| 123 | if vm.Status == VMStatusRunning { |
| 124 | runningVMCount++ |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | c.logger.Debug("[BACKGROUND] Found %d running VMs to enrich", runningVMCount) |
| 131 | |
| 132 | // Reset guestAgentChecked for all VMs before enrichment |
| 133 | for _, node := range cluster.Nodes { |
| 134 | if node.Online && node.VMs != nil { |
| 135 | for _, vm := range node.VMs { |
| 136 | vm.guestAgentChecked = false |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if err := c.EnrichVMs(cluster); err != nil { |
| 142 | c.logger.Debug("[BACKGROUND] Error enriching VM data: %v", err) |
no test coverage detected