github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/autoscaling/v1/policies/create.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 CreateOpts 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" required:"true"` 12 // Specifies the AS group ID, which can be obtained using the API for querying AS groups. 13 ID string `json:"scaling_group_id" required:"true"` 14 // Specifies the AS policy type. 15 // ALARM (corresponding to alarm_id): indicates that the scaling action is triggered by an alarm. 16 // SCHEDULED (corresponding to scheduled_policy): indicates that the scaling action is triggered as scheduled. 17 // RECURRENCE (corresponding to scheduled_policy): indicates that the scaling action is triggered periodically. 18 Type string `json:"scaling_policy_type" required:"true"` 19 // Specifies the alarm rule ID. This parameter is mandatory when scaling_policy_type is set to ALARM. 20 // After this parameter is specified, the value of scheduled_policy does not take effect. 21 // After you create an alarm policy, the system automatically adds an alarm triggering 22 // activity of the autoscaling type to the alarm_actions field in the alarm rule specified by the parameter value. 23 AlarmID string `json:"alarm_id,omitempty"` 24 // Specifies the periodic or scheduled AS policy. This parameter is mandatory 25 // when scaling_policy_type is set to SCHEDULED or RECURRENCE. 26 // After this parameter is specified, the value of alarm_id does not take effect. 27 SchedulePolicy SchedulePolicyOpts `json:"scheduled_policy,omitempty"` 28 // Specifies the scaling action of the AS policy. 29 Action Action `json:"scaling_policy_action,omitempty"` 30 // Specifies the cooldown period (in seconds). The value ranges from 0 to 86400 and is 300 by default. 31 CoolDownTime int `json:"cool_down_time,omitempty"` 32 } 33 34 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (string, error) { 35 b, err := build.RequestBody(opts, "") 36 if err != nil { 37 return "", err 38 } 39 40 raw, err := client.Post(client.ServiceURL("scaling_policy"), b, nil, &golangsdk.RequestOpts{ 41 OkCodes: []int{200}, 42 }) 43 if err != nil { 44 return "", err 45 } 46 47 var res struct { 48 ID string `json:"scaling_policy_id"` 49 } 50 err = extract.Into(raw.Body, &res) 51 return res.ID, err 52 }