github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/autoscaling/v1/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 UpdateOpts struct { 10 // Specifies the AS policy name. The name contains only letters, digits, underscores (_), and hyphens (-), and cannot exceed 64 characters. 11 Name string `json:"scaling_policy_name,omitempty"` 12 // Specifies the AS policy type. 13 // ALARM (corresponding to alarm_id): indicates that the scaling action is triggered by an alarm. 14 // SCHEDULED (corresponding to scheduled_policy): indicates that the scaling action is triggered as scheduled. 15 // RECURRENCE (corresponding to scheduled_policy): indicates that the scaling action is triggered periodically. 16 Type string `json:"scaling_policy_type,omitempty"` 17 // Specifies the alarm rule ID. This parameter is mandatory when scaling_policy_type is set to ALARM. 18 // After this parameter is specified, the value of scheduled_policy does not take effect. 19 // After you modify an alarm policy, the system automatically adds an alarm triggering activity of the autoscaling 20 // type to the alarm_actions field in the alarm rule specified by the parameter value. 21 // You can obtain the parameter value by querying Cloud Eye alarm rules. 22 AlarmID string `json:"alarm_id,omitempty"` 23 // Specifies the periodic or scheduled AS policy. This parameter is mandatory when scaling_policy_type is set to SCHEDULED or RECURRENCE. 24 // After this parameter is specified, the value of alarm_id does not take effect. 25 SchedulePolicy SchedulePolicyOpts `json:"scheduled_policy,omitempty"` 26 // Specifies the scaling action of the AS policy. 27 Action Action `json:"scaling_policy_action,omitempty"` 28 // Specifies the cooldown period (in seconds). The value ranges from 0 to 86400. 29 CoolDownTime int `json:"cool_down_time,omitempty"` 30 } 31 32 type SchedulePolicyOpts struct { 33 // Specifies the time when the scaling action is triggered. The time format complies with UTC. 34 // If scaling_policy_type is set to SCHEDULED, the time format is YYYY-MM-DDThh:mmZ. 35 // If scaling_policy_type is set to RECURRENCE, the time format is hh:mm. 36 LaunchTime string `json:"launch_time" required:"true"` 37 // Specifies the periodic triggering type. This parameter is mandatory when scaling_policy_type is set to RECURRENCE. 38 // Daily: indicates that the scaling action is triggered once a day. 39 // Weekly: indicates that the scaling action is triggered once a week. 40 // Monthly: indicates that the scaling action is triggered once a month. 41 RecurrenceType string `json:"recurrence_type,omitempty"` 42 // Specifies the day when a periodic scaling action is triggered. This parameter is mandatory when scaling_policy_type is set to RECURRENCE. 43 // If recurrence_type is set to Daily, the value is null, indicating that the scaling action is triggered once a day. 44 // If recurrence_type is set to Weekly, the value ranges from 1 (Sunday) to 7 (Saturday). 45 // The digits refer to dates in each week and separated by a comma, such as 1,3,5. 46 // If recurrence_type is set to Monthly, the value ranges from 1 to 31. 47 // The digits refer to the dates in each month and separated by a comma, such as 1,10,13,28. 48 RecurrenceValue string `json:"recurrence_value,omitempty"` 49 // Specifies the start time of the scaling action triggered periodically. The time format complies with UTC. 50 // The time format is YYYY-MM-DDThh:mmZ. 51 StartTime string `json:"start_time,omitempty"` 52 // Specifies the end time of the scaling action triggered periodically. The time format complies with UTC. 53 // This parameter is mandatory when scaling_policy_type is set to RECURRENCE. 54 // When the scaling action is triggered periodically, the end time cannot be earlier than the current and start time. 55 // The time format is YYYY-MM-DDThh:mmZ. 56 EndTime string `json:"end_time,omitempty"` 57 } 58 59 func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (string, error) { 60 body, err := build.RequestBody(opts, "") 61 if err != nil { 62 return "", err 63 } 64 65 raw, err := client.Put(client.ServiceURL("scaling_policy", id), body, nil, &golangsdk.RequestOpts{ 66 OkCodes: []int{200}, 67 }) 68 if err != nil { 69 return "", err 70 } 71 72 var res struct { 73 ID string `json:"scaling_policy_id"` 74 } 75 err = extract.Into(raw.Body, &res) 76 return res.ID, err 77 }