github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cloudtable/v2/clusters/requests.go (about) 1 package clusters 2 3 import "github.com/chnsz/golangsdk" 4 5 // CreateOpts is a struct which will be used to create a new cloudtable cluster. 6 type CreateOpts struct { 7 // Create cluster database parameters. 8 Datastore Datastore `json:"datastore" required:"true"` 9 // Cluster name 10 Name string `json:"name" required:"true"` 11 // The instance object of the cluster. 12 Instance Instance `json:"instance" required:"true"` 13 // Storage type, the valid values are: 14 // ULTRAHIGH 15 // COMMON 16 StorageType string `json:"storage_type" required:"true"` 17 // The VPC where the cluster is located. 18 VpcId string `json:"vpc_id" required:"true"` 19 // Whether the IAM auth is enabled. 20 IAMAuthEnabled bool `json:"auth_mode,omitempty"` 21 // Whether the Lemon is enabled. 22 LemonEnabled bool `json:"enable_lemon,omitempty"` 23 // Whether the OpenTSDB is enabled. 24 OpenTSDBEnabled bool `json:"enable_openTSDB,omitempty"` 25 // The size of the stored value. 26 StorageSize int `json:"storage_size,omitempty"` 27 } 28 29 // Datastore is an object specifying the cluster storage. 30 type Datastore struct { 31 // Cluster database type. 32 Type string `json:"type" required:"true"` 33 // Controller version number, default to '1.0.6'. 34 Version string `json:"version" required:"true"` 35 } 36 37 // Instance is an object specifying the information of the nodes number, az and network. 38 type Instance struct { 39 // The ID of the availability zone where the cluster is located. 40 AvailabilityZone string `json:"availability_zone" required:"true"` 41 // The number of computing unit nodes in the CloudTable cluster must be at least 2. 42 CUNum int `json:"cu_num" required:"true"` 43 // Information about the network where the cluster is located. 44 Networks []Network `json:"nics" required:"true"` 45 // The number of Lemon nodes in the CloudTable cluster. 46 LemonNum int `json:"lemon_num,omitempty"` 47 // The number of TSD nodes in the CloudTable cluster must be at least 2. 48 TSDNum int `json:"tsd_num,omitempty"` 49 } 50 51 // Network is an object specifying the cluster network. 52 type Network struct { 53 // The ID of the network where the CloudTable cluster is located. 54 SubnetId string `json:"net_id" required:"true"` 55 // The ID of the security group to which the CloudTable belongs. 56 SecurityGroupId string `json:"security_group_id" required:"true"` 57 } 58 59 // Create is a method to create a new cluster. 60 func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*RequestResp, error) { 61 b, err := golangsdk.BuildRequestBody(opts, "cluster") 62 if err != nil { 63 return nil, err 64 } 65 66 var rst golangsdk.Result 67 _, err = c.Post(rootURL(c), b, &rst.Body, &golangsdk.RequestOpts{ 68 MoreHeaders: map[string]string{ 69 "Content-Type": "application/json", 70 "X-Language": "en-us", 71 }, 72 }) 73 if err == nil { 74 var r RequestResp 75 rst.ExtractInto(&r) 76 return &r, nil 77 } 78 return nil, err 79 } 80 81 // Get is a method to obtain the detail of the cluster. 82 func Get(c *golangsdk.ServiceClient, clusterId string) (*Cluster, error) { 83 var rst golangsdk.Result 84 _, err := c.Get(resourceURL(c, clusterId), &rst.Body, &golangsdk.RequestOpts{ 85 MoreHeaders: map[string]string{ 86 "Content-Type": "application/json", 87 "X-Language": "en-us", 88 }, 89 }) 90 if err == nil { 91 var r Cluster 92 rst.ExtractInto(&r) 93 return &r, nil 94 } 95 return nil, err 96 } 97 98 // Delete is a method to remove an existing cluster by ID. 99 func Delete(c *golangsdk.ServiceClient, clusterId string) *golangsdk.ErrResult { 100 var r golangsdk.ErrResult 101 _, r.Err = c.Delete(resourceURL(c, clusterId), &golangsdk.RequestOpts{ 102 MoreHeaders: map[string]string{ 103 "Content-Type": "application/json", 104 "X-Language": "en-us", 105 }, 106 }) 107 return &r 108 }