...

Source file src/github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2021-09-01/storagecache/storagetargets.go

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

     1  package storagecache
     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  // StorageTargetsClient is the a Storage Cache provides scalable caching service for NAS clients, serving data from
    19  // either NFSv3 or Blob at-rest storage (referred to as "Storage Targets"). These operations allow you to manage
    20  // Caches.
    21  type StorageTargetsClient struct {
    22  	BaseClient
    23  }
    24  
    25  // NewStorageTargetsClient creates an instance of the StorageTargetsClient client.
    26  func NewStorageTargetsClient(subscriptionID string) StorageTargetsClient {
    27  	return NewStorageTargetsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    28  }
    29  
    30  // NewStorageTargetsClientWithBaseURI creates an instance of the StorageTargetsClient client using a custom endpoint.
    31  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    32  func NewStorageTargetsClientWithBaseURI(baseURI string, subscriptionID string) StorageTargetsClient {
    33  	return StorageTargetsClient{NewWithBaseURI(baseURI, subscriptionID)}
    34  }
    35  
    36  // CreateOrUpdate create or update a Storage Target. This operation is allowed at any time, but if the Cache is down or
    37  // unhealthy, the actual creation/modification of the Storage Target may be delayed until the Cache is healthy again.
    38  // Parameters:
    39  // resourceGroupName - target resource group.
    40  // cacheName - name of Cache. Length of name must not be greater than 80 and chars must be from the
    41  // [-0-9a-zA-Z_] char class.
    42  // storageTargetName - name of Storage Target.
    43  // storagetarget - object containing the definition of a Storage Target.
    44  func (client StorageTargetsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, cacheName string, storageTargetName string, storagetarget *StorageTarget) (result StorageTargetsCreateOrUpdateFuture, err error) {
    45  	if tracing.IsEnabled() {
    46  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageTargetsClient.CreateOrUpdate")
    47  		defer func() {
    48  			sc := -1
    49  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    50  				sc = result.FutureAPI.Response().StatusCode
    51  			}
    52  			tracing.EndSpan(ctx, sc, err)
    53  		}()
    54  	}
    55  	if err := validation.Validate([]validation.Validation{
    56  		{TargetValue: cacheName,
    57  			Constraints: []validation.Constraint{{Target: "cacheName", Name: validation.Pattern, Rule: `^[-0-9a-zA-Z_]{1,80}$`, Chain: nil}}},
    58  		{TargetValue: storageTargetName,
    59  			Constraints: []validation.Constraint{{Target: "storageTargetName", Name: validation.Pattern, Rule: `^[-0-9a-zA-Z_]{1,80}$`, Chain: nil}}},
    60  		{TargetValue: storagetarget,
    61  			Constraints: []validation.Constraint{{Target: "storagetarget", Name: validation.Null, Rule: false,
    62  				Chain: []validation.Constraint{{Target: "storagetarget.StorageTargetProperties", Name: validation.Null, Rule: false,
    63  					Chain: []validation.Constraint{{Target: "storagetarget.StorageTargetProperties.Nfs3", Name: validation.Null, Rule: false,
    64  						Chain: []validation.Constraint{{Target: "storagetarget.StorageTargetProperties.Nfs3.Target", Name: validation.Null, Rule: false,
    65  							Chain: []validation.Constraint{{Target: "storagetarget.StorageTargetProperties.Nfs3.Target", Name: validation.Pattern, Rule: `^[-.,0-9a-zA-Z]+$`, Chain: nil}}},
    66  						}},
    67  					}},
    68  				}}}}}); err != nil {
    69  		return result, validation.NewError("storagecache.StorageTargetsClient", "CreateOrUpdate", err.Error())
    70  	}
    71  
    72  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, cacheName, storageTargetName, storagetarget)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "CreateOrUpdate", nil, "Failure preparing request")
    75  		return
    76  	}
    77  
    78  	result, err = client.CreateOrUpdateSender(req)
    79  	if err != nil {
    80  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    81  		return
    82  	}
    83  
    84  	return
    85  }
    86  
    87  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    88  func (client StorageTargetsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, cacheName string, storageTargetName string, storagetarget *StorageTarget) (*http.Request, error) {
    89  	pathParameters := map[string]interface{}{
    90  		"cacheName":         autorest.Encode("path", cacheName),
    91  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    92  		"storageTargetName": autorest.Encode("path", storageTargetName),
    93  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    94  	}
    95  
    96  	const APIVersion = "2021-09-01"
    97  	queryParameters := map[string]interface{}{
    98  		"api-version": APIVersion,
    99  	}
   100  
   101  	preparer := autorest.CreatePreparer(
   102  		autorest.AsContentType("application/json; charset=utf-8"),
   103  		autorest.AsPut(),
   104  		autorest.WithBaseURL(client.BaseURI),
   105  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}", pathParameters),
   106  		autorest.WithQueryParameters(queryParameters))
   107  	if storagetarget != nil {
   108  		preparer = autorest.DecoratePreparer(preparer,
   109  			autorest.WithJSON(storagetarget))
   110  	}
   111  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   112  }
   113  
   114  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   115  // http.Response Body if it receives an error.
   116  func (client StorageTargetsClient) CreateOrUpdateSender(req *http.Request) (future StorageTargetsCreateOrUpdateFuture, err error) {
   117  	var resp *http.Response
   118  	future.FutureAPI = &azure.Future{}
   119  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   120  	if err != nil {
   121  		return
   122  	}
   123  	var azf azure.Future
   124  	azf, err = azure.NewFutureFromResponse(resp)
   125  	future.FutureAPI = &azf
   126  	future.Result = future.result
   127  	return
   128  }
   129  
   130  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   131  // closes the http.Response Body.
   132  func (client StorageTargetsClient) CreateOrUpdateResponder(resp *http.Response) (result StorageTarget, err error) {
   133  	err = autorest.Respond(
   134  		resp,
   135  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
   136  		autorest.ByUnmarshallingJSON(&result),
   137  		autorest.ByClosing())
   138  	result.Response = autorest.Response{Response: resp}
   139  	return
   140  }
   141  
   142  // Delete removes a Storage Target from a Cache. This operation is allowed at any time, but if the Cache is down or
   143  // unhealthy, the actual removal of the Storage Target may be delayed until the Cache is healthy again. Note that if
   144  // the Cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
   145  // deleted.
   146  // Parameters:
   147  // resourceGroupName - target resource group.
   148  // cacheName - name of Cache. Length of name must not be greater than 80 and chars must be from the
   149  // [-0-9a-zA-Z_] char class.
   150  // storageTargetName - name of Storage Target.
   151  // force - boolean value requesting the force delete operation for a storage target. Force delete discards
   152  // unwritten-data in the cache instead of flushing it to back-end storage.
   153  func (client StorageTargetsClient) Delete(ctx context.Context, resourceGroupName string, cacheName string, storageTargetName string, force string) (result StorageTargetsDeleteFuture, err error) {
   154  	if tracing.IsEnabled() {
   155  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageTargetsClient.Delete")
   156  		defer func() {
   157  			sc := -1
   158  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   159  				sc = result.FutureAPI.Response().StatusCode
   160  			}
   161  			tracing.EndSpan(ctx, sc, err)
   162  		}()
   163  	}
   164  	if err := validation.Validate([]validation.Validation{
   165  		{TargetValue: cacheName,
   166  			Constraints: []validation.Constraint{{Target: "cacheName", Name: validation.Pattern, Rule: `^[-0-9a-zA-Z_]{1,80}$`, Chain: nil}}},
   167  		{TargetValue: storageTargetName,
   168  			Constraints: []validation.Constraint{{Target: "storageTargetName", Name: validation.Pattern, Rule: `^[-0-9a-zA-Z_]{1,80}$`, Chain: nil}}}}); err != nil {
   169  		return result, validation.NewError("storagecache.StorageTargetsClient", "Delete", err.Error())
   170  	}
   171  
   172  	req, err := client.DeletePreparer(ctx, resourceGroupName, cacheName, storageTargetName, force)
   173  	if err != nil {
   174  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "Delete", nil, "Failure preparing request")
   175  		return
   176  	}
   177  
   178  	result, err = client.DeleteSender(req)
   179  	if err != nil {
   180  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "Delete", result.Response(), "Failure sending request")
   181  		return
   182  	}
   183  
   184  	return
   185  }
   186  
   187  // DeletePreparer prepares the Delete request.
   188  func (client StorageTargetsClient) DeletePreparer(ctx context.Context, resourceGroupName string, cacheName string, storageTargetName string, force string) (*http.Request, error) {
   189  	pathParameters := map[string]interface{}{
   190  		"cacheName":         autorest.Encode("path", cacheName),
   191  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   192  		"storageTargetName": autorest.Encode("path", storageTargetName),
   193  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   194  	}
   195  
   196  	const APIVersion = "2021-09-01"
   197  	queryParameters := map[string]interface{}{
   198  		"api-version": APIVersion,
   199  	}
   200  	if len(force) > 0 {
   201  		queryParameters["force"] = autorest.Encode("query", force)
   202  	}
   203  
   204  	preparer := autorest.CreatePreparer(
   205  		autorest.AsDelete(),
   206  		autorest.WithBaseURL(client.BaseURI),
   207  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}", pathParameters),
   208  		autorest.WithQueryParameters(queryParameters))
   209  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   210  }
   211  
   212  // DeleteSender sends the Delete request. The method will close the
   213  // http.Response Body if it receives an error.
   214  func (client StorageTargetsClient) DeleteSender(req *http.Request) (future StorageTargetsDeleteFuture, err error) {
   215  	var resp *http.Response
   216  	future.FutureAPI = &azure.Future{}
   217  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   218  	if err != nil {
   219  		return
   220  	}
   221  	var azf azure.Future
   222  	azf, err = azure.NewFutureFromResponse(resp)
   223  	future.FutureAPI = &azf
   224  	future.Result = future.result
   225  	return
   226  }
   227  
   228  // DeleteResponder handles the response to the Delete request. The method always
   229  // closes the http.Response Body.
   230  func (client StorageTargetsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   231  	err = autorest.Respond(
   232  		resp,
   233  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   234  		autorest.ByClosing())
   235  	result.Response = resp
   236  	return
   237  }
   238  
   239  // DNSRefresh tells a storage target to refresh its DNS information.
   240  // Parameters:
   241  // resourceGroupName - target resource group.
   242  // cacheName - name of Cache. Length of name must not be greater than 80 and chars must be from the
   243  // [-0-9a-zA-Z_] char class.
   244  // storageTargetName - name of Storage Target.
   245  func (client StorageTargetsClient) DNSRefresh(ctx context.Context, resourceGroupName string, cacheName string, storageTargetName string) (result StorageTargetsDNSRefreshFuture, err error) {
   246  	if tracing.IsEnabled() {
   247  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageTargetsClient.DNSRefresh")
   248  		defer func() {
   249  			sc := -1
   250  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   251  				sc = result.FutureAPI.Response().StatusCode
   252  			}
   253  			tracing.EndSpan(ctx, sc, err)
   254  		}()
   255  	}
   256  	if err := validation.Validate([]validation.Validation{
   257  		{TargetValue: cacheName,
   258  			Constraints: []validation.Constraint{{Target: "cacheName", Name: validation.Pattern, Rule: `^[-0-9a-zA-Z_]{1,80}$`, Chain: nil}}},
   259  		{TargetValue: storageTargetName,
   260  			Constraints: []validation.Constraint{{Target: "storageTargetName", Name: validation.Pattern, Rule: `^[-0-9a-zA-Z_]{1,80}$`, Chain: nil}}}}); err != nil {
   261  		return result, validation.NewError("storagecache.StorageTargetsClient", "DNSRefresh", err.Error())
   262  	}
   263  
   264  	req, err := client.DNSRefreshPreparer(ctx, resourceGroupName, cacheName, storageTargetName)
   265  	if err != nil {
   266  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "DNSRefresh", nil, "Failure preparing request")
   267  		return
   268  	}
   269  
   270  	result, err = client.DNSRefreshSender(req)
   271  	if err != nil {
   272  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "DNSRefresh", result.Response(), "Failure sending request")
   273  		return
   274  	}
   275  
   276  	return
   277  }
   278  
   279  // DNSRefreshPreparer prepares the DNSRefresh request.
   280  func (client StorageTargetsClient) DNSRefreshPreparer(ctx context.Context, resourceGroupName string, cacheName string, storageTargetName string) (*http.Request, error) {
   281  	pathParameters := map[string]interface{}{
   282  		"cacheName":         autorest.Encode("path", cacheName),
   283  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   284  		"storageTargetName": autorest.Encode("path", storageTargetName),
   285  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   286  	}
   287  
   288  	const APIVersion = "2021-09-01"
   289  	queryParameters := map[string]interface{}{
   290  		"api-version": APIVersion,
   291  	}
   292  
   293  	preparer := autorest.CreatePreparer(
   294  		autorest.AsPost(),
   295  		autorest.WithBaseURL(client.BaseURI),
   296  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}/dnsRefresh", pathParameters),
   297  		autorest.WithQueryParameters(queryParameters))
   298  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   299  }
   300  
   301  // DNSRefreshSender sends the DNSRefresh request. The method will close the
   302  // http.Response Body if it receives an error.
   303  func (client StorageTargetsClient) DNSRefreshSender(req *http.Request) (future StorageTargetsDNSRefreshFuture, err error) {
   304  	var resp *http.Response
   305  	future.FutureAPI = &azure.Future{}
   306  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   307  	if err != nil {
   308  		return
   309  	}
   310  	var azf azure.Future
   311  	azf, err = azure.NewFutureFromResponse(resp)
   312  	future.FutureAPI = &azf
   313  	future.Result = future.result
   314  	return
   315  }
   316  
   317  // DNSRefreshResponder handles the response to the DNSRefresh request. The method always
   318  // closes the http.Response Body.
   319  func (client StorageTargetsClient) DNSRefreshResponder(resp *http.Response) (result autorest.Response, err error) {
   320  	err = autorest.Respond(
   321  		resp,
   322  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   323  		autorest.ByClosing())
   324  	result.Response = resp
   325  	return
   326  }
   327  
   328  // Get returns a Storage Target from a Cache.
   329  // Parameters:
   330  // resourceGroupName - target resource group.
   331  // cacheName - name of Cache. Length of name must not be greater than 80 and chars must be from the
   332  // [-0-9a-zA-Z_] char class.
   333  // storageTargetName - name of Storage Target.
   334  func (client StorageTargetsClient) Get(ctx context.Context, resourceGroupName string, cacheName string, storageTargetName string) (result StorageTarget, err error) {
   335  	if tracing.IsEnabled() {
   336  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageTargetsClient.Get")
   337  		defer func() {
   338  			sc := -1
   339  			if result.Response.Response != nil {
   340  				sc = result.Response.Response.StatusCode
   341  			}
   342  			tracing.EndSpan(ctx, sc, err)
   343  		}()
   344  	}
   345  	if err := validation.Validate([]validation.Validation{
   346  		{TargetValue: cacheName,
   347  			Constraints: []validation.Constraint{{Target: "cacheName", Name: validation.Pattern, Rule: `^[-0-9a-zA-Z_]{1,80}$`, Chain: nil}}},
   348  		{TargetValue: storageTargetName,
   349  			Constraints: []validation.Constraint{{Target: "storageTargetName", Name: validation.Pattern, Rule: `^[-0-9a-zA-Z_]{1,80}$`, Chain: nil}}}}); err != nil {
   350  		return result, validation.NewError("storagecache.StorageTargetsClient", "Get", err.Error())
   351  	}
   352  
   353  	req, err := client.GetPreparer(ctx, resourceGroupName, cacheName, storageTargetName)
   354  	if err != nil {
   355  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "Get", nil, "Failure preparing request")
   356  		return
   357  	}
   358  
   359  	resp, err := client.GetSender(req)
   360  	if err != nil {
   361  		result.Response = autorest.Response{Response: resp}
   362  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "Get", resp, "Failure sending request")
   363  		return
   364  	}
   365  
   366  	result, err = client.GetResponder(resp)
   367  	if err != nil {
   368  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "Get", resp, "Failure responding to request")
   369  		return
   370  	}
   371  
   372  	return
   373  }
   374  
   375  // GetPreparer prepares the Get request.
   376  func (client StorageTargetsClient) GetPreparer(ctx context.Context, resourceGroupName string, cacheName string, storageTargetName string) (*http.Request, error) {
   377  	pathParameters := map[string]interface{}{
   378  		"cacheName":         autorest.Encode("path", cacheName),
   379  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   380  		"storageTargetName": autorest.Encode("path", storageTargetName),
   381  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   382  	}
   383  
   384  	const APIVersion = "2021-09-01"
   385  	queryParameters := map[string]interface{}{
   386  		"api-version": APIVersion,
   387  	}
   388  
   389  	preparer := autorest.CreatePreparer(
   390  		autorest.AsGet(),
   391  		autorest.WithBaseURL(client.BaseURI),
   392  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}", pathParameters),
   393  		autorest.WithQueryParameters(queryParameters))
   394  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   395  }
   396  
   397  // GetSender sends the Get request. The method will close the
   398  // http.Response Body if it receives an error.
   399  func (client StorageTargetsClient) GetSender(req *http.Request) (*http.Response, error) {
   400  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   401  }
   402  
   403  // GetResponder handles the response to the Get request. The method always
   404  // closes the http.Response Body.
   405  func (client StorageTargetsClient) GetResponder(resp *http.Response) (result StorageTarget, err error) {
   406  	err = autorest.Respond(
   407  		resp,
   408  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   409  		autorest.ByUnmarshallingJSON(&result),
   410  		autorest.ByClosing())
   411  	result.Response = autorest.Response{Response: resp}
   412  	return
   413  }
   414  
   415  // ListByCache returns a list of Storage Targets for the specified Cache.
   416  // Parameters:
   417  // resourceGroupName - target resource group.
   418  // cacheName - name of Cache. Length of name must not be greater than 80 and chars must be from the
   419  // [-0-9a-zA-Z_] char class.
   420  func (client StorageTargetsClient) ListByCache(ctx context.Context, resourceGroupName string, cacheName string) (result StorageTargetsResultPage, err error) {
   421  	if tracing.IsEnabled() {
   422  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageTargetsClient.ListByCache")
   423  		defer func() {
   424  			sc := -1
   425  			if result.str.Response.Response != nil {
   426  				sc = result.str.Response.Response.StatusCode
   427  			}
   428  			tracing.EndSpan(ctx, sc, err)
   429  		}()
   430  	}
   431  	if err := validation.Validate([]validation.Validation{
   432  		{TargetValue: cacheName,
   433  			Constraints: []validation.Constraint{{Target: "cacheName", Name: validation.Pattern, Rule: `^[-0-9a-zA-Z_]{1,80}$`, Chain: nil}}}}); err != nil {
   434  		return result, validation.NewError("storagecache.StorageTargetsClient", "ListByCache", err.Error())
   435  	}
   436  
   437  	result.fn = client.listByCacheNextResults
   438  	req, err := client.ListByCachePreparer(ctx, resourceGroupName, cacheName)
   439  	if err != nil {
   440  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "ListByCache", nil, "Failure preparing request")
   441  		return
   442  	}
   443  
   444  	resp, err := client.ListByCacheSender(req)
   445  	if err != nil {
   446  		result.str.Response = autorest.Response{Response: resp}
   447  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "ListByCache", resp, "Failure sending request")
   448  		return
   449  	}
   450  
   451  	result.str, err = client.ListByCacheResponder(resp)
   452  	if err != nil {
   453  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "ListByCache", resp, "Failure responding to request")
   454  		return
   455  	}
   456  	if result.str.hasNextLink() && result.str.IsEmpty() {
   457  		err = result.NextWithContext(ctx)
   458  		return
   459  	}
   460  
   461  	return
   462  }
   463  
   464  // ListByCachePreparer prepares the ListByCache request.
   465  func (client StorageTargetsClient) ListByCachePreparer(ctx context.Context, resourceGroupName string, cacheName string) (*http.Request, error) {
   466  	pathParameters := map[string]interface{}{
   467  		"cacheName":         autorest.Encode("path", cacheName),
   468  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   469  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   470  	}
   471  
   472  	const APIVersion = "2021-09-01"
   473  	queryParameters := map[string]interface{}{
   474  		"api-version": APIVersion,
   475  	}
   476  
   477  	preparer := autorest.CreatePreparer(
   478  		autorest.AsGet(),
   479  		autorest.WithBaseURL(client.BaseURI),
   480  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets", pathParameters),
   481  		autorest.WithQueryParameters(queryParameters))
   482  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   483  }
   484  
   485  // ListByCacheSender sends the ListByCache request. The method will close the
   486  // http.Response Body if it receives an error.
   487  func (client StorageTargetsClient) ListByCacheSender(req *http.Request) (*http.Response, error) {
   488  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   489  }
   490  
   491  // ListByCacheResponder handles the response to the ListByCache request. The method always
   492  // closes the http.Response Body.
   493  func (client StorageTargetsClient) ListByCacheResponder(resp *http.Response) (result StorageTargetsResult, err error) {
   494  	err = autorest.Respond(
   495  		resp,
   496  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   497  		autorest.ByUnmarshallingJSON(&result),
   498  		autorest.ByClosing())
   499  	result.Response = autorest.Response{Response: resp}
   500  	return
   501  }
   502  
   503  // listByCacheNextResults retrieves the next set of results, if any.
   504  func (client StorageTargetsClient) listByCacheNextResults(ctx context.Context, lastResults StorageTargetsResult) (result StorageTargetsResult, err error) {
   505  	req, err := lastResults.storageTargetsResultPreparer(ctx)
   506  	if err != nil {
   507  		return result, autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "listByCacheNextResults", nil, "Failure preparing next results request")
   508  	}
   509  	if req == nil {
   510  		return
   511  	}
   512  	resp, err := client.ListByCacheSender(req)
   513  	if err != nil {
   514  		result.Response = autorest.Response{Response: resp}
   515  		return result, autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "listByCacheNextResults", resp, "Failure sending next results request")
   516  	}
   517  	result, err = client.ListByCacheResponder(resp)
   518  	if err != nil {
   519  		err = autorest.NewErrorWithError(err, "storagecache.StorageTargetsClient", "listByCacheNextResults", resp, "Failure responding to next results request")
   520  	}
   521  	return
   522  }
   523  
   524  // ListByCacheComplete enumerates all values, automatically crossing page boundaries as required.
   525  func (client StorageTargetsClient) ListByCacheComplete(ctx context.Context, resourceGroupName string, cacheName string) (result StorageTargetsResultIterator, err error) {
   526  	if tracing.IsEnabled() {
   527  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageTargetsClient.ListByCache")
   528  		defer func() {
   529  			sc := -1
   530  			if result.Response().Response.Response != nil {
   531  				sc = result.page.Response().Response.Response.StatusCode
   532  			}
   533  			tracing.EndSpan(ctx, sc, err)
   534  		}()
   535  	}
   536  	result.page, err = client.ListByCache(ctx, resourceGroupName, cacheName)
   537  	return
   538  }
   539  

View as plain text