github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/autoscaler_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 "bytes" 25 "context" 26 "io" 27 "net/http" 28 "net/url" 29 "time" 30 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // AutoscalerClient is the client of the 'autoscaler' resource. 36 // 37 // Manages global autoscaler configurations for a cluster. 38 type AutoscalerClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewAutoscalerClient creates a new client for the 'autoscaler' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewAutoscalerClient(transport http.RoundTripper, path string) *AutoscalerClient { 47 return &AutoscalerClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Delete creates a request for the 'delete' method. 54 // 55 // Deletes the cluster autoscaler. 56 func (c *AutoscalerClient) Delete() *AutoscalerDeleteRequest { 57 return &AutoscalerDeleteRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // Get creates a request for the 'get' method. 64 // 65 // Retrieves the autoscaler of a cluster. 66 func (c *AutoscalerClient) Get() *AutoscalerGetRequest { 67 return &AutoscalerGetRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // Post creates a request for the 'post' method. 74 // 75 // Creates a new cluster autoscaler object. 76 func (c *AutoscalerClient) Post() *AutoscalerPostRequest { 77 return &AutoscalerPostRequest{ 78 transport: c.transport, 79 path: c.path, 80 } 81 } 82 83 // Update creates a request for the 'update' method. 84 // 85 // Updates the cluster autoscaler. 86 func (c *AutoscalerClient) Update() *AutoscalerUpdateRequest { 87 return &AutoscalerUpdateRequest{ 88 transport: c.transport, 89 path: c.path, 90 } 91 } 92 93 // AutoscalerPollRequest is the request for the Poll method. 94 type AutoscalerPollRequest struct { 95 request *AutoscalerGetRequest 96 interval time.Duration 97 statuses []int 98 predicates []func(interface{}) bool 99 } 100 101 // Parameter adds a query parameter to all the requests that will be used to retrieve the object. 102 func (r *AutoscalerPollRequest) Parameter(name string, value interface{}) *AutoscalerPollRequest { 103 r.request.Parameter(name, value) 104 return r 105 } 106 107 // Header adds a request header to all the requests that will be used to retrieve the object. 108 func (r *AutoscalerPollRequest) Header(name string, value interface{}) *AutoscalerPollRequest { 109 r.request.Header(name, value) 110 return r 111 } 112 113 // Interval sets the polling interval. This parameter is mandatory and must be greater than zero. 114 func (r *AutoscalerPollRequest) Interval(value time.Duration) *AutoscalerPollRequest { 115 r.interval = value 116 return r 117 } 118 119 // Status set the expected status of the response. Multiple values can be set calling this method 120 // multiple times. The response will be considered successful if the status is any of those values. 121 func (r *AutoscalerPollRequest) Status(value int) *AutoscalerPollRequest { 122 r.statuses = append(r.statuses, value) 123 return r 124 } 125 126 // Predicate adds a predicate that the response should satisfy be considered successful. Multiple 127 // predicates can be set calling this method multiple times. The response will be considered successful 128 // if all the predicates are satisfied. 129 func (r *AutoscalerPollRequest) Predicate(value func(*AutoscalerGetResponse) bool) *AutoscalerPollRequest { 130 r.predicates = append(r.predicates, func(response interface{}) bool { 131 return value(response.(*AutoscalerGetResponse)) 132 }) 133 return r 134 } 135 136 // StartContext starts the polling loop. Responses will be considered successful if the status is one of 137 // the values specified with the Status method and if all the predicates specified with the Predicate 138 // method return nil. 139 // 140 // The context must have a timeout or deadline, otherwise this method will immediately return an error. 141 func (r *AutoscalerPollRequest) StartContext(ctx context.Context) (response *AutoscalerPollResponse, err error) { 142 result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task) 143 if result != nil { 144 response = &AutoscalerPollResponse{ 145 response: result.(*AutoscalerGetResponse), 146 } 147 } 148 return 149 } 150 151 // task adapts the types of the request/response types so that they can be used with the generic 152 // polling function from the helpers package. 153 func (r *AutoscalerPollRequest) task(ctx context.Context) (status int, result interface{}, err error) { 154 response, err := r.request.SendContext(ctx) 155 if response != nil { 156 status = response.Status() 157 result = response 158 } 159 return 160 } 161 162 // AutoscalerPollResponse is the response for the Poll method. 163 type AutoscalerPollResponse struct { 164 response *AutoscalerGetResponse 165 } 166 167 // Status returns the response status code. 168 func (r *AutoscalerPollResponse) Status() int { 169 if r == nil { 170 return 0 171 } 172 return r.response.Status() 173 } 174 175 // Header returns header of the response. 176 func (r *AutoscalerPollResponse) Header() http.Header { 177 if r == nil { 178 return nil 179 } 180 return r.response.Header() 181 } 182 183 // Error returns the response error. 184 func (r *AutoscalerPollResponse) Error() *errors.Error { 185 if r == nil { 186 return nil 187 } 188 return r.response.Error() 189 } 190 191 // Body returns the value of the 'body' parameter. 192 func (r *AutoscalerPollResponse) Body() *ClusterAutoscaler { 193 return r.response.Body() 194 } 195 196 // GetBody returns the value of the 'body' parameter and 197 // a flag indicating if the parameter has a value. 198 func (r *AutoscalerPollResponse) GetBody() (value *ClusterAutoscaler, ok bool) { 199 return r.response.GetBody() 200 } 201 202 // Poll creates a request to repeatedly retrieve the object till the response has one of a given set 203 // of states and satisfies a set of predicates. 204 func (c *AutoscalerClient) Poll() *AutoscalerPollRequest { 205 return &AutoscalerPollRequest{ 206 request: c.Get(), 207 } 208 } 209 210 // AutoscalerDeleteRequest is the request for the 'delete' method. 211 type AutoscalerDeleteRequest struct { 212 transport http.RoundTripper 213 path string 214 query url.Values 215 header http.Header 216 } 217 218 // Parameter adds a query parameter. 219 func (r *AutoscalerDeleteRequest) Parameter(name string, value interface{}) *AutoscalerDeleteRequest { 220 helpers.AddValue(&r.query, name, value) 221 return r 222 } 223 224 // Header adds a request header. 225 func (r *AutoscalerDeleteRequest) Header(name string, value interface{}) *AutoscalerDeleteRequest { 226 helpers.AddHeader(&r.header, name, value) 227 return r 228 } 229 230 // Impersonate wraps requests on behalf of another user. 231 // Note: Services that do not support this feature may silently ignore this call. 232 func (r *AutoscalerDeleteRequest) Impersonate(user string) *AutoscalerDeleteRequest { 233 helpers.AddImpersonationHeader(&r.header, user) 234 return r 235 } 236 237 // Send sends this request, waits for the response, and returns it. 238 // 239 // This is a potentially lengthy operation, as it requires network communication. 240 // Consider using a context and the SendContext method. 241 func (r *AutoscalerDeleteRequest) Send() (result *AutoscalerDeleteResponse, err error) { 242 return r.SendContext(context.Background()) 243 } 244 245 // SendContext sends this request, waits for the response, and returns it. 246 func (r *AutoscalerDeleteRequest) SendContext(ctx context.Context) (result *AutoscalerDeleteResponse, err error) { 247 query := helpers.CopyQuery(r.query) 248 header := helpers.CopyHeader(r.header) 249 uri := &url.URL{ 250 Path: r.path, 251 RawQuery: query.Encode(), 252 } 253 request := &http.Request{ 254 Method: "DELETE", 255 URL: uri, 256 Header: header, 257 } 258 if ctx != nil { 259 request = request.WithContext(ctx) 260 } 261 response, err := r.transport.RoundTrip(request) 262 if err != nil { 263 return 264 } 265 defer response.Body.Close() 266 result = &AutoscalerDeleteResponse{} 267 result.status = response.StatusCode 268 result.header = response.Header 269 reader := bufio.NewReader(response.Body) 270 _, err = reader.Peek(1) 271 if err == io.EOF { 272 err = nil 273 return 274 } 275 if result.status >= 400 { 276 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 277 if err != nil { 278 return 279 } 280 err = result.err 281 return 282 } 283 return 284 } 285 286 // AutoscalerDeleteResponse is the response for the 'delete' method. 287 type AutoscalerDeleteResponse struct { 288 status int 289 header http.Header 290 err *errors.Error 291 } 292 293 // Status returns the response status code. 294 func (r *AutoscalerDeleteResponse) Status() int { 295 if r == nil { 296 return 0 297 } 298 return r.status 299 } 300 301 // Header returns header of the response. 302 func (r *AutoscalerDeleteResponse) Header() http.Header { 303 if r == nil { 304 return nil 305 } 306 return r.header 307 } 308 309 // Error returns the response error. 310 func (r *AutoscalerDeleteResponse) Error() *errors.Error { 311 if r == nil { 312 return nil 313 } 314 return r.err 315 } 316 317 // AutoscalerGetRequest is the request for the 'get' method. 318 type AutoscalerGetRequest struct { 319 transport http.RoundTripper 320 path string 321 query url.Values 322 header http.Header 323 } 324 325 // Parameter adds a query parameter. 326 func (r *AutoscalerGetRequest) Parameter(name string, value interface{}) *AutoscalerGetRequest { 327 helpers.AddValue(&r.query, name, value) 328 return r 329 } 330 331 // Header adds a request header. 332 func (r *AutoscalerGetRequest) Header(name string, value interface{}) *AutoscalerGetRequest { 333 helpers.AddHeader(&r.header, name, value) 334 return r 335 } 336 337 // Impersonate wraps requests on behalf of another user. 338 // Note: Services that do not support this feature may silently ignore this call. 339 func (r *AutoscalerGetRequest) Impersonate(user string) *AutoscalerGetRequest { 340 helpers.AddImpersonationHeader(&r.header, user) 341 return r 342 } 343 344 // Send sends this request, waits for the response, and returns it. 345 // 346 // This is a potentially lengthy operation, as it requires network communication. 347 // Consider using a context and the SendContext method. 348 func (r *AutoscalerGetRequest) Send() (result *AutoscalerGetResponse, err error) { 349 return r.SendContext(context.Background()) 350 } 351 352 // SendContext sends this request, waits for the response, and returns it. 353 func (r *AutoscalerGetRequest) SendContext(ctx context.Context) (result *AutoscalerGetResponse, err error) { 354 query := helpers.CopyQuery(r.query) 355 header := helpers.CopyHeader(r.header) 356 uri := &url.URL{ 357 Path: r.path, 358 RawQuery: query.Encode(), 359 } 360 request := &http.Request{ 361 Method: "GET", 362 URL: uri, 363 Header: header, 364 } 365 if ctx != nil { 366 request = request.WithContext(ctx) 367 } 368 response, err := r.transport.RoundTrip(request) 369 if err != nil { 370 return 371 } 372 defer response.Body.Close() 373 result = &AutoscalerGetResponse{} 374 result.status = response.StatusCode 375 result.header = response.Header 376 reader := bufio.NewReader(response.Body) 377 _, err = reader.Peek(1) 378 if err == io.EOF { 379 err = nil 380 return 381 } 382 if result.status >= 400 { 383 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 384 if err != nil { 385 return 386 } 387 err = result.err 388 return 389 } 390 err = readAutoscalerGetResponse(result, reader) 391 if err != nil { 392 return 393 } 394 return 395 } 396 397 // AutoscalerGetResponse is the response for the 'get' method. 398 type AutoscalerGetResponse struct { 399 status int 400 header http.Header 401 err *errors.Error 402 body *ClusterAutoscaler 403 } 404 405 // Status returns the response status code. 406 func (r *AutoscalerGetResponse) Status() int { 407 if r == nil { 408 return 0 409 } 410 return r.status 411 } 412 413 // Header returns header of the response. 414 func (r *AutoscalerGetResponse) Header() http.Header { 415 if r == nil { 416 return nil 417 } 418 return r.header 419 } 420 421 // Error returns the response error. 422 func (r *AutoscalerGetResponse) Error() *errors.Error { 423 if r == nil { 424 return nil 425 } 426 return r.err 427 } 428 429 // Body returns the value of the 'body' parameter. 430 func (r *AutoscalerGetResponse) Body() *ClusterAutoscaler { 431 if r == nil { 432 return nil 433 } 434 return r.body 435 } 436 437 // GetBody returns the value of the 'body' parameter and 438 // a flag indicating if the parameter has a value. 439 func (r *AutoscalerGetResponse) GetBody() (value *ClusterAutoscaler, ok bool) { 440 ok = r != nil && r.body != nil 441 if ok { 442 value = r.body 443 } 444 return 445 } 446 447 // AutoscalerPostRequest is the request for the 'post' method. 448 type AutoscalerPostRequest struct { 449 transport http.RoundTripper 450 path string 451 query url.Values 452 header http.Header 453 request *ClusterAutoscaler 454 } 455 456 // Parameter adds a query parameter. 457 func (r *AutoscalerPostRequest) Parameter(name string, value interface{}) *AutoscalerPostRequest { 458 helpers.AddValue(&r.query, name, value) 459 return r 460 } 461 462 // Header adds a request header. 463 func (r *AutoscalerPostRequest) Header(name string, value interface{}) *AutoscalerPostRequest { 464 helpers.AddHeader(&r.header, name, value) 465 return r 466 } 467 468 // Impersonate wraps requests on behalf of another user. 469 // Note: Services that do not support this feature may silently ignore this call. 470 func (r *AutoscalerPostRequest) Impersonate(user string) *AutoscalerPostRequest { 471 helpers.AddImpersonationHeader(&r.header, user) 472 return r 473 } 474 475 // Request sets the value of the 'request' parameter. 476 func (r *AutoscalerPostRequest) Request(value *ClusterAutoscaler) *AutoscalerPostRequest { 477 r.request = value 478 return r 479 } 480 481 // Send sends this request, waits for the response, and returns it. 482 // 483 // This is a potentially lengthy operation, as it requires network communication. 484 // Consider using a context and the SendContext method. 485 func (r *AutoscalerPostRequest) Send() (result *AutoscalerPostResponse, err error) { 486 return r.SendContext(context.Background()) 487 } 488 489 // SendContext sends this request, waits for the response, and returns it. 490 func (r *AutoscalerPostRequest) SendContext(ctx context.Context) (result *AutoscalerPostResponse, err error) { 491 query := helpers.CopyQuery(r.query) 492 header := helpers.CopyHeader(r.header) 493 buffer := &bytes.Buffer{} 494 err = writeAutoscalerPostRequest(r, buffer) 495 if err != nil { 496 return 497 } 498 uri := &url.URL{ 499 Path: r.path, 500 RawQuery: query.Encode(), 501 } 502 request := &http.Request{ 503 Method: "POST", 504 URL: uri, 505 Header: header, 506 Body: io.NopCloser(buffer), 507 } 508 if ctx != nil { 509 request = request.WithContext(ctx) 510 } 511 response, err := r.transport.RoundTrip(request) 512 if err != nil { 513 return 514 } 515 defer response.Body.Close() 516 result = &AutoscalerPostResponse{} 517 result.status = response.StatusCode 518 result.header = response.Header 519 reader := bufio.NewReader(response.Body) 520 _, err = reader.Peek(1) 521 if err == io.EOF { 522 err = nil 523 return 524 } 525 if result.status >= 400 { 526 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 527 if err != nil { 528 return 529 } 530 err = result.err 531 return 532 } 533 err = readAutoscalerPostResponse(result, reader) 534 if err != nil { 535 return 536 } 537 return 538 } 539 540 // AutoscalerPostResponse is the response for the 'post' method. 541 type AutoscalerPostResponse struct { 542 status int 543 header http.Header 544 err *errors.Error 545 body *ClusterAutoscaler 546 } 547 548 // Status returns the response status code. 549 func (r *AutoscalerPostResponse) Status() int { 550 if r == nil { 551 return 0 552 } 553 return r.status 554 } 555 556 // Header returns header of the response. 557 func (r *AutoscalerPostResponse) Header() http.Header { 558 if r == nil { 559 return nil 560 } 561 return r.header 562 } 563 564 // Error returns the response error. 565 func (r *AutoscalerPostResponse) Error() *errors.Error { 566 if r == nil { 567 return nil 568 } 569 return r.err 570 } 571 572 // Body returns the value of the 'body' parameter. 573 func (r *AutoscalerPostResponse) Body() *ClusterAutoscaler { 574 if r == nil { 575 return nil 576 } 577 return r.body 578 } 579 580 // GetBody returns the value of the 'body' parameter and 581 // a flag indicating if the parameter has a value. 582 func (r *AutoscalerPostResponse) GetBody() (value *ClusterAutoscaler, ok bool) { 583 ok = r != nil && r.body != nil 584 if ok { 585 value = r.body 586 } 587 return 588 } 589 590 // AutoscalerUpdateRequest is the request for the 'update' method. 591 type AutoscalerUpdateRequest struct { 592 transport http.RoundTripper 593 path string 594 query url.Values 595 header http.Header 596 body *ClusterAutoscaler 597 } 598 599 // Parameter adds a query parameter. 600 func (r *AutoscalerUpdateRequest) Parameter(name string, value interface{}) *AutoscalerUpdateRequest { 601 helpers.AddValue(&r.query, name, value) 602 return r 603 } 604 605 // Header adds a request header. 606 func (r *AutoscalerUpdateRequest) Header(name string, value interface{}) *AutoscalerUpdateRequest { 607 helpers.AddHeader(&r.header, name, value) 608 return r 609 } 610 611 // Impersonate wraps requests on behalf of another user. 612 // Note: Services that do not support this feature may silently ignore this call. 613 func (r *AutoscalerUpdateRequest) Impersonate(user string) *AutoscalerUpdateRequest { 614 helpers.AddImpersonationHeader(&r.header, user) 615 return r 616 } 617 618 // Body sets the value of the 'body' parameter. 619 func (r *AutoscalerUpdateRequest) Body(value *ClusterAutoscaler) *AutoscalerUpdateRequest { 620 r.body = value 621 return r 622 } 623 624 // Send sends this request, waits for the response, and returns it. 625 // 626 // This is a potentially lengthy operation, as it requires network communication. 627 // Consider using a context and the SendContext method. 628 func (r *AutoscalerUpdateRequest) Send() (result *AutoscalerUpdateResponse, err error) { 629 return r.SendContext(context.Background()) 630 } 631 632 // SendContext sends this request, waits for the response, and returns it. 633 func (r *AutoscalerUpdateRequest) SendContext(ctx context.Context) (result *AutoscalerUpdateResponse, err error) { 634 query := helpers.CopyQuery(r.query) 635 header := helpers.CopyHeader(r.header) 636 buffer := &bytes.Buffer{} 637 err = writeAutoscalerUpdateRequest(r, buffer) 638 if err != nil { 639 return 640 } 641 uri := &url.URL{ 642 Path: r.path, 643 RawQuery: query.Encode(), 644 } 645 request := &http.Request{ 646 Method: "PATCH", 647 URL: uri, 648 Header: header, 649 Body: io.NopCloser(buffer), 650 } 651 if ctx != nil { 652 request = request.WithContext(ctx) 653 } 654 response, err := r.transport.RoundTrip(request) 655 if err != nil { 656 return 657 } 658 defer response.Body.Close() 659 result = &AutoscalerUpdateResponse{} 660 result.status = response.StatusCode 661 result.header = response.Header 662 reader := bufio.NewReader(response.Body) 663 _, err = reader.Peek(1) 664 if err == io.EOF { 665 err = nil 666 return 667 } 668 if result.status >= 400 { 669 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 670 if err != nil { 671 return 672 } 673 err = result.err 674 return 675 } 676 err = readAutoscalerUpdateResponse(result, reader) 677 if err != nil { 678 return 679 } 680 return 681 } 682 683 // AutoscalerUpdateResponse is the response for the 'update' method. 684 type AutoscalerUpdateResponse struct { 685 status int 686 header http.Header 687 err *errors.Error 688 body *ClusterAutoscaler 689 } 690 691 // Status returns the response status code. 692 func (r *AutoscalerUpdateResponse) Status() int { 693 if r == nil { 694 return 0 695 } 696 return r.status 697 } 698 699 // Header returns header of the response. 700 func (r *AutoscalerUpdateResponse) Header() http.Header { 701 if r == nil { 702 return nil 703 } 704 return r.header 705 } 706 707 // Error returns the response error. 708 func (r *AutoscalerUpdateResponse) Error() *errors.Error { 709 if r == nil { 710 return nil 711 } 712 return r.err 713 } 714 715 // Body returns the value of the 'body' parameter. 716 func (r *AutoscalerUpdateResponse) Body() *ClusterAutoscaler { 717 if r == nil { 718 return nil 719 } 720 return r.body 721 } 722 723 // GetBody returns the value of the 'body' parameter and 724 // a flag indicating if the parameter has a value. 725 func (r *AutoscalerUpdateResponse) GetBody() (value *ClusterAutoscaler, ok bool) { 726 ok = r != nil && r.body != nil 727 if ok { 728 value = r.body 729 } 730 return 731 }