github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dli/v1/queues/requests.go (about) 1 package queues 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/openstack/common/tags" 6 ) 7 8 // CreateOpts contains the options for create a service. This object is passed to Create(). 9 type CreateOpts struct { 10 // Name of a newly created resource queue. The name can contain only digits, letters, and underscores (_), 11 //but cannot contain only digits or start with an underscore (_). Length range: 1 to 128 characters. 12 QueueName string `json:"queue_name" required:"true"` 13 14 // Indicates the queue type. The options are as follows: 15 // sql 16 // general 17 // all 18 // NOTE: 19 // If the type is not specified, the default value sql is used. 20 QueueType string `json:"queue_type,omitempty"` 21 22 // Description of a queue. 23 Description string `json:"description,omitempty"` 24 25 // Minimum number of CUs that are bound to a queue. Currently, the value can only be 16, 64, or 256. 26 CuCount int `json:"cu_count" required:"true"` 27 28 // Billing mode of a queue. This value can only be set to 1, indicating that the billing is based on the CUH used. 29 ChargingMode int `json:"charging_mode,omitempty"` 30 31 // Enterprise project ID. The value 0 indicates the default enterprise project. 32 // NOTE: 33 // Users who have enabled Enterprise Management can set this parameter to bind a specified project. 34 EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` 35 36 // CPU architecture of queue computing resources. 37 // x86_64 (default) 38 // aarch64 39 Platform string `json:"platform,omitempty"` 40 41 // Queue resource mode. The options are as follows: 42 // 0: indicates the shared resource mode. 43 // 1: indicates the exclusive resource mode. 44 ResourceMode int `json:"resource_mode"` 45 46 // Specifies the tag information of the queue to be created, 47 // including the JSON character string indicating whether the queue is Dual-AZ. Currently, 48 // only the value 2 is supported, indicating that two queues are created. 49 Labels []string `json:"labels,omitempty"` 50 51 // Indicates the queue feature. The options are as follows: 52 // basic: basic type 53 // ai: AI-enhanced (Only the SQL x86_64 dedicated queue supports this option.) 54 // The default value is basic. 55 // NOTE: 56 // For an enhanced AI queue, an AI image is loaded in the background. 57 // The image integrates AI algorithm packages based on the basic image. 58 Feature string `json:"feature,omitempty"` 59 60 Tags []tags.ResourceTag `json:"tags,omitempty"` 61 // The name of the elastic resource pool. 62 ElasticResourcePoolName string `json:"elastic_resource_pool_name,omitempty"` 63 } 64 65 type ListOpts struct { 66 QueueType string `q:"queue_type"` 67 WithPriv bool `q:"with-priv"` 68 WithChargeInfo bool `q:"with-charge-info"` 69 Tags string `q:"tags"` 70 } 71 72 type ActionOpts struct { 73 Action string `json:"action" required:"true"` //Operations to be performed: restart; scale_out;scale_in 74 Force bool `json:"force,omitempty"` //when action= restart,can Specifies whether to forcibly restart 75 CuCount int `json:"cu_count,omitempty"` // Number of CUs to be scaled in or out. 76 QueueName string `json:"-" required:"true"` 77 } 78 79 type UpdateCidrOpts struct { 80 Cidr string `json:"cidr_in_vpc,omitempty"` 81 } 82 83 // CreateOptsBuilder allows extensions to add additional parameters to the 84 // Create request. 85 type CreateOptsBuilder interface { 86 ToDomainCreateMap() (map[string]interface{}, error) 87 } 88 89 // ToDomainCreateMap builds a create request body from CreateOpts. 90 func (opts CreateOpts) ToDomainCreateMap() (map[string]interface{}, error) { 91 return golangsdk.BuildRequestBody(opts, "") 92 } 93 94 type ListOptsBuilder interface { 95 ToListQuery() (string, error) 96 } 97 98 func (opts ListOpts) ToListQuery() (string, error) { 99 q, err := golangsdk.BuildQueryString(opts) 100 return q.String(), err 101 } 102 103 /* 104 This API is used to create a queue. 105 106 @cloudAPI-URL: POST /v1.0/{project_id}/queues 107 @cloudAPI-ResourceType: dli 108 @cloudAPI-version: v1.0 109 110 @since: 2021-07-07 12:12:12 111 */ 112 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 113 requstbody, err := opts.ToDomainCreateMap() 114 if err != nil { 115 r.Err = err 116 return 117 } 118 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 119 _, r.Err = c.Post(createURL(c), requstbody, &r.Body, reqOpt) 120 return 121 } 122 123 /* 124 This API is used to delete a queue. 125 126 @cloudAPI-URL: Delete /v1.0/{project_id}/queues/{queueName} 127 @cloudAPI-ResourceType: dli 128 @cloudAPI-version: v1.0 129 130 @since: 2021-07-07 12:12:12 131 */ 132 func Delete(c *golangsdk.ServiceClient, queueName string) (r DeleteResult) { 133 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 134 _, r.Err = c.Delete(resourceURL(c, queueName), reqOpt) 135 return 136 } 137 138 /* 139 This API is used to query all Queue list 140 141 @cloudAPI-URL: GET /v1.0/{project_id}/queues 142 @cloudAPI-ResourceType: dli 143 @cloudAPI-version: v1.0 144 145 @since: 2021-07-07 12:12:12 146 */ 147 func List(c *golangsdk.ServiceClient, listOpts ListOptsBuilder) (r GetResult) { 148 listResult := new(ListResult) 149 150 url := queryAllURL(c) 151 if listOpts != nil { 152 query, err := listOpts.ToListQuery() 153 if err != nil { 154 r.Err = err 155 return 156 } 157 url += query 158 } 159 160 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 161 _, r.Err = c.Get(url, &listResult, reqOpt) 162 r.Body = listResult 163 return r 164 } 165 166 /* 167 This API is used to query the Details of a Queue 168 169 @cloudAPI-URL: GET /v1.0/{project_id}/queues/{queueName} 170 @cloudAPI-ResourceType: dli 171 @cloudAPI-version: v1.0 172 173 @since: 2021-07-07 12:12:12 174 */ 175 func Get(c *golangsdk.ServiceClient, queueName string) (r GetResult) { 176 result := new(Queue4Get) 177 178 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 179 _, r.Err = c.Get(resourceURL(c, queueName), &result, reqOpt) 180 181 if result != nil { 182 r.Body = result 183 } 184 185 return r 186 } 187 188 func ScaleOrRestart(c *golangsdk.ServiceClient, opts ActionOpts) (r PutResult) { 189 requstbody, err := golangsdk.BuildRequestBody(opts, "") 190 if err != nil { 191 r.Err = err 192 return 193 } 194 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 195 _, r.Err = c.Put(ActionURL(c, opts.QueueName), requstbody, &r.Body, reqOpt) 196 return 197 } 198 199 func UpdateCidr(c *golangsdk.ServiceClient, queueName string, opts UpdateCidrOpts) (*UpdateCidrResp, error) { 200 b, err := golangsdk.BuildRequestBody(opts, "") 201 if err != nil { 202 return nil, err 203 } 204 205 var rst UpdateCidrResp 206 _, err = c.Put(resourceURL(c, queueName), b, &rst, nil) 207 return &rst, err 208 }