...

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

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

View as plain text