1package siterecovery
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// ReplicationProtectionContainerMappingsClient is the client for the ReplicationProtectionContainerMappings methods of
29// the Siterecovery service.
30type ReplicationProtectionContainerMappingsClient struct {
31	BaseClient
32}
33
34// NewReplicationProtectionContainerMappingsClient creates an instance of the
35// ReplicationProtectionContainerMappingsClient client.
36func NewReplicationProtectionContainerMappingsClient(subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectionContainerMappingsClient {
37	return NewReplicationProtectionContainerMappingsClientWithBaseURI(DefaultBaseURI, subscriptionID, resourceGroupName, resourceName)
38}
39
40// NewReplicationProtectionContainerMappingsClientWithBaseURI creates an instance of the
41// ReplicationProtectionContainerMappingsClient client using a custom endpoint.  Use this when interacting with an
42// Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
43func NewReplicationProtectionContainerMappingsClientWithBaseURI(baseURI string, subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectionContainerMappingsClient {
44	return ReplicationProtectionContainerMappingsClient{NewWithBaseURI(baseURI, subscriptionID, resourceGroupName, resourceName)}
45}
46
47// Create the operation to create a protection container mapping.
48// Parameters:
49// fabricName - fabric name.
50// protectionContainerName - protection container name.
51// mappingName - protection container mapping name.
52// creationInput - mapping creation input.
53func (client ReplicationProtectionContainerMappingsClient) Create(ctx context.Context, fabricName string, protectionContainerName string, mappingName string, creationInput CreateProtectionContainerMappingInput) (result ReplicationProtectionContainerMappingsCreateFuture, err error) {
54	if tracing.IsEnabled() {
55		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainerMappingsClient.Create")
56		defer func() {
57			sc := -1
58			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
59				sc = result.FutureAPI.Response().StatusCode
60			}
61			tracing.EndSpan(ctx, sc, err)
62		}()
63	}
64	req, err := client.CreatePreparer(ctx, fabricName, protectionContainerName, mappingName, creationInput)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "Create", nil, "Failure preparing request")
67		return
68	}
69
70	result, err = client.CreateSender(req)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "Create", nil, "Failure sending request")
73		return
74	}
75
76	return
77}
78
79// CreatePreparer prepares the Create request.
80func (client ReplicationProtectionContainerMappingsClient) CreatePreparer(ctx context.Context, fabricName string, protectionContainerName string, mappingName string, creationInput CreateProtectionContainerMappingInput) (*http.Request, error) {
81	pathParameters := map[string]interface{}{
82		"fabricName":              autorest.Encode("path", fabricName),
83		"mappingName":             autorest.Encode("path", mappingName),
84		"protectionContainerName": autorest.Encode("path", protectionContainerName),
85		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
86		"resourceName":            autorest.Encode("path", client.ResourceName),
87		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
88	}
89
90	const APIVersion = "2016-08-10"
91	queryParameters := map[string]interface{}{
92		"api-version": APIVersion,
93	}
94
95	preparer := autorest.CreatePreparer(
96		autorest.AsContentType("application/json; charset=utf-8"),
97		autorest.AsPut(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectionContainerMappings/{mappingName}", pathParameters),
100		autorest.WithJSON(creationInput),
101		autorest.WithQueryParameters(queryParameters))
102	return preparer.Prepare((&http.Request{}).WithContext(ctx))
103}
104
105// CreateSender sends the Create request. The method will close the
106// http.Response Body if it receives an error.
107func (client ReplicationProtectionContainerMappingsClient) CreateSender(req *http.Request) (future ReplicationProtectionContainerMappingsCreateFuture, err error) {
108	var resp *http.Response
109	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
110	if err != nil {
111		return
112	}
113	var azf azure.Future
114	azf, err = azure.NewFutureFromResponse(resp)
115	future.FutureAPI = &azf
116	future.Result = func(client ReplicationProtectionContainerMappingsClient) (pcm ProtectionContainerMapping, err error) {
117		var done bool
118		done, err = future.DoneWithContext(context.Background(), client)
119		if err != nil {
120			err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsCreateFuture", "Result", future.Response(), "Polling failure")
121			return
122		}
123		if !done {
124			err = azure.NewAsyncOpIncompleteError("siterecovery.ReplicationProtectionContainerMappingsCreateFuture")
125			return
126		}
127		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
128		pcm.Response.Response, err = future.GetResult(sender)
129		if pcm.Response.Response == nil && err == nil {
130			err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsCreateFuture", "Result", nil, "received nil response and error")
131		}
132		if err == nil && pcm.Response.Response.StatusCode != http.StatusNoContent {
133			pcm, err = client.CreateResponder(pcm.Response.Response)
134			if err != nil {
135				err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsCreateFuture", "Result", pcm.Response.Response, "Failure responding to request")
136			}
137		}
138		return
139	}
140	return
141}
142
143// CreateResponder handles the response to the Create request. The method always
144// closes the http.Response Body.
145func (client ReplicationProtectionContainerMappingsClient) CreateResponder(resp *http.Response) (result ProtectionContainerMapping, err error) {
146	err = autorest.Respond(
147		resp,
148		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
149		autorest.ByUnmarshallingJSON(&result),
150		autorest.ByClosing())
151	result.Response = autorest.Response{Response: resp}
152	return
153}
154
155// Delete the operation to delete or remove a protection container mapping.
156// Parameters:
157// fabricName - fabric name.
158// protectionContainerName - protection container name.
159// mappingName - protection container mapping name.
160// removalInput - removal input.
161func (client ReplicationProtectionContainerMappingsClient) Delete(ctx context.Context, fabricName string, protectionContainerName string, mappingName string, removalInput RemoveProtectionContainerMappingInput) (result ReplicationProtectionContainerMappingsDeleteFuture, err error) {
162	if tracing.IsEnabled() {
163		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainerMappingsClient.Delete")
164		defer func() {
165			sc := -1
166			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
167				sc = result.FutureAPI.Response().StatusCode
168			}
169			tracing.EndSpan(ctx, sc, err)
170		}()
171	}
172	req, err := client.DeletePreparer(ctx, fabricName, protectionContainerName, mappingName, removalInput)
173	if err != nil {
174		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "Delete", nil, "Failure preparing request")
175		return
176	}
177
178	result, err = client.DeleteSender(req)
179	if err != nil {
180		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "Delete", nil, "Failure sending request")
181		return
182	}
183
184	return
185}
186
187// DeletePreparer prepares the Delete request.
188func (client ReplicationProtectionContainerMappingsClient) DeletePreparer(ctx context.Context, fabricName string, protectionContainerName string, mappingName string, removalInput RemoveProtectionContainerMappingInput) (*http.Request, error) {
189	pathParameters := map[string]interface{}{
190		"fabricName":              autorest.Encode("path", fabricName),
191		"mappingName":             autorest.Encode("path", mappingName),
192		"protectionContainerName": autorest.Encode("path", protectionContainerName),
193		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
194		"resourceName":            autorest.Encode("path", client.ResourceName),
195		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
196	}
197
198	const APIVersion = "2016-08-10"
199	queryParameters := map[string]interface{}{
200		"api-version": APIVersion,
201	}
202
203	preparer := autorest.CreatePreparer(
204		autorest.AsContentType("application/json; charset=utf-8"),
205		autorest.AsPost(),
206		autorest.WithBaseURL(client.BaseURI),
207		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectionContainerMappings/{mappingName}/remove", pathParameters),
208		autorest.WithJSON(removalInput),
209		autorest.WithQueryParameters(queryParameters))
210	return preparer.Prepare((&http.Request{}).WithContext(ctx))
211}
212
213// DeleteSender sends the Delete request. The method will close the
214// http.Response Body if it receives an error.
215func (client ReplicationProtectionContainerMappingsClient) DeleteSender(req *http.Request) (future ReplicationProtectionContainerMappingsDeleteFuture, err error) {
216	var resp *http.Response
217	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
218	if err != nil {
219		return
220	}
221	var azf azure.Future
222	azf, err = azure.NewFutureFromResponse(resp)
223	future.FutureAPI = &azf
224	future.Result = func(client ReplicationProtectionContainerMappingsClient) (ar autorest.Response, err error) {
225		var done bool
226		done, err = future.DoneWithContext(context.Background(), client)
227		if err != nil {
228			err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsDeleteFuture", "Result", future.Response(), "Polling failure")
229			return
230		}
231		if !done {
232			err = azure.NewAsyncOpIncompleteError("siterecovery.ReplicationProtectionContainerMappingsDeleteFuture")
233			return
234		}
235		ar.Response = future.Response()
236		return
237	}
238	return
239}
240
241// DeleteResponder handles the response to the Delete request. The method always
242// closes the http.Response Body.
243func (client ReplicationProtectionContainerMappingsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
244	err = autorest.Respond(
245		resp,
246		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
247		autorest.ByClosing())
248	result.Response = resp
249	return
250}
251
252// Get gets the details of a protection container mapping.
253// Parameters:
254// fabricName - fabric name.
255// protectionContainerName - protection container name.
256// mappingName - protection Container mapping name.
257func (client ReplicationProtectionContainerMappingsClient) Get(ctx context.Context, fabricName string, protectionContainerName string, mappingName string) (result ProtectionContainerMapping, err error) {
258	if tracing.IsEnabled() {
259		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainerMappingsClient.Get")
260		defer func() {
261			sc := -1
262			if result.Response.Response != nil {
263				sc = result.Response.Response.StatusCode
264			}
265			tracing.EndSpan(ctx, sc, err)
266		}()
267	}
268	req, err := client.GetPreparer(ctx, fabricName, protectionContainerName, mappingName)
269	if err != nil {
270		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "Get", nil, "Failure preparing request")
271		return
272	}
273
274	resp, err := client.GetSender(req)
275	if err != nil {
276		result.Response = autorest.Response{Response: resp}
277		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "Get", resp, "Failure sending request")
278		return
279	}
280
281	result, err = client.GetResponder(resp)
282	if err != nil {
283		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "Get", resp, "Failure responding to request")
284		return
285	}
286
287	return
288}
289
290// GetPreparer prepares the Get request.
291func (client ReplicationProtectionContainerMappingsClient) GetPreparer(ctx context.Context, fabricName string, protectionContainerName string, mappingName string) (*http.Request, error) {
292	pathParameters := map[string]interface{}{
293		"fabricName":              autorest.Encode("path", fabricName),
294		"mappingName":             autorest.Encode("path", mappingName),
295		"protectionContainerName": autorest.Encode("path", protectionContainerName),
296		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
297		"resourceName":            autorest.Encode("path", client.ResourceName),
298		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
299	}
300
301	const APIVersion = "2016-08-10"
302	queryParameters := map[string]interface{}{
303		"api-version": APIVersion,
304	}
305
306	preparer := autorest.CreatePreparer(
307		autorest.AsGet(),
308		autorest.WithBaseURL(client.BaseURI),
309		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectionContainerMappings/{mappingName}", pathParameters),
310		autorest.WithQueryParameters(queryParameters))
311	return preparer.Prepare((&http.Request{}).WithContext(ctx))
312}
313
314// GetSender sends the Get request. The method will close the
315// http.Response Body if it receives an error.
316func (client ReplicationProtectionContainerMappingsClient) GetSender(req *http.Request) (*http.Response, error) {
317	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
318}
319
320// GetResponder handles the response to the Get request. The method always
321// closes the http.Response Body.
322func (client ReplicationProtectionContainerMappingsClient) GetResponder(resp *http.Response) (result ProtectionContainerMapping, err error) {
323	err = autorest.Respond(
324		resp,
325		azure.WithErrorUnlessStatusCode(http.StatusOK),
326		autorest.ByUnmarshallingJSON(&result),
327		autorest.ByClosing())
328	result.Response = autorest.Response{Response: resp}
329	return
330}
331
332// List lists the protection container mappings in the vault.
333func (client ReplicationProtectionContainerMappingsClient) List(ctx context.Context) (result ProtectionContainerMappingCollectionPage, err error) {
334	if tracing.IsEnabled() {
335		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainerMappingsClient.List")
336		defer func() {
337			sc := -1
338			if result.pcmc.Response.Response != nil {
339				sc = result.pcmc.Response.Response.StatusCode
340			}
341			tracing.EndSpan(ctx, sc, err)
342		}()
343	}
344	result.fn = client.listNextResults
345	req, err := client.ListPreparer(ctx)
346	if err != nil {
347		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "List", nil, "Failure preparing request")
348		return
349	}
350
351	resp, err := client.ListSender(req)
352	if err != nil {
353		result.pcmc.Response = autorest.Response{Response: resp}
354		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "List", resp, "Failure sending request")
355		return
356	}
357
358	result.pcmc, err = client.ListResponder(resp)
359	if err != nil {
360		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "List", resp, "Failure responding to request")
361		return
362	}
363	if result.pcmc.hasNextLink() && result.pcmc.IsEmpty() {
364		err = result.NextWithContext(ctx)
365		return
366	}
367
368	return
369}
370
371// ListPreparer prepares the List request.
372func (client ReplicationProtectionContainerMappingsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
373	pathParameters := map[string]interface{}{
374		"resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
375		"resourceName":      autorest.Encode("path", client.ResourceName),
376		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
377	}
378
379	const APIVersion = "2016-08-10"
380	queryParameters := map[string]interface{}{
381		"api-version": APIVersion,
382	}
383
384	preparer := autorest.CreatePreparer(
385		autorest.AsGet(),
386		autorest.WithBaseURL(client.BaseURI),
387		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationProtectionContainerMappings", pathParameters),
388		autorest.WithQueryParameters(queryParameters))
389	return preparer.Prepare((&http.Request{}).WithContext(ctx))
390}
391
392// ListSender sends the List request. The method will close the
393// http.Response Body if it receives an error.
394func (client ReplicationProtectionContainerMappingsClient) ListSender(req *http.Request) (*http.Response, error) {
395	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
396}
397
398// ListResponder handles the response to the List request. The method always
399// closes the http.Response Body.
400func (client ReplicationProtectionContainerMappingsClient) ListResponder(resp *http.Response) (result ProtectionContainerMappingCollection, err error) {
401	err = autorest.Respond(
402		resp,
403		azure.WithErrorUnlessStatusCode(http.StatusOK),
404		autorest.ByUnmarshallingJSON(&result),
405		autorest.ByClosing())
406	result.Response = autorest.Response{Response: resp}
407	return
408}
409
410// listNextResults retrieves the next set of results, if any.
411func (client ReplicationProtectionContainerMappingsClient) listNextResults(ctx context.Context, lastResults ProtectionContainerMappingCollection) (result ProtectionContainerMappingCollection, err error) {
412	req, err := lastResults.protectionContainerMappingCollectionPreparer(ctx)
413	if err != nil {
414		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "listNextResults", nil, "Failure preparing next results request")
415	}
416	if req == nil {
417		return
418	}
419	resp, err := client.ListSender(req)
420	if err != nil {
421		result.Response = autorest.Response{Response: resp}
422		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "listNextResults", resp, "Failure sending next results request")
423	}
424	result, err = client.ListResponder(resp)
425	if err != nil {
426		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "listNextResults", resp, "Failure responding to next results request")
427	}
428	return
429}
430
431// ListComplete enumerates all values, automatically crossing page boundaries as required.
432func (client ReplicationProtectionContainerMappingsClient) ListComplete(ctx context.Context) (result ProtectionContainerMappingCollectionIterator, err error) {
433	if tracing.IsEnabled() {
434		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainerMappingsClient.List")
435		defer func() {
436			sc := -1
437			if result.Response().Response.Response != nil {
438				sc = result.page.Response().Response.Response.StatusCode
439			}
440			tracing.EndSpan(ctx, sc, err)
441		}()
442	}
443	result.page, err = client.List(ctx)
444	return
445}
446
447// ListByReplicationProtectionContainers lists the protection container mappings for a protection container.
448// Parameters:
449// fabricName - fabric name.
450// protectionContainerName - protection container name.
451func (client ReplicationProtectionContainerMappingsClient) ListByReplicationProtectionContainers(ctx context.Context, fabricName string, protectionContainerName string) (result ProtectionContainerMappingCollectionPage, err error) {
452	if tracing.IsEnabled() {
453		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainerMappingsClient.ListByReplicationProtectionContainers")
454		defer func() {
455			sc := -1
456			if result.pcmc.Response.Response != nil {
457				sc = result.pcmc.Response.Response.StatusCode
458			}
459			tracing.EndSpan(ctx, sc, err)
460		}()
461	}
462	result.fn = client.listByReplicationProtectionContainersNextResults
463	req, err := client.ListByReplicationProtectionContainersPreparer(ctx, fabricName, protectionContainerName)
464	if err != nil {
465		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "ListByReplicationProtectionContainers", nil, "Failure preparing request")
466		return
467	}
468
469	resp, err := client.ListByReplicationProtectionContainersSender(req)
470	if err != nil {
471		result.pcmc.Response = autorest.Response{Response: resp}
472		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "ListByReplicationProtectionContainers", resp, "Failure sending request")
473		return
474	}
475
476	result.pcmc, err = client.ListByReplicationProtectionContainersResponder(resp)
477	if err != nil {
478		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "ListByReplicationProtectionContainers", resp, "Failure responding to request")
479		return
480	}
481	if result.pcmc.hasNextLink() && result.pcmc.IsEmpty() {
482		err = result.NextWithContext(ctx)
483		return
484	}
485
486	return
487}
488
489// ListByReplicationProtectionContainersPreparer prepares the ListByReplicationProtectionContainers request.
490func (client ReplicationProtectionContainerMappingsClient) ListByReplicationProtectionContainersPreparer(ctx context.Context, fabricName string, protectionContainerName string) (*http.Request, error) {
491	pathParameters := map[string]interface{}{
492		"fabricName":              autorest.Encode("path", fabricName),
493		"protectionContainerName": autorest.Encode("path", protectionContainerName),
494		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
495		"resourceName":            autorest.Encode("path", client.ResourceName),
496		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
497	}
498
499	const APIVersion = "2016-08-10"
500	queryParameters := map[string]interface{}{
501		"api-version": APIVersion,
502	}
503
504	preparer := autorest.CreatePreparer(
505		autorest.AsGet(),
506		autorest.WithBaseURL(client.BaseURI),
507		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectionContainerMappings", pathParameters),
508		autorest.WithQueryParameters(queryParameters))
509	return preparer.Prepare((&http.Request{}).WithContext(ctx))
510}
511
512// ListByReplicationProtectionContainersSender sends the ListByReplicationProtectionContainers request. The method will close the
513// http.Response Body if it receives an error.
514func (client ReplicationProtectionContainerMappingsClient) ListByReplicationProtectionContainersSender(req *http.Request) (*http.Response, error) {
515	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
516}
517
518// ListByReplicationProtectionContainersResponder handles the response to the ListByReplicationProtectionContainers request. The method always
519// closes the http.Response Body.
520func (client ReplicationProtectionContainerMappingsClient) ListByReplicationProtectionContainersResponder(resp *http.Response) (result ProtectionContainerMappingCollection, err error) {
521	err = autorest.Respond(
522		resp,
523		azure.WithErrorUnlessStatusCode(http.StatusOK),
524		autorest.ByUnmarshallingJSON(&result),
525		autorest.ByClosing())
526	result.Response = autorest.Response{Response: resp}
527	return
528}
529
530// listByReplicationProtectionContainersNextResults retrieves the next set of results, if any.
531func (client ReplicationProtectionContainerMappingsClient) listByReplicationProtectionContainersNextResults(ctx context.Context, lastResults ProtectionContainerMappingCollection) (result ProtectionContainerMappingCollection, err error) {
532	req, err := lastResults.protectionContainerMappingCollectionPreparer(ctx)
533	if err != nil {
534		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "listByReplicationProtectionContainersNextResults", nil, "Failure preparing next results request")
535	}
536	if req == nil {
537		return
538	}
539	resp, err := client.ListByReplicationProtectionContainersSender(req)
540	if err != nil {
541		result.Response = autorest.Response{Response: resp}
542		return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "listByReplicationProtectionContainersNextResults", resp, "Failure sending next results request")
543	}
544	result, err = client.ListByReplicationProtectionContainersResponder(resp)
545	if err != nil {
546		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "listByReplicationProtectionContainersNextResults", resp, "Failure responding to next results request")
547	}
548	return
549}
550
551// ListByReplicationProtectionContainersComplete enumerates all values, automatically crossing page boundaries as required.
552func (client ReplicationProtectionContainerMappingsClient) ListByReplicationProtectionContainersComplete(ctx context.Context, fabricName string, protectionContainerName string) (result ProtectionContainerMappingCollectionIterator, err error) {
553	if tracing.IsEnabled() {
554		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainerMappingsClient.ListByReplicationProtectionContainers")
555		defer func() {
556			sc := -1
557			if result.Response().Response.Response != nil {
558				sc = result.page.Response().Response.Response.StatusCode
559			}
560			tracing.EndSpan(ctx, sc, err)
561		}()
562	}
563	result.page, err = client.ListByReplicationProtectionContainers(ctx, fabricName, protectionContainerName)
564	return
565}
566
567// Purge the operation to purge(force delete) a protection container mapping
568// Parameters:
569// fabricName - fabric name.
570// protectionContainerName - protection container name.
571// mappingName - protection container mapping name.
572func (client ReplicationProtectionContainerMappingsClient) Purge(ctx context.Context, fabricName string, protectionContainerName string, mappingName string) (result ReplicationProtectionContainerMappingsPurgeFuture, err error) {
573	if tracing.IsEnabled() {
574		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionContainerMappingsClient.Purge")
575		defer func() {
576			sc := -1
577			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
578				sc = result.FutureAPI.Response().StatusCode
579			}
580			tracing.EndSpan(ctx, sc, err)
581		}()
582	}
583	req, err := client.PurgePreparer(ctx, fabricName, protectionContainerName, mappingName)
584	if err != nil {
585		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "Purge", nil, "Failure preparing request")
586		return
587	}
588
589	result, err = client.PurgeSender(req)
590	if err != nil {
591		err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsClient", "Purge", nil, "Failure sending request")
592		return
593	}
594
595	return
596}
597
598// PurgePreparer prepares the Purge request.
599func (client ReplicationProtectionContainerMappingsClient) PurgePreparer(ctx context.Context, fabricName string, protectionContainerName string, mappingName string) (*http.Request, error) {
600	pathParameters := map[string]interface{}{
601		"fabricName":              autorest.Encode("path", fabricName),
602		"mappingName":             autorest.Encode("path", mappingName),
603		"protectionContainerName": autorest.Encode("path", protectionContainerName),
604		"resourceGroupName":       autorest.Encode("path", client.ResourceGroupName),
605		"resourceName":            autorest.Encode("path", client.ResourceName),
606		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
607	}
608
609	const APIVersion = "2016-08-10"
610	queryParameters := map[string]interface{}{
611		"api-version": APIVersion,
612	}
613
614	preparer := autorest.CreatePreparer(
615		autorest.AsDelete(),
616		autorest.WithBaseURL(client.BaseURI),
617		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectionContainerMappings/{mappingName}", pathParameters),
618		autorest.WithQueryParameters(queryParameters))
619	return preparer.Prepare((&http.Request{}).WithContext(ctx))
620}
621
622// PurgeSender sends the Purge request. The method will close the
623// http.Response Body if it receives an error.
624func (client ReplicationProtectionContainerMappingsClient) PurgeSender(req *http.Request) (future ReplicationProtectionContainerMappingsPurgeFuture, err error) {
625	var resp *http.Response
626	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
627	if err != nil {
628		return
629	}
630	var azf azure.Future
631	azf, err = azure.NewFutureFromResponse(resp)
632	future.FutureAPI = &azf
633	future.Result = func(client ReplicationProtectionContainerMappingsClient) (ar autorest.Response, err error) {
634		var done bool
635		done, err = future.DoneWithContext(context.Background(), client)
636		if err != nil {
637			err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionContainerMappingsPurgeFuture", "Result", future.Response(), "Polling failure")
638			return
639		}
640		if !done {
641			err = azure.NewAsyncOpIncompleteError("siterecovery.ReplicationProtectionContainerMappingsPurgeFuture")
642			return
643		}
644		ar.Response = future.Response()
645		return
646	}
647	return
648}
649
650// PurgeResponder handles the response to the Purge request. The method always
651// closes the http.Response Body.
652func (client ReplicationProtectionContainerMappingsClient) PurgeResponder(resp *http.Response) (result autorest.Response, err error) {
653	err = autorest.Respond(
654		resp,
655		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
656		autorest.ByClosing())
657	result.Response = resp
658	return
659}
660