github.com/openshift-online/ocm-sdk-go@v0.1.473/arohcp/v1alpha1/node_pool_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  	"bytes"
    25  	"context"
    26  	"io"
    27  	"net/http"
    28  	"net/url"
    29  	"path"
    30  	"time"
    31  
    32  	"github.com/openshift-online/ocm-sdk-go/errors"
    33  	"github.com/openshift-online/ocm-sdk-go/helpers"
    34  )
    35  
    36  // NodePoolClient is the client of the 'node_pool' resource.
    37  //
    38  // Manages a specific nodepool.
    39  type NodePoolClient struct {
    40  	transport http.RoundTripper
    41  	path      string
    42  }
    43  
    44  // NewNodePoolClient creates a new client for the 'node_pool'
    45  // resource using the given transport to send the requests and receive the
    46  // responses.
    47  func NewNodePoolClient(transport http.RoundTripper, path string) *NodePoolClient {
    48  	return &NodePoolClient{
    49  		transport: transport,
    50  		path:      path,
    51  	}
    52  }
    53  
    54  // Delete creates a request for the 'async_delete' method.
    55  //
    56  // Deletes the node pool.
    57  func (c *NodePoolClient) Delete() *NodePoolDeleteRequest {
    58  	return &NodePoolDeleteRequest{
    59  		transport: c.transport,
    60  		path:      c.path,
    61  	}
    62  }
    63  
    64  // Update creates a request for the 'async_update' method.
    65  //
    66  // Updates the node pool.
    67  func (c *NodePoolClient) Update() *NodePoolUpdateRequest {
    68  	return &NodePoolUpdateRequest{
    69  		transport: c.transport,
    70  		path:      c.path,
    71  	}
    72  }
    73  
    74  // Get creates a request for the 'get' method.
    75  //
    76  // Retrieves the details of the node pool.
    77  func (c *NodePoolClient) Get() *NodePoolGetRequest {
    78  	return &NodePoolGetRequest{
    79  		transport: c.transport,
    80  		path:      c.path,
    81  	}
    82  }
    83  
    84  // Status returns the target 'node_pool_status' resource.
    85  func (c *NodePoolClient) Status() *NodePoolStatusClient {
    86  	return NewNodePoolStatusClient(
    87  		c.transport,
    88  		path.Join(c.path, "status"),
    89  	)
    90  }
    91  
    92  // NodePoolPollRequest is the request for the Poll method.
    93  type NodePoolPollRequest struct {
    94  	request    *NodePoolGetRequest
    95  	interval   time.Duration
    96  	statuses   []int
    97  	predicates []func(interface{}) bool
    98  }
    99  
   100  // Parameter adds a query parameter to all the requests that will be used to retrieve the object.
   101  func (r *NodePoolPollRequest) Parameter(name string, value interface{}) *NodePoolPollRequest {
   102  	r.request.Parameter(name, value)
   103  	return r
   104  }
   105  
   106  // Header adds a request header to all the requests that will be used to retrieve the object.
   107  func (r *NodePoolPollRequest) Header(name string, value interface{}) *NodePoolPollRequest {
   108  	r.request.Header(name, value)
   109  	return r
   110  }
   111  
   112  // Interval sets the polling interval. This parameter is mandatory and must be greater than zero.
   113  func (r *NodePoolPollRequest) Interval(value time.Duration) *NodePoolPollRequest {
   114  	r.interval = value
   115  	return r
   116  }
   117  
   118  // Status set the expected status of the response. Multiple values can be set calling this method
   119  // multiple times. The response will be considered successful if the status is any of those values.
   120  func (r *NodePoolPollRequest) Status(value int) *NodePoolPollRequest {
   121  	r.statuses = append(r.statuses, value)
   122  	return r
   123  }
   124  
   125  // Predicate adds a predicate that the response should satisfy be considered successful. Multiple
   126  // predicates can be set calling this method multiple times. The response will be considered successful
   127  // if all the predicates are satisfied.
   128  func (r *NodePoolPollRequest) Predicate(value func(*NodePoolGetResponse) bool) *NodePoolPollRequest {
   129  	r.predicates = append(r.predicates, func(response interface{}) bool {
   130  		return value(response.(*NodePoolGetResponse))
   131  	})
   132  	return r
   133  }
   134  
   135  // StartContext starts the polling loop. Responses will be considered successful if the status is one of
   136  // the values specified with the Status method and if all the predicates specified with the Predicate
   137  // method return nil.
   138  //
   139  // The context must have a timeout or deadline, otherwise this method will immediately return an error.
   140  func (r *NodePoolPollRequest) StartContext(ctx context.Context) (response *NodePoolPollResponse, err error) {
   141  	result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task)
   142  	if result != nil {
   143  		response = &NodePoolPollResponse{
   144  			response: result.(*NodePoolGetResponse),
   145  		}
   146  	}
   147  	return
   148  }
   149  
   150  // task adapts the types of the request/response types so that they can be used with the generic
   151  // polling function from the helpers package.
   152  func (r *NodePoolPollRequest) task(ctx context.Context) (status int, result interface{}, err error) {
   153  	response, err := r.request.SendContext(ctx)
   154  	if response != nil {
   155  		status = response.Status()
   156  		result = response
   157  	}
   158  	return
   159  }
   160  
   161  // NodePoolPollResponse is the response for the Poll method.
   162  type NodePoolPollResponse struct {
   163  	response *NodePoolGetResponse
   164  }
   165  
   166  // Status returns the response status code.
   167  func (r *NodePoolPollResponse) Status() int {
   168  	if r == nil {
   169  		return 0
   170  	}
   171  	return r.response.Status()
   172  }
   173  
   174  // Header returns header of the response.
   175  func (r *NodePoolPollResponse) Header() http.Header {
   176  	if r == nil {
   177  		return nil
   178  	}
   179  	return r.response.Header()
   180  }
   181  
   182  // Error returns the response error.
   183  func (r *NodePoolPollResponse) Error() *errors.Error {
   184  	if r == nil {
   185  		return nil
   186  	}
   187  	return r.response.Error()
   188  }
   189  
   190  // Body returns the value of the 'body' parameter.
   191  func (r *NodePoolPollResponse) Body() *NodePool {
   192  	return r.response.Body()
   193  }
   194  
   195  // GetBody returns the value of the 'body' parameter and
   196  // a flag indicating if the parameter has a value.
   197  func (r *NodePoolPollResponse) GetBody() (value *NodePool, ok bool) {
   198  	return r.response.GetBody()
   199  }
   200  
   201  // Poll creates a request to repeatedly retrieve the object till the response has one of a given set
   202  // of states and satisfies a set of predicates.
   203  func (c *NodePoolClient) Poll() *NodePoolPollRequest {
   204  	return &NodePoolPollRequest{
   205  		request: c.Get(),
   206  	}
   207  }
   208  
   209  // NodePoolDeleteRequest is the request for the 'async_delete' method.
   210  type NodePoolDeleteRequest struct {
   211  	transport http.RoundTripper
   212  	path      string
   213  	query     url.Values
   214  	header    http.Header
   215  }
   216  
   217  // Parameter adds a query parameter.
   218  func (r *NodePoolDeleteRequest) Parameter(name string, value interface{}) *NodePoolDeleteRequest {
   219  	helpers.AddValue(&r.query, name, value)
   220  	return r
   221  }
   222  
   223  // Header adds a request header.
   224  func (r *NodePoolDeleteRequest) Header(name string, value interface{}) *NodePoolDeleteRequest {
   225  	helpers.AddHeader(&r.header, name, value)
   226  	return r
   227  }
   228  
   229  // Impersonate wraps requests on behalf of another user.
   230  // Note: Services that do not support this feature may silently ignore this call.
   231  func (r *NodePoolDeleteRequest) Impersonate(user string) *NodePoolDeleteRequest {
   232  	helpers.AddImpersonationHeader(&r.header, user)
   233  	return r
   234  }
   235  
   236  // Send sends this request, waits for the response, and returns it.
   237  //
   238  // This is a potentially lengthy operation, as it requires network communication.
   239  // Consider using a context and the SendContext method.
   240  func (r *NodePoolDeleteRequest) Send() (result *NodePoolDeleteResponse, err error) {
   241  	return r.SendContext(context.Background())
   242  }
   243  
   244  // SendContext sends this request, waits for the response, and returns it.
   245  func (r *NodePoolDeleteRequest) SendContext(ctx context.Context) (result *NodePoolDeleteResponse, err error) {
   246  	query := helpers.CopyQuery(r.query)
   247  	header := helpers.CopyHeader(r.header)
   248  	uri := &url.URL{
   249  		Path:     r.path,
   250  		RawQuery: query.Encode(),
   251  	}
   252  	request := &http.Request{
   253  		Method: "DELETE",
   254  		URL:    uri,
   255  		Header: header,
   256  	}
   257  	if ctx != nil {
   258  		request = request.WithContext(ctx)
   259  	}
   260  	response, err := r.transport.RoundTrip(request)
   261  	if err != nil {
   262  		return
   263  	}
   264  	defer response.Body.Close()
   265  	result = &NodePoolDeleteResponse{}
   266  	result.status = response.StatusCode
   267  	result.header = response.Header
   268  	reader := bufio.NewReader(response.Body)
   269  	_, err = reader.Peek(1)
   270  	if err == io.EOF {
   271  		err = nil
   272  		return
   273  	}
   274  	if result.status >= 400 {
   275  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   276  		if err != nil {
   277  			return
   278  		}
   279  		err = result.err
   280  		return
   281  	}
   282  	return
   283  }
   284  
   285  // NodePoolDeleteResponse is the response for the 'async_delete' method.
   286  type NodePoolDeleteResponse struct {
   287  	status int
   288  	header http.Header
   289  	err    *errors.Error
   290  }
   291  
   292  // Status returns the response status code.
   293  func (r *NodePoolDeleteResponse) Status() int {
   294  	if r == nil {
   295  		return 0
   296  	}
   297  	return r.status
   298  }
   299  
   300  // Header returns header of the response.
   301  func (r *NodePoolDeleteResponse) Header() http.Header {
   302  	if r == nil {
   303  		return nil
   304  	}
   305  	return r.header
   306  }
   307  
   308  // Error returns the response error.
   309  func (r *NodePoolDeleteResponse) Error() *errors.Error {
   310  	if r == nil {
   311  		return nil
   312  	}
   313  	return r.err
   314  }
   315  
   316  // NodePoolUpdateRequest is the request for the 'async_update' method.
   317  type NodePoolUpdateRequest struct {
   318  	transport http.RoundTripper
   319  	path      string
   320  	query     url.Values
   321  	header    http.Header
   322  	body      *NodePool
   323  }
   324  
   325  // Parameter adds a query parameter.
   326  func (r *NodePoolUpdateRequest) Parameter(name string, value interface{}) *NodePoolUpdateRequest {
   327  	helpers.AddValue(&r.query, name, value)
   328  	return r
   329  }
   330  
   331  // Header adds a request header.
   332  func (r *NodePoolUpdateRequest) Header(name string, value interface{}) *NodePoolUpdateRequest {
   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 *NodePoolUpdateRequest) Impersonate(user string) *NodePoolUpdateRequest {
   340  	helpers.AddImpersonationHeader(&r.header, user)
   341  	return r
   342  }
   343  
   344  // Body sets the value of the 'body' parameter.
   345  func (r *NodePoolUpdateRequest) Body(value *NodePool) *NodePoolUpdateRequest {
   346  	r.body = value
   347  	return r
   348  }
   349  
   350  // Send sends this request, waits for the response, and returns it.
   351  //
   352  // This is a potentially lengthy operation, as it requires network communication.
   353  // Consider using a context and the SendContext method.
   354  func (r *NodePoolUpdateRequest) Send() (result *NodePoolUpdateResponse, err error) {
   355  	return r.SendContext(context.Background())
   356  }
   357  
   358  // SendContext sends this request, waits for the response, and returns it.
   359  func (r *NodePoolUpdateRequest) SendContext(ctx context.Context) (result *NodePoolUpdateResponse, err error) {
   360  	query := helpers.CopyQuery(r.query)
   361  	header := helpers.CopyHeader(r.header)
   362  	buffer := &bytes.Buffer{}
   363  	err = writeNodePoolAsyncUpdateRequest(r, buffer)
   364  	if err != nil {
   365  		return
   366  	}
   367  	uri := &url.URL{
   368  		Path:     r.path,
   369  		RawQuery: query.Encode(),
   370  	}
   371  	request := &http.Request{
   372  		Method: "PATCH",
   373  		URL:    uri,
   374  		Header: header,
   375  		Body:   io.NopCloser(buffer),
   376  	}
   377  	if ctx != nil {
   378  		request = request.WithContext(ctx)
   379  	}
   380  	response, err := r.transport.RoundTrip(request)
   381  	if err != nil {
   382  		return
   383  	}
   384  	defer response.Body.Close()
   385  	result = &NodePoolUpdateResponse{}
   386  	result.status = response.StatusCode
   387  	result.header = response.Header
   388  	reader := bufio.NewReader(response.Body)
   389  	_, err = reader.Peek(1)
   390  	if err == io.EOF {
   391  		err = nil
   392  		return
   393  	}
   394  	if result.status >= 400 {
   395  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   396  		if err != nil {
   397  			return
   398  		}
   399  		err = result.err
   400  		return
   401  	}
   402  	err = readNodePoolAsyncUpdateResponse(result, reader)
   403  	if err != nil {
   404  		return
   405  	}
   406  	return
   407  }
   408  
   409  // NodePoolUpdateResponse is the response for the 'async_update' method.
   410  type NodePoolUpdateResponse struct {
   411  	status int
   412  	header http.Header
   413  	err    *errors.Error
   414  	body   *NodePool
   415  }
   416  
   417  // Status returns the response status code.
   418  func (r *NodePoolUpdateResponse) Status() int {
   419  	if r == nil {
   420  		return 0
   421  	}
   422  	return r.status
   423  }
   424  
   425  // Header returns header of the response.
   426  func (r *NodePoolUpdateResponse) Header() http.Header {
   427  	if r == nil {
   428  		return nil
   429  	}
   430  	return r.header
   431  }
   432  
   433  // Error returns the response error.
   434  func (r *NodePoolUpdateResponse) Error() *errors.Error {
   435  	if r == nil {
   436  		return nil
   437  	}
   438  	return r.err
   439  }
   440  
   441  // Body returns the value of the 'body' parameter.
   442  func (r *NodePoolUpdateResponse) Body() *NodePool {
   443  	if r == nil {
   444  		return nil
   445  	}
   446  	return r.body
   447  }
   448  
   449  // GetBody returns the value of the 'body' parameter and
   450  // a flag indicating if the parameter has a value.
   451  func (r *NodePoolUpdateResponse) GetBody() (value *NodePool, ok bool) {
   452  	ok = r != nil && r.body != nil
   453  	if ok {
   454  		value = r.body
   455  	}
   456  	return
   457  }
   458  
   459  // NodePoolGetRequest is the request for the 'get' method.
   460  type NodePoolGetRequest struct {
   461  	transport http.RoundTripper
   462  	path      string
   463  	query     url.Values
   464  	header    http.Header
   465  }
   466  
   467  // Parameter adds a query parameter.
   468  func (r *NodePoolGetRequest) Parameter(name string, value interface{}) *NodePoolGetRequest {
   469  	helpers.AddValue(&r.query, name, value)
   470  	return r
   471  }
   472  
   473  // Header adds a request header.
   474  func (r *NodePoolGetRequest) Header(name string, value interface{}) *NodePoolGetRequest {
   475  	helpers.AddHeader(&r.header, name, value)
   476  	return r
   477  }
   478  
   479  // Impersonate wraps requests on behalf of another user.
   480  // Note: Services that do not support this feature may silently ignore this call.
   481  func (r *NodePoolGetRequest) Impersonate(user string) *NodePoolGetRequest {
   482  	helpers.AddImpersonationHeader(&r.header, user)
   483  	return r
   484  }
   485  
   486  // Send sends this request, waits for the response, and returns it.
   487  //
   488  // This is a potentially lengthy operation, as it requires network communication.
   489  // Consider using a context and the SendContext method.
   490  func (r *NodePoolGetRequest) Send() (result *NodePoolGetResponse, err error) {
   491  	return r.SendContext(context.Background())
   492  }
   493  
   494  // SendContext sends this request, waits for the response, and returns it.
   495  func (r *NodePoolGetRequest) SendContext(ctx context.Context) (result *NodePoolGetResponse, err error) {
   496  	query := helpers.CopyQuery(r.query)
   497  	header := helpers.CopyHeader(r.header)
   498  	uri := &url.URL{
   499  		Path:     r.path,
   500  		RawQuery: query.Encode(),
   501  	}
   502  	request := &http.Request{
   503  		Method: "GET",
   504  		URL:    uri,
   505  		Header: header,
   506  	}
   507  	if ctx != nil {
   508  		request = request.WithContext(ctx)
   509  	}
   510  	response, err := r.transport.RoundTrip(request)
   511  	if err != nil {
   512  		return
   513  	}
   514  	defer response.Body.Close()
   515  	result = &NodePoolGetResponse{}
   516  	result.status = response.StatusCode
   517  	result.header = response.Header
   518  	reader := bufio.NewReader(response.Body)
   519  	_, err = reader.Peek(1)
   520  	if err == io.EOF {
   521  		err = nil
   522  		return
   523  	}
   524  	if result.status >= 400 {
   525  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   526  		if err != nil {
   527  			return
   528  		}
   529  		err = result.err
   530  		return
   531  	}
   532  	err = readNodePoolGetResponse(result, reader)
   533  	if err != nil {
   534  		return
   535  	}
   536  	return
   537  }
   538  
   539  // NodePoolGetResponse is the response for the 'get' method.
   540  type NodePoolGetResponse struct {
   541  	status int
   542  	header http.Header
   543  	err    *errors.Error
   544  	body   *NodePool
   545  }
   546  
   547  // Status returns the response status code.
   548  func (r *NodePoolGetResponse) Status() int {
   549  	if r == nil {
   550  		return 0
   551  	}
   552  	return r.status
   553  }
   554  
   555  // Header returns header of the response.
   556  func (r *NodePoolGetResponse) Header() http.Header {
   557  	if r == nil {
   558  		return nil
   559  	}
   560  	return r.header
   561  }
   562  
   563  // Error returns the response error.
   564  func (r *NodePoolGetResponse) Error() *errors.Error {
   565  	if r == nil {
   566  		return nil
   567  	}
   568  	return r.err
   569  }
   570  
   571  // Body returns the value of the 'body' parameter.
   572  func (r *NodePoolGetResponse) Body() *NodePool {
   573  	if r == nil {
   574  		return nil
   575  	}
   576  	return r.body
   577  }
   578  
   579  // GetBody returns the value of the 'body' parameter and
   580  // a flag indicating if the parameter has a value.
   581  func (r *NodePoolGetResponse) GetBody() (value *NodePool, ok bool) {
   582  	ok = r != nil && r.body != nil
   583  	if ok {
   584  		value = r.body
   585  	}
   586  	return
   587  }