...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-08-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 = "2016-08-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  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainers(ctx context.Context, fabricName string, protectionContainerName string) (result ProtectableItemCollectionPage, err error) {
   120  	if tracing.IsEnabled() {
   121  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectableItemsClient.ListByReplicationProtectionContainers")
   122  		defer func() {
   123  			sc := -1
   124  			if result.pic.Response.Response != nil {
   125  				sc = result.pic.Response.Response.StatusCode
   126  			}
   127  			tracing.EndSpan(ctx, sc, err)
   128  		}()
   129  	}
   130  	result.fn = client.listByReplicationProtectionContainersNextResults
   131  	req, err := client.ListByReplicationProtectionContainersPreparer(ctx, fabricName, protectionContainerName)
   132  	if err != nil {
   133  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request")
   134  		return
   135  	}
   136  
   137  	resp, err := client.ListByReplicationProtectionContainersSender(req)
   138  	if err != nil {
   139  		result.pic.Response = autorest.Response{Response: resp}
   140  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp, "Failure sending request")
   141  		return
   142  	}
   143  
   144  	result.pic, err = client.ListByReplicationProtectionContainersResponder(resp)
   145  	if err != nil {
   146  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "ListByReplicationProtectionContainers", resp, "Failure responding to request")
   147  		return
   148  	}
   149  	if result.pic.hasNextLink() && result.pic.IsEmpty() {
   150  		err = result.NextWithContext(ctx)
   151  		return
   152  	}
   153  
   154  	return
   155  }
   156  
   157  // ListByReplicationProtectionContainersPreparer prepares the ListByReplicationProtectionContainers request.
   158  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersPreparer(ctx context.Context, fabricName string, protectionContainerName string) (*http.Request, error) {
   159  	pathParameters := map[string]interface{}{
   160  		"fabricName":              autorest.Encode("path", fabricName),
   161  		"protectionContainerName": autorest.Encode("path", protectionContainerName),
   162  		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
   163  		"resourceName":            autorest.Encode("path", client.ResourceName),
   164  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
   165  	}
   166  
   167  	const APIVersion = "2016-08-10"
   168  	queryParameters := map[string]interface{}{
   169  		"api-version": APIVersion,
   170  	}
   171  
   172  	preparer := autorest.CreatePreparer(
   173  		autorest.AsGet(),
   174  		autorest.WithBaseURL(client.BaseURI),
   175  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectableItems", pathParameters),
   176  		autorest.WithQueryParameters(queryParameters))
   177  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   178  }
   179  
   180  // ListByReplicationProtectionContainersSender sends the ListByReplicationProtectionContainers request. The method will close the
   181  // http.Response Body if it receives an error.
   182  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersSender(req *http.Request) (*http.Response, error) {
   183  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   184  }
   185  
   186  // ListByReplicationProtectionContainersResponder handles the response to the ListByReplicationProtectionContainers request. The method always
   187  // closes the http.Response Body.
   188  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersResponder(resp *http.Response) (result ProtectableItemCollection, err error) {
   189  	err = autorest.Respond(
   190  		resp,
   191  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   192  		autorest.ByUnmarshallingJSON(&result),
   193  		autorest.ByClosing())
   194  	result.Response = autorest.Response{Response: resp}
   195  	return
   196  }
   197  
   198  // listByReplicationProtectionContainersNextResults retrieves the next set of results, if any.
   199  func (client ReplicationProtectableItemsClient) listByReplicationProtectionContainersNextResults(ctx context.Context, lastResults ProtectableItemCollection) (result ProtectableItemCollection, err error) {
   200  	req, err := lastResults.protectableItemCollectionPreparer(ctx)
   201  	if err != nil {
   202  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "listByReplicationProtectionContainersNextResults", nil, "Failure preparing next results request")
   203  	}
   204  	if req == nil {
   205  		return
   206  	}
   207  	resp, err := client.ListByReplicationProtectionContainersSender(req)
   208  	if err != nil {
   209  		result.Response = autorest.Response{Response: resp}
   210  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "listByReplicationProtectionContainersNextResults", resp, "Failure sending next results request")
   211  	}
   212  	result, err = client.ListByReplicationProtectionContainersResponder(resp)
   213  	if err != nil {
   214  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectableItemsClient", "listByReplicationProtectionContainersNextResults", resp, "Failure responding to next results request")
   215  	}
   216  	return
   217  }
   218  
   219  // ListByReplicationProtectionContainersComplete enumerates all values, automatically crossing page boundaries as required.
   220  func (client ReplicationProtectableItemsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, fabricName string, protectionContainerName string) (result ProtectableItemCollectionIterator, err error) {
   221  	if tracing.IsEnabled() {
   222  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectableItemsClient.ListByReplicationProtectionContainers")
   223  		defer func() {
   224  			sc := -1
   225  			if result.Response().Response.Response != nil {
   226  				sc = result.page.Response().Response.Response.StatusCode
   227  			}
   228  			tracing.EndSpan(ctx, sc, err)
   229  		}()
   230  	}
   231  	result.page, err = client.ListByReplicationProtectionContainers(ctx, fabricName, protectionContainerName)
   232  	return
   233  }
   234  

View as plain text