...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-12-01/backup/recoverypoints.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-12-01/backup

     1  package backup
     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  // RecoveryPointsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type RecoveryPointsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewRecoveryPointsClient creates an instance of the RecoveryPointsClient client.
    23  func NewRecoveryPointsClient(subscriptionID string) RecoveryPointsClient {
    24  	return NewRecoveryPointsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewRecoveryPointsClientWithBaseURI creates an instance of the RecoveryPointsClient client using a custom endpoint.
    28  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewRecoveryPointsClientWithBaseURI(baseURI string, subscriptionID string) RecoveryPointsClient {
    30  	return RecoveryPointsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Get provides the information of the backed up data identified using RecoveryPointID. This is an asynchronous
    34  // operation.
    35  // To know the status of the operation, call the GetProtectedItemOperationResult API.
    36  // Parameters:
    37  // vaultName - the name of the recovery services vault.
    38  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    39  // fabricName - fabric name associated with backed up item.
    40  // containerName - container name associated with backed up item.
    41  // protectedItemName - backed up item name whose backup data needs to be fetched.
    42  // recoveryPointID - recoveryPointID represents the backed up data to be fetched.
    43  func (client RecoveryPointsClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string) (result RecoveryPointResource, err error) {
    44  	if tracing.IsEnabled() {
    45  		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.Get")
    46  		defer func() {
    47  			sc := -1
    48  			if result.Response.Response != nil {
    49  				sc = result.Response.Response.StatusCode
    50  			}
    51  			tracing.EndSpan(ctx, sc, err)
    52  		}()
    53  	}
    54  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, recoveryPointID)
    55  	if err != nil {
    56  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "Get", nil, "Failure preparing request")
    57  		return
    58  	}
    59  
    60  	resp, err := client.GetSender(req)
    61  	if err != nil {
    62  		result.Response = autorest.Response{Response: resp}
    63  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "Get", resp, "Failure sending request")
    64  		return
    65  	}
    66  
    67  	result, err = client.GetResponder(resp)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "Get", resp, "Failure responding to request")
    70  		return
    71  	}
    72  
    73  	return
    74  }
    75  
    76  // GetPreparer prepares the Get request.
    77  func (client RecoveryPointsClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string) (*http.Request, error) {
    78  	pathParameters := map[string]interface{}{
    79  		"containerName":     autorest.Encode("path", containerName),
    80  		"fabricName":        autorest.Encode("path", fabricName),
    81  		"protectedItemName": autorest.Encode("path", protectedItemName),
    82  		"recoveryPointId":   autorest.Encode("path", recoveryPointID),
    83  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    84  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    85  		"vaultName":         autorest.Encode("path", vaultName),
    86  	}
    87  
    88  	const APIVersion = "2021-12-01"
    89  	queryParameters := map[string]interface{}{
    90  		"api-version": APIVersion,
    91  	}
    92  
    93  	preparer := autorest.CreatePreparer(
    94  		autorest.AsGet(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}", pathParameters),
    97  		autorest.WithQueryParameters(queryParameters))
    98  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    99  }
   100  
   101  // GetSender sends the Get request. The method will close the
   102  // http.Response Body if it receives an error.
   103  func (client RecoveryPointsClient) GetSender(req *http.Request) (*http.Response, error) {
   104  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   105  }
   106  
   107  // GetResponder handles the response to the Get request. The method always
   108  // closes the http.Response Body.
   109  func (client RecoveryPointsClient) GetResponder(resp *http.Response) (result RecoveryPointResource, err error) {
   110  	err = autorest.Respond(
   111  		resp,
   112  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   113  		autorest.ByUnmarshallingJSON(&result),
   114  		autorest.ByClosing())
   115  	result.Response = autorest.Response{Response: resp}
   116  	return
   117  }
   118  
   119  // List lists the backup copies for the backed up item.
   120  // Parameters:
   121  // vaultName - the name of the recovery services vault.
   122  // resourceGroupName - the name of the resource group where the recovery services vault is present.
   123  // fabricName - fabric name associated with the backed up item.
   124  // containerName - container name associated with the backed up item.
   125  // protectedItemName - backed up item whose backup copies are to be fetched.
   126  // filter - oData filter options.
   127  func (client RecoveryPointsClient) List(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (result RecoveryPointResourceListPage, err error) {
   128  	if tracing.IsEnabled() {
   129  		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.List")
   130  		defer func() {
   131  			sc := -1
   132  			if result.rprl.Response.Response != nil {
   133  				sc = result.rprl.Response.Response.StatusCode
   134  			}
   135  			tracing.EndSpan(ctx, sc, err)
   136  		}()
   137  	}
   138  	result.fn = client.listNextResults
   139  	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, filter)
   140  	if err != nil {
   141  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "List", nil, "Failure preparing request")
   142  		return
   143  	}
   144  
   145  	resp, err := client.ListSender(req)
   146  	if err != nil {
   147  		result.rprl.Response = autorest.Response{Response: resp}
   148  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "List", resp, "Failure sending request")
   149  		return
   150  	}
   151  
   152  	result.rprl, err = client.ListResponder(resp)
   153  	if err != nil {
   154  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "List", resp, "Failure responding to request")
   155  		return
   156  	}
   157  	if result.rprl.hasNextLink() && result.rprl.IsEmpty() {
   158  		err = result.NextWithContext(ctx)
   159  		return
   160  	}
   161  
   162  	return
   163  }
   164  
   165  // ListPreparer prepares the List request.
   166  func (client RecoveryPointsClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (*http.Request, error) {
   167  	pathParameters := map[string]interface{}{
   168  		"containerName":     autorest.Encode("path", containerName),
   169  		"fabricName":        autorest.Encode("path", fabricName),
   170  		"protectedItemName": autorest.Encode("path", protectedItemName),
   171  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   172  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   173  		"vaultName":         autorest.Encode("path", vaultName),
   174  	}
   175  
   176  	const APIVersion = "2021-12-01"
   177  	queryParameters := map[string]interface{}{
   178  		"api-version": APIVersion,
   179  	}
   180  	if len(filter) > 0 {
   181  		queryParameters["$filter"] = autorest.Encode("query", filter)
   182  	}
   183  
   184  	preparer := autorest.CreatePreparer(
   185  		autorest.AsGet(),
   186  		autorest.WithBaseURL(client.BaseURI),
   187  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints", pathParameters),
   188  		autorest.WithQueryParameters(queryParameters))
   189  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   190  }
   191  
   192  // ListSender sends the List request. The method will close the
   193  // http.Response Body if it receives an error.
   194  func (client RecoveryPointsClient) ListSender(req *http.Request) (*http.Response, error) {
   195  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   196  }
   197  
   198  // ListResponder handles the response to the List request. The method always
   199  // closes the http.Response Body.
   200  func (client RecoveryPointsClient) ListResponder(resp *http.Response) (result RecoveryPointResourceList, err error) {
   201  	err = autorest.Respond(
   202  		resp,
   203  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   204  		autorest.ByUnmarshallingJSON(&result),
   205  		autorest.ByClosing())
   206  	result.Response = autorest.Response{Response: resp}
   207  	return
   208  }
   209  
   210  // listNextResults retrieves the next set of results, if any.
   211  func (client RecoveryPointsClient) listNextResults(ctx context.Context, lastResults RecoveryPointResourceList) (result RecoveryPointResourceList, err error) {
   212  	req, err := lastResults.recoveryPointResourceListPreparer(ctx)
   213  	if err != nil {
   214  		return result, autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "listNextResults", nil, "Failure preparing next results request")
   215  	}
   216  	if req == nil {
   217  		return
   218  	}
   219  	resp, err := client.ListSender(req)
   220  	if err != nil {
   221  		result.Response = autorest.Response{Response: resp}
   222  		return result, autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "listNextResults", resp, "Failure sending next results request")
   223  	}
   224  	result, err = client.ListResponder(resp)
   225  	if err != nil {
   226  		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "listNextResults", resp, "Failure responding to next results request")
   227  	}
   228  	return
   229  }
   230  
   231  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   232  func (client RecoveryPointsClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (result RecoveryPointResourceListIterator, err error) {
   233  	if tracing.IsEnabled() {
   234  		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.List")
   235  		defer func() {
   236  			sc := -1
   237  			if result.Response().Response.Response != nil {
   238  				sc = result.page.Response().Response.Response.StatusCode
   239  			}
   240  			tracing.EndSpan(ctx, sc, err)
   241  		}()
   242  	}
   243  	result.page, err = client.List(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, filter)
   244  	return
   245  }
   246  

View as plain text