github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/autoscaling/v1/policyexecutelogs/results.go (about) 1 package policyexecutelogs 2 3 import ( 4 "strconv" 5 6 "github.com/chnsz/golangsdk/pagination" 7 ) 8 9 // ExecuteLog is the structure that represents the execution log detail. 10 type ExecuteLog struct { 11 // The policy execution log ID. 12 ID string `json:"id"` 13 // The policy execution status. The value can be SUCCESS, FAIL or EXECUTING. 14 Status string `json:"status"` 15 // The reason of policy execution failure. 16 FailedReason string `json:"failed_reason"` 17 // The policy execution type. The value can be SCHEDULED, RECURRENCE, ALARM or MANUAL. 18 ExecuteType string `json:"execute_type"` 19 // The policy execution time. 20 ExecuteTime string `json:"execute_time"` 21 // The scaling policy ID. 22 PolicyID string `json:"scaling_policy_id"` 23 // The scaling resource type. The value can be SCALING_GROUP or BANDWIDTH. 24 ResourceType string `json:"scaling_resource_type"` 25 // The scaling resource ID. 26 ResourceID string `json:"scaling_resource_id"` 27 // The scaling original value, indicates the number of instances or bandwidth size. 28 OldValue string `json:"old_value"` 29 // The scaling target value, indicates the number of instances or bandwidth size. 30 DesireValue string `json:"desire_value"` 31 // The operational limitations. 32 LimitValue string `json:"limit_value"` 33 // The policy execution task type. The value can be REMOVE, ADD or SET. 34 Type string `json:"type"` 35 // The concrete tasks included in executing actions. 36 JobRecords []JobRecord `json:"job_records"` 37 // The additional information. 38 MetaData map[string]interface{} `json:"meta_data"` 39 // The project ID. 40 TenantID string `json:"tenant_id"` 41 } 42 43 // JobRecord is the structure that represents the concrete tasks included in executing actions. 44 type JobRecord struct { 45 // The job name. 46 JobName string `json:"job_name"` 47 // The record type. The value can be API or MEG. 48 RecordType string `json:"record_type"` 49 // The record time. 50 RecordTime string `json:"record_time"` 51 // The request information. 52 Request string `json:"request"` 53 // The response information. 54 Response string `json:"response"` 55 // The response code. 56 Code string `json:"code"` 57 // The message content. 58 Message string `json:"message"` 59 // The job execution status. The value can be SUCCESS or FAIL. 60 JobStatus string `json:"job_status"` 61 } 62 63 // ExecuteLogPage is a single page maximum result representing a query by start_number page. 64 type ExecuteLogPage struct { 65 pagination.OffsetPageBase 66 } 67 68 // NextStartNumber returns startNumber of the next element of the page. 69 func (current ExecuteLogPage) NextStartNumber() int { 70 q := current.URL.Query() 71 // get `start_number` and `limit` from query path. 72 // If the limit is not set, it will be set to `20` by default for querying. 73 startNumber, _ := strconv.Atoi(q.Get("start_number")) 74 limit, _ := strconv.Atoi(q.Get("limit")) 75 if limit == 0 { 76 limit = 20 77 } 78 79 return startNumber + limit 80 } 81 82 // NextPageURL generates the URL for the page of results after this one. 83 func (current ExecuteLogPage) NextPageURL() (string, error) { 84 next := current.NextStartNumber() 85 if next == 0 { 86 return "", nil 87 } 88 89 currentURL := current.URL 90 q := currentURL.Query() 91 q.Set("start_number", strconv.Itoa(next)) 92 currentURL.RawQuery = q.Encode() 93 94 return currentURL.String(), nil 95 } 96 97 // IsEmpty checks whether a ExecuteLogPage struct is empty. 98 func (b ExecuteLogPage) IsEmpty() (bool, error) { 99 logs, err := extractExecuteLogs(b) 100 return len(logs) == 0, err 101 } 102 103 // extractExecuteLogs is a method to extract the list of execution logs for specified scaling policy. 104 func extractExecuteLogs(r pagination.Page) ([]ExecuteLog, error) { 105 var s []ExecuteLog 106 err := r.(ExecuteLogPage).Result.ExtractIntoSlicePtr(&s, "scaling_policy_execute_log") 107 return s, err 108 }