github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/autoscaling/v2/policies/update.go (about) 1 package policies 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 6 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 7 ) 8 9 type SchedulePolicyOpts struct { 10 // Specifies the time when the scaling action is triggered. The time format complies with UTC. 11 // If scaling_policy_type is set to SCHEDULED, the time format is YYYY-MM-DDThh:mmZ. 12 // If scaling_policy_type is set to RECURRENCE, the time format is hh:mm. 13 LaunchTime string `json:"launch_time" required:"true"` 14 // Specifies the periodic triggering type. This parameter is mandatory when scaling_policy_type is set to RECURRENCE. 15 // Daily: indicates that the scaling action is triggered once a day. 16 // Weekly: indicates that the scaling action is triggered once a week. 17 // Monthly: indicates that the scaling action is triggered once a month. 18 RecurrenceType string `json:"recurrence_type,omitempty"` 19 // Specifies the day when a periodic scaling action is triggered. This parameter is mandatory when scaling_policy_type is set to RECURRENCE. 20 // If recurrence_type is set to Daily, the value is null, indicating that the scaling action is triggered once a day. 21 // If recurrence_type is set to Weekly, the value ranges from 1 (Sunday) to 7 (Saturday). 22 // The digits refer to dates in each week and separated by a comma, such as 1,3,5. 23 // If recurrence_type is set to Monthly, the value ranges from 1 to 31. 24 // The digits refer to the dates in each month and separated by a comma, such as 1,10,13,28. 25 RecurrenceValue string `json:"recurrence_value,omitempty"` 26 // Specifies the start time of the scaling action triggered periodically. The time format complies with UTC. 27 // The time format is YYYY-MM-DDThh:mmZ. 28 StartTime string `json:"start_time,omitempty"` 29 // Specifies the end time of the scaling action triggered periodically. The time format complies with UTC. 30 // This parameter is mandatory when scaling_policy_type is set to RECURRENCE. 31 // When the scaling action is triggered periodically, the end time cannot be earlier than the current and start time. 32 // The time format is YYYY-MM-DDThh:mmZ. 33 EndTime string `json:"end_time,omitempty"` 34 } 35 36 type ActionOpts struct { 37 // Specifies the operation to be performed. The default operation is ADD. 38 // If scaling_resource_type is set to SCALING_GROUP, the following operations are supported: 39 // ADD: indicates adding instances. 40 // REMOVE/REDUCE: indicates removing or reducing instances. 41 // SET: indicates setting the number of instances to a specified value. 42 // If scaling_resource_type is set to BANDWIDTH, the following operations are supported: 43 // ADD: indicates adding instances. 44 // REDUCE: indicates reducing instances. 45 // SET: indicates setting the number of instances to a specified value. 46 Operation string `json:"operation,omitempty"` 47 // Specifies the operation size. The value is an integer from 0 to 300. The default value is 1. 48 // This parameter can be set to 0 only when operation is set to SET. 49 // If scaling_resource_type is set to SCALING_GROUP, this parameter indicates the number of instances. 50 // The value is an integer from 0 to 300 and the default value is 1. 51 // If scaling_resource_type is set to BANDWIDTH, this parameter indicates the bandwidth (Mbit/s). 52 // The value is an integer from 1 to 300 and the default value is 1. 53 // If scaling_resource_type is set to SCALING_GROUP, either size or percentage can be set. 54 Size int `json:"size,omitempty"` 55 // Specifies the percentage of instances to be operated. If operation is set to ADD, REMOVE, or REDUCE, 56 // the value of this parameter is an integer from 1 to 20000. If operation is set to SET, the value is an integer from 0 to 20000. 57 // If scaling_resource_type is set to SCALING_GROUP, either size or percentage can be set. 58 // If neither size nor percentage is set, the default value of size is 1. 59 // If scaling_resource_type is set to BANDWIDTH, percentage is unavailable. 60 Percentage int `json:"percentage,omitempty"` 61 // Specifies the operation restrictions. 62 // If scaling_resource_type is set to BANDWIDTH and operation is not SET, this parameter takes effect and the unit is Mbit/s. 63 // If operation is set to ADD, this parameter indicates the maximum bandwidth allowed. 64 // If operation is set to REDUCE, this parameter indicates the minimum bandwidth allowed. 65 Limits int `json:"limits,omitempty"` 66 } 67 68 func Update(client *golangsdk.ServiceClient, id string, opts PolicyOpts) (string, error) { 69 b, err := build.RequestBody(opts, "") 70 if err != nil { 71 return "", err 72 } 73 74 raw, err := client.Put(client.ServiceURL("scaling_policy", id), b, nil, &golangsdk.RequestOpts{ 75 OkCodes: []int{200}, 76 }) 77 if err != nil { 78 return "", err 79 } 80 81 var res struct { 82 ID string `json:"scaling_policy_id"` 83 } 84 err = extract.Into(raw.Body, &res) 85 return res.ID, err 86 }