...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-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 this operation enables an item to be backed up, or modifies the existing backup policy information
    34  // for an item that has been backed up. This is an asynchronous operation. To learn the status of the operation, call
    35  // the GetItemOperationResult API.
    36  // Parameters:
    37  // vaultName - the name of the Recovery Services vault.
    38  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
    39  // fabricName - the fabric name associated with the backup item.
    40  // containerName - the container name associated with the backup item.
    41  // protectedItemName - the name of the backup item.
    42  // resourceProtectedItem - the resource backup item.
    43  func (client ProtectedItemsClient) CreateOrUpdate(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, resourceProtectedItem ProtectedItemResource) (result autorest.Response, err error) {
    44  	if tracing.IsEnabled() {
    45  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectedItemsClient.CreateOrUpdate")
    46  		defer func() {
    47  			sc := -1
    48  			if result.Response != nil {
    49  				sc = result.Response.StatusCode
    50  			}
    51  			tracing.EndSpan(ctx, sc, err)
    52  		}()
    53  	}
    54  	req, err := client.CreateOrUpdatePreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, resourceProtectedItem)
    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 = 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, resourceProtectedItem 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 = "2016-06-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(resourceProtectedItem),
    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 autorest.Response, err error) {
   111  	err = autorest.Respond(
   112  		resp,
   113  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   114  		autorest.ByClosing())
   115  	result.Response = resp
   116  	return
   117  }
   118  
   119  // Delete used to disable the backup job for an item within a container. This is an asynchronous operation. To learn
   120  // the status of the request, call the GetItemOperationResult API.
   121  // Parameters:
   122  // vaultName - the name of the Recovery Services vault.
   123  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
   124  // fabricName - the fabric name associated with the backup item.
   125  // containerName - the container name associated with the backup item.
   126  // protectedItemName - the backup item to be deleted.
   127  func (client ProtectedItemsClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string) (result autorest.Response, err error) {
   128  	if tracing.IsEnabled() {
   129  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectedItemsClient.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, vaultName, resourceGroupName, fabricName, containerName, protectedItemName)
   139  	if err != nil {
   140  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "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, "backup.ProtectedItemsClient", "Delete", resp, "Failure sending request")
   148  		return
   149  	}
   150  
   151  	result, err = client.DeleteResponder(resp)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Delete", resp, "Failure responding to request")
   154  		return
   155  	}
   156  
   157  	return
   158  }
   159  
   160  // DeletePreparer prepares the Delete request.
   161  func (client ProtectedItemsClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string) (*http.Request, error) {
   162  	pathParameters := map[string]interface{}{
   163  		"containerName":     autorest.Encode("path", containerName),
   164  		"fabricName":        autorest.Encode("path", fabricName),
   165  		"protectedItemName": autorest.Encode("path", protectedItemName),
   166  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   167  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   168  		"vaultName":         autorest.Encode("path", vaultName),
   169  	}
   170  
   171  	const APIVersion = "2016-06-01"
   172  	queryParameters := map[string]interface{}{
   173  		"api-version": APIVersion,
   174  	}
   175  
   176  	preparer := autorest.CreatePreparer(
   177  		autorest.AsDelete(),
   178  		autorest.WithBaseURL(client.BaseURI),
   179  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}", pathParameters),
   180  		autorest.WithQueryParameters(queryParameters))
   181  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   182  }
   183  
   184  // DeleteSender sends the Delete request. The method will close the
   185  // http.Response Body if it receives an error.
   186  func (client ProtectedItemsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   187  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   188  }
   189  
   190  // DeleteResponder handles the response to the Delete request. The method always
   191  // closes the http.Response Body.
   192  func (client ProtectedItemsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   193  	err = autorest.Respond(
   194  		resp,
   195  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   196  		autorest.ByClosing())
   197  	result.Response = resp
   198  	return
   199  }
   200  
   201  // Get provides the details of the backup item. This is an asynchronous operation. To know the status of the operation,
   202  // call the GetItemOperationResult API.
   203  // Parameters:
   204  // vaultName - the name of the Recovery Services vault.
   205  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
   206  // fabricName - the fabric name associated with the backup item.
   207  // containerName - the container name associated with the backup item.
   208  // protectedItemName - the backup item name used in this GET operation.
   209  // filter - expand eq {extendedInfo}. This filter enables you to choose (or filter) specific items in the list
   210  // of backup items.
   211  func (client ProtectedItemsClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (result ProtectedItemResource, err error) {
   212  	if tracing.IsEnabled() {
   213  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectedItemsClient.Get")
   214  		defer func() {
   215  			sc := -1
   216  			if result.Response.Response != nil {
   217  				sc = result.Response.Response.StatusCode
   218  			}
   219  			tracing.EndSpan(ctx, sc, err)
   220  		}()
   221  	}
   222  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, filter)
   223  	if err != nil {
   224  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Get", nil, "Failure preparing request")
   225  		return
   226  	}
   227  
   228  	resp, err := client.GetSender(req)
   229  	if err != nil {
   230  		result.Response = autorest.Response{Response: resp}
   231  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Get", resp, "Failure sending request")
   232  		return
   233  	}
   234  
   235  	result, err = client.GetResponder(resp)
   236  	if err != nil {
   237  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "Get", resp, "Failure responding to request")
   238  		return
   239  	}
   240  
   241  	return
   242  }
   243  
   244  // GetPreparer prepares the Get request.
   245  func (client ProtectedItemsClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (*http.Request, error) {
   246  	pathParameters := map[string]interface{}{
   247  		"containerName":     autorest.Encode("path", containerName),
   248  		"fabricName":        autorest.Encode("path", fabricName),
   249  		"protectedItemName": autorest.Encode("path", protectedItemName),
   250  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   251  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   252  		"vaultName":         autorest.Encode("path", vaultName),
   253  	}
   254  
   255  	const APIVersion = "2016-06-01"
   256  	queryParameters := map[string]interface{}{
   257  		"api-version": APIVersion,
   258  	}
   259  	if len(filter) > 0 {
   260  		queryParameters["$filter"] = autorest.Encode("query", filter)
   261  	}
   262  
   263  	preparer := autorest.CreatePreparer(
   264  		autorest.AsGet(),
   265  		autorest.WithBaseURL(client.BaseURI),
   266  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}", pathParameters),
   267  		autorest.WithQueryParameters(queryParameters))
   268  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   269  }
   270  
   271  // GetSender sends the Get request. The method will close the
   272  // http.Response Body if it receives an error.
   273  func (client ProtectedItemsClient) GetSender(req *http.Request) (*http.Response, error) {
   274  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   275  }
   276  
   277  // GetResponder handles the response to the Get request. The method always
   278  // closes the http.Response Body.
   279  func (client ProtectedItemsClient) GetResponder(resp *http.Response) (result ProtectedItemResource, err error) {
   280  	err = autorest.Respond(
   281  		resp,
   282  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   283  		autorest.ByUnmarshallingJSON(&result),
   284  		autorest.ByClosing())
   285  	result.Response = autorest.Response{Response: resp}
   286  	return
   287  }
   288  
   289  // List provides a pageable list of all items in a subscription, that can be protected.
   290  // Parameters:
   291  // vaultName - the name of the Recovery Services vault.
   292  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
   293  // filter - itemType eq { VM , FileFolder , AzureSqlDb , SQLDB , Exchange , Sharepoint , DPMUnknown } and
   294  // providerType eq { AzureIaasVM, MAB, DPM, AzureBackupServer, AzureSql } and policyName eq {policyName} and
   295  // containerName eq {containername} and backupManagementType eq { AzureIaasVM, MAB, DPM, AzureBackupServer,
   296  // AzureSql }.
   297  // skipToken - the Skip Token filter.
   298  func (client ProtectedItemsClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (result ProtectedItemResourceListPage, err error) {
   299  	if tracing.IsEnabled() {
   300  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectedItemsClient.List")
   301  		defer func() {
   302  			sc := -1
   303  			if result.pirl.Response.Response != nil {
   304  				sc = result.pirl.Response.Response.StatusCode
   305  			}
   306  			tracing.EndSpan(ctx, sc, err)
   307  		}()
   308  	}
   309  	result.fn = client.listNextResults
   310  	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter, skipToken)
   311  	if err != nil {
   312  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "List", nil, "Failure preparing request")
   313  		return
   314  	}
   315  
   316  	resp, err := client.ListSender(req)
   317  	if err != nil {
   318  		result.pirl.Response = autorest.Response{Response: resp}
   319  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "List", resp, "Failure sending request")
   320  		return
   321  	}
   322  
   323  	result.pirl, err = client.ListResponder(resp)
   324  	if err != nil {
   325  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "List", resp, "Failure responding to request")
   326  		return
   327  	}
   328  	if result.pirl.hasNextLink() && result.pirl.IsEmpty() {
   329  		err = result.NextWithContext(ctx)
   330  		return
   331  	}
   332  
   333  	return
   334  }
   335  
   336  // ListPreparer prepares the List request.
   337  func (client ProtectedItemsClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (*http.Request, error) {
   338  	pathParameters := map[string]interface{}{
   339  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   340  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   341  		"vaultName":         autorest.Encode("path", vaultName),
   342  	}
   343  
   344  	const APIVersion = "2016-06-01"
   345  	queryParameters := map[string]interface{}{
   346  		"api-version": APIVersion,
   347  	}
   348  	if len(filter) > 0 {
   349  		queryParameters["$filter"] = autorest.Encode("query", filter)
   350  	}
   351  	if len(skipToken) > 0 {
   352  		queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
   353  	}
   354  
   355  	preparer := autorest.CreatePreparer(
   356  		autorest.AsGet(),
   357  		autorest.WithBaseURL(client.BaseURI),
   358  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupProtectedItems", pathParameters),
   359  		autorest.WithQueryParameters(queryParameters))
   360  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   361  }
   362  
   363  // ListSender sends the List request. The method will close the
   364  // http.Response Body if it receives an error.
   365  func (client ProtectedItemsClient) ListSender(req *http.Request) (*http.Response, error) {
   366  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   367  }
   368  
   369  // ListResponder handles the response to the List request. The method always
   370  // closes the http.Response Body.
   371  func (client ProtectedItemsClient) ListResponder(resp *http.Response) (result ProtectedItemResourceList, err error) {
   372  	err = autorest.Respond(
   373  		resp,
   374  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   375  		autorest.ByUnmarshallingJSON(&result),
   376  		autorest.ByClosing())
   377  	result.Response = autorest.Response{Response: resp}
   378  	return
   379  }
   380  
   381  // listNextResults retrieves the next set of results, if any.
   382  func (client ProtectedItemsClient) listNextResults(ctx context.Context, lastResults ProtectedItemResourceList) (result ProtectedItemResourceList, err error) {
   383  	req, err := lastResults.protectedItemResourceListPreparer(ctx)
   384  	if err != nil {
   385  		return result, autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "listNextResults", nil, "Failure preparing next results request")
   386  	}
   387  	if req == nil {
   388  		return
   389  	}
   390  	resp, err := client.ListSender(req)
   391  	if err != nil {
   392  		result.Response = autorest.Response{Response: resp}
   393  		return result, autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "listNextResults", resp, "Failure sending next results request")
   394  	}
   395  	result, err = client.ListResponder(resp)
   396  	if err != nil {
   397  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemsClient", "listNextResults", resp, "Failure responding to next results request")
   398  	}
   399  	return
   400  }
   401  
   402  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   403  func (client ProtectedItemsClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (result ProtectedItemResourceListIterator, err error) {
   404  	if tracing.IsEnabled() {
   405  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectedItemsClient.List")
   406  		defer func() {
   407  			sc := -1
   408  			if result.Response().Response.Response != nil {
   409  				sc = result.page.Response().Response.Response.StatusCode
   410  			}
   411  			tracing.EndSpan(ctx, sc, err)
   412  		}()
   413  	}
   414  	result.page, err = client.List(ctx, vaultName, resourceGroupName, filter, skipToken)
   415  	return
   416  }
   417  

View as plain text