github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/cpu_total_by_node_roles_os_metric_query_client.go (about) 1 /* 2 Copyright (c) 2020 Red Hat, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // IMPORTANT: This file has been generated automatically, refrain from modifying it manually as all 18 // your changes will be lost when the file is generated again. 19 20 package v1 // github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1 21 22 import ( 23 "bufio" 24 "context" 25 "io" 26 "net/http" 27 "net/url" 28 "time" 29 30 "github.com/openshift-online/ocm-sdk-go/errors" 31 "github.com/openshift-online/ocm-sdk-go/helpers" 32 ) 33 34 // CPUTotalByNodeRolesOSMetricQueryClient is the client of the 'CPU_total_by_node_roles_OS_metric_query' resource. 35 // 36 // Total cpu capacity in the cluster by node role and operating system. 37 type CPUTotalByNodeRolesOSMetricQueryClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewCPUTotalByNodeRolesOSMetricQueryClient creates a new client for the 'CPU_total_by_node_roles_OS_metric_query' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewCPUTotalByNodeRolesOSMetricQueryClient(transport http.RoundTripper, path string) *CPUTotalByNodeRolesOSMetricQueryClient { 46 return &CPUTotalByNodeRolesOSMetricQueryClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // Get creates a request for the 'get' method. 53 // 54 // Retrieves the metrics. 55 func (c *CPUTotalByNodeRolesOSMetricQueryClient) Get() *CPUTotalByNodeRolesOSMetricQueryGetRequest { 56 return &CPUTotalByNodeRolesOSMetricQueryGetRequest{ 57 transport: c.transport, 58 path: c.path, 59 } 60 } 61 62 // CPUTotalByNodeRolesOSMetricQueryPollRequest is the request for the Poll method. 63 type CPUTotalByNodeRolesOSMetricQueryPollRequest struct { 64 request *CPUTotalByNodeRolesOSMetricQueryGetRequest 65 interval time.Duration 66 statuses []int 67 predicates []func(interface{}) bool 68 } 69 70 // Parameter adds a query parameter to all the requests that will be used to retrieve the object. 71 func (r *CPUTotalByNodeRolesOSMetricQueryPollRequest) Parameter(name string, value interface{}) *CPUTotalByNodeRolesOSMetricQueryPollRequest { 72 r.request.Parameter(name, value) 73 return r 74 } 75 76 // Header adds a request header to all the requests that will be used to retrieve the object. 77 func (r *CPUTotalByNodeRolesOSMetricQueryPollRequest) Header(name string, value interface{}) *CPUTotalByNodeRolesOSMetricQueryPollRequest { 78 r.request.Header(name, value) 79 return r 80 } 81 82 // Interval sets the polling interval. This parameter is mandatory and must be greater than zero. 83 func (r *CPUTotalByNodeRolesOSMetricQueryPollRequest) Interval(value time.Duration) *CPUTotalByNodeRolesOSMetricQueryPollRequest { 84 r.interval = value 85 return r 86 } 87 88 // Status set the expected status of the response. Multiple values can be set calling this method 89 // multiple times. The response will be considered successful if the status is any of those values. 90 func (r *CPUTotalByNodeRolesOSMetricQueryPollRequest) Status(value int) *CPUTotalByNodeRolesOSMetricQueryPollRequest { 91 r.statuses = append(r.statuses, value) 92 return r 93 } 94 95 // Predicate adds a predicate that the response should satisfy be considered successful. Multiple 96 // predicates can be set calling this method multiple times. The response will be considered successful 97 // if all the predicates are satisfied. 98 func (r *CPUTotalByNodeRolesOSMetricQueryPollRequest) Predicate(value func(*CPUTotalByNodeRolesOSMetricQueryGetResponse) bool) *CPUTotalByNodeRolesOSMetricQueryPollRequest { 99 r.predicates = append(r.predicates, func(response interface{}) bool { 100 return value(response.(*CPUTotalByNodeRolesOSMetricQueryGetResponse)) 101 }) 102 return r 103 } 104 105 // StartContext starts the polling loop. Responses will be considered successful if the status is one of 106 // the values specified with the Status method and if all the predicates specified with the Predicate 107 // method return nil. 108 // 109 // The context must have a timeout or deadline, otherwise this method will immediately return an error. 110 func (r *CPUTotalByNodeRolesOSMetricQueryPollRequest) StartContext(ctx context.Context) (response *CPUTotalByNodeRolesOSMetricQueryPollResponse, err error) { 111 result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task) 112 if result != nil { 113 response = &CPUTotalByNodeRolesOSMetricQueryPollResponse{ 114 response: result.(*CPUTotalByNodeRolesOSMetricQueryGetResponse), 115 } 116 } 117 return 118 } 119 120 // task adapts the types of the request/response types so that they can be used with the generic 121 // polling function from the helpers package. 122 func (r *CPUTotalByNodeRolesOSMetricQueryPollRequest) task(ctx context.Context) (status int, result interface{}, err error) { 123 response, err := r.request.SendContext(ctx) 124 if response != nil { 125 status = response.Status() 126 result = response 127 } 128 return 129 } 130 131 // CPUTotalByNodeRolesOSMetricQueryPollResponse is the response for the Poll method. 132 type CPUTotalByNodeRolesOSMetricQueryPollResponse struct { 133 response *CPUTotalByNodeRolesOSMetricQueryGetResponse 134 } 135 136 // Status returns the response status code. 137 func (r *CPUTotalByNodeRolesOSMetricQueryPollResponse) Status() int { 138 if r == nil { 139 return 0 140 } 141 return r.response.Status() 142 } 143 144 // Header returns header of the response. 145 func (r *CPUTotalByNodeRolesOSMetricQueryPollResponse) Header() http.Header { 146 if r == nil { 147 return nil 148 } 149 return r.response.Header() 150 } 151 152 // Error returns the response error. 153 func (r *CPUTotalByNodeRolesOSMetricQueryPollResponse) Error() *errors.Error { 154 if r == nil { 155 return nil 156 } 157 return r.response.Error() 158 } 159 160 // Body returns the value of the 'body' parameter. 161 func (r *CPUTotalByNodeRolesOSMetricQueryPollResponse) Body() *CPUTotalsNodeRoleOSMetricNode { 162 return r.response.Body() 163 } 164 165 // GetBody returns the value of the 'body' parameter and 166 // a flag indicating if the parameter has a value. 167 func (r *CPUTotalByNodeRolesOSMetricQueryPollResponse) GetBody() (value *CPUTotalsNodeRoleOSMetricNode, ok bool) { 168 return r.response.GetBody() 169 } 170 171 // Poll creates a request to repeatedly retrieve the object till the response has one of a given set 172 // of states and satisfies a set of predicates. 173 func (c *CPUTotalByNodeRolesOSMetricQueryClient) Poll() *CPUTotalByNodeRolesOSMetricQueryPollRequest { 174 return &CPUTotalByNodeRolesOSMetricQueryPollRequest{ 175 request: c.Get(), 176 } 177 } 178 179 // CPUTotalByNodeRolesOSMetricQueryGetRequest is the request for the 'get' method. 180 type CPUTotalByNodeRolesOSMetricQueryGetRequest struct { 181 transport http.RoundTripper 182 path string 183 query url.Values 184 header http.Header 185 } 186 187 // Parameter adds a query parameter. 188 func (r *CPUTotalByNodeRolesOSMetricQueryGetRequest) Parameter(name string, value interface{}) *CPUTotalByNodeRolesOSMetricQueryGetRequest { 189 helpers.AddValue(&r.query, name, value) 190 return r 191 } 192 193 // Header adds a request header. 194 func (r *CPUTotalByNodeRolesOSMetricQueryGetRequest) Header(name string, value interface{}) *CPUTotalByNodeRolesOSMetricQueryGetRequest { 195 helpers.AddHeader(&r.header, name, value) 196 return r 197 } 198 199 // Impersonate wraps requests on behalf of another user. 200 // Note: Services that do not support this feature may silently ignore this call. 201 func (r *CPUTotalByNodeRolesOSMetricQueryGetRequest) Impersonate(user string) *CPUTotalByNodeRolesOSMetricQueryGetRequest { 202 helpers.AddImpersonationHeader(&r.header, user) 203 return r 204 } 205 206 // Send sends this request, waits for the response, and returns it. 207 // 208 // This is a potentially lengthy operation, as it requires network communication. 209 // Consider using a context and the SendContext method. 210 func (r *CPUTotalByNodeRolesOSMetricQueryGetRequest) Send() (result *CPUTotalByNodeRolesOSMetricQueryGetResponse, err error) { 211 return r.SendContext(context.Background()) 212 } 213 214 // SendContext sends this request, waits for the response, and returns it. 215 func (r *CPUTotalByNodeRolesOSMetricQueryGetRequest) SendContext(ctx context.Context) (result *CPUTotalByNodeRolesOSMetricQueryGetResponse, err error) { 216 query := helpers.CopyQuery(r.query) 217 header := helpers.CopyHeader(r.header) 218 uri := &url.URL{ 219 Path: r.path, 220 RawQuery: query.Encode(), 221 } 222 request := &http.Request{ 223 Method: "GET", 224 URL: uri, 225 Header: header, 226 } 227 if ctx != nil { 228 request = request.WithContext(ctx) 229 } 230 response, err := r.transport.RoundTrip(request) 231 if err != nil { 232 return 233 } 234 defer response.Body.Close() 235 result = &CPUTotalByNodeRolesOSMetricQueryGetResponse{} 236 result.status = response.StatusCode 237 result.header = response.Header 238 reader := bufio.NewReader(response.Body) 239 _, err = reader.Peek(1) 240 if err == io.EOF { 241 err = nil 242 return 243 } 244 if result.status >= 400 { 245 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 246 if err != nil { 247 return 248 } 249 err = result.err 250 return 251 } 252 err = readCPUTotalByNodeRolesOSMetricQueryGetResponse(result, reader) 253 if err != nil { 254 return 255 } 256 return 257 } 258 259 // CPUTotalByNodeRolesOSMetricQueryGetResponse is the response for the 'get' method. 260 type CPUTotalByNodeRolesOSMetricQueryGetResponse struct { 261 status int 262 header http.Header 263 err *errors.Error 264 body *CPUTotalsNodeRoleOSMetricNode 265 } 266 267 // Status returns the response status code. 268 func (r *CPUTotalByNodeRolesOSMetricQueryGetResponse) Status() int { 269 if r == nil { 270 return 0 271 } 272 return r.status 273 } 274 275 // Header returns header of the response. 276 func (r *CPUTotalByNodeRolesOSMetricQueryGetResponse) Header() http.Header { 277 if r == nil { 278 return nil 279 } 280 return r.header 281 } 282 283 // Error returns the response error. 284 func (r *CPUTotalByNodeRolesOSMetricQueryGetResponse) Error() *errors.Error { 285 if r == nil { 286 return nil 287 } 288 return r.err 289 } 290 291 // Body returns the value of the 'body' parameter. 292 func (r *CPUTotalByNodeRolesOSMetricQueryGetResponse) Body() *CPUTotalsNodeRoleOSMetricNode { 293 if r == nil { 294 return nil 295 } 296 return r.body 297 } 298 299 // GetBody returns the value of the 'body' parameter and 300 // a flag indicating if the parameter has a value. 301 func (r *CPUTotalByNodeRolesOSMetricQueryGetResponse) GetBody() (value *CPUTotalsNodeRoleOSMetricNode, ok bool) { 302 ok = r != nil && r.body != nil 303 if ok { 304 value = r.body 305 } 306 return 307 }