github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/css/v1/clusters/ExtendCluster.go (about) 1 package clusters 2 3 import ( 4 "fmt" 5 6 "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 8 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 9 ) 10 11 type ClusterExtendOptsBuilder interface { 12 } 13 14 // ClusterExtendCommonOpts is used to extend cluster with only `common` nodes. 15 // Clusters with master, client, or cold data nodes cannot use this. 16 type ClusterExtendCommonOpts struct { 17 // ModifySize - number of instances to be added. 18 ModifySize int `json:"modifySize"` 19 } 20 21 // ClusterExtendSpecialOpts is used to extend cluster with special nodes. 22 // If a cluster has master, client, or cold data nodes, this should be used 23 type ClusterExtendSpecialOpts struct { 24 // Type of the instance to be scaled out. 25 // Select at least one from `ess`, `ess-cold`, `ess-master`, and `ess-client`. 26 // You can only add instances, rather than increase storage capacity, on nodes of the `ess-master` and `ess-client` types. 27 Type string `json:"type"` 28 // NodeSize - number of instances to be scaled out. 29 // The total number of existing instances and newly added instances in a cluster cannot exceed 32. 30 NodeSize int `json:"nodesize"` 31 // DiskSize - Storage capacity of the instance to be expanded. 32 // The total storage capacity of existing instances and newly added instances in a cluster cannot exceed the maximum instance storage capacity allowed when a cluster is being created. 33 // In addition, you can expand the instance storage capacity for a cluster for up to six times. 34 // Unit: GB 35 DiskSize int `json:"disksize"` 36 } 37 38 // ExtendCluster - extends cluster capacity. 39 // ClusterExtendCommonOpts should be used as options to extend cluster with only `common` nodes. 40 // ClusterExtendSpecialOpts should be used if extended cluster has master, client, or cold data nodes. 41 func ExtendCluster(client *golangsdk.ServiceClient, clusterID string, opts ClusterExtendOptsBuilder) (*ExtendedCluster, error) { 42 url := "" 43 switch opts.(type) { 44 case ClusterExtendCommonOpts: 45 url = client.ServiceURL("clusters", clusterID, "extend") 46 case []ClusterExtendSpecialOpts: 47 url = client.ServiceURL("clusters", clusterID, "role_extend") 48 default: 49 return nil, fmt.Errorf("invalid options type provided: %T", opts) 50 } 51 52 b, err := build.RequestBody(opts, "grow") 53 if err != nil { 54 return nil, err 55 } 56 57 raw, err := client.Post(url, b, nil, &golangsdk.RequestOpts{ 58 OkCodes: []int{200, 202}, 59 }) 60 if err != nil { 61 return nil, err 62 } 63 64 var res ExtendedCluster 65 err = extract.Into(raw.Body, &res) 66 return &res, err 67 } 68 69 type ExtendedCluster struct { 70 ID string `json:"id"` 71 Instances []ExtendedInstance `json:"instances"` 72 } 73 74 type ExtendedInstance struct { 75 ID string `json:"id"` 76 Name string `json:"name"` 77 Type string `json:"type"` 78 ShardID string `json:"shard_id"` 79 }