github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/autoscaling/v1/policies/results.go (about) 1 package policies 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 ) 6 7 // CreateResult is a struct which represents the create result of policy 8 type CreateResult struct { 9 golangsdk.Result 10 } 11 12 // Extract of CreateResult will deserialize the result of Creation 13 func (r CreateResult) Extract() (string, error) { 14 var a struct { 15 ID string `json:"scaling_policy_id"` 16 } 17 err := r.Result.ExtractInto(&a) 18 return a.ID, err 19 } 20 21 // DeleteResult is a struct which represents the delete result. 22 type DeleteResult struct { 23 golangsdk.ErrResult 24 } 25 26 // Policy is a struct that represents the result of get policy 27 type Policy struct { 28 ID string `json:"scaling_group_id"` 29 Name string `json:"scaling_policy_name"` 30 PolicyID string `json:"scaling_policy_id"` 31 Status string `json:"policy_status"` 32 Type string `json:"scaling_policy_type"` 33 AlarmID string `json:"alarm_id"` 34 SchedulePolicy SchedulePolicy `json:"scheduled_policy"` 35 Action Action `json:"scaling_policy_action"` 36 CoolDownTime int `json:"cool_down_time"` 37 CreateTime string `json:"create_time"` 38 } 39 40 type SchedulePolicy struct { 41 LaunchTime string `json:"launch_time"` 42 RecurrenceType string `json:"recurrence_type"` 43 RecurrenceValue string `json:"recurrence_value"` 44 StartTime string `json:"start_time"` 45 EndTime string `json:"end_time"` 46 } 47 48 type Action struct { 49 Operation string `json:"operation"` 50 InstanceNum int `json:"instance_number"` 51 InstancePercentage int `json:"instance_percentage"` 52 } 53 54 // GetResult is a struct which represents the get result 55 type GetResult struct { 56 golangsdk.Result 57 } 58 59 func (r GetResult) Extract() (Policy, error) { 60 var p Policy 61 err := r.Result.ExtractIntoStructPtr(&p, "scaling_policy") 62 return p, err 63 } 64 65 // UpdateResult is a struct from which can get the result of update method 66 type UpdateResult struct { 67 golangsdk.Result 68 } 69 70 // Extract will deserialize the result to group id with string 71 func (r UpdateResult) Extract() (string, error) { 72 var a struct { 73 ID string `json:"scaling_policy_id"` 74 } 75 err := r.Result.ExtractInto(&a) 76 return a.ID, err 77 } 78 79 type commonResult struct { 80 golangsdk.Result 81 } 82 83 // ListResult represents a result of the List method. 84 type ListResult struct { 85 commonResult 86 } 87 88 // Extract is a method to extract the list of policies for specified scaling group. 89 func (r ListResult) Extract() ([]Policy, error) { 90 var s struct { 91 Policies []Policy `json:"scaling_policies"` 92 } 93 err := r.ExtractInto(&s) 94 return s.Policies, err 95 }