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 "net/http" 25) 26 27// WorkloadItemsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service 28type WorkloadItemsClient struct { 29 BaseClient 30} 31 32// NewWorkloadItemsClient creates an instance of the WorkloadItemsClient client. 33func NewWorkloadItemsClient(subscriptionID string) WorkloadItemsClient { 34 return NewWorkloadItemsClientWithBaseURI(DefaultBaseURI, subscriptionID) 35} 36 37// NewWorkloadItemsClientWithBaseURI creates an instance of the WorkloadItemsClient client. 38func NewWorkloadItemsClientWithBaseURI(baseURI string, subscriptionID string) WorkloadItemsClient { 39 return WorkloadItemsClient{NewWithBaseURI(baseURI, subscriptionID)} 40} 41 42// List provides a pageable list of workload item of a specific container according to the query filter and the 43// pagination 44// parameters. 45// Parameters: 46// vaultName - the name of the recovery services vault. 47// resourceGroupName - the name of the resource group where the recovery services vault is present. 48// fabricName - fabric name associated with the container. 49// containerName - name of the container. 50// filter - oData filter options. 51// skipToken - skipToken Filter. 52func (client WorkloadItemsClient) List(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string, skipToken string) (result WorkloadItemResourceListPage, err error) { 53 result.fn = client.listNextResults 54 req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, filter, skipToken) 55 if err != nil { 56 err = autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "List", nil, "Failure preparing request") 57 return 58 } 59 60 resp, err := client.ListSender(req) 61 if err != nil { 62 result.wirl.Response = autorest.Response{Response: resp} 63 err = autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "List", resp, "Failure sending request") 64 return 65 } 66 67 result.wirl, err = client.ListResponder(resp) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "List", resp, "Failure responding to request") 70 } 71 72 return 73} 74 75// ListPreparer prepares the List request. 76func (client WorkloadItemsClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string, skipToken string) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "containerName": autorest.Encode("path", containerName), 79 "fabricName": autorest.Encode("path", fabricName), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 "vaultName": autorest.Encode("path", vaultName), 83 } 84 85 const APIVersion = "2016-12-01" 86 queryParameters := map[string]interface{}{ 87 "api-version": APIVersion, 88 } 89 if len(filter) > 0 { 90 queryParameters["$filter"] = autorest.Encode("query", filter) 91 } 92 if len(skipToken) > 0 { 93 queryParameters["$skipToken"] = autorest.Encode("query", skipToken) 94 } 95 96 preparer := autorest.CreatePreparer( 97 autorest.AsGet(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/items", pathParameters), 100 autorest.WithQueryParameters(queryParameters)) 101 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 102} 103 104// ListSender sends the List request. The method will close the 105// http.Response Body if it receives an error. 106func (client WorkloadItemsClient) ListSender(req *http.Request) (*http.Response, error) { 107 return autorest.SendWithSender(client, req, 108 azure.DoRetryWithRegistration(client.Client)) 109} 110 111// ListResponder handles the response to the List request. The method always 112// closes the http.Response Body. 113func (client WorkloadItemsClient) ListResponder(resp *http.Response) (result WorkloadItemResourceList, err error) { 114 err = autorest.Respond( 115 resp, 116 client.ByInspecting(), 117 azure.WithErrorUnlessStatusCode(http.StatusOK), 118 autorest.ByUnmarshallingJSON(&result), 119 autorest.ByClosing()) 120 result.Response = autorest.Response{Response: resp} 121 return 122} 123 124// listNextResults retrieves the next set of results, if any. 125func (client WorkloadItemsClient) listNextResults(lastResults WorkloadItemResourceList) (result WorkloadItemResourceList, err error) { 126 req, err := lastResults.workloadItemResourceListPreparer() 127 if err != nil { 128 return result, autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "listNextResults", nil, "Failure preparing next results request") 129 } 130 if req == nil { 131 return 132 } 133 resp, err := client.ListSender(req) 134 if err != nil { 135 result.Response = autorest.Response{Response: resp} 136 return result, autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "listNextResults", resp, "Failure sending next results request") 137 } 138 result, err = client.ListResponder(resp) 139 if err != nil { 140 err = autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "listNextResults", resp, "Failure responding to next results request") 141 } 142 return 143} 144 145// ListComplete enumerates all values, automatically crossing page boundaries as required. 146func (client WorkloadItemsClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string, skipToken string) (result WorkloadItemResourceListIterator, err error) { 147 result.page, err = client.List(ctx, vaultName, resourceGroupName, fabricName, containerName, filter, skipToken) 148 return 149} 150