...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2022-03-01/backup/protecteditems.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2022-03-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  // ProtectedItemsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type ProtectedItemsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewProtectedItemsClient creates an instance of the ProtectedItemsClient client.
    23  func NewProtectedItemsClient(subscriptionID string) ProtectedItemsClient {
    24  	return NewProtectedItemsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewProtectedItemsClientWithBaseURI creates an instance of the ProtectedItemsClient 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 NewProtectedItemsClientWithBaseURI(baseURI string, subscriptionID string) ProtectedItemsClient {
    30  	return ProtectedItemsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate enables backup of an item or to modifies the backup policy information of an already backed up item.
    34  // This is an
    35  // asynchronous operation. To know the status of the operation, call the GetItemOperationResult 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 the backup item.
    40  // containerName - container name associated with the backup item.
    41  // protectedItemName - item name to be backed up.
    42  // parameters - resource backed up item
    43  func (client ProtectedItemsClient) CreateOrUpdate(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, parameters ProtectedItemResource) (result ProtectedItemResource, err error) {
    44  	if tracing.IsEnabled() {
    45  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectedItemsClient.CreateOrUpdate")
    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.CreateOrUpdatePreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, parameters)
    55  	if err != nil {
    56  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "CreateOrUpdate", nil, "Failure preparing request")
    57  		return
    58  	}
    59  
    60  	resp, err := client.CreateOrUpdateSender(req)
    61  	if err != nil {
    62  		result.Response = autorest.Response{Response: resp}
    63  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "CreateOrUpdate", resp, "Failure sending request")
    64  		return
    65  	}
    66  
    67  	result, err = client.CreateOrUpdateResponder(resp)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "CreateOrUpdate", resp, "Failure responding to request")
    70  		return
    71  	}
    72  
    73  	return
    74  }
    75  
    76  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    77  func (client ProtectedItemsClient) CreateOrUpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, parameters ProtectedItemResource) (*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  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    83  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    84  		"vaultName":         autorest.Encode("path", vaultName),
    85  	}
    86  
    87  	const APIVersion = "2022-03-01"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  
    92  	preparer := autorest.CreatePreparer(
    93  		autorest.AsContentType("application/json; charset=utf-8"),
    94  		autorest.AsPut(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}", pathParameters),
    97  		autorest.WithJSON(parameters),
    98  		autorest.WithQueryParameters(queryParameters))
    99  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   100  }
   101  
   102  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   103  // http.Response Body if it receives an error.
   104  func (client ProtectedItemsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   105  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   106  }
   107  
   108  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   109  // closes the http.Response Body.
   110  func (client ProtectedItemsClient) CreateOrUpdateResponder(resp *http.Response) (result ProtectedItemResource, err error) {
   111  	err = autorest.Respond(
   112  		resp,
   113  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   114  		autorest.ByUnmarshallingJSON(&result),
   115  		autorest.ByClosing())
   116  	result.Response = autorest.Response{Response: resp}
   117  	return
   118  }
   119  
   120  // Delete used to disable backup of an item within a container. This is an asynchronous operation. To know the status
   121  // of the
   122  // request, call the GetItemOperationResult API.
   123  // Parameters:
   124  // vaultName - the name of the recovery services vault.
   125  // resourceGroupName - the name of the resource group where the recovery services vault is present.
   126  // fabricName - fabric name associated with the backed up item.
   127  // containerName - container name associated with the backed up item.
   128  // protectedItemName - backed up item to be deleted.
   129  func (client ProtectedItemsClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string) (result autorest.Response, err error) {
   130  	if tracing.IsEnabled() {
   131  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectedItemsClient.Delete")
   132  		defer func() {
   133  			sc := -1
   134  			if result.Response != nil {
   135  				sc = result.Response.StatusCode
   136  			}
   137  			tracing.EndSpan(ctx, sc, err)
   138  		}()
   139  	}
   140  	req, err := client.DeletePreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName)
   141  	if err != nil {
   142  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Delete", nil, "Failure preparing request")
   143  		return
   144  	}
   145  
   146  	resp, err := client.DeleteSender(req)
   147  	if err != nil {
   148  		result.Response = resp
   149  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Delete", resp, "Failure sending request")
   150  		return
   151  	}
   152  
   153  	result, err = client.DeleteResponder(resp)
   154  	if err != nil {
   155  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Delete", resp, "Failure responding to request")
   156  		return
   157  	}
   158  
   159  	return
   160  }
   161  
   162  // DeletePreparer prepares the Delete request.
   163  func (client ProtectedItemsClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string) (*http.Request, error) {
   164  	pathParameters := map[string]interface{}{
   165  		"containerName":     autorest.Encode("path", containerName),
   166  		"fabricName":        autorest.Encode("path", fabricName),
   167  		"protectedItemName": autorest.Encode("path", protectedItemName),
   168  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   169  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   170  		"vaultName":         autorest.Encode("path", vaultName),
   171  	}
   172  
   173  	const APIVersion = "2022-03-01"
   174  	queryParameters := map[string]interface{}{
   175  		"api-version": APIVersion,
   176  	}
   177  
   178  	preparer := autorest.CreatePreparer(
   179  		autorest.AsDelete(),
   180  		autorest.WithBaseURL(client.BaseURI),
   181  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}", pathParameters),
   182  		autorest.WithQueryParameters(queryParameters))
   183  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   184  }
   185  
   186  // DeleteSender sends the Delete request. The method will close the
   187  // http.Response Body if it receives an error.
   188  func (client ProtectedItemsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   189  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   190  }
   191  
   192  // DeleteResponder handles the response to the Delete request. The method always
   193  // closes the http.Response Body.
   194  func (client ProtectedItemsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   195  	err = autorest.Respond(
   196  		resp,
   197  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   198  		autorest.ByClosing())
   199  	result.Response = resp
   200  	return
   201  }
   202  
   203  // Get provides the details of the backed up item. This is an asynchronous operation. To know the status of the
   204  // operation,
   205  // call the GetItemOperationResult API.
   206  // Parameters:
   207  // vaultName - the name of the recovery services vault.
   208  // resourceGroupName - the name of the resource group where the recovery services vault is present.
   209  // fabricName - fabric name associated with the backed up item.
   210  // containerName - container name associated with the backed up item.
   211  // protectedItemName - backed up item name whose details are to be fetched.
   212  // filter - oData filter options.
   213  func (client ProtectedItemsClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (result ProtectedItemResource, err error) {
   214  	if tracing.IsEnabled() {
   215  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectedItemsClient.Get")
   216  		defer func() {
   217  			sc := -1
   218  			if result.Response.Response != nil {
   219  				sc = result.Response.Response.StatusCode
   220  			}
   221  			tracing.EndSpan(ctx, sc, err)
   222  		}()
   223  	}
   224  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, filter)
   225  	if err != nil {
   226  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Get", nil, "Failure preparing request")
   227  		return
   228  	}
   229  
   230  	resp, err := client.GetSender(req)
   231  	if err != nil {
   232  		result.Response = autorest.Response{Response: resp}
   233  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Get", resp, "Failure sending request")
   234  		return
   235  	}
   236  
   237  	result, err = client.GetResponder(resp)
   238  	if err != nil {
   239  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Get", resp, "Failure responding to request")
   240  		return
   241  	}
   242  
   243  	return
   244  }
   245  
   246  // GetPreparer prepares the Get request.
   247  func (client ProtectedItemsClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (*http.Request, error) {
   248  	pathParameters := map[string]interface{}{
   249  		"containerName":     autorest.Encode("path", containerName),
   250  		"fabricName":        autorest.Encode("path", fabricName),
   251  		"protectedItemName": autorest.Encode("path", protectedItemName),
   252  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   253  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   254  		"vaultName":         autorest.Encode("path", vaultName),
   255  	}
   256  
   257  	const APIVersion = "2022-03-01"
   258  	queryParameters := map[string]interface{}{
   259  		"api-version": APIVersion,
   260  	}
   261  	if len(filter) > 0 {
   262  		queryParameters["$filter"] = autorest.Encode("query", filter)
   263  	}
   264  
   265  	preparer := autorest.CreatePreparer(
   266  		autorest.AsGet(),
   267  		autorest.WithBaseURL(client.BaseURI),
   268  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}", pathParameters),
   269  		autorest.WithQueryParameters(queryParameters))
   270  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   271  }
   272  
   273  // GetSender sends the Get request. The method will close the
   274  // http.Response Body if it receives an error.
   275  func (client ProtectedItemsClient) GetSender(req *http.Request) (*http.Response, error) {
   276  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   277  }
   278  
   279  // GetResponder handles the response to the Get request. The method always
   280  // closes the http.Response Body.
   281  func (client ProtectedItemsClient) GetResponder(resp *http.Response) (result ProtectedItemResource, err error) {
   282  	err = autorest.Respond(
   283  		resp,
   284  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   285  		autorest.ByUnmarshallingJSON(&result),
   286  		autorest.ByClosing())
   287  	result.Response = autorest.Response{Response: resp}
   288  	return
   289  }
   290  

View as plain text