github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/autoscaling/v1/scheduledtasks/results.go (about) 1 package scheduledtasks 2 3 import ( 4 "github.com/chnsz/golangsdk/pagination" 5 ) 6 7 // createResp is the structure that represents the response to creation planned task. 8 type createResp struct { 9 // The ID of planned task. 10 TaskID string `json:"task_id"` 11 } 12 13 // ScheduledTask is the structure that represents the planned task detail. 14 type ScheduledTask struct { 15 // The ID of created planned task. 16 ID string `json:"task_id"` 17 // The ID of scaling group. 18 GroupID string `json:"scaling_group_id"` 19 // The name of created planned task. 20 Name string `json:"name"` 21 // The policy of created planned task. 22 ScheduledPolicy ScheduledPolicy `json:"scheduled_policy"` 23 // The numbers of scaling group instance of created planned task. 24 InstanceNumber InstanceNumber `json:"instance_number"` 25 // The creation time of planned task. 26 CreateTime string `json:"create_time"` 27 // The ID of the tenant to which this planned task belongs. 28 TenantID string `json:"tenant_id"` 29 // The ID of the domain to which this planned task belongs. 30 DomainID string `json:"domain_id"` 31 } 32 33 // listResp is the structure that represents the planned tasks list and page detail. 34 type listResp struct { 35 // The list of the planned tasks. 36 ScheduledTasks []ScheduledTask `json:"scheduled_tasks"` 37 // The page information. 38 PageInfo pageInfo `json:"page_info"` 39 } 40 41 // pageInfo is the structure that represents the page information. 42 type pageInfo struct { 43 // The next marker information. 44 NextMarker string `json:"next_marker"` 45 } 46 47 // ScheduledTaskPage represents the response pages of the List method. 48 type ScheduledTaskPage struct { 49 pagination.MarkerPageBase 50 } 51 52 // IsEmpty method checks whether the current planned task page is empty. 53 func (r ScheduledTaskPage) IsEmpty() (bool, error) { 54 tasks, err := ExtractScheduledTasks(r) 55 return len(tasks) == 0, err 56 } 57 58 // LastMarker method returns the last planned task ID in a planned task page. 59 func (p ScheduledTaskPage) LastMarker() (string, error) { 60 tasks, err := ExtractScheduledTasks(p) 61 if err != nil { 62 return "", err 63 } 64 if len(tasks) == 0 { 65 return "", nil 66 } 67 return tasks[len(tasks)-1].ID, nil 68 } 69 70 // ExtractScheduledTasks is a method to extract the list of planned task details. 71 func ExtractScheduledTasks(r pagination.Page) ([]ScheduledTask, error) { 72 var s []ScheduledTask 73 err := r.(ScheduledTaskPage).Result.ExtractIntoSlicePtr(&s, "scheduled_tasks") 74 return s, err 75 }