github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/autoscaling/v2/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 PolicyOpts struct { 10 // Specifies the AS policy name. The name contains only letters, digits, underscores (_), and hyphens (-), and cannot exceed 64 characters. 11 PolicyName string `json:"scaling_policy_name"` 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 PolicyType string `json:"scaling_policy_type"` 17 // Specifies the scaling resource ID, which is the unique ID of an AS group or bandwidth. 18 // If scaling_resource_type is set to SCALING_GROUP, this parameter indicates the unique AS group ID. 19 // If scaling_resource_type is set to BANDWIDTH, this parameter indicates the unique bandwidth ID. 20 ResourceID string `json:"scaling_resource_id"` 21 // Specifies the scaling resource type. 22 // AS group: SCALING_GROUP 23 // Bandwidth: BANDWIDTH 24 ResourceType string `json:"scaling_resource_type"` 25 // Specifies the alarm rule ID. This parameter is mandatory when scaling_policy_type is set to ALARM. 26 // After this parameter is specified, the value of scheduled_policy does not take effect. 27 // After you create an alarm policy, the system automatically adds an alarm triggering 28 // activity of the autoscaling type to the alarm_actions field in the alarm rule specified by the parameter value. 29 // You can obtain the parameter value by querying Cloud Eye alarm rules. 30 AlarmID string `json:"alarm_id,omitempty"` 31 // Specifies the periodic or scheduled AS policy. 32 // This parameter is mandatory when scaling_policy_type is set to SCHEDULED or RECURRENCE. 33 // After this parameter is specified, the value of alarm_id does not take effect. 34 SchedulePolicy SchedulePolicyOpts `json:"scheduled_policy,omitempty"` 35 // Specifies the scaling action of the AS policy. 36 PolicyAction ActionOpts `json:"scaling_policy_action,omitempty"` 37 // Specifies the cooldown period (in seconds). The value ranges from 0 to 86400 and is 300 by default. 38 CoolDownTime int `json:"cool_down_time,omitempty"` 39 } 40 41 func Create(client *golangsdk.ServiceClient, opts PolicyOpts) (string, error) { 42 b, err := build.RequestBody(opts, "") 43 if err != nil { 44 return "", err 45 } 46 47 raw, err := client.Post(client.ServiceURL("scaling_policy"), b, nil, &golangsdk.RequestOpts{ 48 OkCodes: []int{200}, 49 }) 50 if err != nil { 51 return "", err 52 } 53 54 var res struct { 55 ID string `json:"scaling_policy_id"` 56 } 57 err = extract.Into(raw.Body, &res) 58 return res.ID, err 59 }