...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-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  // AvailabilitySetsClient is the compute Client
    18  type AvailabilitySetsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewAvailabilitySetsClient creates an instance of the AvailabilitySetsClient client.
    23  func NewAvailabilitySetsClient(subscriptionID string) AvailabilitySetsClient {
    24  	return NewAvailabilitySetsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewAvailabilitySetsClientWithBaseURI creates an instance of the AvailabilitySetsClient 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 NewAvailabilitySetsClientWithBaseURI(baseURI string, subscriptionID string) AvailabilitySetsClient {
    31  	return AvailabilitySetsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate create or update an availability set.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // availabilitySetName - the name of the availability set.
    38  // parameters - parameters supplied to the Create Availability Set operation.
    39  func (client AvailabilitySetsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, availabilitySetName string, parameters AvailabilitySet) (result AvailabilitySet, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, availabilitySetName, parameters)
    51  	if err != nil {
    52  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "CreateOrUpdate", nil, "Failure preparing request")
    53  		return
    54  	}
    55  
    56  	resp, err := client.CreateOrUpdateSender(req)
    57  	if err != nil {
    58  		result.Response = autorest.Response{Response: resp}
    59  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "CreateOrUpdate", resp, "Failure sending request")
    60  		return
    61  	}
    62  
    63  	result, err = client.CreateOrUpdateResponder(resp)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "CreateOrUpdate", resp, "Failure responding to request")
    66  		return
    67  	}
    68  
    69  	return
    70  }
    71  
    72  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    73  func (client AvailabilitySetsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, availabilitySetName string, parameters AvailabilitySet) (*http.Request, error) {
    74  	pathParameters := map[string]interface{}{
    75  		"availabilitySetName": autorest.Encode("path", availabilitySetName),
    76  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
    77  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
    78  	}
    79  
    80  	const APIVersion = "2021-11-01"
    81  	queryParameters := map[string]interface{}{
    82  		"api-version": APIVersion,
    83  	}
    84  
    85  	preparer := autorest.CreatePreparer(
    86  		autorest.AsContentType("application/json; charset=utf-8"),
    87  		autorest.AsPut(),
    88  		autorest.WithBaseURL(client.BaseURI),
    89  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}", pathParameters),
    90  		autorest.WithJSON(parameters),
    91  		autorest.WithQueryParameters(queryParameters))
    92  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    93  }
    94  
    95  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    96  // http.Response Body if it receives an error.
    97  func (client AvailabilitySetsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
    98  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    99  }
   100  
   101  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   102  // closes the http.Response Body.
   103  func (client AvailabilitySetsClient) CreateOrUpdateResponder(resp *http.Response) (result AvailabilitySet, err error) {
   104  	err = autorest.Respond(
   105  		resp,
   106  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   107  		autorest.ByUnmarshallingJSON(&result),
   108  		autorest.ByClosing())
   109  	result.Response = autorest.Response{Response: resp}
   110  	return
   111  }
   112  
   113  // Delete delete an availability set.
   114  // Parameters:
   115  // resourceGroupName - the name of the resource group.
   116  // availabilitySetName - the name of the availability set.
   117  func (client AvailabilitySetsClient) Delete(ctx context.Context, resourceGroupName string, availabilitySetName string) (result autorest.Response, err error) {
   118  	if tracing.IsEnabled() {
   119  		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.Delete")
   120  		defer func() {
   121  			sc := -1
   122  			if result.Response != nil {
   123  				sc = result.Response.StatusCode
   124  			}
   125  			tracing.EndSpan(ctx, sc, err)
   126  		}()
   127  	}
   128  	req, err := client.DeletePreparer(ctx, resourceGroupName, availabilitySetName)
   129  	if err != nil {
   130  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Delete", nil, "Failure preparing request")
   131  		return
   132  	}
   133  
   134  	resp, err := client.DeleteSender(req)
   135  	if err != nil {
   136  		result.Response = resp
   137  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Delete", resp, "Failure sending request")
   138  		return
   139  	}
   140  
   141  	result, err = client.DeleteResponder(resp)
   142  	if err != nil {
   143  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Delete", resp, "Failure responding to request")
   144  		return
   145  	}
   146  
   147  	return
   148  }
   149  
   150  // DeletePreparer prepares the Delete request.
   151  func (client AvailabilitySetsClient) DeletePreparer(ctx context.Context, resourceGroupName string, availabilitySetName string) (*http.Request, error) {
   152  	pathParameters := map[string]interface{}{
   153  		"availabilitySetName": autorest.Encode("path", availabilitySetName),
   154  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   155  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   156  	}
   157  
   158  	const APIVersion = "2021-11-01"
   159  	queryParameters := map[string]interface{}{
   160  		"api-version": APIVersion,
   161  	}
   162  
   163  	preparer := autorest.CreatePreparer(
   164  		autorest.AsDelete(),
   165  		autorest.WithBaseURL(client.BaseURI),
   166  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}", pathParameters),
   167  		autorest.WithQueryParameters(queryParameters))
   168  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   169  }
   170  
   171  // DeleteSender sends the Delete request. The method will close the
   172  // http.Response Body if it receives an error.
   173  func (client AvailabilitySetsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   174  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   175  }
   176  
   177  // DeleteResponder handles the response to the Delete request. The method always
   178  // closes the http.Response Body.
   179  func (client AvailabilitySetsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   180  	err = autorest.Respond(
   181  		resp,
   182  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   183  		autorest.ByClosing())
   184  	result.Response = resp
   185  	return
   186  }
   187  
   188  // Get retrieves information about an availability set.
   189  // Parameters:
   190  // resourceGroupName - the name of the resource group.
   191  // availabilitySetName - the name of the availability set.
   192  func (client AvailabilitySetsClient) Get(ctx context.Context, resourceGroupName string, availabilitySetName string) (result AvailabilitySet, err error) {
   193  	if tracing.IsEnabled() {
   194  		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.Get")
   195  		defer func() {
   196  			sc := -1
   197  			if result.Response.Response != nil {
   198  				sc = result.Response.Response.StatusCode
   199  			}
   200  			tracing.EndSpan(ctx, sc, err)
   201  		}()
   202  	}
   203  	req, err := client.GetPreparer(ctx, resourceGroupName, availabilitySetName)
   204  	if err != nil {
   205  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Get", nil, "Failure preparing request")
   206  		return
   207  	}
   208  
   209  	resp, err := client.GetSender(req)
   210  	if err != nil {
   211  		result.Response = autorest.Response{Response: resp}
   212  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Get", resp, "Failure sending request")
   213  		return
   214  	}
   215  
   216  	result, err = client.GetResponder(resp)
   217  	if err != nil {
   218  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Get", resp, "Failure responding to request")
   219  		return
   220  	}
   221  
   222  	return
   223  }
   224  
   225  // GetPreparer prepares the Get request.
   226  func (client AvailabilitySetsClient) GetPreparer(ctx context.Context, resourceGroupName string, availabilitySetName string) (*http.Request, error) {
   227  	pathParameters := map[string]interface{}{
   228  		"availabilitySetName": autorest.Encode("path", availabilitySetName),
   229  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   230  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   231  	}
   232  
   233  	const APIVersion = "2021-11-01"
   234  	queryParameters := map[string]interface{}{
   235  		"api-version": APIVersion,
   236  	}
   237  
   238  	preparer := autorest.CreatePreparer(
   239  		autorest.AsGet(),
   240  		autorest.WithBaseURL(client.BaseURI),
   241  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}", pathParameters),
   242  		autorest.WithQueryParameters(queryParameters))
   243  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   244  }
   245  
   246  // GetSender sends the Get request. The method will close the
   247  // http.Response Body if it receives an error.
   248  func (client AvailabilitySetsClient) GetSender(req *http.Request) (*http.Response, error) {
   249  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   250  }
   251  
   252  // GetResponder handles the response to the Get request. The method always
   253  // closes the http.Response Body.
   254  func (client AvailabilitySetsClient) GetResponder(resp *http.Response) (result AvailabilitySet, err error) {
   255  	err = autorest.Respond(
   256  		resp,
   257  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   258  		autorest.ByUnmarshallingJSON(&result),
   259  		autorest.ByClosing())
   260  	result.Response = autorest.Response{Response: resp}
   261  	return
   262  }
   263  
   264  // List lists all availability sets in a resource group.
   265  // Parameters:
   266  // resourceGroupName - the name of the resource group.
   267  func (client AvailabilitySetsClient) List(ctx context.Context, resourceGroupName string) (result AvailabilitySetListResultPage, err error) {
   268  	if tracing.IsEnabled() {
   269  		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.List")
   270  		defer func() {
   271  			sc := -1
   272  			if result.aslr.Response.Response != nil {
   273  				sc = result.aslr.Response.Response.StatusCode
   274  			}
   275  			tracing.EndSpan(ctx, sc, err)
   276  		}()
   277  	}
   278  	result.fn = client.listNextResults
   279  	req, err := client.ListPreparer(ctx, resourceGroupName)
   280  	if err != nil {
   281  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "List", nil, "Failure preparing request")
   282  		return
   283  	}
   284  
   285  	resp, err := client.ListSender(req)
   286  	if err != nil {
   287  		result.aslr.Response = autorest.Response{Response: resp}
   288  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "List", resp, "Failure sending request")
   289  		return
   290  	}
   291  
   292  	result.aslr, err = client.ListResponder(resp)
   293  	if err != nil {
   294  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "List", resp, "Failure responding to request")
   295  		return
   296  	}
   297  	if result.aslr.hasNextLink() && result.aslr.IsEmpty() {
   298  		err = result.NextWithContext(ctx)
   299  		return
   300  	}
   301  
   302  	return
   303  }
   304  
   305  // ListPreparer prepares the List request.
   306  func (client AvailabilitySetsClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   307  	pathParameters := map[string]interface{}{
   308  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   309  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   310  	}
   311  
   312  	const APIVersion = "2021-11-01"
   313  	queryParameters := map[string]interface{}{
   314  		"api-version": APIVersion,
   315  	}
   316  
   317  	preparer := autorest.CreatePreparer(
   318  		autorest.AsGet(),
   319  		autorest.WithBaseURL(client.BaseURI),
   320  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets", pathParameters),
   321  		autorest.WithQueryParameters(queryParameters))
   322  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   323  }
   324  
   325  // ListSender sends the List request. The method will close the
   326  // http.Response Body if it receives an error.
   327  func (client AvailabilitySetsClient) ListSender(req *http.Request) (*http.Response, error) {
   328  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   329  }
   330  
   331  // ListResponder handles the response to the List request. The method always
   332  // closes the http.Response Body.
   333  func (client AvailabilitySetsClient) ListResponder(resp *http.Response) (result AvailabilitySetListResult, err error) {
   334  	err = autorest.Respond(
   335  		resp,
   336  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   337  		autorest.ByUnmarshallingJSON(&result),
   338  		autorest.ByClosing())
   339  	result.Response = autorest.Response{Response: resp}
   340  	return
   341  }
   342  
   343  // listNextResults retrieves the next set of results, if any.
   344  func (client AvailabilitySetsClient) listNextResults(ctx context.Context, lastResults AvailabilitySetListResult) (result AvailabilitySetListResult, err error) {
   345  	req, err := lastResults.availabilitySetListResultPreparer(ctx)
   346  	if err != nil {
   347  		return result, autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "listNextResults", nil, "Failure preparing next results request")
   348  	}
   349  	if req == nil {
   350  		return
   351  	}
   352  	resp, err := client.ListSender(req)
   353  	if err != nil {
   354  		result.Response = autorest.Response{Response: resp}
   355  		return result, autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "listNextResults", resp, "Failure sending next results request")
   356  	}
   357  	result, err = client.ListResponder(resp)
   358  	if err != nil {
   359  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "listNextResults", resp, "Failure responding to next results request")
   360  	}
   361  	return
   362  }
   363  
   364  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   365  func (client AvailabilitySetsClient) ListComplete(ctx context.Context, resourceGroupName string) (result AvailabilitySetListResultIterator, err error) {
   366  	if tracing.IsEnabled() {
   367  		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.List")
   368  		defer func() {
   369  			sc := -1
   370  			if result.Response().Response.Response != nil {
   371  				sc = result.page.Response().Response.Response.StatusCode
   372  			}
   373  			tracing.EndSpan(ctx, sc, err)
   374  		}()
   375  	}
   376  	result.page, err = client.List(ctx, resourceGroupName)
   377  	return
   378  }
   379  
   380  // ListAvailableSizes lists all available virtual machine sizes that can be used to create a new virtual machine in an
   381  // existing availability set.
   382  // Parameters:
   383  // resourceGroupName - the name of the resource group.
   384  // availabilitySetName - the name of the availability set.
   385  func (client AvailabilitySetsClient) ListAvailableSizes(ctx context.Context, resourceGroupName string, availabilitySetName string) (result VirtualMachineSizeListResult, err error) {
   386  	if tracing.IsEnabled() {
   387  		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.ListAvailableSizes")
   388  		defer func() {
   389  			sc := -1
   390  			if result.Response.Response != nil {
   391  				sc = result.Response.Response.StatusCode
   392  			}
   393  			tracing.EndSpan(ctx, sc, err)
   394  		}()
   395  	}
   396  	req, err := client.ListAvailableSizesPreparer(ctx, resourceGroupName, availabilitySetName)
   397  	if err != nil {
   398  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "ListAvailableSizes", nil, "Failure preparing request")
   399  		return
   400  	}
   401  
   402  	resp, err := client.ListAvailableSizesSender(req)
   403  	if err != nil {
   404  		result.Response = autorest.Response{Response: resp}
   405  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "ListAvailableSizes", resp, "Failure sending request")
   406  		return
   407  	}
   408  
   409  	result, err = client.ListAvailableSizesResponder(resp)
   410  	if err != nil {
   411  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "ListAvailableSizes", resp, "Failure responding to request")
   412  		return
   413  	}
   414  
   415  	return
   416  }
   417  
   418  // ListAvailableSizesPreparer prepares the ListAvailableSizes request.
   419  func (client AvailabilitySetsClient) ListAvailableSizesPreparer(ctx context.Context, resourceGroupName string, availabilitySetName string) (*http.Request, error) {
   420  	pathParameters := map[string]interface{}{
   421  		"availabilitySetName": autorest.Encode("path", availabilitySetName),
   422  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   423  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   424  	}
   425  
   426  	const APIVersion = "2021-11-01"
   427  	queryParameters := map[string]interface{}{
   428  		"api-version": APIVersion,
   429  	}
   430  
   431  	preparer := autorest.CreatePreparer(
   432  		autorest.AsGet(),
   433  		autorest.WithBaseURL(client.BaseURI),
   434  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}/vmSizes", pathParameters),
   435  		autorest.WithQueryParameters(queryParameters))
   436  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   437  }
   438  
   439  // ListAvailableSizesSender sends the ListAvailableSizes request. The method will close the
   440  // http.Response Body if it receives an error.
   441  func (client AvailabilitySetsClient) ListAvailableSizesSender(req *http.Request) (*http.Response, error) {
   442  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   443  }
   444  
   445  // ListAvailableSizesResponder handles the response to the ListAvailableSizes request. The method always
   446  // closes the http.Response Body.
   447  func (client AvailabilitySetsClient) ListAvailableSizesResponder(resp *http.Response) (result VirtualMachineSizeListResult, err error) {
   448  	err = autorest.Respond(
   449  		resp,
   450  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   451  		autorest.ByUnmarshallingJSON(&result),
   452  		autorest.ByClosing())
   453  	result.Response = autorest.Response{Response: resp}
   454  	return
   455  }
   456  
   457  // ListBySubscription lists all availability sets in a subscription.
   458  // Parameters:
   459  // expand - the expand expression to apply to the operation. Allowed values are 'instanceView'.
   460  func (client AvailabilitySetsClient) ListBySubscription(ctx context.Context, expand string) (result AvailabilitySetListResultPage, err error) {
   461  	if tracing.IsEnabled() {
   462  		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.ListBySubscription")
   463  		defer func() {
   464  			sc := -1
   465  			if result.aslr.Response.Response != nil {
   466  				sc = result.aslr.Response.Response.StatusCode
   467  			}
   468  			tracing.EndSpan(ctx, sc, err)
   469  		}()
   470  	}
   471  	result.fn = client.listBySubscriptionNextResults
   472  	req, err := client.ListBySubscriptionPreparer(ctx, expand)
   473  	if err != nil {
   474  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "ListBySubscription", nil, "Failure preparing request")
   475  		return
   476  	}
   477  
   478  	resp, err := client.ListBySubscriptionSender(req)
   479  	if err != nil {
   480  		result.aslr.Response = autorest.Response{Response: resp}
   481  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "ListBySubscription", resp, "Failure sending request")
   482  		return
   483  	}
   484  
   485  	result.aslr, err = client.ListBySubscriptionResponder(resp)
   486  	if err != nil {
   487  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "ListBySubscription", resp, "Failure responding to request")
   488  		return
   489  	}
   490  	if result.aslr.hasNextLink() && result.aslr.IsEmpty() {
   491  		err = result.NextWithContext(ctx)
   492  		return
   493  	}
   494  
   495  	return
   496  }
   497  
   498  // ListBySubscriptionPreparer prepares the ListBySubscription request.
   499  func (client AvailabilitySetsClient) ListBySubscriptionPreparer(ctx context.Context, expand string) (*http.Request, error) {
   500  	pathParameters := map[string]interface{}{
   501  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   502  	}
   503  
   504  	const APIVersion = "2021-11-01"
   505  	queryParameters := map[string]interface{}{
   506  		"api-version": APIVersion,
   507  	}
   508  	if len(expand) > 0 {
   509  		queryParameters["$expand"] = autorest.Encode("query", expand)
   510  	}
   511  
   512  	preparer := autorest.CreatePreparer(
   513  		autorest.AsGet(),
   514  		autorest.WithBaseURL(client.BaseURI),
   515  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/availabilitySets", pathParameters),
   516  		autorest.WithQueryParameters(queryParameters))
   517  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   518  }
   519  
   520  // ListBySubscriptionSender sends the ListBySubscription request. The method will close the
   521  // http.Response Body if it receives an error.
   522  func (client AvailabilitySetsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
   523  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   524  }
   525  
   526  // ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
   527  // closes the http.Response Body.
   528  func (client AvailabilitySetsClient) ListBySubscriptionResponder(resp *http.Response) (result AvailabilitySetListResult, err error) {
   529  	err = autorest.Respond(
   530  		resp,
   531  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   532  		autorest.ByUnmarshallingJSON(&result),
   533  		autorest.ByClosing())
   534  	result.Response = autorest.Response{Response: resp}
   535  	return
   536  }
   537  
   538  // listBySubscriptionNextResults retrieves the next set of results, if any.
   539  func (client AvailabilitySetsClient) listBySubscriptionNextResults(ctx context.Context, lastResults AvailabilitySetListResult) (result AvailabilitySetListResult, err error) {
   540  	req, err := lastResults.availabilitySetListResultPreparer(ctx)
   541  	if err != nil {
   542  		return result, autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request")
   543  	}
   544  	if req == nil {
   545  		return
   546  	}
   547  	resp, err := client.ListBySubscriptionSender(req)
   548  	if err != nil {
   549  		result.Response = autorest.Response{Response: resp}
   550  		return result, autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "listBySubscriptionNextResults", resp, "Failure sending next results request")
   551  	}
   552  	result, err = client.ListBySubscriptionResponder(resp)
   553  	if err != nil {
   554  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request")
   555  	}
   556  	return
   557  }
   558  
   559  // ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required.
   560  func (client AvailabilitySetsClient) ListBySubscriptionComplete(ctx context.Context, expand string) (result AvailabilitySetListResultIterator, err error) {
   561  	if tracing.IsEnabled() {
   562  		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.ListBySubscription")
   563  		defer func() {
   564  			sc := -1
   565  			if result.Response().Response.Response != nil {
   566  				sc = result.page.Response().Response.Response.StatusCode
   567  			}
   568  			tracing.EndSpan(ctx, sc, err)
   569  		}()
   570  	}
   571  	result.page, err = client.ListBySubscription(ctx, expand)
   572  	return
   573  }
   574  
   575  // Update update an availability set.
   576  // Parameters:
   577  // resourceGroupName - the name of the resource group.
   578  // availabilitySetName - the name of the availability set.
   579  // parameters - parameters supplied to the Update Availability Set operation.
   580  func (client AvailabilitySetsClient) Update(ctx context.Context, resourceGroupName string, availabilitySetName string, parameters AvailabilitySetUpdate) (result AvailabilitySet, err error) {
   581  	if tracing.IsEnabled() {
   582  		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.Update")
   583  		defer func() {
   584  			sc := -1
   585  			if result.Response.Response != nil {
   586  				sc = result.Response.Response.StatusCode
   587  			}
   588  			tracing.EndSpan(ctx, sc, err)
   589  		}()
   590  	}
   591  	req, err := client.UpdatePreparer(ctx, resourceGroupName, availabilitySetName, parameters)
   592  	if err != nil {
   593  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Update", nil, "Failure preparing request")
   594  		return
   595  	}
   596  
   597  	resp, err := client.UpdateSender(req)
   598  	if err != nil {
   599  		result.Response = autorest.Response{Response: resp}
   600  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Update", resp, "Failure sending request")
   601  		return
   602  	}
   603  
   604  	result, err = client.UpdateResponder(resp)
   605  	if err != nil {
   606  		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Update", resp, "Failure responding to request")
   607  		return
   608  	}
   609  
   610  	return
   611  }
   612  
   613  // UpdatePreparer prepares the Update request.
   614  func (client AvailabilitySetsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, availabilitySetName string, parameters AvailabilitySetUpdate) (*http.Request, error) {
   615  	pathParameters := map[string]interface{}{
   616  		"availabilitySetName": autorest.Encode("path", availabilitySetName),
   617  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   618  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   619  	}
   620  
   621  	const APIVersion = "2021-11-01"
   622  	queryParameters := map[string]interface{}{
   623  		"api-version": APIVersion,
   624  	}
   625  
   626  	preparer := autorest.CreatePreparer(
   627  		autorest.AsContentType("application/json; charset=utf-8"),
   628  		autorest.AsPatch(),
   629  		autorest.WithBaseURL(client.BaseURI),
   630  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}", pathParameters),
   631  		autorest.WithJSON(parameters),
   632  		autorest.WithQueryParameters(queryParameters))
   633  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   634  }
   635  
   636  // UpdateSender sends the Update request. The method will close the
   637  // http.Response Body if it receives an error.
   638  func (client AvailabilitySetsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   639  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   640  }
   641  
   642  // UpdateResponder handles the response to the Update request. The method always
   643  // closes the http.Response Body.
   644  func (client AvailabilitySetsClient) UpdateResponder(resp *http.Response) (result AvailabilitySet, err error) {
   645  	err = autorest.Respond(
   646  		resp,
   647  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   648  		autorest.ByUnmarshallingJSON(&result),
   649  		autorest.ByClosing())
   650  	result.Response = autorest.Response{Response: resp}
   651  	return
   652  }
   653  

View as plain text