github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dli/v3/elasticresourcepool/requests.go (about) 1 package elasticresourcepool 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // AssociateQueueOpts is the structure that used to associate a queue with an elastic resource pool. 9 type AssociateQueueOpts struct { 10 // The name of the elastic resource pool. 11 ElasticResourcePoolName string `json:"-" required:"true"` 12 // The name of queue. 13 QueueName string `json:"queue_name" required:"true"` 14 } 15 16 // AssociateQueue is a method to associate a queue with an elastic resource pool using given parameters. 17 func AssociateQueue(c *golangsdk.ServiceClient, opts AssociateQueueOpts) (*AssociateQueueResp, error) { 18 b, err := golangsdk.BuildRequestBody(opts, "") 19 if err != nil { 20 return nil, err 21 } 22 23 var r AssociateQueueResp 24 _, err = c.Post(associateQueueURl(c, opts.ElasticResourcePoolName), b, &r, nil) 25 return &r, err 26 } 27 28 // UpdateQueuePolicyOpts is the structure that used to modify the scaling policy of the queue associated with an elastic resource pool. 29 type UpdateQueuePolicyOpts struct { 30 // The name of the elastic resource pool. 31 ElasticResourcePoolName string `json:"-" required:"true"` 32 // The name of queue. 33 QueueName string `json:"-" required:"true"` 34 // The list of the queue scaling policies. 35 QueueScalingPolicies []QueueScalingPolicy `json:"queue_scaling_policies" required:"true"` 36 } 37 38 // QueueScalingPolicy is the structure that represents the policy detail of specified queue associated with the specified elastic resource pool. 39 type QueueScalingPolicy struct { 40 // The priority of the queue scaling policy. The valid value ranges from 1 to 100. 41 // The larger the value, the higher the priority. 42 Priority int `json:"priority" required:"true"` 43 // The effective time of the queue scaling policy. 44 ImpactStartTime string `json:"impact_start_time" required:"true"` 45 // The expiration time of the queue scaling policy. 46 ImpactStopTime string `json:"impact_stop_time" required:"true"` 47 // The minimum number of CUs allowed by the scaling policy. 48 MinCu int `json:"min_cu" required:"true"` 49 // The maximum number of CUs allowed by the scaling policy. 50 MaxCu int `json:"max_cu" required:"true"` 51 } 52 53 // UpdateElasticResourcePoolQueuePolicy is a method to modify the scaling policy of the queue associated with 54 // specified elastic resource pool using given parameters. 55 func UpdateElasticResourcePoolQueuePolicy(c *golangsdk.ServiceClient, opts UpdateQueuePolicyOpts) (*AssociateQueueResp, error) { 56 b, err := golangsdk.BuildRequestBody(opts, "") 57 if err != nil { 58 return nil, err 59 } 60 61 var r AssociateQueueResp 62 _, err = c.Put(queueScalingPolicyURL(c, opts.ElasticResourcePoolName, opts.QueueName), b, &r, nil) 63 return &r, err 64 } 65 66 // ListElasticResourcePoolQueuesOpts is the structure used to query the list of queue scaling policies in an elastic resource pool. 67 type ListElasticResourcePoolQueuesOpts struct { 68 // The name of the elastic resource pool. 69 ElasticResourcePoolName string `json:"-" required:"true"` 70 // The name of the queue. 71 QueueName string `q:"queue_name"` 72 // Offset from which the query starts. Default to 0. 73 Offset int `q:"offset"` 74 // The number of items displayed on each page. Default to 100. 75 Limit int `q:"limit"` 76 } 77 78 // ListElasticResourcePoolQueues is a method to query all queue scaling policies in an elastic resource pool using given parameters. 79 func ListElasticResourcePoolQueues(c *golangsdk.ServiceClient, opts ListElasticResourcePoolQueuesOpts) ([]Queue, error) { 80 url := associateQueueURl(c, opts.ElasticResourcePoolName) 81 query, err := golangsdk.BuildQueryString(opts) 82 if err != nil { 83 return nil, err 84 } 85 url += query.String() 86 87 pages, err := pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { 88 p := QueuePage{pagination.OffsetPageBase{PageResult: r}} 89 return p 90 }).AllPages() 91 92 if err != nil { 93 return nil, err 94 } 95 96 return ExtractQueues(pages) 97 }