1package backup 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// ProtectionContainersGroupClient is the open API 2.0 Specs for Azure RecoveryServices Backup service 29type ProtectionContainersGroupClient struct { 30 BaseClient 31} 32 33// NewProtectionContainersGroupClient creates an instance of the ProtectionContainersGroupClient client. 34func NewProtectionContainersGroupClient(subscriptionID string) ProtectionContainersGroupClient { 35 return NewProtectionContainersGroupClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewProtectionContainersGroupClientWithBaseURI creates an instance of the ProtectionContainersGroupClient client 39// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 40// clouds, Azure stack). 41func NewProtectionContainersGroupClientWithBaseURI(baseURI string, subscriptionID string) ProtectionContainersGroupClient { 42 return ProtectionContainersGroupClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// List lists the containers registered to Recovery Services Vault. 46// Parameters: 47// vaultName - the name of the recovery services vault. 48// resourceGroupName - the name of the resource group where the recovery services vault is present. 49// filter - oData filter options. 50func (client ProtectionContainersGroupClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result ProtectionContainerResourceListPage, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersGroupClient.List") 53 defer func() { 54 sc := -1 55 if result.pcrl.Response.Response != nil { 56 sc = result.pcrl.Response.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 result.fn = client.listNextResults 62 req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "List", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.ListSender(req) 69 if err != nil { 70 result.pcrl.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "List", resp, "Failure sending request") 72 return 73 } 74 75 result.pcrl, err = client.ListResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "List", resp, "Failure responding to request") 78 } 79 80 return 81} 82 83// ListPreparer prepares the List request. 84func (client ProtectionContainersGroupClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string) (*http.Request, error) { 85 pathParameters := map[string]interface{}{ 86 "resourceGroupName": autorest.Encode("path", resourceGroupName), 87 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 88 "vaultName": autorest.Encode("path", vaultName), 89 } 90 91 const APIVersion = "2016-12-01" 92 queryParameters := map[string]interface{}{ 93 "api-version": APIVersion, 94 } 95 if len(filter) > 0 { 96 queryParameters["$filter"] = autorest.Encode("query", filter) 97 } 98 99 preparer := autorest.CreatePreparer( 100 autorest.AsGet(), 101 autorest.WithBaseURL(client.BaseURI), 102 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupProtectionContainers", pathParameters), 103 autorest.WithQueryParameters(queryParameters)) 104 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 105} 106 107// ListSender sends the List request. The method will close the 108// http.Response Body if it receives an error. 109func (client ProtectionContainersGroupClient) ListSender(req *http.Request) (*http.Response, error) { 110 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 111} 112 113// ListResponder handles the response to the List request. The method always 114// closes the http.Response Body. 115func (client ProtectionContainersGroupClient) ListResponder(resp *http.Response) (result ProtectionContainerResourceList, err error) { 116 err = autorest.Respond( 117 resp, 118 client.ByInspecting(), 119 azure.WithErrorUnlessStatusCode(http.StatusOK), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// listNextResults retrieves the next set of results, if any. 127func (client ProtectionContainersGroupClient) listNextResults(ctx context.Context, lastResults ProtectionContainerResourceList) (result ProtectionContainerResourceList, err error) { 128 req, err := lastResults.protectionContainerResourceListPreparer(ctx) 129 if err != nil { 130 return result, autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "listNextResults", nil, "Failure preparing next results request") 131 } 132 if req == nil { 133 return 134 } 135 resp, err := client.ListSender(req) 136 if err != nil { 137 result.Response = autorest.Response{Response: resp} 138 return result, autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "listNextResults", resp, "Failure sending next results request") 139 } 140 result, err = client.ListResponder(resp) 141 if err != nil { 142 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "listNextResults", resp, "Failure responding to next results request") 143 } 144 return 145} 146 147// ListComplete enumerates all values, automatically crossing page boundaries as required. 148func (client ProtectionContainersGroupClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result ProtectionContainerResourceListIterator, err error) { 149 if tracing.IsEnabled() { 150 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersGroupClient.List") 151 defer func() { 152 sc := -1 153 if result.Response().Response.Response != nil { 154 sc = result.page.Response().Response.Response.StatusCode 155 } 156 tracing.EndSpan(ctx, sc, err) 157 }() 158 } 159 result.page, err = client.List(ctx, vaultName, resourceGroupName, filter) 160 return 161} 162