...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2018-03-01/insights/autoscalesettings.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2018-03-01/insights

     1  package insights
     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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // AutoscaleSettingsClient is the monitor Management Client
    19  type AutoscaleSettingsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewAutoscaleSettingsClient creates an instance of the AutoscaleSettingsClient client.
    24  func NewAutoscaleSettingsClient(subscriptionID string) AutoscaleSettingsClient {
    25  	return NewAutoscaleSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewAutoscaleSettingsClientWithBaseURI creates an instance of the AutoscaleSettingsClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewAutoscaleSettingsClientWithBaseURI(baseURI string, subscriptionID string) AutoscaleSettingsClient {
    32  	return AutoscaleSettingsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate creates or updates an autoscale setting.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group.
    38  // autoscaleSettingName - the autoscale setting name.
    39  // parameters - parameters supplied to the operation.
    40  func (client AutoscaleSettingsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, autoscaleSettingName string, parameters AutoscaleSettingResource) (result AutoscaleSettingResource, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/AutoscaleSettingsClient.CreateOrUpdate")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	if err := validation.Validate([]validation.Validation{
    52  		{TargetValue: parameters,
    53  			Constraints: []validation.Constraint{{Target: "parameters.AutoscaleSetting", Name: validation.Null, Rule: true,
    54  				Chain: []validation.Constraint{{Target: "parameters.AutoscaleSetting.Profiles", Name: validation.Null, Rule: true,
    55  					Chain: []validation.Constraint{{Target: "parameters.AutoscaleSetting.Profiles", Name: validation.MaxItems, Rule: 20, Chain: nil}}},
    56  				}}}}}); err != nil {
    57  		return result, validation.NewError("insights.AutoscaleSettingsClient", "CreateOrUpdate", err.Error())
    58  	}
    59  
    60  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, autoscaleSettingName, parameters)
    61  	if err != nil {
    62  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "CreateOrUpdate", nil, "Failure preparing request")
    63  		return
    64  	}
    65  
    66  	resp, err := client.CreateOrUpdateSender(req)
    67  	if err != nil {
    68  		result.Response = autorest.Response{Response: resp}
    69  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "CreateOrUpdate", resp, "Failure sending request")
    70  		return
    71  	}
    72  
    73  	result, err = client.CreateOrUpdateResponder(resp)
    74  	if err != nil {
    75  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "CreateOrUpdate", resp, "Failure responding to request")
    76  		return
    77  	}
    78  
    79  	return
    80  }
    81  
    82  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    83  func (client AutoscaleSettingsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, autoscaleSettingName string, parameters AutoscaleSettingResource) (*http.Request, error) {
    84  	pathParameters := map[string]interface{}{
    85  		"autoscaleSettingName": autorest.Encode("path", autoscaleSettingName),
    86  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
    87  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
    88  	}
    89  
    90  	const APIVersion = "2015-04-01"
    91  	queryParameters := map[string]interface{}{
    92  		"api-version": APIVersion,
    93  	}
    94  
    95  	preparer := autorest.CreatePreparer(
    96  		autorest.AsContentType("application/json; charset=utf-8"),
    97  		autorest.AsPut(),
    98  		autorest.WithBaseURL(client.BaseURI),
    99  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings/{autoscaleSettingName}", pathParameters),
   100  		autorest.WithJSON(parameters),
   101  		autorest.WithQueryParameters(queryParameters))
   102  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   103  }
   104  
   105  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   106  // http.Response Body if it receives an error.
   107  func (client AutoscaleSettingsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   108  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   109  }
   110  
   111  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   112  // closes the http.Response Body.
   113  func (client AutoscaleSettingsClient) CreateOrUpdateResponder(resp *http.Response) (result AutoscaleSettingResource, err error) {
   114  	err = autorest.Respond(
   115  		resp,
   116  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   117  		autorest.ByUnmarshallingJSON(&result),
   118  		autorest.ByClosing())
   119  	result.Response = autorest.Response{Response: resp}
   120  	return
   121  }
   122  
   123  // Delete deletes and autoscale setting
   124  // Parameters:
   125  // resourceGroupName - the name of the resource group.
   126  // autoscaleSettingName - the autoscale setting name.
   127  func (client AutoscaleSettingsClient) Delete(ctx context.Context, resourceGroupName string, autoscaleSettingName string) (result autorest.Response, err error) {
   128  	if tracing.IsEnabled() {
   129  		ctx = tracing.StartSpan(ctx, fqdn+"/AutoscaleSettingsClient.Delete")
   130  		defer func() {
   131  			sc := -1
   132  			if result.Response != nil {
   133  				sc = result.Response.StatusCode
   134  			}
   135  			tracing.EndSpan(ctx, sc, err)
   136  		}()
   137  	}
   138  	req, err := client.DeletePreparer(ctx, resourceGroupName, autoscaleSettingName)
   139  	if err != nil {
   140  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "Delete", nil, "Failure preparing request")
   141  		return
   142  	}
   143  
   144  	resp, err := client.DeleteSender(req)
   145  	if err != nil {
   146  		result.Response = resp
   147  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "Delete", resp, "Failure sending request")
   148  		return
   149  	}
   150  
   151  	result, err = client.DeleteResponder(resp)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "Delete", resp, "Failure responding to request")
   154  		return
   155  	}
   156  
   157  	return
   158  }
   159  
   160  // DeletePreparer prepares the Delete request.
   161  func (client AutoscaleSettingsClient) DeletePreparer(ctx context.Context, resourceGroupName string, autoscaleSettingName string) (*http.Request, error) {
   162  	pathParameters := map[string]interface{}{
   163  		"autoscaleSettingName": autorest.Encode("path", autoscaleSettingName),
   164  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   165  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   166  	}
   167  
   168  	const APIVersion = "2015-04-01"
   169  	queryParameters := map[string]interface{}{
   170  		"api-version": APIVersion,
   171  	}
   172  
   173  	preparer := autorest.CreatePreparer(
   174  		autorest.AsDelete(),
   175  		autorest.WithBaseURL(client.BaseURI),
   176  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings/{autoscaleSettingName}", pathParameters),
   177  		autorest.WithQueryParameters(queryParameters))
   178  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   179  }
   180  
   181  // DeleteSender sends the Delete request. The method will close the
   182  // http.Response Body if it receives an error.
   183  func (client AutoscaleSettingsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   184  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   185  }
   186  
   187  // DeleteResponder handles the response to the Delete request. The method always
   188  // closes the http.Response Body.
   189  func (client AutoscaleSettingsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   190  	err = autorest.Respond(
   191  		resp,
   192  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   193  		autorest.ByClosing())
   194  	result.Response = resp
   195  	return
   196  }
   197  
   198  // Get gets an autoscale setting
   199  // Parameters:
   200  // resourceGroupName - the name of the resource group.
   201  // autoscaleSettingName - the autoscale setting name.
   202  func (client AutoscaleSettingsClient) Get(ctx context.Context, resourceGroupName string, autoscaleSettingName string) (result AutoscaleSettingResource, err error) {
   203  	if tracing.IsEnabled() {
   204  		ctx = tracing.StartSpan(ctx, fqdn+"/AutoscaleSettingsClient.Get")
   205  		defer func() {
   206  			sc := -1
   207  			if result.Response.Response != nil {
   208  				sc = result.Response.Response.StatusCode
   209  			}
   210  			tracing.EndSpan(ctx, sc, err)
   211  		}()
   212  	}
   213  	req, err := client.GetPreparer(ctx, resourceGroupName, autoscaleSettingName)
   214  	if err != nil {
   215  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "Get", nil, "Failure preparing request")
   216  		return
   217  	}
   218  
   219  	resp, err := client.GetSender(req)
   220  	if err != nil {
   221  		result.Response = autorest.Response{Response: resp}
   222  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "Get", resp, "Failure sending request")
   223  		return
   224  	}
   225  
   226  	result, err = client.GetResponder(resp)
   227  	if err != nil {
   228  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "Get", resp, "Failure responding to request")
   229  		return
   230  	}
   231  
   232  	return
   233  }
   234  
   235  // GetPreparer prepares the Get request.
   236  func (client AutoscaleSettingsClient) GetPreparer(ctx context.Context, resourceGroupName string, autoscaleSettingName string) (*http.Request, error) {
   237  	pathParameters := map[string]interface{}{
   238  		"autoscaleSettingName": autorest.Encode("path", autoscaleSettingName),
   239  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   240  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   241  	}
   242  
   243  	const APIVersion = "2015-04-01"
   244  	queryParameters := map[string]interface{}{
   245  		"api-version": APIVersion,
   246  	}
   247  
   248  	preparer := autorest.CreatePreparer(
   249  		autorest.AsGet(),
   250  		autorest.WithBaseURL(client.BaseURI),
   251  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings/{autoscaleSettingName}", pathParameters),
   252  		autorest.WithQueryParameters(queryParameters))
   253  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   254  }
   255  
   256  // GetSender sends the Get request. The method will close the
   257  // http.Response Body if it receives an error.
   258  func (client AutoscaleSettingsClient) GetSender(req *http.Request) (*http.Response, error) {
   259  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   260  }
   261  
   262  // GetResponder handles the response to the Get request. The method always
   263  // closes the http.Response Body.
   264  func (client AutoscaleSettingsClient) GetResponder(resp *http.Response) (result AutoscaleSettingResource, err error) {
   265  	err = autorest.Respond(
   266  		resp,
   267  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   268  		autorest.ByUnmarshallingJSON(&result),
   269  		autorest.ByClosing())
   270  	result.Response = autorest.Response{Response: resp}
   271  	return
   272  }
   273  
   274  // ListByResourceGroup lists the autoscale settings for a resource group
   275  // Parameters:
   276  // resourceGroupName - the name of the resource group.
   277  func (client AutoscaleSettingsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result AutoscaleSettingResourceCollectionPage, err error) {
   278  	if tracing.IsEnabled() {
   279  		ctx = tracing.StartSpan(ctx, fqdn+"/AutoscaleSettingsClient.ListByResourceGroup")
   280  		defer func() {
   281  			sc := -1
   282  			if result.asrc.Response.Response != nil {
   283  				sc = result.asrc.Response.Response.StatusCode
   284  			}
   285  			tracing.EndSpan(ctx, sc, err)
   286  		}()
   287  	}
   288  	result.fn = client.listByResourceGroupNextResults
   289  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
   290  	if err != nil {
   291  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "ListByResourceGroup", nil, "Failure preparing request")
   292  		return
   293  	}
   294  
   295  	resp, err := client.ListByResourceGroupSender(req)
   296  	if err != nil {
   297  		result.asrc.Response = autorest.Response{Response: resp}
   298  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "ListByResourceGroup", resp, "Failure sending request")
   299  		return
   300  	}
   301  
   302  	result.asrc, err = client.ListByResourceGroupResponder(resp)
   303  	if err != nil {
   304  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "ListByResourceGroup", resp, "Failure responding to request")
   305  		return
   306  	}
   307  	if result.asrc.hasNextLink() && result.asrc.IsEmpty() {
   308  		err = result.NextWithContext(ctx)
   309  		return
   310  	}
   311  
   312  	return
   313  }
   314  
   315  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   316  func (client AutoscaleSettingsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   317  	pathParameters := map[string]interface{}{
   318  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   319  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   320  	}
   321  
   322  	const APIVersion = "2015-04-01"
   323  	queryParameters := map[string]interface{}{
   324  		"api-version": APIVersion,
   325  	}
   326  
   327  	preparer := autorest.CreatePreparer(
   328  		autorest.AsGet(),
   329  		autorest.WithBaseURL(client.BaseURI),
   330  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings", pathParameters),
   331  		autorest.WithQueryParameters(queryParameters))
   332  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   333  }
   334  
   335  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   336  // http.Response Body if it receives an error.
   337  func (client AutoscaleSettingsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   338  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   339  }
   340  
   341  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   342  // closes the http.Response Body.
   343  func (client AutoscaleSettingsClient) ListByResourceGroupResponder(resp *http.Response) (result AutoscaleSettingResourceCollection, err error) {
   344  	err = autorest.Respond(
   345  		resp,
   346  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   347  		autorest.ByUnmarshallingJSON(&result),
   348  		autorest.ByClosing())
   349  	result.Response = autorest.Response{Response: resp}
   350  	return
   351  }
   352  
   353  // listByResourceGroupNextResults retrieves the next set of results, if any.
   354  func (client AutoscaleSettingsClient) listByResourceGroupNextResults(ctx context.Context, lastResults AutoscaleSettingResourceCollection) (result AutoscaleSettingResourceCollection, err error) {
   355  	req, err := lastResults.autoscaleSettingResourceCollectionPreparer(ctx)
   356  	if err != nil {
   357  		return result, autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
   358  	}
   359  	if req == nil {
   360  		return
   361  	}
   362  	resp, err := client.ListByResourceGroupSender(req)
   363  	if err != nil {
   364  		result.Response = autorest.Response{Response: resp}
   365  		return result, autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
   366  	}
   367  	result, err = client.ListByResourceGroupResponder(resp)
   368  	if err != nil {
   369  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
   370  	}
   371  	return
   372  }
   373  
   374  // ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
   375  func (client AutoscaleSettingsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result AutoscaleSettingResourceCollectionIterator, err error) {
   376  	if tracing.IsEnabled() {
   377  		ctx = tracing.StartSpan(ctx, fqdn+"/AutoscaleSettingsClient.ListByResourceGroup")
   378  		defer func() {
   379  			sc := -1
   380  			if result.Response().Response.Response != nil {
   381  				sc = result.page.Response().Response.Response.StatusCode
   382  			}
   383  			tracing.EndSpan(ctx, sc, err)
   384  		}()
   385  	}
   386  	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
   387  	return
   388  }
   389  
   390  // ListBySubscription lists the autoscale settings for a subscription
   391  func (client AutoscaleSettingsClient) ListBySubscription(ctx context.Context) (result AutoscaleSettingResourceCollectionPage, err error) {
   392  	if tracing.IsEnabled() {
   393  		ctx = tracing.StartSpan(ctx, fqdn+"/AutoscaleSettingsClient.ListBySubscription")
   394  		defer func() {
   395  			sc := -1
   396  			if result.asrc.Response.Response != nil {
   397  				sc = result.asrc.Response.Response.StatusCode
   398  			}
   399  			tracing.EndSpan(ctx, sc, err)
   400  		}()
   401  	}
   402  	result.fn = client.listBySubscriptionNextResults
   403  	req, err := client.ListBySubscriptionPreparer(ctx)
   404  	if err != nil {
   405  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "ListBySubscription", nil, "Failure preparing request")
   406  		return
   407  	}
   408  
   409  	resp, err := client.ListBySubscriptionSender(req)
   410  	if err != nil {
   411  		result.asrc.Response = autorest.Response{Response: resp}
   412  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "ListBySubscription", resp, "Failure sending request")
   413  		return
   414  	}
   415  
   416  	result.asrc, err = client.ListBySubscriptionResponder(resp)
   417  	if err != nil {
   418  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "ListBySubscription", resp, "Failure responding to request")
   419  		return
   420  	}
   421  	if result.asrc.hasNextLink() && result.asrc.IsEmpty() {
   422  		err = result.NextWithContext(ctx)
   423  		return
   424  	}
   425  
   426  	return
   427  }
   428  
   429  // ListBySubscriptionPreparer prepares the ListBySubscription request.
   430  func (client AutoscaleSettingsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
   431  	pathParameters := map[string]interface{}{
   432  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   433  	}
   434  
   435  	const APIVersion = "2015-04-01"
   436  	queryParameters := map[string]interface{}{
   437  		"api-version": APIVersion,
   438  	}
   439  
   440  	preparer := autorest.CreatePreparer(
   441  		autorest.AsGet(),
   442  		autorest.WithBaseURL(client.BaseURI),
   443  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/autoscalesettings", pathParameters),
   444  		autorest.WithQueryParameters(queryParameters))
   445  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   446  }
   447  
   448  // ListBySubscriptionSender sends the ListBySubscription request. The method will close the
   449  // http.Response Body if it receives an error.
   450  func (client AutoscaleSettingsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
   451  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   452  }
   453  
   454  // ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
   455  // closes the http.Response Body.
   456  func (client AutoscaleSettingsClient) ListBySubscriptionResponder(resp *http.Response) (result AutoscaleSettingResourceCollection, err error) {
   457  	err = autorest.Respond(
   458  		resp,
   459  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   460  		autorest.ByUnmarshallingJSON(&result),
   461  		autorest.ByClosing())
   462  	result.Response = autorest.Response{Response: resp}
   463  	return
   464  }
   465  
   466  // listBySubscriptionNextResults retrieves the next set of results, if any.
   467  func (client AutoscaleSettingsClient) listBySubscriptionNextResults(ctx context.Context, lastResults AutoscaleSettingResourceCollection) (result AutoscaleSettingResourceCollection, err error) {
   468  	req, err := lastResults.autoscaleSettingResourceCollectionPreparer(ctx)
   469  	if err != nil {
   470  		return result, autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request")
   471  	}
   472  	if req == nil {
   473  		return
   474  	}
   475  	resp, err := client.ListBySubscriptionSender(req)
   476  	if err != nil {
   477  		result.Response = autorest.Response{Response: resp}
   478  		return result, autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "listBySubscriptionNextResults", resp, "Failure sending next results request")
   479  	}
   480  	result, err = client.ListBySubscriptionResponder(resp)
   481  	if err != nil {
   482  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request")
   483  	}
   484  	return
   485  }
   486  
   487  // ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required.
   488  func (client AutoscaleSettingsClient) ListBySubscriptionComplete(ctx context.Context) (result AutoscaleSettingResourceCollectionIterator, err error) {
   489  	if tracing.IsEnabled() {
   490  		ctx = tracing.StartSpan(ctx, fqdn+"/AutoscaleSettingsClient.ListBySubscription")
   491  		defer func() {
   492  			sc := -1
   493  			if result.Response().Response.Response != nil {
   494  				sc = result.page.Response().Response.Response.StatusCode
   495  			}
   496  			tracing.EndSpan(ctx, sc, err)
   497  		}()
   498  	}
   499  	result.page, err = client.ListBySubscription(ctx)
   500  	return
   501  }
   502  
   503  // Update updates an existing AutoscaleSettingsResource. To update other fields use the CreateOrUpdate method.
   504  // Parameters:
   505  // resourceGroupName - the name of the resource group.
   506  // autoscaleSettingName - the autoscale setting name.
   507  // autoscaleSettingResource - parameters supplied to the operation.
   508  func (client AutoscaleSettingsClient) Update(ctx context.Context, resourceGroupName string, autoscaleSettingName string, autoscaleSettingResource AutoscaleSettingResourcePatch) (result AutoscaleSettingResource, err error) {
   509  	if tracing.IsEnabled() {
   510  		ctx = tracing.StartSpan(ctx, fqdn+"/AutoscaleSettingsClient.Update")
   511  		defer func() {
   512  			sc := -1
   513  			if result.Response.Response != nil {
   514  				sc = result.Response.Response.StatusCode
   515  			}
   516  			tracing.EndSpan(ctx, sc, err)
   517  		}()
   518  	}
   519  	req, err := client.UpdatePreparer(ctx, resourceGroupName, autoscaleSettingName, autoscaleSettingResource)
   520  	if err != nil {
   521  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "Update", nil, "Failure preparing request")
   522  		return
   523  	}
   524  
   525  	resp, err := client.UpdateSender(req)
   526  	if err != nil {
   527  		result.Response = autorest.Response{Response: resp}
   528  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "Update", resp, "Failure sending request")
   529  		return
   530  	}
   531  
   532  	result, err = client.UpdateResponder(resp)
   533  	if err != nil {
   534  		err = autorest.NewErrorWithError(err, "insights.AutoscaleSettingsClient", "Update", resp, "Failure responding to request")
   535  		return
   536  	}
   537  
   538  	return
   539  }
   540  
   541  // UpdatePreparer prepares the Update request.
   542  func (client AutoscaleSettingsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, autoscaleSettingName string, autoscaleSettingResource AutoscaleSettingResourcePatch) (*http.Request, error) {
   543  	pathParameters := map[string]interface{}{
   544  		"autoscaleSettingName": autorest.Encode("path", autoscaleSettingName),
   545  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   546  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   547  	}
   548  
   549  	const APIVersion = "2015-04-01"
   550  	queryParameters := map[string]interface{}{
   551  		"api-version": APIVersion,
   552  	}
   553  
   554  	preparer := autorest.CreatePreparer(
   555  		autorest.AsContentType("application/json; charset=utf-8"),
   556  		autorest.AsPatch(),
   557  		autorest.WithBaseURL(client.BaseURI),
   558  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings/{autoscaleSettingName}", pathParameters),
   559  		autorest.WithJSON(autoscaleSettingResource),
   560  		autorest.WithQueryParameters(queryParameters))
   561  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   562  }
   563  
   564  // UpdateSender sends the Update request. The method will close the
   565  // http.Response Body if it receives an error.
   566  func (client AutoscaleSettingsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   567  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   568  }
   569  
   570  // UpdateResponder handles the response to the Update request. The method always
   571  // closes the http.Response Body.
   572  func (client AutoscaleSettingsClient) UpdateResponder(resp *http.Response) (result AutoscaleSettingResource, err error) {
   573  	err = autorest.Respond(
   574  		resp,
   575  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   576  		autorest.ByUnmarshallingJSON(&result),
   577  		autorest.ByClosing())
   578  	result.Response = autorest.Response{Response: resp}
   579  	return
   580  }
   581  

View as plain text