RefreshNodeData refreshes data for a specific node by clearing its cache entries and fetching fresh data.
(nodeName string)
| 474 | |
| 475 | // RefreshNodeData refreshes data for a specific node by clearing its cache entries and fetching fresh data. |
| 476 | func (c *Client) RefreshNodeData(nodeName string) (*Node, error) { |
| 477 | // Clear cache entries for this specific node |
| 478 | nodeStatusPath := fmt.Sprintf("/nodes/%s/status", nodeName) |
| 479 | nodeVersionPath := fmt.Sprintf("/nodes/%s/version", nodeName) |
| 480 | nodeConfigPath := fmt.Sprintf("/nodes/%s/config", nodeName) |
| 481 | |
| 482 | // Generate cache keys and delete them |
| 483 | statusCacheKey := fmt.Sprintf("proxmox_api_%s_%s", c.baseURL, nodeStatusPath) |
| 484 | statusCacheKey = strings.ReplaceAll(statusCacheKey, "/", "_") |
| 485 | |
| 486 | versionCacheKey := fmt.Sprintf("proxmox_api_%s_%s", c.baseURL, nodeVersionPath) |
| 487 | versionCacheKey = strings.ReplaceAll(versionCacheKey, "/", "_") |
| 488 | |
| 489 | configCacheKey := fmt.Sprintf("proxmox_api_%s_%s", c.baseURL, nodeConfigPath) |
| 490 | configCacheKey = strings.ReplaceAll(configCacheKey, "/", "_") |
| 491 | |
| 492 | // Delete cache entries (ignore errors as they might not exist) |
| 493 | _ = c.cache.Delete(statusCacheKey) |
| 494 | _ = c.cache.Delete(versionCacheKey) |
| 495 | _ = c.cache.Delete(configCacheKey) |
| 496 | |
| 497 | c.logger.Debug("Cleared cache for node %s", nodeName) |
| 498 | |
| 499 | // Get the current node to preserve certain data like VMs and online status |
| 500 | var originalNode *Node |
| 501 | |
| 502 | if c.Cluster != nil { |
| 503 | for _, node := range c.Cluster.Nodes { |
| 504 | if node != nil && node.Name == nodeName { |
| 505 | originalNode = node |
| 506 | |
| 507 | break |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | // Fetch node status, disks, and updates concurrently. |
| 513 | // Disks and updates only need the node name and are independent of each other. |
| 514 | var ( |
| 515 | freshNode *Node |
| 516 | statusErr error |
| 517 | disks []NodeDisk |
| 518 | updates []NodeUpdate |
| 519 | wg sync.WaitGroup |
| 520 | ) |
| 521 | |
| 522 | wg.Add(3) //nolint:mnd // status + disks + updates |
| 523 | |
| 524 | go func() { |
| 525 | defer wg.Done() |
| 526 | |
| 527 | freshNode, statusErr = c.GetNodeStatus(nodeName) |
| 528 | }() |
| 529 | |
| 530 | go func() { |
| 531 | defer wg.Done() |
| 532 | |
| 533 | if d, err := c.GetNodeDisks(nodeName); err == nil { |
no test coverage detected