...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-07-10/siterecovery/replicationprotectioncontainers.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  // ReplicationProtectionContainersClient is the client for the ReplicationProtectionContainers methods of the
    18  // Siterecovery service.
    19  type ReplicationProtectionContainersClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewReplicationProtectionContainersClient creates an instance of the ReplicationProtectionContainersClient client.
    24  func NewReplicationProtectionContainersClient(subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectionContainersClient {
    25  	return NewReplicationProtectionContainersClientWithBaseURI(DefaultBaseURI, subscriptionID, resourceGroupName, resourceName)
    26  }
    27  
    28  // NewReplicationProtectionContainersClientWithBaseURI creates an instance of the ReplicationProtectionContainersClient
    29  // client using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI
    30  // (sovereign clouds, Azure stack).
    31  func NewReplicationProtectionContainersClientWithBaseURI(baseURI string, subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectionContainersClient {
    32  	return ReplicationProtectionContainersClient{NewWithBaseURI(baseURI, subscriptionID, resourceGroupName, resourceName)}
    33  }
    34  
    35  // Create operation to create a protection container.
    36  // Parameters:
    37  // fabricName - unique fabric ARM name.
    38  // protectionContainerName - unique protection container ARM name.
    39  // creationInput - creation input.
    40  func (client ReplicationProtectionContainersClient) Create(ctx context.Context, fabricName string, protectionContainerName string, creationInput CreateProtectionContainerInput) (result ReplicationProtectionContainersCreateFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainersClient.Create")
    43  		defer func() {
    44  			sc := -1
    45  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    46  				sc = result.FutureAPI.Response().StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	req, err := client.CreatePreparer(ctx, fabricName, protectionContainerName, creationInput)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "Create", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	result, err = client.CreateSender(req)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "Create", result.Response(), "Failure sending request")
    60  		return
    61  	}
    62  
    63  	return
    64  }
    65  
    66  // CreatePreparer prepares the Create request.
    67  func (client ReplicationProtectionContainersClient) CreatePreparer(ctx context.Context, fabricName string, protectionContainerName string, creationInput CreateProtectionContainerInput) (*http.Request, error) {
    68  	pathParameters := map[string]interface{}{
    69  		"fabricName":              autorest.Encode("path", fabricName),
    70  		"protectionContainerName": autorest.Encode("path", protectionContainerName),
    71  		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
    72  		"resourceName":            autorest.Encode("path", client.ResourceName),
    73  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
    74  	}
    75  
    76  	const APIVersion = "2018-07-10"
    77  	queryParameters := map[string]interface{}{
    78  		"api-version": APIVersion,
    79  	}
    80  
    81  	preparer := autorest.CreatePreparer(
    82  		autorest.AsContentType("application/json; charset=utf-8"),
    83  		autorest.AsPut(),
    84  		autorest.WithBaseURL(client.BaseURI),
    85  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}", pathParameters),
    86  		autorest.WithJSON(creationInput),
    87  		autorest.WithQueryParameters(queryParameters))
    88  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    89  }
    90  
    91  // CreateSender sends the Create request. The method will close the
    92  // http.Response Body if it receives an error.
    93  func (client ReplicationProtectionContainersClient) CreateSender(req *http.Request) (future ReplicationProtectionContainersCreateFuture, err error) {
    94  	var resp *http.Response
    95  	future.FutureAPI = &azure.Future{}
    96  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
    97  	if err != nil {
    98  		return
    99  	}
   100  	var azf azure.Future
   101  	azf, err = azure.NewFutureFromResponse(resp)
   102  	future.FutureAPI = &azf
   103  	future.Result = future.result
   104  	return
   105  }
   106  
   107  // CreateResponder handles the response to the Create request. The method always
   108  // closes the http.Response Body.
   109  func (client ReplicationProtectionContainersClient) CreateResponder(resp *http.Response) (result ProtectionContainer, err error) {
   110  	err = autorest.Respond(
   111  		resp,
   112  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   113  		autorest.ByUnmarshallingJSON(&result),
   114  		autorest.ByClosing())
   115  	result.Response = autorest.Response{Response: resp}
   116  	return
   117  }
   118  
   119  // Delete operation to remove a protection container.
   120  // Parameters:
   121  // fabricName - unique fabric ARM name.
   122  // protectionContainerName - unique protection container ARM name.
   123  func (client ReplicationProtectionContainersClient) Delete(ctx context.Context, fabricName string, protectionContainerName string) (result ReplicationProtectionContainersDeleteFuture, err error) {
   124  	if tracing.IsEnabled() {
   125  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainersClient.Delete")
   126  		defer func() {
   127  			sc := -1
   128  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   129  				sc = result.FutureAPI.Response().StatusCode
   130  			}
   131  			tracing.EndSpan(ctx, sc, err)
   132  		}()
   133  	}
   134  	req, err := client.DeletePreparer(ctx, fabricName, protectionContainerName)
   135  	if err != nil {
   136  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "Delete", nil, "Failure preparing request")
   137  		return
   138  	}
   139  
   140  	result, err = client.DeleteSender(req)
   141  	if err != nil {
   142  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "Delete", result.Response(), "Failure sending request")
   143  		return
   144  	}
   145  
   146  	return
   147  }
   148  
   149  // DeletePreparer prepares the Delete request.
   150  func (client ReplicationProtectionContainersClient) DeletePreparer(ctx context.Context, fabricName string, protectionContainerName string) (*http.Request, error) {
   151  	pathParameters := map[string]interface{}{
   152  		"fabricName":              autorest.Encode("path", fabricName),
   153  		"protectionContainerName": autorest.Encode("path", protectionContainerName),
   154  		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
   155  		"resourceName":            autorest.Encode("path", client.ResourceName),
   156  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
   157  	}
   158  
   159  	const APIVersion = "2018-07-10"
   160  	queryParameters := map[string]interface{}{
   161  		"api-version": APIVersion,
   162  	}
   163  
   164  	preparer := autorest.CreatePreparer(
   165  		autorest.AsPost(),
   166  		autorest.WithBaseURL(client.BaseURI),
   167  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/remove", pathParameters),
   168  		autorest.WithQueryParameters(queryParameters))
   169  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   170  }
   171  
   172  // DeleteSender sends the Delete request. The method will close the
   173  // http.Response Body if it receives an error.
   174  func (client ReplicationProtectionContainersClient) DeleteSender(req *http.Request) (future ReplicationProtectionContainersDeleteFuture, err error) {
   175  	var resp *http.Response
   176  	future.FutureAPI = &azure.Future{}
   177  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   178  	if err != nil {
   179  		return
   180  	}
   181  	var azf azure.Future
   182  	azf, err = azure.NewFutureFromResponse(resp)
   183  	future.FutureAPI = &azf
   184  	future.Result = future.result
   185  	return
   186  }
   187  
   188  // DeleteResponder handles the response to the Delete request. The method always
   189  // closes the http.Response Body.
   190  func (client ReplicationProtectionContainersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   191  	err = autorest.Respond(
   192  		resp,
   193  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   194  		autorest.ByClosing())
   195  	result.Response = resp
   196  	return
   197  }
   198  
   199  // DiscoverProtectableItem the operation to a add a protectable item to a protection container(Add physical server.)
   200  // Parameters:
   201  // fabricName - the name of the fabric.
   202  // protectionContainerName - the name of the protection container.
   203  // discoverProtectableItemRequest - the request object to add a protectable item.
   204  func (client ReplicationProtectionContainersClient) DiscoverProtectableItem(ctx context.Context, fabricName string, protectionContainerName string, discoverProtectableItemRequest DiscoverProtectableItemRequest) (result ReplicationProtectionContainersDiscoverProtectableItemFuture, err error) {
   205  	if tracing.IsEnabled() {
   206  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainersClient.DiscoverProtectableItem")
   207  		defer func() {
   208  			sc := -1
   209  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   210  				sc = result.FutureAPI.Response().StatusCode
   211  			}
   212  			tracing.EndSpan(ctx, sc, err)
   213  		}()
   214  	}
   215  	req, err := client.DiscoverProtectableItemPreparer(ctx, fabricName, protectionContainerName, discoverProtectableItemRequest)
   216  	if err != nil {
   217  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "DiscoverProtectableItem", nil, "Failure preparing request")
   218  		return
   219  	}
   220  
   221  	result, err = client.DiscoverProtectableItemSender(req)
   222  	if err != nil {
   223  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "DiscoverProtectableItem", result.Response(), "Failure sending request")
   224  		return
   225  	}
   226  
   227  	return
   228  }
   229  
   230  // DiscoverProtectableItemPreparer prepares the DiscoverProtectableItem request.
   231  func (client ReplicationProtectionContainersClient) DiscoverProtectableItemPreparer(ctx context.Context, fabricName string, protectionContainerName string, discoverProtectableItemRequest DiscoverProtectableItemRequest) (*http.Request, error) {
   232  	pathParameters := map[string]interface{}{
   233  		"fabricName":              autorest.Encode("path", fabricName),
   234  		"protectionContainerName": autorest.Encode("path", protectionContainerName),
   235  		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
   236  		"resourceName":            autorest.Encode("path", client.ResourceName),
   237  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
   238  	}
   239  
   240  	const APIVersion = "2018-07-10"
   241  	queryParameters := map[string]interface{}{
   242  		"api-version": APIVersion,
   243  	}
   244  
   245  	preparer := autorest.CreatePreparer(
   246  		autorest.AsContentType("application/json; charset=utf-8"),
   247  		autorest.AsPost(),
   248  		autorest.WithBaseURL(client.BaseURI),
   249  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/discoverProtectableItem", pathParameters),
   250  		autorest.WithJSON(discoverProtectableItemRequest),
   251  		autorest.WithQueryParameters(queryParameters))
   252  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   253  }
   254  
   255  // DiscoverProtectableItemSender sends the DiscoverProtectableItem request. The method will close the
   256  // http.Response Body if it receives an error.
   257  func (client ReplicationProtectionContainersClient) DiscoverProtectableItemSender(req *http.Request) (future ReplicationProtectionContainersDiscoverProtectableItemFuture, err error) {
   258  	var resp *http.Response
   259  	future.FutureAPI = &azure.Future{}
   260  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   261  	if err != nil {
   262  		return
   263  	}
   264  	var azf azure.Future
   265  	azf, err = azure.NewFutureFromResponse(resp)
   266  	future.FutureAPI = &azf
   267  	future.Result = future.result
   268  	return
   269  }
   270  
   271  // DiscoverProtectableItemResponder handles the response to the DiscoverProtectableItem request. The method always
   272  // closes the http.Response Body.
   273  func (client ReplicationProtectionContainersClient) DiscoverProtectableItemResponder(resp *http.Response) (result ProtectionContainer, err error) {
   274  	err = autorest.Respond(
   275  		resp,
   276  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   277  		autorest.ByUnmarshallingJSON(&result),
   278  		autorest.ByClosing())
   279  	result.Response = autorest.Response{Response: resp}
   280  	return
   281  }
   282  
   283  // Get gets the details of a protection container.
   284  // Parameters:
   285  // fabricName - fabric name.
   286  // protectionContainerName - protection container name.
   287  func (client ReplicationProtectionContainersClient) Get(ctx context.Context, fabricName string, protectionContainerName string) (result ProtectionContainer, err error) {
   288  	if tracing.IsEnabled() {
   289  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainersClient.Get")
   290  		defer func() {
   291  			sc := -1
   292  			if result.Response.Response != nil {
   293  				sc = result.Response.Response.StatusCode
   294  			}
   295  			tracing.EndSpan(ctx, sc, err)
   296  		}()
   297  	}
   298  	req, err := client.GetPreparer(ctx, fabricName, protectionContainerName)
   299  	if err != nil {
   300  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "Get", nil, "Failure preparing request")
   301  		return
   302  	}
   303  
   304  	resp, err := client.GetSender(req)
   305  	if err != nil {
   306  		result.Response = autorest.Response{Response: resp}
   307  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "Get", resp, "Failure sending request")
   308  		return
   309  	}
   310  
   311  	result, err = client.GetResponder(resp)
   312  	if err != nil {
   313  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "Get", resp, "Failure responding to request")
   314  		return
   315  	}
   316  
   317  	return
   318  }
   319  
   320  // GetPreparer prepares the Get request.
   321  func (client ReplicationProtectionContainersClient) GetPreparer(ctx context.Context, fabricName string, protectionContainerName string) (*http.Request, error) {
   322  	pathParameters := map[string]interface{}{
   323  		"fabricName":              autorest.Encode("path", fabricName),
   324  		"protectionContainerName": autorest.Encode("path", protectionContainerName),
   325  		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
   326  		"resourceName":            autorest.Encode("path", client.ResourceName),
   327  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
   328  	}
   329  
   330  	const APIVersion = "2018-07-10"
   331  	queryParameters := map[string]interface{}{
   332  		"api-version": APIVersion,
   333  	}
   334  
   335  	preparer := autorest.CreatePreparer(
   336  		autorest.AsGet(),
   337  		autorest.WithBaseURL(client.BaseURI),
   338  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}", pathParameters),
   339  		autorest.WithQueryParameters(queryParameters))
   340  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   341  }
   342  
   343  // GetSender sends the Get request. The method will close the
   344  // http.Response Body if it receives an error.
   345  func (client ReplicationProtectionContainersClient) GetSender(req *http.Request) (*http.Response, error) {
   346  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   347  }
   348  
   349  // GetResponder handles the response to the Get request. The method always
   350  // closes the http.Response Body.
   351  func (client ReplicationProtectionContainersClient) GetResponder(resp *http.Response) (result ProtectionContainer, err error) {
   352  	err = autorest.Respond(
   353  		resp,
   354  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   355  		autorest.ByUnmarshallingJSON(&result),
   356  		autorest.ByClosing())
   357  	result.Response = autorest.Response{Response: resp}
   358  	return
   359  }
   360  
   361  // List lists the protection containers in a vault.
   362  func (client ReplicationProtectionContainersClient) List(ctx context.Context) (result ProtectionContainerCollectionPage, err error) {
   363  	if tracing.IsEnabled() {
   364  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainersClient.List")
   365  		defer func() {
   366  			sc := -1
   367  			if result.pcc.Response.Response != nil {
   368  				sc = result.pcc.Response.Response.StatusCode
   369  			}
   370  			tracing.EndSpan(ctx, sc, err)
   371  		}()
   372  	}
   373  	result.fn = client.listNextResults
   374  	req, err := client.ListPreparer(ctx)
   375  	if err != nil {
   376  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "List", nil, "Failure preparing request")
   377  		return
   378  	}
   379  
   380  	resp, err := client.ListSender(req)
   381  	if err != nil {
   382  		result.pcc.Response = autorest.Response{Response: resp}
   383  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "List", resp, "Failure sending request")
   384  		return
   385  	}
   386  
   387  	result.pcc, err = client.ListResponder(resp)
   388  	if err != nil {
   389  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "List", resp, "Failure responding to request")
   390  		return
   391  	}
   392  	if result.pcc.hasNextLink() && result.pcc.IsEmpty() {
   393  		err = result.NextWithContext(ctx)
   394  		return
   395  	}
   396  
   397  	return
   398  }
   399  
   400  // ListPreparer prepares the List request.
   401  func (client ReplicationProtectionContainersClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   402  	pathParameters := map[string]interface{}{
   403  		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
   404  		"resourceName":      autorest.Encode("path", client.ResourceName),
   405  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   406  	}
   407  
   408  	const APIVersion = "2018-07-10"
   409  	queryParameters := map[string]interface{}{
   410  		"api-version": APIVersion,
   411  	}
   412  
   413  	preparer := autorest.CreatePreparer(
   414  		autorest.AsGet(),
   415  		autorest.WithBaseURL(client.BaseURI),
   416  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationProtectionContainers", pathParameters),
   417  		autorest.WithQueryParameters(queryParameters))
   418  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   419  }
   420  
   421  // ListSender sends the List request. The method will close the
   422  // http.Response Body if it receives an error.
   423  func (client ReplicationProtectionContainersClient) ListSender(req *http.Request) (*http.Response, error) {
   424  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   425  }
   426  
   427  // ListResponder handles the response to the List request. The method always
   428  // closes the http.Response Body.
   429  func (client ReplicationProtectionContainersClient) ListResponder(resp *http.Response) (result ProtectionContainerCollection, err error) {
   430  	err = autorest.Respond(
   431  		resp,
   432  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   433  		autorest.ByUnmarshallingJSON(&result),
   434  		autorest.ByClosing())
   435  	result.Response = autorest.Response{Response: resp}
   436  	return
   437  }
   438  
   439  // listNextResults retrieves the next set of results, if any.
   440  func (client ReplicationProtectionContainersClient) listNextResults(ctx context.Context, lastResults ProtectionContainerCollection) (result ProtectionContainerCollection, err error) {
   441  	req, err := lastResults.protectionContainerCollectionPreparer(ctx)
   442  	if err != nil {
   443  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "listNextResults", nil, "Failure preparing next results request")
   444  	}
   445  	if req == nil {
   446  		return
   447  	}
   448  	resp, err := client.ListSender(req)
   449  	if err != nil {
   450  		result.Response = autorest.Response{Response: resp}
   451  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "listNextResults", resp, "Failure sending next results request")
   452  	}
   453  	result, err = client.ListResponder(resp)
   454  	if err != nil {
   455  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "listNextResults", resp, "Failure responding to next results request")
   456  	}
   457  	return
   458  }
   459  
   460  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   461  func (client ReplicationProtectionContainersClient) ListComplete(ctx context.Context) (result ProtectionContainerCollectionIterator, err error) {
   462  	if tracing.IsEnabled() {
   463  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainersClient.List")
   464  		defer func() {
   465  			sc := -1
   466  			if result.Response().Response.Response != nil {
   467  				sc = result.page.Response().Response.Response.StatusCode
   468  			}
   469  			tracing.EndSpan(ctx, sc, err)
   470  		}()
   471  	}
   472  	result.page, err = client.List(ctx)
   473  	return
   474  }
   475  
   476  // ListByReplicationFabrics lists the protection containers in the specified fabric.
   477  // Parameters:
   478  // fabricName - fabric name.
   479  func (client ReplicationProtectionContainersClient) ListByReplicationFabrics(ctx context.Context, fabricName string) (result ProtectionContainerCollectionPage, err error) {
   480  	if tracing.IsEnabled() {
   481  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainersClient.ListByReplicationFabrics")
   482  		defer func() {
   483  			sc := -1
   484  			if result.pcc.Response.Response != nil {
   485  				sc = result.pcc.Response.Response.StatusCode
   486  			}
   487  			tracing.EndSpan(ctx, sc, err)
   488  		}()
   489  	}
   490  	result.fn = client.listByReplicationFabricsNextResults
   491  	req, err := client.ListByReplicationFabricsPreparer(ctx, fabricName)
   492  	if err != nil {
   493  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "ListByReplicationFabrics", nil, "Failure preparing request")
   494  		return
   495  	}
   496  
   497  	resp, err := client.ListByReplicationFabricsSender(req)
   498  	if err != nil {
   499  		result.pcc.Response = autorest.Response{Response: resp}
   500  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "ListByReplicationFabrics", resp, "Failure sending request")
   501  		return
   502  	}
   503  
   504  	result.pcc, err = client.ListByReplicationFabricsResponder(resp)
   505  	if err != nil {
   506  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "ListByReplicationFabrics", resp, "Failure responding to request")
   507  		return
   508  	}
   509  	if result.pcc.hasNextLink() && result.pcc.IsEmpty() {
   510  		err = result.NextWithContext(ctx)
   511  		return
   512  	}
   513  
   514  	return
   515  }
   516  
   517  // ListByReplicationFabricsPreparer prepares the ListByReplicationFabrics request.
   518  func (client ReplicationProtectionContainersClient) ListByReplicationFabricsPreparer(ctx context.Context, fabricName string) (*http.Request, error) {
   519  	pathParameters := map[string]interface{}{
   520  		"fabricName":        autorest.Encode("path", fabricName),
   521  		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
   522  		"resourceName":      autorest.Encode("path", client.ResourceName),
   523  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   524  	}
   525  
   526  	const APIVersion = "2018-07-10"
   527  	queryParameters := map[string]interface{}{
   528  		"api-version": APIVersion,
   529  	}
   530  
   531  	preparer := autorest.CreatePreparer(
   532  		autorest.AsGet(),
   533  		autorest.WithBaseURL(client.BaseURI),
   534  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers", pathParameters),
   535  		autorest.WithQueryParameters(queryParameters))
   536  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   537  }
   538  
   539  // ListByReplicationFabricsSender sends the ListByReplicationFabrics request. The method will close the
   540  // http.Response Body if it receives an error.
   541  func (client ReplicationProtectionContainersClient) ListByReplicationFabricsSender(req *http.Request) (*http.Response, error) {
   542  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   543  }
   544  
   545  // ListByReplicationFabricsResponder handles the response to the ListByReplicationFabrics request. The method always
   546  // closes the http.Response Body.
   547  func (client ReplicationProtectionContainersClient) ListByReplicationFabricsResponder(resp *http.Response) (result ProtectionContainerCollection, err error) {
   548  	err = autorest.Respond(
   549  		resp,
   550  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   551  		autorest.ByUnmarshallingJSON(&result),
   552  		autorest.ByClosing())
   553  	result.Response = autorest.Response{Response: resp}
   554  	return
   555  }
   556  
   557  // listByReplicationFabricsNextResults retrieves the next set of results, if any.
   558  func (client ReplicationProtectionContainersClient) listByReplicationFabricsNextResults(ctx context.Context, lastResults ProtectionContainerCollection) (result ProtectionContainerCollection, err error) {
   559  	req, err := lastResults.protectionContainerCollectionPreparer(ctx)
   560  	if err != nil {
   561  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "listByReplicationFabricsNextResults", nil, "Failure preparing next results request")
   562  	}
   563  	if req == nil {
   564  		return
   565  	}
   566  	resp, err := client.ListByReplicationFabricsSender(req)
   567  	if err != nil {
   568  		result.Response = autorest.Response{Response: resp}
   569  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "listByReplicationFabricsNextResults", resp, "Failure sending next results request")
   570  	}
   571  	result, err = client.ListByReplicationFabricsResponder(resp)
   572  	if err != nil {
   573  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "listByReplicationFabricsNextResults", resp, "Failure responding to next results request")
   574  	}
   575  	return
   576  }
   577  
   578  // ListByReplicationFabricsComplete enumerates all values, automatically crossing page boundaries as required.
   579  func (client ReplicationProtectionContainersClient) ListByReplicationFabricsComplete(ctx context.Context, fabricName string) (result ProtectionContainerCollectionIterator, err error) {
   580  	if tracing.IsEnabled() {
   581  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainersClient.ListByReplicationFabrics")
   582  		defer func() {
   583  			sc := -1
   584  			if result.Response().Response.Response != nil {
   585  				sc = result.page.Response().Response.Response.StatusCode
   586  			}
   587  			tracing.EndSpan(ctx, sc, err)
   588  		}()
   589  	}
   590  	result.page, err = client.ListByReplicationFabrics(ctx, fabricName)
   591  	return
   592  }
   593  
   594  // SwitchProtection operation to switch protection from one container to another or one replication provider to
   595  // another.
   596  // Parameters:
   597  // fabricName - unique fabric name.
   598  // protectionContainerName - protection container name.
   599  // switchInput - switch protection input.
   600  func (client ReplicationProtectionContainersClient) SwitchProtection(ctx context.Context, fabricName string, protectionContainerName string, switchInput SwitchProtectionInput) (result ReplicationProtectionContainersSwitchProtectionFuture, err error) {
   601  	if tracing.IsEnabled() {
   602  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainersClient.SwitchProtection")
   603  		defer func() {
   604  			sc := -1
   605  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   606  				sc = result.FutureAPI.Response().StatusCode
   607  			}
   608  			tracing.EndSpan(ctx, sc, err)
   609  		}()
   610  	}
   611  	req, err := client.SwitchProtectionPreparer(ctx, fabricName, protectionContainerName, switchInput)
   612  	if err != nil {
   613  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "SwitchProtection", nil, "Failure preparing request")
   614  		return
   615  	}
   616  
   617  	result, err = client.SwitchProtectionSender(req)
   618  	if err != nil {
   619  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainersClient", "SwitchProtection", result.Response(), "Failure sending request")
   620  		return
   621  	}
   622  
   623  	return
   624  }
   625  
   626  // SwitchProtectionPreparer prepares the SwitchProtection request.
   627  func (client ReplicationProtectionContainersClient) SwitchProtectionPreparer(ctx context.Context, fabricName string, protectionContainerName string, switchInput SwitchProtectionInput) (*http.Request, error) {
   628  	pathParameters := map[string]interface{}{
   629  		"fabricName":              autorest.Encode("path", fabricName),
   630  		"protectionContainerName": autorest.Encode("path", protectionContainerName),
   631  		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
   632  		"resourceName":            autorest.Encode("path", client.ResourceName),
   633  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
   634  	}
   635  
   636  	const APIVersion = "2018-07-10"
   637  	queryParameters := map[string]interface{}{
   638  		"api-version": APIVersion,
   639  	}
   640  
   641  	preparer := autorest.CreatePreparer(
   642  		autorest.AsContentType("application/json; charset=utf-8"),
   643  		autorest.AsPost(),
   644  		autorest.WithBaseURL(client.BaseURI),
   645  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/switchprotection", pathParameters),
   646  		autorest.WithJSON(switchInput),
   647  		autorest.WithQueryParameters(queryParameters))
   648  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   649  }
   650  
   651  // SwitchProtectionSender sends the SwitchProtection request. The method will close the
   652  // http.Response Body if it receives an error.
   653  func (client ReplicationProtectionContainersClient) SwitchProtectionSender(req *http.Request) (future ReplicationProtectionContainersSwitchProtectionFuture, err error) {
   654  	var resp *http.Response
   655  	future.FutureAPI = &azure.Future{}
   656  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   657  	if err != nil {
   658  		return
   659  	}
   660  	var azf azure.Future
   661  	azf, err = azure.NewFutureFromResponse(resp)
   662  	future.FutureAPI = &azf
   663  	future.Result = future.result
   664  	return
   665  }
   666  
   667  // SwitchProtectionResponder handles the response to the SwitchProtection request. The method always
   668  // closes the http.Response Body.
   669  func (client ReplicationProtectionContainersClient) SwitchProtectionResponder(resp *http.Response) (result ProtectionContainer, err error) {
   670  	err = autorest.Respond(
   671  		resp,
   672  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   673  		autorest.ByUnmarshallingJSON(&result),
   674  		autorest.ByClosing())
   675  	result.Response = autorest.Response{Response: resp}
   676  	return
   677  }
   678  

View as plain text