...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-07-10/siterecovery/replicationprotectableitems.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-07-10/siterecovery

     1  package siterecovery
     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  // ReplicationProtectableItemsClient is the client for the ReplicationProtectableItems methods of the Siterecovery
    18  // service.
    19  type ReplicationProtectableItemsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewReplicationProtectableItemsClient creates an instance of the ReplicationProtectableItemsClient client.
    24  func NewReplicationProtectableItemsClient(subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectableItemsClient {
    25  	return NewReplicationProtectableItemsClientWithBaseURI(DefaultBaseURI, subscriptionID, resourceGroupName, resourceName)
    26  }
    27  
    28  // NewReplicationProtectableItemsClientWithBaseURI creates an instance of the ReplicationProtectableItemsClient client
    29  // using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    30  // clouds, Azure stack).
    31  func NewReplicationProtectableItemsClientWithBaseURI(baseURI string, subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectableItemsClient {
    32  	return ReplicationProtectableItemsClient{NewWithBaseURI(baseURI, subscriptionID, resourceGroupName, resourceName)}
    33  }
    34  
    35  // Get the operation to get the details of a protectable item.
    36  // Parameters:
    37  // fabricName - fabric name.
    38  // protectionContainerName - protection container name.
    39  // protectableItemName - protectable item name.
    40  func (client ReplicationProtectableItemsClient) Get(ctx context.Context, fabricName string, protectionContainerName string, protectableItemName string) (result ProtectableItem, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectableItemsClient.Get")
    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  	req, err := client.GetPreparer(ctx, fabricName, protectionContainerName, protectableItemName)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "Get", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.GetSender(req)
    58  	if err != nil {
    59  		result.Response = autorest.Response{Response: resp}
    60  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "Get", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result, err = client.GetResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "Get", resp, "Failure responding to request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // GetPreparer prepares the Get request.
    74  func (client ReplicationProtectableItemsClient) GetPreparer(ctx context.Context, fabricName string, protectionContainerName string, protectableItemName string) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"fabricName":              autorest.Encode("path", fabricName),
    77  		"protectableItemName":     autorest.Encode("path", protectableItemName),
    78  		"protectionContainerName": autorest.Encode("path", protectionContainerName),
    79  		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
    80  		"resourceName":            autorest.Encode("path", client.ResourceName),
    81  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
    82  	}
    83  
    84  	const APIVersion = "2018-07-10"
    85  	queryParameters := map[string]interface{}{
    86  		"api-version": APIVersion,
    87  	}
    88  
    89  	preparer := autorest.CreatePreparer(
    90  		autorest.AsGet(),
    91  		autorest.WithBaseURL(client.BaseURI),
    92  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectableItems/{protectableItemName}", pathParameters),
    93  		autorest.WithQueryParameters(queryParameters))
    94  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    95  }
    96  
    97  // GetSender sends the Get request. The method will close the
    98  // http.Response Body if it receives an error.
    99  func (client ReplicationProtectableItemsClient) GetSender(req *http.Request) (*http.Response, error) {
   100  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   101  }
   102  
   103  // GetResponder handles the response to the Get request. The method always
   104  // closes the http.Response Body.
   105  func (client ReplicationProtectableItemsClient) GetResponder(resp *http.Response) (result ProtectableItem, err error) {
   106  	err = autorest.Respond(
   107  		resp,
   108  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   109  		autorest.ByUnmarshallingJSON(&result),
   110  		autorest.ByClosing())
   111  	result.Response = autorest.Response{Response: resp}
   112  	return
   113  }
   114  
   115  // ListByReplicationProtectionContainers lists the protectable items in a protection container.
   116  // Parameters:
   117  // fabricName - fabric name.
   118  // protectionContainerName - protection container name.
   119  // filter - oData filter options.
   120  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainers(ctx context.Context, fabricName string, protectionContainerName string, filter string) (result ProtectableItemCollectionPage, err error) {
   121  	if tracing.IsEnabled() {
   122  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectableItemsClient.ListByReplicationProtectionContainers")
   123  		defer func() {
   124  			sc := -1
   125  			if result.pic.Response.Response != nil {
   126  				sc = result.pic.Response.Response.StatusCode
   127  			}
   128  			tracing.EndSpan(ctx, sc, err)
   129  		}()
   130  	}
   131  	result.fn = client.listByReplicationProtectionContainersNextResults
   132  	req, err := client.ListByReplicationProtectionContainersPreparer(ctx, fabricName, protectionContainerName, filter)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request")
   135  		return
   136  	}
   137  
   138  	resp, err := client.ListByReplicationProtectionContainersSender(req)
   139  	if err != nil {
   140  		result.pic.Response = autorest.Response{Response: resp}
   141  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp, "Failure sending request")
   142  		return
   143  	}
   144  
   145  	result.pic, err = client.ListByReplicationProtectionContainersResponder(resp)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp, "Failure responding to request")
   148  		return
   149  	}
   150  	if result.pic.hasNextLink() && result.pic.IsEmpty() {
   151  		err = result.NextWithContext(ctx)
   152  		return
   153  	}
   154  
   155  	return
   156  }
   157  
   158  // ListByReplicationProtectionContainersPreparer prepares the ListByReplicationProtectionContainers request.
   159  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersPreparer(ctx context.Context, fabricName string, protectionContainerName string, filter string) (*http.Request, error) {
   160  	pathParameters := map[string]interface{}{
   161  		"fabricName":              autorest.Encode("path", fabricName),
   162  		"protectionContainerName": autorest.Encode("path", protectionContainerName),
   163  		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
   164  		"resourceName":            autorest.Encode("path", client.ResourceName),
   165  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
   166  	}
   167  
   168  	const APIVersion = "2018-07-10"
   169  	queryParameters := map[string]interface{}{
   170  		"api-version": APIVersion,
   171  	}
   172  	if len(filter) > 0 {
   173  		queryParameters["$filter"] = autorest.Encode("query", filter)
   174  	}
   175  
   176  	preparer := autorest.CreatePreparer(
   177  		autorest.AsGet(),
   178  		autorest.WithBaseURL(client.BaseURI),
   179  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectableItems", pathParameters),
   180  		autorest.WithQueryParameters(queryParameters))
   181  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   182  }
   183  
   184  // ListByReplicationProtectionContainersSender sends the ListByReplicationProtectionContainers request. The method will close the
   185  // http.Response Body if it receives an error.
   186  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersSender(req *http.Request) (*http.Response, error) {
   187  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   188  }
   189  
   190  // ListByReplicationProtectionContainersResponder handles the response to the ListByReplicationProtectionContainers request. The method always
   191  // closes the http.Response Body.
   192  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersResponder(resp *http.Response) (result ProtectableItemCollection, err error) {
   193  	err = autorest.Respond(
   194  		resp,
   195  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   196  		autorest.ByUnmarshallingJSON(&result),
   197  		autorest.ByClosing())
   198  	result.Response = autorest.Response{Response: resp}
   199  	return
   200  }
   201  
   202  // listByReplicationProtectionContainersNextResults retrieves the next set of results, if any.
   203  func (client ReplicationProtectableItemsClient) listByReplicationProtectionContainersNextResults(ctx context.Context, lastResults ProtectableItemCollection) (result ProtectableItemCollection, err error) {
   204  	req, err := lastResults.protectableItemCollectionPreparer(ctx)
   205  	if err != nil {
   206  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "listByReplicationProtectionContainersNextResults", nil, "Failure preparing next results request")
   207  	}
   208  	if req == nil {
   209  		return
   210  	}
   211  	resp, err := client.ListByReplicationProtectionContainersSender(req)
   212  	if err != nil {
   213  		result.Response = autorest.Response{Response: resp}
   214  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "listByReplicationProtectionContainersNextResults", resp, "Failure sending next results request")
   215  	}
   216  	result, err = client.ListByReplicationProtectionContainersResponder(resp)
   217  	if err != nil {
   218  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "listByReplicationProtectionContainersNextResults", resp, "Failure responding to next results request")
   219  	}
   220  	return
   221  }
   222  
   223  // ListByReplicationProtectionContainersComplete enumerates all values, automatically crossing page boundaries as required.
   224  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, fabricName string, protectionContainerName string, filter string) (result ProtectableItemCollectionIterator, err error) {
   225  	if tracing.IsEnabled() {
   226  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectableItemsClient.ListByReplicationProtectionContainers")
   227  		defer func() {
   228  			sc := -1
   229  			if result.Response().Response.Response != nil {
   230  				sc = result.page.Response().Response.Response.StatusCode
   231  			}
   232  			tracing.EndSpan(ctx, sc, err)
   233  		}()
   234  	}
   235  	result.page, err = client.ListByReplicationProtectionContainers(ctx, fabricName, protectionContainerName, filter)
   236  	return
   237  }
   238  

View as plain text