GetStoragePoolNodeConfigs returns the node-specific configuration of all nodes grouped by node name, for the given poolID. If the storage pool is not defined on all nodes, an error is returned.
(ctx context.Context, poolID int64)
| 505 | // |
| 506 | // If the storage pool is not defined on all nodes, an error is returned. |
| 507 | func (c *ClusterTx) GetStoragePoolNodeConfigs(ctx context.Context, poolID int64) (map[string]map[string]string, error) { |
| 508 | // Fetch all nodes. |
| 509 | nodes, err := c.GetNodes(ctx) |
| 510 | if err != nil { |
| 511 | return nil, err |
| 512 | } |
| 513 | |
| 514 | // Fetch the names of the nodes where the storage pool is defined. |
| 515 | stmt := ` |
| 516 | SELECT nodes.name FROM nodes |
| 517 | LEFT JOIN storage_pools_nodes ON storage_pools_nodes.node_id = nodes.id |
| 518 | LEFT JOIN storage_pools ON storage_pools_nodes.storage_pool_id = storage_pools.id |
| 519 | WHERE storage_pools.id = ? AND storage_pools.state = ? |
| 520 | ` |
| 521 | defined, err := query.SelectStrings(ctx, c.tx, stmt, poolID, StoragePoolPending) |
| 522 | if err != nil { |
| 523 | return nil, err |
| 524 | } |
| 525 | |
| 526 | // Figure which nodes are missing |
| 527 | missing := []string{} |
| 528 | for _, node := range nodes { |
| 529 | if !slices.Contains(defined, node.Name) { |
| 530 | missing = append(missing, node.Name) |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | if len(missing) > 0 { |
| 535 | return nil, fmt.Errorf("Pool not defined on nodes: %s", strings.Join(missing, ", ")) |
| 536 | } |
| 537 | |
| 538 | configs := map[string]map[string]string{} |
| 539 | for _, node := range nodes { |
| 540 | config, err := query.SelectConfig(ctx, c.tx, "storage_pools_config", "storage_pool_id=? AND node_id=?", poolID, node.ID) |
| 541 | if err != nil { |
| 542 | return nil, err |
| 543 | } |
| 544 | |
| 545 | configs[node.Name] = config |
| 546 | } |
| 547 | |
| 548 | return configs, nil |
| 549 | } |
| 550 | |
| 551 | // GetStoragePoolNames returns the names of all storage pools. |
| 552 | func (c *ClusterTx) GetStoragePoolNames(ctx context.Context) ([]string, error) { |