Skip to content

Commit

Permalink
Updated CSS AddClusterNodes function
Browse files Browse the repository at this point in the history
  • Loading branch information
vineet-pruthi authored and sattila1999 committed Dec 14, 2024
1 parent 94abc92 commit 3a7ce65
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
4 changes: 1 addition & 3 deletions acceptance/openstack/css/v1/cluster_add_nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ func TestAddClusterNodes(t *testing.T) {
clusterID := getEnvVar("CSS_CLUSTER_ID")

_, err = clusters.AddClusterNodes(client, clusterID, nodeType, clusters.AddNodesOpts{
// css.medium.8: ced8d1a7-eff8-4e30-a3de-cd9578fd518f
// css.xlarge.2: d9dc06ae-b9c4-4ef4-acd8-953ef4205e27
Flavor: "d9dc06ae-b9c4-4ef4-acd8-953ef4205e27",
Flavor: "css.xlarge.2",
NodeSize: 1,
VolumeType: "HIGH",
})
Expand Down
39 changes: 35 additions & 4 deletions openstack/css/v1/clusters/AddClusterNodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ type AddNodesOpts struct {
// If the node type is ess-client, the number of nodes must be in the range 1 to 32.
NodeSize int `json:"node_size" required:"true"`
// Flavor - Flavor ID.
Flavor string `json:"flavor_ref" required:"true"`
Flavor string `json:"-" required:"true"`
// Type of the volume.
// One of:
// - `COMMON`: Common I/O
// - `HIGH`: High I/O
// - `ULTRAHIGH`: Ultra-high I/O
VolumeType string `json:"volume_type" required:"true"`
}

type apiAddNodesOpts struct {
// NodeSize - Number of nodes. The value range is 1 to 32.
// If the node type is ess-master, the number of nodes must be an odd number in the range 3 to 10.
// If the node type is ess-client, the number of nodes must be in the range 1 to 32.
NodeSize int `json:"node_size" required:"true"`
// ID of the new flavor.
FlavorRef string `json:"flavor_ref" required:"true"`
// Type of the volume.
// One of:
// - `COMMON`: Common I/O
Expand All @@ -23,14 +38,31 @@ type AddNodesOpts struct {
}

func AddClusterNodes(client *golangsdk.ServiceClient, clusterID string, NodeType string, opts AddNodesOpts) (*AddNodesResponse, error) {
var (
url string
flavorID string
err error
res AddNodesResponse
)

flavorID, err = getFlavorIDByName(client, opts.Flavor, NodeType)
if err != nil {
return &res, err
}

apiOpts := apiAddNodesOpts{
NodeSize: opts.NodeSize,
VolumeType: opts.VolumeType,
FlavorRef: flavorID,
}

b, err := build.RequestBody(opts, "type")
b, err := build.RequestBody(apiOpts, "type")
if err != nil {
return nil, err
}

// POST /v1.0/{project_id}/clusters/{cluster_id}/type/{type}/independent
url := client.ServiceURL("clusters", clusterID, "type", NodeType, "independent")
url = client.ServiceURL("clusters", clusterID, "type", NodeType, "independent")

raw, err := client.Post(url, b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
Expand All @@ -42,7 +74,6 @@ func AddClusterNodes(client *golangsdk.ServiceClient, clusterID string, NodeType
return nil, err
}

var res AddNodesResponse
err = extract.IntoStructPtr(raw.Body, &res, "")

return &res, err
Expand Down

0 comments on commit 3a7ce65

Please sign in to comment.