github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vbs/v2/policies/results.go (about) 1 package policies 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 type Policy struct { 9 //Backup policy ID 10 ID string `json:"backup_policy_id"` 11 //Backup policy name 12 Name string `json:"backup_policy_name"` 13 //Details about the scheduling policy 14 ScheduledPolicy ScheduledPolicy `json:"scheduled_policy"` 15 //Number of volumes associated with the backup policy 16 ResourceCount int `json:"policy_resource_count"` 17 } 18 19 type ResultResources struct { 20 //List of successfully associated/disassociated resources 21 SuccessResources []Resource `json:"success_resources"` 22 //List of the resources that fail to be associated/disassociated 23 FailResources []Resource `json:"fail_resources"` 24 } 25 26 type Resource struct { 27 //Resource ID 28 ResourceID string `json:"resource_id"` 29 //Resource type 30 ResourceType string `json:"resource_type"` 31 //Availability zone to which the resource belongs 32 AvailabilityZone string `json:"availability_zone"` 33 //POD to which the resource belongs 34 Pod string `json:"os_vol_host_attr"` 35 } 36 37 type commonResult struct { 38 golangsdk.Result 39 } 40 41 // CreateResult represents the result of a create operation. 42 type CreateResult struct { 43 commonResult 44 } 45 46 // DeleteResult represents the result of a delete operation. 47 type DeleteResult struct { 48 commonResult 49 } 50 51 // UpdateResult represents the result of a update operation. 52 type UpdateResult struct { 53 commonResult 54 } 55 56 // ResourceResult represents the result of a associate/diassociate operation. 57 type ResourceResult struct { 58 commonResult 59 } 60 61 // Extract will get the Policy object from the commonResult 62 func (r commonResult) Extract() (*Policy, error) { 63 var response Policy 64 err := r.ExtractInto(&response) 65 return &response, err 66 } 67 68 type PolicyPage struct { 69 pagination.LinkedPageBase 70 } 71 72 // IsEmpty returns true if a page contains no Policies results. 73 func (r PolicyPage) IsEmpty() (bool, error) { 74 s, err := ExtractPolicies(r) 75 return len(s) == 0, err 76 } 77 78 // NextPageURL uses the response's embedded link reference to navigate to the 79 // next page of results. 80 func (r PolicyPage) NextPageURL() (string, error) { 81 var s struct { 82 Policies []golangsdk.Link `json:"backup_policies_links"` 83 } 84 err := r.ExtractInto(&s) 85 if err != nil { 86 return "", err 87 } 88 return golangsdk.ExtractNextURL(s.Policies) 89 } 90 91 // ExtractPolicies accepts a Page struct, specifically a PolicyPage struct, 92 // and extracts the elements into a slice of Policy structs. In other words, 93 // a generic collection is mapped into a relevant slice. 94 func ExtractPolicies(r pagination.Page) ([]Policy, error) { 95 var s struct { 96 Policies []Policy `json:"backup_policies"` 97 } 98 err := (r.(PolicyPage)).ExtractInto(&s) 99 return s.Policies, err 100 } 101 102 // ExtractResource will get the Association/disassociation of resources from the ResourceResult 103 func (r ResourceResult) ExtractResource() (*ResultResources, error) { 104 var response ResultResources 105 err := r.ExtractInto(&response) 106 return &response, err 107 }