...

Source file src/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-07-01/compute/cloudserviceroles.go

Documentation: github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-07-01/compute

     1  package compute
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/tracing"
    14  	"net/http"
    15  )
    16  
    17  // CloudServiceRolesClient is the compute Client
    18  type CloudServiceRolesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewCloudServiceRolesClient creates an instance of the CloudServiceRolesClient client.
    23  func NewCloudServiceRolesClient(subscriptionID string) CloudServiceRolesClient {
    24  	return NewCloudServiceRolesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewCloudServiceRolesClientWithBaseURI creates an instance of the CloudServiceRolesClient client using a custom
    28  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    29  // stack).
    30  func NewCloudServiceRolesClientWithBaseURI(baseURI string, subscriptionID string) CloudServiceRolesClient {
    31  	return CloudServiceRolesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Get gets a role from a cloud service.
    35  // Parameters:
    36  // roleName - name of the role.
    37  func (client CloudServiceRolesClient) Get(ctx context.Context, roleName string, resourceGroupName string, cloudServiceName string) (result CloudServiceRole, err error) {
    38  	if tracing.IsEnabled() {
    39  		ctx = tracing.StartSpan(ctx, fqdn+"/CloudServiceRolesClient.Get")
    40  		defer func() {
    41  			sc := -1
    42  			if result.Response.Response != nil {
    43  				sc = result.Response.Response.StatusCode
    44  			}
    45  			tracing.EndSpan(ctx, sc, err)
    46  		}()
    47  	}
    48  	req, err := client.GetPreparer(ctx, roleName, resourceGroupName, cloudServiceName)
    49  	if err != nil {
    50  		err = autorest.NewErrorWithError(err, "compute.CloudServiceRolesClient", "Get", nil, "Failure preparing request")
    51  		return
    52  	}
    53  
    54  	resp, err := client.GetSender(req)
    55  	if err != nil {
    56  		result.Response = autorest.Response{Response: resp}
    57  		err = autorest.NewErrorWithError(err, "compute.CloudServiceRolesClient", "Get", resp, "Failure sending request")
    58  		return
    59  	}
    60  
    61  	result, err = client.GetResponder(resp)
    62  	if err != nil {
    63  		err = autorest.NewErrorWithError(err, "compute.CloudServiceRolesClient", "Get", resp, "Failure responding to request")
    64  		return
    65  	}
    66  
    67  	return
    68  }
    69  
    70  // GetPreparer prepares the Get request.
    71  func (client CloudServiceRolesClient) GetPreparer(ctx context.Context, roleName string, resourceGroupName string, cloudServiceName string) (*http.Request, error) {
    72  	pathParameters := map[string]interface{}{
    73  		"cloudServiceName":  autorest.Encode("path", cloudServiceName),
    74  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    75  		"roleName":          autorest.Encode("path", roleName),
    76  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    77  	}
    78  
    79  	const APIVersion = "2021-03-01"
    80  	queryParameters := map[string]interface{}{
    81  		"api-version": APIVersion,
    82  	}
    83  
    84  	preparer := autorest.CreatePreparer(
    85  		autorest.AsGet(),
    86  		autorest.WithBaseURL(client.BaseURI),
    87  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/cloudServices/{cloudServiceName}/roles/{roleName}", pathParameters),
    88  		autorest.WithQueryParameters(queryParameters))
    89  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    90  }
    91  
    92  // GetSender sends the Get request. The method will close the
    93  // http.Response Body if it receives an error.
    94  func (client CloudServiceRolesClient) GetSender(req *http.Request) (*http.Response, error) {
    95  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    96  }
    97  
    98  // GetResponder handles the response to the Get request. The method always
    99  // closes the http.Response Body.
   100  func (client CloudServiceRolesClient) GetResponder(resp *http.Response) (result CloudServiceRole, err error) {
   101  	err = autorest.Respond(
   102  		resp,
   103  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   104  		autorest.ByUnmarshallingJSON(&result),
   105  		autorest.ByClosing())
   106  	result.Response = autorest.Response{Response: resp}
   107  	return
   108  }
   109  
   110  // List gets a list of all roles in a cloud service. Use nextLink property in the response to get the next page of
   111  // roles. Do this till nextLink is null to fetch all the roles.
   112  func (client CloudServiceRolesClient) List(ctx context.Context, resourceGroupName string, cloudServiceName string) (result CloudServiceRoleListResultPage, err error) {
   113  	if tracing.IsEnabled() {
   114  		ctx = tracing.StartSpan(ctx, fqdn+"/CloudServiceRolesClient.List")
   115  		defer func() {
   116  			sc := -1
   117  			if result.csrlr.Response.Response != nil {
   118  				sc = result.csrlr.Response.Response.StatusCode
   119  			}
   120  			tracing.EndSpan(ctx, sc, err)
   121  		}()
   122  	}
   123  	result.fn = client.listNextResults
   124  	req, err := client.ListPreparer(ctx, resourceGroupName, cloudServiceName)
   125  	if err != nil {
   126  		err = autorest.NewErrorWithError(err, "compute.CloudServiceRolesClient", "List", nil, "Failure preparing request")
   127  		return
   128  	}
   129  
   130  	resp, err := client.ListSender(req)
   131  	if err != nil {
   132  		result.csrlr.Response = autorest.Response{Response: resp}
   133  		err = autorest.NewErrorWithError(err, "compute.CloudServiceRolesClient", "List", resp, "Failure sending request")
   134  		return
   135  	}
   136  
   137  	result.csrlr, err = client.ListResponder(resp)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "compute.CloudServiceRolesClient", "List", resp, "Failure responding to request")
   140  		return
   141  	}
   142  	if result.csrlr.hasNextLink() && result.csrlr.IsEmpty() {
   143  		err = result.NextWithContext(ctx)
   144  		return
   145  	}
   146  
   147  	return
   148  }
   149  
   150  // ListPreparer prepares the List request.
   151  func (client CloudServiceRolesClient) ListPreparer(ctx context.Context, resourceGroupName string, cloudServiceName string) (*http.Request, error) {
   152  	pathParameters := map[string]interface{}{
   153  		"cloudServiceName":  autorest.Encode("path", cloudServiceName),
   154  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   155  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   156  	}
   157  
   158  	const APIVersion = "2021-03-01"
   159  	queryParameters := map[string]interface{}{
   160  		"api-version": APIVersion,
   161  	}
   162  
   163  	preparer := autorest.CreatePreparer(
   164  		autorest.AsGet(),
   165  		autorest.WithBaseURL(client.BaseURI),
   166  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/cloudServices/{cloudServiceName}/roles", pathParameters),
   167  		autorest.WithQueryParameters(queryParameters))
   168  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   169  }
   170  
   171  // ListSender sends the List request. The method will close the
   172  // http.Response Body if it receives an error.
   173  func (client CloudServiceRolesClient) ListSender(req *http.Request) (*http.Response, error) {
   174  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   175  }
   176  
   177  // ListResponder handles the response to the List request. The method always
   178  // closes the http.Response Body.
   179  func (client CloudServiceRolesClient) ListResponder(resp *http.Response) (result CloudServiceRoleListResult, err error) {
   180  	err = autorest.Respond(
   181  		resp,
   182  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   183  		autorest.ByUnmarshallingJSON(&result),
   184  		autorest.ByClosing())
   185  	result.Response = autorest.Response{Response: resp}
   186  	return
   187  }
   188  
   189  // listNextResults retrieves the next set of results, if any.
   190  func (client CloudServiceRolesClient) listNextResults(ctx context.Context, lastResults CloudServiceRoleListResult) (result CloudServiceRoleListResult, err error) {
   191  	req, err := lastResults.cloudServiceRoleListResultPreparer(ctx)
   192  	if err != nil {
   193  		return result, autorest.NewErrorWithError(err, "compute.CloudServiceRolesClient", "listNextResults", nil, "Failure preparing next results request")
   194  	}
   195  	if req == nil {
   196  		return
   197  	}
   198  	resp, err := client.ListSender(req)
   199  	if err != nil {
   200  		result.Response = autorest.Response{Response: resp}
   201  		return result, autorest.NewErrorWithError(err, "compute.CloudServiceRolesClient", "listNextResults", resp, "Failure sending next results request")
   202  	}
   203  	result, err = client.ListResponder(resp)
   204  	if err != nil {
   205  		err = autorest.NewErrorWithError(err, "compute.CloudServiceRolesClient", "listNextResults", resp, "Failure responding to next results request")
   206  	}
   207  	return
   208  }
   209  
   210  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   211  func (client CloudServiceRolesClient) ListComplete(ctx context.Context, resourceGroupName string, cloudServiceName string) (result CloudServiceRoleListResultIterator, err error) {
   212  	if tracing.IsEnabled() {
   213  		ctx = tracing.StartSpan(ctx, fqdn+"/CloudServiceRolesClient.List")
   214  		defer func() {
   215  			sc := -1
   216  			if result.Response().Response.Response != nil {
   217  				sc = result.page.Response().Response.Response.StatusCode
   218  			}
   219  			tracing.EndSpan(ctx, sc, err)
   220  		}()
   221  	}
   222  	result.page, err = client.List(ctx, resourceGroupName, cloudServiceName)
   223  	return
   224  }
   225  

View as plain text