1 package backup
2
3
4
5
6
7
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
18 type WorkloadItemsClient struct {
19 BaseClient
20 }
21
22
23 func NewWorkloadItemsClient(subscriptionID string) WorkloadItemsClient {
24 return NewWorkloadItemsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewWorkloadItemsClientWithBaseURI(baseURI string, subscriptionID string) WorkloadItemsClient {
30 return WorkloadItemsClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34
35
36
37
38
39
40
41
42
43 func (client WorkloadItemsClient) List(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string, skipToken string) (result WorkloadItemResourceListPage, err error) {
44 if tracing.IsEnabled() {
45 ctx = tracing.StartSpan(ctx, fqdn+"/WorkloadItemsClient.List")
46 defer func() {
47 sc := -1
48 if result.wirl.Response.Response != nil {
49 sc = result.wirl.Response.Response.StatusCode
50 }
51 tracing.EndSpan(ctx, sc, err)
52 }()
53 }
54 result.fn = client.listNextResults
55 req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, filter, skipToken)
56 if err != nil {
57 err = autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "List", nil, "Failure preparing request")
58 return
59 }
60
61 resp, err := client.ListSender(req)
62 if err != nil {
63 result.wirl.Response = autorest.Response{Response: resp}
64 err = autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "List", resp, "Failure sending request")
65 return
66 }
67
68 result.wirl, err = client.ListResponder(resp)
69 if err != nil {
70 err = autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "List", resp, "Failure responding to request")
71 return
72 }
73 if result.wirl.hasNextLink() && result.wirl.IsEmpty() {
74 err = result.NextWithContext(ctx)
75 return
76 }
77
78 return
79 }
80
81
82 func (client WorkloadItemsClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string, skipToken string) (*http.Request, error) {
83 pathParameters := map[string]interface{}{
84 "containerName": autorest.Encode("path", containerName),
85 "fabricName": autorest.Encode("path", fabricName),
86 "resourceGroupName": autorest.Encode("path", resourceGroupName),
87 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
88 "vaultName": autorest.Encode("path", vaultName),
89 }
90
91 const APIVersion = "2022-03-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 if len(skipToken) > 0 {
99 queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
100 }
101
102 preparer := autorest.CreatePreparer(
103 autorest.AsGet(),
104 autorest.WithBaseURL(client.BaseURI),
105 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/items", pathParameters),
106 autorest.WithQueryParameters(queryParameters))
107 return preparer.Prepare((&http.Request{}).WithContext(ctx))
108 }
109
110
111
112 func (client WorkloadItemsClient) ListSender(req *http.Request) (*http.Response, error) {
113 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
114 }
115
116
117
118 func (client WorkloadItemsClient) ListResponder(resp *http.Response) (result WorkloadItemResourceList, err error) {
119 err = autorest.Respond(
120 resp,
121 azure.WithErrorUnlessStatusCode(http.StatusOK),
122 autorest.ByUnmarshallingJSON(&result),
123 autorest.ByClosing())
124 result.Response = autorest.Response{Response: resp}
125 return
126 }
127
128
129 func (client WorkloadItemsClient) listNextResults(ctx context.Context, lastResults WorkloadItemResourceList) (result WorkloadItemResourceList, err error) {
130 req, err := lastResults.workloadItemResourceListPreparer(ctx)
131 if err != nil {
132 return result, autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "listNextResults", nil, "Failure preparing next results request")
133 }
134 if req == nil {
135 return
136 }
137 resp, err := client.ListSender(req)
138 if err != nil {
139 result.Response = autorest.Response{Response: resp}
140 return result, autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "listNextResults", resp, "Failure sending next results request")
141 }
142 result, err = client.ListResponder(resp)
143 if err != nil {
144 err = autorest.NewErrorWithError(err, "backup.WorkloadItemsClient", "listNextResults", resp, "Failure responding to next results request")
145 }
146 return
147 }
148
149
150 func (client WorkloadItemsClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string, skipToken string) (result WorkloadItemResourceListIterator, err error) {
151 if tracing.IsEnabled() {
152 ctx = tracing.StartSpan(ctx, fqdn+"/WorkloadItemsClient.List")
153 defer func() {
154 sc := -1
155 if result.Response().Response.Response != nil {
156 sc = result.page.Response().Response.Response.StatusCode
157 }
158 tracing.EndSpan(ctx, sc, err)
159 }()
160 }
161 result.page, err = client.List(ctx, vaultName, resourceGroupName, fabricName, containerName, filter, skipToken)
162 return
163 }
164
View as plain text