github.com/openshift-online/ocm-sdk-go@v0.1.473/arohcp/v1alpha1/node_pool_status_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 v1alpha1 // github.com/openshift-online/ocm-sdk-go/arohcp/v1alpha1
    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  // NodePoolStatusClient is the client of the 'node_pool_status' resource.
    35  //
    36  // Provides detailed information about the status of an specific NodePool.
    37  type NodePoolStatusClient struct {
    38  	transport http.RoundTripper
    39  	path      string
    40  }
    41  
    42  // NewNodePoolStatusClient creates a new client for the 'node_pool_status'
    43  // resource using the given transport to send the requests and receive the
    44  // responses.
    45  func NewNodePoolStatusClient(transport http.RoundTripper, path string) *NodePoolStatusClient {
    46  	return &NodePoolStatusClient{
    47  		transport: transport,
    48  		path:      path,
    49  	}
    50  }
    51  
    52  // Get creates a request for the 'get' method.
    53  func (c *NodePoolStatusClient) Get() *NodePoolStatusGetRequest {
    54  	return &NodePoolStatusGetRequest{
    55  		transport: c.transport,
    56  		path:      c.path,
    57  	}
    58  }
    59  
    60  // NodePoolStatusPollRequest is the request for the Poll method.
    61  type NodePoolStatusPollRequest struct {
    62  	request    *NodePoolStatusGetRequest
    63  	interval   time.Duration
    64  	statuses   []int
    65  	predicates []func(interface{}) bool
    66  }
    67  
    68  // Parameter adds a query parameter to all the requests that will be used to retrieve the object.
    69  func (r *NodePoolStatusPollRequest) Parameter(name string, value interface{}) *NodePoolStatusPollRequest {
    70  	r.request.Parameter(name, value)
    71  	return r
    72  }
    73  
    74  // Header adds a request header to all the requests that will be used to retrieve the object.
    75  func (r *NodePoolStatusPollRequest) Header(name string, value interface{}) *NodePoolStatusPollRequest {
    76  	r.request.Header(name, value)
    77  	return r
    78  }
    79  
    80  // Interval sets the polling interval. This parameter is mandatory and must be greater than zero.
    81  func (r *NodePoolStatusPollRequest) Interval(value time.Duration) *NodePoolStatusPollRequest {
    82  	r.interval = value
    83  	return r
    84  }
    85  
    86  // Status set the expected status of the response. Multiple values can be set calling this method
    87  // multiple times. The response will be considered successful if the status is any of those values.
    88  func (r *NodePoolStatusPollRequest) Status(value int) *NodePoolStatusPollRequest {
    89  	r.statuses = append(r.statuses, value)
    90  	return r
    91  }
    92  
    93  // Predicate adds a predicate that the response should satisfy be considered successful. Multiple
    94  // predicates can be set calling this method multiple times. The response will be considered successful
    95  // if all the predicates are satisfied.
    96  func (r *NodePoolStatusPollRequest) Predicate(value func(*NodePoolStatusGetResponse) bool) *NodePoolStatusPollRequest {
    97  	r.predicates = append(r.predicates, func(response interface{}) bool {
    98  		return value(response.(*NodePoolStatusGetResponse))
    99  	})
   100  	return r
   101  }
   102  
   103  // StartContext starts the polling loop. Responses will be considered successful if the status is one of
   104  // the values specified with the Status method and if all the predicates specified with the Predicate
   105  // method return nil.
   106  //
   107  // The context must have a timeout or deadline, otherwise this method will immediately return an error.
   108  func (r *NodePoolStatusPollRequest) StartContext(ctx context.Context) (response *NodePoolStatusPollResponse, err error) {
   109  	result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task)
   110  	if result != nil {
   111  		response = &NodePoolStatusPollResponse{
   112  			response: result.(*NodePoolStatusGetResponse),
   113  		}
   114  	}
   115  	return
   116  }
   117  
   118  // task adapts the types of the request/response types so that they can be used with the generic
   119  // polling function from the helpers package.
   120  func (r *NodePoolStatusPollRequest) task(ctx context.Context) (status int, result interface{}, err error) {
   121  	response, err := r.request.SendContext(ctx)
   122  	if response != nil {
   123  		status = response.Status()
   124  		result = response
   125  	}
   126  	return
   127  }
   128  
   129  // NodePoolStatusPollResponse is the response for the Poll method.
   130  type NodePoolStatusPollResponse struct {
   131  	response *NodePoolStatusGetResponse
   132  }
   133  
   134  // Status returns the response status code.
   135  func (r *NodePoolStatusPollResponse) Status() int {
   136  	if r == nil {
   137  		return 0
   138  	}
   139  	return r.response.Status()
   140  }
   141  
   142  // Header returns header of the response.
   143  func (r *NodePoolStatusPollResponse) Header() http.Header {
   144  	if r == nil {
   145  		return nil
   146  	}
   147  	return r.response.Header()
   148  }
   149  
   150  // Error returns the response error.
   151  func (r *NodePoolStatusPollResponse) Error() *errors.Error {
   152  	if r == nil {
   153  		return nil
   154  	}
   155  	return r.response.Error()
   156  }
   157  
   158  // Body returns the value of the 'body' parameter.
   159  func (r *NodePoolStatusPollResponse) Body() *NodePoolStatus {
   160  	return r.response.Body()
   161  }
   162  
   163  // GetBody returns the value of the 'body' parameter and
   164  // a flag indicating if the parameter has a value.
   165  func (r *NodePoolStatusPollResponse) GetBody() (value *NodePoolStatus, ok bool) {
   166  	return r.response.GetBody()
   167  }
   168  
   169  // Poll creates a request to repeatedly retrieve the object till the response has one of a given set
   170  // of states and satisfies a set of predicates.
   171  func (c *NodePoolStatusClient) Poll() *NodePoolStatusPollRequest {
   172  	return &NodePoolStatusPollRequest{
   173  		request: c.Get(),
   174  	}
   175  }
   176  
   177  // NodePoolStatusGetRequest is the request for the 'get' method.
   178  type NodePoolStatusGetRequest struct {
   179  	transport http.RoundTripper
   180  	path      string
   181  	query     url.Values
   182  	header    http.Header
   183  }
   184  
   185  // Parameter adds a query parameter.
   186  func (r *NodePoolStatusGetRequest) Parameter(name string, value interface{}) *NodePoolStatusGetRequest {
   187  	helpers.AddValue(&r.query, name, value)
   188  	return r
   189  }
   190  
   191  // Header adds a request header.
   192  func (r *NodePoolStatusGetRequest) Header(name string, value interface{}) *NodePoolStatusGetRequest {
   193  	helpers.AddHeader(&r.header, name, value)
   194  	return r
   195  }
   196  
   197  // Impersonate wraps requests on behalf of another user.
   198  // Note: Services that do not support this feature may silently ignore this call.
   199  func (r *NodePoolStatusGetRequest) Impersonate(user string) *NodePoolStatusGetRequest {
   200  	helpers.AddImpersonationHeader(&r.header, user)
   201  	return r
   202  }
   203  
   204  // Send sends this request, waits for the response, and returns it.
   205  //
   206  // This is a potentially lengthy operation, as it requires network communication.
   207  // Consider using a context and the SendContext method.
   208  func (r *NodePoolStatusGetRequest) Send() (result *NodePoolStatusGetResponse, err error) {
   209  	return r.SendContext(context.Background())
   210  }
   211  
   212  // SendContext sends this request, waits for the response, and returns it.
   213  func (r *NodePoolStatusGetRequest) SendContext(ctx context.Context) (result *NodePoolStatusGetResponse, err error) {
   214  	query := helpers.CopyQuery(r.query)
   215  	header := helpers.CopyHeader(r.header)
   216  	uri := &url.URL{
   217  		Path:     r.path,
   218  		RawQuery: query.Encode(),
   219  	}
   220  	request := &http.Request{
   221  		Method: "GET",
   222  		URL:    uri,
   223  		Header: header,
   224  	}
   225  	if ctx != nil {
   226  		request = request.WithContext(ctx)
   227  	}
   228  	response, err := r.transport.RoundTrip(request)
   229  	if err != nil {
   230  		return
   231  	}
   232  	defer response.Body.Close()
   233  	result = &NodePoolStatusGetResponse{}
   234  	result.status = response.StatusCode
   235  	result.header = response.Header
   236  	reader := bufio.NewReader(response.Body)
   237  	_, err = reader.Peek(1)
   238  	if err == io.EOF {
   239  		err = nil
   240  		return
   241  	}
   242  	if result.status >= 400 {
   243  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   244  		if err != nil {
   245  			return
   246  		}
   247  		err = result.err
   248  		return
   249  	}
   250  	err = readNodePoolStatusGetResponse(result, reader)
   251  	if err != nil {
   252  		return
   253  	}
   254  	return
   255  }
   256  
   257  // NodePoolStatusGetResponse is the response for the 'get' method.
   258  type NodePoolStatusGetResponse struct {
   259  	status int
   260  	header http.Header
   261  	err    *errors.Error
   262  	body   *NodePoolStatus
   263  }
   264  
   265  // Status returns the response status code.
   266  func (r *NodePoolStatusGetResponse) Status() int {
   267  	if r == nil {
   268  		return 0
   269  	}
   270  	return r.status
   271  }
   272  
   273  // Header returns header of the response.
   274  func (r *NodePoolStatusGetResponse) Header() http.Header {
   275  	if r == nil {
   276  		return nil
   277  	}
   278  	return r.header
   279  }
   280  
   281  // Error returns the response error.
   282  func (r *NodePoolStatusGetResponse) Error() *errors.Error {
   283  	if r == nil {
   284  		return nil
   285  	}
   286  	return r.err
   287  }
   288  
   289  // Body returns the value of the 'body' parameter.
   290  func (r *NodePoolStatusGetResponse) Body() *NodePoolStatus {
   291  	if r == nil {
   292  		return nil
   293  	}
   294  	return r.body
   295  }
   296  
   297  // GetBody returns the value of the 'body' parameter and
   298  // a flag indicating if the parameter has a value.
   299  func (r *NodePoolStatusGetResponse) GetBody() (value *NodePoolStatus, ok bool) {
   300  	ok = r != nil && r.body != nil
   301  	if ok {
   302  		value = r.body
   303  	}
   304  	return
   305  }