From 3a7ce658ec47a368cdce5c3b1c0473c0291f66e4 Mon Sep 17 00:00:00 2001 From: Vineet Pruthi Date: Thu, 21 Nov 2024 09:44:45 +0100 Subject: [PATCH] Updated CSS AddClusterNodes function --- .../css/v1/cluster_add_nodes_test.go | 4 +- openstack/css/v1/clusters/AddClusterNodes.go | 39 +++++++++++++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/acceptance/openstack/css/v1/cluster_add_nodes_test.go b/acceptance/openstack/css/v1/cluster_add_nodes_test.go index 92335beb2..0f973f8db 100644 --- a/acceptance/openstack/css/v1/cluster_add_nodes_test.go +++ b/acceptance/openstack/css/v1/cluster_add_nodes_test.go @@ -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", }) diff --git a/openstack/css/v1/clusters/AddClusterNodes.go b/openstack/css/v1/clusters/AddClusterNodes.go index 553c3dba6..c2142bc80 100644 --- a/openstack/css/v1/clusters/AddClusterNodes.go +++ b/openstack/css/v1/clusters/AddClusterNodes.go @@ -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 @@ -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}, @@ -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