github.com/openshift-online/ocm-sdk-go@v0.1.473/arohcp/v1alpha1/node_pools_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  
    31  	"github.com/openshift-online/ocm-sdk-go/errors"
    32  	"github.com/openshift-online/ocm-sdk-go/helpers"
    33  )
    34  
    35  // NodePoolsClient is the client of the 'node_pools' resource.
    36  //
    37  // Manages the collection of node pools of a cluster.
    38  type NodePoolsClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewNodePoolsClient creates a new client for the 'node_pools'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewNodePoolsClient(transport http.RoundTripper, path string) *NodePoolsClient {
    47  	return &NodePoolsClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Add creates a request for the 'async_add' method.
    54  //
    55  // Adds a new node pool to the cluster.
    56  func (c *NodePoolsClient) Add() *NodePoolsAddRequest {
    57  	return &NodePoolsAddRequest{
    58  		transport: c.transport,
    59  		path:      c.path,
    60  	}
    61  }
    62  
    63  // List creates a request for the 'list' method.
    64  //
    65  // Retrieves the list of node pools.
    66  func (c *NodePoolsClient) List() *NodePoolsListRequest {
    67  	return &NodePoolsListRequest{
    68  		transport: c.transport,
    69  		path:      c.path,
    70  	}
    71  }
    72  
    73  // NodePool returns the target 'node_pool' resource for the given identifier.
    74  //
    75  // Reference to the service that manages a specific node pool.
    76  func (c *NodePoolsClient) NodePool(id string) *NodePoolClient {
    77  	return NewNodePoolClient(
    78  		c.transport,
    79  		path.Join(c.path, id),
    80  	)
    81  }
    82  
    83  // NodePoolsAddRequest is the request for the 'async_add' method.
    84  type NodePoolsAddRequest struct {
    85  	transport http.RoundTripper
    86  	path      string
    87  	query     url.Values
    88  	header    http.Header
    89  	body      *NodePool
    90  }
    91  
    92  // Parameter adds a query parameter.
    93  func (r *NodePoolsAddRequest) Parameter(name string, value interface{}) *NodePoolsAddRequest {
    94  	helpers.AddValue(&r.query, name, value)
    95  	return r
    96  }
    97  
    98  // Header adds a request header.
    99  func (r *NodePoolsAddRequest) Header(name string, value interface{}) *NodePoolsAddRequest {
   100  	helpers.AddHeader(&r.header, name, value)
   101  	return r
   102  }
   103  
   104  // Impersonate wraps requests on behalf of another user.
   105  // Note: Services that do not support this feature may silently ignore this call.
   106  func (r *NodePoolsAddRequest) Impersonate(user string) *NodePoolsAddRequest {
   107  	helpers.AddImpersonationHeader(&r.header, user)
   108  	return r
   109  }
   110  
   111  // Body sets the value of the 'body' parameter.
   112  //
   113  // Description of the node pool
   114  func (r *NodePoolsAddRequest) Body(value *NodePool) *NodePoolsAddRequest {
   115  	r.body = value
   116  	return r
   117  }
   118  
   119  // Send sends this request, waits for the response, and returns it.
   120  //
   121  // This is a potentially lengthy operation, as it requires network communication.
   122  // Consider using a context and the SendContext method.
   123  func (r *NodePoolsAddRequest) Send() (result *NodePoolsAddResponse, err error) {
   124  	return r.SendContext(context.Background())
   125  }
   126  
   127  // SendContext sends this request, waits for the response, and returns it.
   128  func (r *NodePoolsAddRequest) SendContext(ctx context.Context) (result *NodePoolsAddResponse, err error) {
   129  	query := helpers.CopyQuery(r.query)
   130  	header := helpers.CopyHeader(r.header)
   131  	buffer := &bytes.Buffer{}
   132  	err = writeNodePoolsAsyncAddRequest(r, buffer)
   133  	if err != nil {
   134  		return
   135  	}
   136  	uri := &url.URL{
   137  		Path:     r.path,
   138  		RawQuery: query.Encode(),
   139  	}
   140  	request := &http.Request{
   141  		Method: "POST",
   142  		URL:    uri,
   143  		Header: header,
   144  		Body:   io.NopCloser(buffer),
   145  	}
   146  	if ctx != nil {
   147  		request = request.WithContext(ctx)
   148  	}
   149  	response, err := r.transport.RoundTrip(request)
   150  	if err != nil {
   151  		return
   152  	}
   153  	defer response.Body.Close()
   154  	result = &NodePoolsAddResponse{}
   155  	result.status = response.StatusCode
   156  	result.header = response.Header
   157  	reader := bufio.NewReader(response.Body)
   158  	_, err = reader.Peek(1)
   159  	if err == io.EOF {
   160  		err = nil
   161  		return
   162  	}
   163  	if result.status >= 400 {
   164  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   165  		if err != nil {
   166  			return
   167  		}
   168  		err = result.err
   169  		return
   170  	}
   171  	err = readNodePoolsAsyncAddResponse(result, reader)
   172  	if err != nil {
   173  		return
   174  	}
   175  	return
   176  }
   177  
   178  // NodePoolsAddResponse is the response for the 'async_add' method.
   179  type NodePoolsAddResponse struct {
   180  	status int
   181  	header http.Header
   182  	err    *errors.Error
   183  	body   *NodePool
   184  }
   185  
   186  // Status returns the response status code.
   187  func (r *NodePoolsAddResponse) Status() int {
   188  	if r == nil {
   189  		return 0
   190  	}
   191  	return r.status
   192  }
   193  
   194  // Header returns header of the response.
   195  func (r *NodePoolsAddResponse) Header() http.Header {
   196  	if r == nil {
   197  		return nil
   198  	}
   199  	return r.header
   200  }
   201  
   202  // Error returns the response error.
   203  func (r *NodePoolsAddResponse) Error() *errors.Error {
   204  	if r == nil {
   205  		return nil
   206  	}
   207  	return r.err
   208  }
   209  
   210  // Body returns the value of the 'body' parameter.
   211  //
   212  // Description of the node pool
   213  func (r *NodePoolsAddResponse) Body() *NodePool {
   214  	if r == nil {
   215  		return nil
   216  	}
   217  	return r.body
   218  }
   219  
   220  // GetBody returns the value of the 'body' parameter and
   221  // a flag indicating if the parameter has a value.
   222  //
   223  // Description of the node pool
   224  func (r *NodePoolsAddResponse) GetBody() (value *NodePool, ok bool) {
   225  	ok = r != nil && r.body != nil
   226  	if ok {
   227  		value = r.body
   228  	}
   229  	return
   230  }
   231  
   232  // NodePoolsListRequest is the request for the 'list' method.
   233  type NodePoolsListRequest struct {
   234  	transport http.RoundTripper
   235  	path      string
   236  	query     url.Values
   237  	header    http.Header
   238  	order     *string
   239  	page      *int
   240  	search    *string
   241  	size      *int
   242  }
   243  
   244  // Parameter adds a query parameter.
   245  func (r *NodePoolsListRequest) Parameter(name string, value interface{}) *NodePoolsListRequest {
   246  	helpers.AddValue(&r.query, name, value)
   247  	return r
   248  }
   249  
   250  // Header adds a request header.
   251  func (r *NodePoolsListRequest) Header(name string, value interface{}) *NodePoolsListRequest {
   252  	helpers.AddHeader(&r.header, name, value)
   253  	return r
   254  }
   255  
   256  // Impersonate wraps requests on behalf of another user.
   257  // Note: Services that do not support this feature may silently ignore this call.
   258  func (r *NodePoolsListRequest) Impersonate(user string) *NodePoolsListRequest {
   259  	helpers.AddImpersonationHeader(&r.header, user)
   260  	return r
   261  }
   262  
   263  // Order sets the value of the 'order' parameter.
   264  //
   265  // Order criteria.
   266  //
   267  // The syntax of this parameter is similar to the syntax of the _order by_ clause of
   268  // a SQL statement, but using the names of the attributes of the node pools instead of
   269  // the names of the columns of a table. For example, in order to sort the node pools
   270  // descending by identifier the value should be:
   271  //
   272  // ```sql
   273  // id desc
   274  // ```
   275  //
   276  // If the parameter isn't provided, or if the value is empty, then the order of the
   277  // results is undefined.
   278  func (r *NodePoolsListRequest) Order(value string) *NodePoolsListRequest {
   279  	r.order = &value
   280  	return r
   281  }
   282  
   283  // Page sets the value of the 'page' parameter.
   284  //
   285  // Index of the requested page, where one corresponds to the first page.
   286  func (r *NodePoolsListRequest) Page(value int) *NodePoolsListRequest {
   287  	r.page = &value
   288  	return r
   289  }
   290  
   291  // Search sets the value of the 'search' parameter.
   292  //
   293  // Search criteria.
   294  //
   295  // The syntax of this parameter is similar to the syntax of the _where_ clause of a
   296  // SQL statement, but using the names of the attributes of the node pools instead of
   297  // the names of the columns of a table. For example, in order to retrieve all the
   298  // node pools with replicas of two the following is required:
   299  //
   300  // ```sql
   301  // replicas = 2
   302  // ```
   303  //
   304  // If the parameter isn't provided, or if the value is empty, then all the
   305  // node pools that the user has permission to see will be returned.
   306  func (r *NodePoolsListRequest) Search(value string) *NodePoolsListRequest {
   307  	r.search = &value
   308  	return r
   309  }
   310  
   311  // Size sets the value of the 'size' parameter.
   312  //
   313  // Number of items contained in the returned page.
   314  func (r *NodePoolsListRequest) Size(value int) *NodePoolsListRequest {
   315  	r.size = &value
   316  	return r
   317  }
   318  
   319  // Send sends this request, waits for the response, and returns it.
   320  //
   321  // This is a potentially lengthy operation, as it requires network communication.
   322  // Consider using a context and the SendContext method.
   323  func (r *NodePoolsListRequest) Send() (result *NodePoolsListResponse, err error) {
   324  	return r.SendContext(context.Background())
   325  }
   326  
   327  // SendContext sends this request, waits for the response, and returns it.
   328  func (r *NodePoolsListRequest) SendContext(ctx context.Context) (result *NodePoolsListResponse, err error) {
   329  	query := helpers.CopyQuery(r.query)
   330  	if r.order != nil {
   331  		helpers.AddValue(&query, "order", *r.order)
   332  	}
   333  	if r.page != nil {
   334  		helpers.AddValue(&query, "page", *r.page)
   335  	}
   336  	if r.search != nil {
   337  		helpers.AddValue(&query, "search", *r.search)
   338  	}
   339  	if r.size != nil {
   340  		helpers.AddValue(&query, "size", *r.size)
   341  	}
   342  	header := helpers.CopyHeader(r.header)
   343  	uri := &url.URL{
   344  		Path:     r.path,
   345  		RawQuery: query.Encode(),
   346  	}
   347  	request := &http.Request{
   348  		Method: "GET",
   349  		URL:    uri,
   350  		Header: header,
   351  	}
   352  	if ctx != nil {
   353  		request = request.WithContext(ctx)
   354  	}
   355  	response, err := r.transport.RoundTrip(request)
   356  	if err != nil {
   357  		return
   358  	}
   359  	defer response.Body.Close()
   360  	result = &NodePoolsListResponse{}
   361  	result.status = response.StatusCode
   362  	result.header = response.Header
   363  	reader := bufio.NewReader(response.Body)
   364  	_, err = reader.Peek(1)
   365  	if err == io.EOF {
   366  		err = nil
   367  		return
   368  	}
   369  	if result.status >= 400 {
   370  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   371  		if err != nil {
   372  			return
   373  		}
   374  		err = result.err
   375  		return
   376  	}
   377  	err = readNodePoolsListResponse(result, reader)
   378  	if err != nil {
   379  		return
   380  	}
   381  	return
   382  }
   383  
   384  // NodePoolsListResponse is the response for the 'list' method.
   385  type NodePoolsListResponse struct {
   386  	status int
   387  	header http.Header
   388  	err    *errors.Error
   389  	items  *NodePoolList
   390  	page   *int
   391  	size   *int
   392  	total  *int
   393  }
   394  
   395  // Status returns the response status code.
   396  func (r *NodePoolsListResponse) Status() int {
   397  	if r == nil {
   398  		return 0
   399  	}
   400  	return r.status
   401  }
   402  
   403  // Header returns header of the response.
   404  func (r *NodePoolsListResponse) Header() http.Header {
   405  	if r == nil {
   406  		return nil
   407  	}
   408  	return r.header
   409  }
   410  
   411  // Error returns the response error.
   412  func (r *NodePoolsListResponse) Error() *errors.Error {
   413  	if r == nil {
   414  		return nil
   415  	}
   416  	return r.err
   417  }
   418  
   419  // Items returns the value of the 'items' parameter.
   420  //
   421  // Retrieved list of node pools.
   422  func (r *NodePoolsListResponse) Items() *NodePoolList {
   423  	if r == nil {
   424  		return nil
   425  	}
   426  	return r.items
   427  }
   428  
   429  // GetItems returns the value of the 'items' parameter and
   430  // a flag indicating if the parameter has a value.
   431  //
   432  // Retrieved list of node pools.
   433  func (r *NodePoolsListResponse) GetItems() (value *NodePoolList, ok bool) {
   434  	ok = r != nil && r.items != nil
   435  	if ok {
   436  		value = r.items
   437  	}
   438  	return
   439  }
   440  
   441  // Page returns the value of the 'page' parameter.
   442  //
   443  // Index of the requested page, where one corresponds to the first page.
   444  func (r *NodePoolsListResponse) Page() int {
   445  	if r != nil && r.page != nil {
   446  		return *r.page
   447  	}
   448  	return 0
   449  }
   450  
   451  // GetPage returns the value of the 'page' parameter and
   452  // a flag indicating if the parameter has a value.
   453  //
   454  // Index of the requested page, where one corresponds to the first page.
   455  func (r *NodePoolsListResponse) GetPage() (value int, ok bool) {
   456  	ok = r != nil && r.page != nil
   457  	if ok {
   458  		value = *r.page
   459  	}
   460  	return
   461  }
   462  
   463  // Size returns the value of the 'size' parameter.
   464  //
   465  // Number of items contained in the returned page.
   466  func (r *NodePoolsListResponse) Size() int {
   467  	if r != nil && r.size != nil {
   468  		return *r.size
   469  	}
   470  	return 0
   471  }
   472  
   473  // GetSize returns the value of the 'size' parameter and
   474  // a flag indicating if the parameter has a value.
   475  //
   476  // Number of items contained in the returned page.
   477  func (r *NodePoolsListResponse) GetSize() (value int, ok bool) {
   478  	ok = r != nil && r.size != nil
   479  	if ok {
   480  		value = *r.size
   481  	}
   482  	return
   483  }
   484  
   485  // Total returns the value of the 'total' parameter.
   486  //
   487  // Total number of items of the collection.
   488  func (r *NodePoolsListResponse) Total() int {
   489  	if r != nil && r.total != nil {
   490  		return *r.total
   491  	}
   492  	return 0
   493  }
   494  
   495  // GetTotal returns the value of the 'total' parameter and
   496  // a flag indicating if the parameter has a value.
   497  //
   498  // Total number of items of the collection.
   499  func (r *NodePoolsListResponse) GetTotal() (value int, ok bool) {
   500  	ok = r != nil && r.total != nil
   501  	if ok {
   502  		value = *r.total
   503  	}
   504  	return
   505  }