...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-01-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  // ReplicationNetworkMappingsClient is the client for the ReplicationNetworkMappings methods of the Siterecovery
    18  // service.
    19  type ReplicationNetworkMappingsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewReplicationNetworkMappingsClient creates an instance of the ReplicationNetworkMappingsClient client.
    24  func NewReplicationNetworkMappingsClient(subscriptionID string, resourceGroupName string, resourceName string) ReplicationNetworkMappingsClient {
    25  	return NewReplicationNetworkMappingsClientWithBaseURI(DefaultBaseURI, subscriptionID, resourceGroupName, resourceName)
    26  }
    27  
    28  // NewReplicationNetworkMappingsClientWithBaseURI creates an instance of the ReplicationNetworkMappingsClient 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 NewReplicationNetworkMappingsClientWithBaseURI(baseURI string, subscriptionID string, resourceGroupName string, resourceName string) ReplicationNetworkMappingsClient {
    32  	return ReplicationNetworkMappingsClient{NewWithBaseURI(baseURI, subscriptionID, resourceGroupName, resourceName)}
    33  }
    34  
    35  // Create the operation to create an ASR network mapping.
    36  // Parameters:
    37  // fabricName - primary fabric name.
    38  // networkName - primary network name.
    39  // networkMappingName - network mapping name.
    40  // input - create network mapping input.
    41  func (client ReplicationNetworkMappingsClient) Create(ctx context.Context, fabricName string, networkName string, networkMappingName string, input CreateNetworkMappingInput) (result ReplicationNetworkMappingsCreateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationNetworkMappingsClient.Create")
    44  		defer func() {
    45  			sc := -1
    46  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    47  				sc = result.FutureAPI.Response().StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	req, err := client.CreatePreparer(ctx, fabricName, networkName, networkMappingName, input)
    53  	if err != nil {
    54  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "Create", nil, "Failure preparing request")
    55  		return
    56  	}
    57  
    58  	result, err = client.CreateSender(req)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "Create", result.Response(), "Failure sending request")
    61  		return
    62  	}
    63  
    64  	return
    65  }
    66  
    67  // CreatePreparer prepares the Create request.
    68  func (client ReplicationNetworkMappingsClient) CreatePreparer(ctx context.Context, fabricName string, networkName string, networkMappingName string, input CreateNetworkMappingInput) (*http.Request, error) {
    69  	pathParameters := map[string]interface{}{
    70  		"fabricName":         autorest.Encode("path", fabricName),
    71  		"networkMappingName": autorest.Encode("path", networkMappingName),
    72  		"networkName":        autorest.Encode("path", networkName),
    73  		"resourceGroupName":  autorest.Encode("path", client.ResourceGroupName),
    74  		"resourceName":       autorest.Encode("path", client.ResourceName),
    75  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
    76  	}
    77  
    78  	const APIVersion = "2018-01-10"
    79  	queryParameters := map[string]interface{}{
    80  		"api-version": APIVersion,
    81  	}
    82  
    83  	preparer := autorest.CreatePreparer(
    84  		autorest.AsContentType("application/json; charset=utf-8"),
    85  		autorest.AsPut(),
    86  		autorest.WithBaseURL(client.BaseURI),
    87  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationNetworks/{networkName}/replicationNetworkMappings/{networkMappingName}", pathParameters),
    88  		autorest.WithJSON(input),
    89  		autorest.WithQueryParameters(queryParameters))
    90  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    91  }
    92  
    93  // CreateSender sends the Create request. The method will close the
    94  // http.Response Body if it receives an error.
    95  func (client ReplicationNetworkMappingsClient) CreateSender(req *http.Request) (future ReplicationNetworkMappingsCreateFuture, err error) {
    96  	var resp *http.Response
    97  	future.FutureAPI = &azure.Future{}
    98  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
    99  	if err != nil {
   100  		return
   101  	}
   102  	var azf azure.Future
   103  	azf, err = azure.NewFutureFromResponse(resp)
   104  	future.FutureAPI = &azf
   105  	future.Result = future.result
   106  	return
   107  }
   108  
   109  // CreateResponder handles the response to the Create request. The method always
   110  // closes the http.Response Body.
   111  func (client ReplicationNetworkMappingsClient) CreateResponder(resp *http.Response) (result NetworkMapping, err error) {
   112  	err = autorest.Respond(
   113  		resp,
   114  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   115  		autorest.ByUnmarshallingJSON(&result),
   116  		autorest.ByClosing())
   117  	result.Response = autorest.Response{Response: resp}
   118  	return
   119  }
   120  
   121  // Delete the operation to delete a network mapping.
   122  // Parameters:
   123  // fabricName - primary fabric name.
   124  // networkName - primary network name.
   125  // networkMappingName - ARM Resource Name for network mapping.
   126  func (client ReplicationNetworkMappingsClient) Delete(ctx context.Context, fabricName string, networkName string, networkMappingName string) (result ReplicationNetworkMappingsDeleteFuture, err error) {
   127  	if tracing.IsEnabled() {
   128  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationNetworkMappingsClient.Delete")
   129  		defer func() {
   130  			sc := -1
   131  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   132  				sc = result.FutureAPI.Response().StatusCode
   133  			}
   134  			tracing.EndSpan(ctx, sc, err)
   135  		}()
   136  	}
   137  	req, err := client.DeletePreparer(ctx, fabricName, networkName, networkMappingName)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "Delete", nil, "Failure preparing request")
   140  		return
   141  	}
   142  
   143  	result, err = client.DeleteSender(req)
   144  	if err != nil {
   145  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "Delete", result.Response(), "Failure sending request")
   146  		return
   147  	}
   148  
   149  	return
   150  }
   151  
   152  // DeletePreparer prepares the Delete request.
   153  func (client ReplicationNetworkMappingsClient) DeletePreparer(ctx context.Context, fabricName string, networkName string, networkMappingName string) (*http.Request, error) {
   154  	pathParameters := map[string]interface{}{
   155  		"fabricName":         autorest.Encode("path", fabricName),
   156  		"networkMappingName": autorest.Encode("path", networkMappingName),
   157  		"networkName":        autorest.Encode("path", networkName),
   158  		"resourceGroupName":  autorest.Encode("path", client.ResourceGroupName),
   159  		"resourceName":       autorest.Encode("path", client.ResourceName),
   160  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   161  	}
   162  
   163  	const APIVersion = "2018-01-10"
   164  	queryParameters := map[string]interface{}{
   165  		"api-version": APIVersion,
   166  	}
   167  
   168  	preparer := autorest.CreatePreparer(
   169  		autorest.AsDelete(),
   170  		autorest.WithBaseURL(client.BaseURI),
   171  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationNetworks/{networkName}/replicationNetworkMappings/{networkMappingName}", pathParameters),
   172  		autorest.WithQueryParameters(queryParameters))
   173  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   174  }
   175  
   176  // DeleteSender sends the Delete request. The method will close the
   177  // http.Response Body if it receives an error.
   178  func (client ReplicationNetworkMappingsClient) DeleteSender(req *http.Request) (future ReplicationNetworkMappingsDeleteFuture, err error) {
   179  	var resp *http.Response
   180  	future.FutureAPI = &azure.Future{}
   181  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   182  	if err != nil {
   183  		return
   184  	}
   185  	var azf azure.Future
   186  	azf, err = azure.NewFutureFromResponse(resp)
   187  	future.FutureAPI = &azf
   188  	future.Result = future.result
   189  	return
   190  }
   191  
   192  // DeleteResponder handles the response to the Delete request. The method always
   193  // closes the http.Response Body.
   194  func (client ReplicationNetworkMappingsClient) 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 gets the details of an ASR network mapping
   204  // Parameters:
   205  // fabricName - primary fabric name.
   206  // networkName - primary network name.
   207  // networkMappingName - network mapping name.
   208  func (client ReplicationNetworkMappingsClient) Get(ctx context.Context, fabricName string, networkName string, networkMappingName string) (result NetworkMapping, err error) {
   209  	if tracing.IsEnabled() {
   210  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationNetworkMappingsClient.Get")
   211  		defer func() {
   212  			sc := -1
   213  			if result.Response.Response != nil {
   214  				sc = result.Response.Response.StatusCode
   215  			}
   216  			tracing.EndSpan(ctx, sc, err)
   217  		}()
   218  	}
   219  	req, err := client.GetPreparer(ctx, fabricName, networkName, networkMappingName)
   220  	if err != nil {
   221  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "Get", nil, "Failure preparing request")
   222  		return
   223  	}
   224  
   225  	resp, err := client.GetSender(req)
   226  	if err != nil {
   227  		result.Response = autorest.Response{Response: resp}
   228  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "Get", resp, "Failure sending request")
   229  		return
   230  	}
   231  
   232  	result, err = client.GetResponder(resp)
   233  	if err != nil {
   234  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "Get", resp, "Failure responding to request")
   235  		return
   236  	}
   237  
   238  	return
   239  }
   240  
   241  // GetPreparer prepares the Get request.
   242  func (client ReplicationNetworkMappingsClient) GetPreparer(ctx context.Context, fabricName string, networkName string, networkMappingName string) (*http.Request, error) {
   243  	pathParameters := map[string]interface{}{
   244  		"fabricName":         autorest.Encode("path", fabricName),
   245  		"networkMappingName": autorest.Encode("path", networkMappingName),
   246  		"networkName":        autorest.Encode("path", networkName),
   247  		"resourceGroupName":  autorest.Encode("path", client.ResourceGroupName),
   248  		"resourceName":       autorest.Encode("path", client.ResourceName),
   249  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   250  	}
   251  
   252  	const APIVersion = "2018-01-10"
   253  	queryParameters := map[string]interface{}{
   254  		"api-version": APIVersion,
   255  	}
   256  
   257  	preparer := autorest.CreatePreparer(
   258  		autorest.AsGet(),
   259  		autorest.WithBaseURL(client.BaseURI),
   260  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationNetworks/{networkName}/replicationNetworkMappings/{networkMappingName}", pathParameters),
   261  		autorest.WithQueryParameters(queryParameters))
   262  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   263  }
   264  
   265  // GetSender sends the Get request. The method will close the
   266  // http.Response Body if it receives an error.
   267  func (client ReplicationNetworkMappingsClient) GetSender(req *http.Request) (*http.Response, error) {
   268  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   269  }
   270  
   271  // GetResponder handles the response to the Get request. The method always
   272  // closes the http.Response Body.
   273  func (client ReplicationNetworkMappingsClient) GetResponder(resp *http.Response) (result NetworkMapping, err error) {
   274  	err = autorest.Respond(
   275  		resp,
   276  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   277  		autorest.ByUnmarshallingJSON(&result),
   278  		autorest.ByClosing())
   279  	result.Response = autorest.Response{Response: resp}
   280  	return
   281  }
   282  
   283  // List lists all ASR network mappings in the vault.
   284  func (client ReplicationNetworkMappingsClient) List(ctx context.Context) (result NetworkMappingCollectionPage, err error) {
   285  	if tracing.IsEnabled() {
   286  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationNetworkMappingsClient.List")
   287  		defer func() {
   288  			sc := -1
   289  			if result.nmc.Response.Response != nil {
   290  				sc = result.nmc.Response.Response.StatusCode
   291  			}
   292  			tracing.EndSpan(ctx, sc, err)
   293  		}()
   294  	}
   295  	result.fn = client.listNextResults
   296  	req, err := client.ListPreparer(ctx)
   297  	if err != nil {
   298  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "List", nil, "Failure preparing request")
   299  		return
   300  	}
   301  
   302  	resp, err := client.ListSender(req)
   303  	if err != nil {
   304  		result.nmc.Response = autorest.Response{Response: resp}
   305  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "List", resp, "Failure sending request")
   306  		return
   307  	}
   308  
   309  	result.nmc, err = client.ListResponder(resp)
   310  	if err != nil {
   311  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "List", resp, "Failure responding to request")
   312  		return
   313  	}
   314  	if result.nmc.hasNextLink() && result.nmc.IsEmpty() {
   315  		err = result.NextWithContext(ctx)
   316  		return
   317  	}
   318  
   319  	return
   320  }
   321  
   322  // ListPreparer prepares the List request.
   323  func (client ReplicationNetworkMappingsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   324  	pathParameters := map[string]interface{}{
   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-01-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}/replicationNetworkMappings", pathParameters),
   339  		autorest.WithQueryParameters(queryParameters))
   340  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   341  }
   342  
   343  // ListSender sends the List request. The method will close the
   344  // http.Response Body if it receives an error.
   345  func (client ReplicationNetworkMappingsClient) ListSender(req *http.Request) (*http.Response, error) {
   346  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   347  }
   348  
   349  // ListResponder handles the response to the List request. The method always
   350  // closes the http.Response Body.
   351  func (client ReplicationNetworkMappingsClient) ListResponder(resp *http.Response) (result NetworkMappingCollection, 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  // listNextResults retrieves the next set of results, if any.
   362  func (client ReplicationNetworkMappingsClient) listNextResults(ctx context.Context, lastResults NetworkMappingCollection) (result NetworkMappingCollection, err error) {
   363  	req, err := lastResults.networkMappingCollectionPreparer(ctx)
   364  	if err != nil {
   365  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "listNextResults", nil, "Failure preparing next results request")
   366  	}
   367  	if req == nil {
   368  		return
   369  	}
   370  	resp, err := client.ListSender(req)
   371  	if err != nil {
   372  		result.Response = autorest.Response{Response: resp}
   373  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "listNextResults", resp, "Failure sending next results request")
   374  	}
   375  	result, err = client.ListResponder(resp)
   376  	if err != nil {
   377  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "listNextResults", resp, "Failure responding to next results request")
   378  	}
   379  	return
   380  }
   381  
   382  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   383  func (client ReplicationNetworkMappingsClient) ListComplete(ctx context.Context) (result NetworkMappingCollectionIterator, err error) {
   384  	if tracing.IsEnabled() {
   385  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationNetworkMappingsClient.List")
   386  		defer func() {
   387  			sc := -1
   388  			if result.Response().Response.Response != nil {
   389  				sc = result.page.Response().Response.Response.StatusCode
   390  			}
   391  			tracing.EndSpan(ctx, sc, err)
   392  		}()
   393  	}
   394  	result.page, err = client.List(ctx)
   395  	return
   396  }
   397  
   398  // ListByReplicationNetworks lists all ASR network mappings for the specified network.
   399  // Parameters:
   400  // fabricName - primary fabric name.
   401  // networkName - primary network name.
   402  func (client ReplicationNetworkMappingsClient) ListByReplicationNetworks(ctx context.Context, fabricName string, networkName string) (result NetworkMappingCollectionPage, err error) {
   403  	if tracing.IsEnabled() {
   404  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationNetworkMappingsClient.ListByReplicationNetworks")
   405  		defer func() {
   406  			sc := -1
   407  			if result.nmc.Response.Response != nil {
   408  				sc = result.nmc.Response.Response.StatusCode
   409  			}
   410  			tracing.EndSpan(ctx, sc, err)
   411  		}()
   412  	}
   413  	result.fn = client.listByReplicationNetworksNextResults
   414  	req, err := client.ListByReplicationNetworksPreparer(ctx, fabricName, networkName)
   415  	if err != nil {
   416  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "ListByReplicationNetworks", nil, "Failure preparing request")
   417  		return
   418  	}
   419  
   420  	resp, err := client.ListByReplicationNetworksSender(req)
   421  	if err != nil {
   422  		result.nmc.Response = autorest.Response{Response: resp}
   423  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "ListByReplicationNetworks", resp, "Failure sending request")
   424  		return
   425  	}
   426  
   427  	result.nmc, err = client.ListByReplicationNetworksResponder(resp)
   428  	if err != nil {
   429  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "ListByReplicationNetworks", resp, "Failure responding to request")
   430  		return
   431  	}
   432  	if result.nmc.hasNextLink() && result.nmc.IsEmpty() {
   433  		err = result.NextWithContext(ctx)
   434  		return
   435  	}
   436  
   437  	return
   438  }
   439  
   440  // ListByReplicationNetworksPreparer prepares the ListByReplicationNetworks request.
   441  func (client ReplicationNetworkMappingsClient) ListByReplicationNetworksPreparer(ctx context.Context, fabricName string, networkName string) (*http.Request, error) {
   442  	pathParameters := map[string]interface{}{
   443  		"fabricName":        autorest.Encode("path", fabricName),
   444  		"networkName":       autorest.Encode("path", networkName),
   445  		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
   446  		"resourceName":      autorest.Encode("path", client.ResourceName),
   447  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   448  	}
   449  
   450  	const APIVersion = "2018-01-10"
   451  	queryParameters := map[string]interface{}{
   452  		"api-version": APIVersion,
   453  	}
   454  
   455  	preparer := autorest.CreatePreparer(
   456  		autorest.AsGet(),
   457  		autorest.WithBaseURL(client.BaseURI),
   458  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationNetworks/{networkName}/replicationNetworkMappings", pathParameters),
   459  		autorest.WithQueryParameters(queryParameters))
   460  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   461  }
   462  
   463  // ListByReplicationNetworksSender sends the ListByReplicationNetworks request. The method will close the
   464  // http.Response Body if it receives an error.
   465  func (client ReplicationNetworkMappingsClient) ListByReplicationNetworksSender(req *http.Request) (*http.Response, error) {
   466  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   467  }
   468  
   469  // ListByReplicationNetworksResponder handles the response to the ListByReplicationNetworks request. The method always
   470  // closes the http.Response Body.
   471  func (client ReplicationNetworkMappingsClient) ListByReplicationNetworksResponder(resp *http.Response) (result NetworkMappingCollection, err error) {
   472  	err = autorest.Respond(
   473  		resp,
   474  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   475  		autorest.ByUnmarshallingJSON(&result),
   476  		autorest.ByClosing())
   477  	result.Response = autorest.Response{Response: resp}
   478  	return
   479  }
   480  
   481  // listByReplicationNetworksNextResults retrieves the next set of results, if any.
   482  func (client ReplicationNetworkMappingsClient) listByReplicationNetworksNextResults(ctx context.Context, lastResults NetworkMappingCollection) (result NetworkMappingCollection, err error) {
   483  	req, err := lastResults.networkMappingCollectionPreparer(ctx)
   484  	if err != nil {
   485  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "listByReplicationNetworksNextResults", nil, "Failure preparing next results request")
   486  	}
   487  	if req == nil {
   488  		return
   489  	}
   490  	resp, err := client.ListByReplicationNetworksSender(req)
   491  	if err != nil {
   492  		result.Response = autorest.Response{Response: resp}
   493  		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "listByReplicationNetworksNextResults", resp, "Failure sending next results request")
   494  	}
   495  	result, err = client.ListByReplicationNetworksResponder(resp)
   496  	if err != nil {
   497  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "listByReplicationNetworksNextResults", resp, "Failure responding to next results request")
   498  	}
   499  	return
   500  }
   501  
   502  // ListByReplicationNetworksComplete enumerates all values, automatically crossing page boundaries as required.
   503  func (client ReplicationNetworkMappingsClient) ListByReplicationNetworksComplete(ctx context.Context, fabricName string, networkName string) (result NetworkMappingCollectionIterator, err error) {
   504  	if tracing.IsEnabled() {
   505  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationNetworkMappingsClient.ListByReplicationNetworks")
   506  		defer func() {
   507  			sc := -1
   508  			if result.Response().Response.Response != nil {
   509  				sc = result.page.Response().Response.Response.StatusCode
   510  			}
   511  			tracing.EndSpan(ctx, sc, err)
   512  		}()
   513  	}
   514  	result.page, err = client.ListByReplicationNetworks(ctx, fabricName, networkName)
   515  	return
   516  }
   517  
   518  // Update the operation to update an ASR network mapping.
   519  // Parameters:
   520  // fabricName - primary fabric name.
   521  // networkName - primary network name.
   522  // networkMappingName - network mapping name.
   523  // input - update network mapping input.
   524  func (client ReplicationNetworkMappingsClient) Update(ctx context.Context, fabricName string, networkName string, networkMappingName string, input UpdateNetworkMappingInput) (result ReplicationNetworkMappingsUpdateFuture, err error) {
   525  	if tracing.IsEnabled() {
   526  		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationNetworkMappingsClient.Update")
   527  		defer func() {
   528  			sc := -1
   529  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   530  				sc = result.FutureAPI.Response().StatusCode
   531  			}
   532  			tracing.EndSpan(ctx, sc, err)
   533  		}()
   534  	}
   535  	req, err := client.UpdatePreparer(ctx, fabricName, networkName, networkMappingName, input)
   536  	if err != nil {
   537  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "Update", nil, "Failure preparing request")
   538  		return
   539  	}
   540  
   541  	result, err = client.UpdateSender(req)
   542  	if err != nil {
   543  		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationNetworkMappingsClient", "Update", result.Response(), "Failure sending request")
   544  		return
   545  	}
   546  
   547  	return
   548  }
   549  
   550  // UpdatePreparer prepares the Update request.
   551  func (client ReplicationNetworkMappingsClient) UpdatePreparer(ctx context.Context, fabricName string, networkName string, networkMappingName string, input UpdateNetworkMappingInput) (*http.Request, error) {
   552  	pathParameters := map[string]interface{}{
   553  		"fabricName":         autorest.Encode("path", fabricName),
   554  		"networkMappingName": autorest.Encode("path", networkMappingName),
   555  		"networkName":        autorest.Encode("path", networkName),
   556  		"resourceGroupName":  autorest.Encode("path", client.ResourceGroupName),
   557  		"resourceName":       autorest.Encode("path", client.ResourceName),
   558  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   559  	}
   560  
   561  	const APIVersion = "2018-01-10"
   562  	queryParameters := map[string]interface{}{
   563  		"api-version": APIVersion,
   564  	}
   565  
   566  	preparer := autorest.CreatePreparer(
   567  		autorest.AsContentType("application/json; charset=utf-8"),
   568  		autorest.AsPatch(),
   569  		autorest.WithBaseURL(client.BaseURI),
   570  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationNetworks/{networkName}/replicationNetworkMappings/{networkMappingName}", pathParameters),
   571  		autorest.WithJSON(input),
   572  		autorest.WithQueryParameters(queryParameters))
   573  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   574  }
   575  
   576  // UpdateSender sends the Update request. The method will close the
   577  // http.Response Body if it receives an error.
   578  func (client ReplicationNetworkMappingsClient) UpdateSender(req *http.Request) (future ReplicationNetworkMappingsUpdateFuture, err error) {
   579  	var resp *http.Response
   580  	future.FutureAPI = &azure.Future{}
   581  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   582  	if err != nil {
   583  		return
   584  	}
   585  	var azf azure.Future
   586  	azf, err = azure.NewFutureFromResponse(resp)
   587  	future.FutureAPI = &azf
   588  	future.Result = future.result
   589  	return
   590  }
   591  
   592  // UpdateResponder handles the response to the Update request. The method always
   593  // closes the http.Response Body.
   594  func (client ReplicationNetworkMappingsClient) UpdateResponder(resp *http.Response) (result NetworkMapping, err error) {
   595  	err = autorest.Respond(
   596  		resp,
   597  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   598  		autorest.ByUnmarshallingJSON(&result),
   599  		autorest.ByClosing())
   600  	result.Response = autorest.Response{Response: resp}
   601  	return
   602  }
   603  

View as plain text