github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/limits/results.go (about) 1 package limits 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // A model describing the configured enforcement model used by the deployment. 9 type EnforcementModel struct { 10 // The name of the enforcement model. 11 Name string `json:"name"` 12 13 // A short description of the enforcement model used. 14 Description string `json:"description"` 15 } 16 17 // EnforcementModelResult is the response from a GetEnforcementModel operation. Call its Extract method 18 // to interpret it as a EnforcementModel. 19 type EnforcementModelResult struct { 20 gophercloud.Result 21 } 22 23 // Extract interprets EnforcementModelResult as a EnforcementModel. 24 func (r EnforcementModelResult) Extract() (*EnforcementModel, error) { 25 var out struct { 26 Model *EnforcementModel `json:"model"` 27 } 28 err := r.ExtractInto(&out) 29 return out.Model, err 30 } 31 32 // A limit is the limit that override the registered limit for each project. 33 type Limit struct { 34 // ID is the unique ID of the limit. 35 ID string `json:"id"` 36 37 // RegionID is the ID of the region where the limit is applied. 38 RegionID string `json:"region_id"` 39 40 // ProjectID is the ID of the project where the limit is applied. 41 ProjectID string `json:"project_id"` 42 43 // DomainID is the ID of the domain where the limit is applied. 44 DomainID string `json:"domain_id"` 45 46 // ServiceID is the ID of the service where the limit is applied. 47 ServiceID string `json:"service_id"` 48 49 // Description of the limit. 50 Description string `json:"description"` 51 52 // ResourceName is the name of the resource that the limit is applied to. 53 ResourceName string `json:"resource_name"` 54 55 // ResourceLimit is the override limit. 56 ResourceLimit int `json:"resource_limit"` 57 58 // Links contains referencing links to the limit. 59 Links map[string]interface{} `json:"links"` 60 } 61 62 // A LimitsOutput is an array of limits returned by List and BatchCreate operations 63 type LimitsOutput struct { 64 Limits []Limit `json:"limits"` 65 } 66 67 // A LimitOutput is an encapsulated Limit returned by Get and Update operations 68 type LimitOutput struct { 69 Limit *Limit `json:"limit"` 70 } 71 72 // LimitPage is a single page of Limit results. 73 type LimitPage struct { 74 pagination.LinkedPageBase 75 } 76 77 // CreateResult is the response from a Create operation. Call its Extract method 78 // to interpret it as a Limits. 79 type CreateResult struct { 80 gophercloud.Result 81 } 82 83 type commonResult struct { 84 gophercloud.Result 85 } 86 87 // GetResult is the response from a Get operation. Call its Extract method 88 // to interpret it as a Limit. 89 type GetResult struct { 90 commonResult 91 } 92 93 // UpdateResult is the result of an Update request. Call its Extract method to 94 // interpret it as a Limit. 95 type UpdateResult struct { 96 commonResult 97 } 98 99 // DeleteResult is the response from a Delete operation. Call its ExtractErr to 100 // determine if the request succeeded or failed. 101 type DeleteResult struct { 102 gophercloud.ErrResult 103 } 104 105 // IsEmpty determines whether or not a page of Limits contains any results. 106 func (r LimitPage) IsEmpty() (bool, error) { 107 if r.StatusCode == 204 { 108 return true, nil 109 } 110 111 limits, err := ExtractLimits(r) 112 return len(limits) == 0, err 113 } 114 115 // NextPageURL extracts the "next" link from the links section of the result. 116 func (r LimitPage) NextPageURL() (string, error) { 117 var s struct { 118 Links struct { 119 Next string `json:"next"` 120 Previous string `json:"previous"` 121 } `json:"links"` 122 } 123 err := r.ExtractInto(&s) 124 if err != nil { 125 return "", err 126 } 127 return s.Links.Next, err 128 } 129 130 // ExtractLimits returns a slice of Limits contained in a single page of 131 // results. 132 func ExtractLimits(r pagination.Page) ([]Limit, error) { 133 var out LimitsOutput 134 err := (r.(LimitPage)).ExtractInto(&out) 135 return out.Limits, err 136 } 137 138 // Extract interprets CreateResult as slice of Limits. 139 func (r CreateResult) Extract() ([]Limit, error) { 140 var out LimitsOutput 141 err := r.ExtractInto(&out) 142 return out.Limits, err 143 } 144 145 // Extract interprets any commonResult as a Limit. 146 func (r commonResult) Extract() (*Limit, error) { 147 var out LimitOutput 148 err := r.ExtractInto(&out) 149 return out.Limit, err 150 }