github.com/gophercloud/gophercloud@v1.11.0/openstack/clustering/v1/policytypes/results.go (about) 1 package policytypes 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // PolicyType represents a clustering policy type in the Openstack cloud. 9 type PolicyType struct { 10 Name string `json:"name"` 11 Version string `json:"version"` 12 SupportStatus map[string][]SupportStatusType `json:"support_status"` 13 } 14 15 // SupportStatusType represents the support status information for a 16 // clustering policy type. 17 type SupportStatusType struct { 18 Status string `json:"status"` 19 Since string `json:"since"` 20 } 21 22 // PolicyTypeDetail represents the detailed policy type information for a 23 // clustering policy type. 24 type PolicyTypeDetail struct { 25 Name string `json:"name"` 26 Schema map[string]interface{} `json:"schema"` 27 SupportStatus map[string][]SupportStatusType `json:"support_status,omitempty"` 28 } 29 30 // policyTypeResult is the base result of a Policy Type operation. 31 type policyTypeResult struct { 32 gophercloud.Result 33 } 34 35 // Extract interprets any policyTypeResult result as a PolicyTypeDetail. 36 func (r policyTypeResult) Extract() (*PolicyTypeDetail, error) { 37 var s struct { 38 PolicyType *PolicyTypeDetail `json:"policy_type"` 39 } 40 err := r.ExtractInto(&s) 41 return s.PolicyType, err 42 } 43 44 // GetResult is the result of a Get operation. Call its Extract method to 45 // interpret it as a PolicyTypeDetail. 46 type GetResult struct { 47 policyTypeResult 48 } 49 50 // PolicyTypePage contains a single page of all policy types from a List call. 51 type PolicyTypePage struct { 52 pagination.SinglePageBase 53 } 54 55 // IsEmpty determines if a PolicyType contains any results. 56 func (page PolicyTypePage) IsEmpty() (bool, error) { 57 if page.StatusCode == 204 { 58 return true, nil 59 } 60 61 policyTypes, err := ExtractPolicyTypes(page) 62 return len(policyTypes) == 0, err 63 } 64 65 // ExtractPolicyTypes returns a slice of PolicyTypes from a List operation. 66 func ExtractPolicyTypes(r pagination.Page) ([]PolicyType, error) { 67 var s struct { 68 PolicyTypes []PolicyType `json:"policy_types"` 69 } 70 err := (r.(PolicyTypePage)).ExtractInto(&s) 71 return s.PolicyTypes, err 72 }