1 package network
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/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type InboundNatRulesClient struct {
20 BaseClient
21 }
22
23
24 func NewInboundNatRulesClient(subscriptionID string) InboundNatRulesClient {
25 return NewInboundNatRulesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewInboundNatRulesClientWithBaseURI(baseURI string, subscriptionID string) InboundNatRulesClient {
31 return InboundNatRulesClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40 func (client InboundNatRulesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, inboundNatRuleParameters InboundNatRule) (result InboundNatRulesCreateOrUpdateFuture, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.CreateOrUpdate")
43 defer func() {
44 sc := -1
45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
46 sc = result.FutureAPI.Response().StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 if err := validation.Validate([]validation.Validation{
52 {TargetValue: inboundNatRuleParameters,
53 Constraints: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat", Name: validation.Null, Rule: false,
54 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration", Name: validation.Null, Rule: false,
55 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat", Name: validation.Null, Rule: false,
56 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress", Name: validation.Null, Rule: false,
57 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat", Name: validation.Null, Rule: false,
58 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration", Name: validation.Null, Rule: false,
59 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat", Name: validation.Null, Rule: false,
60 Chain: []validation.Constraint{{Target: "inboundNatRuleParameters.InboundNatRulePropertiesFormat.BackendIPConfiguration.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat.PublicIPAddress", Name: validation.Null, Rule: false, Chain: nil}}},
61 }},
62 }},
63 }},
64 }},
65 }},
66 }}}}}); err != nil {
67 return result, validation.NewError("network.InboundNatRulesClient", "CreateOrUpdate", err.Error())
68 }
69
70 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, loadBalancerName, inboundNatRuleName, inboundNatRuleParameters)
71 if err != nil {
72 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "CreateOrUpdate", nil, "Failure preparing request")
73 return
74 }
75
76 result, err = client.CreateOrUpdateSender(req)
77 if err != nil {
78 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
79 return
80 }
81
82 return
83 }
84
85
86 func (client InboundNatRulesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, inboundNatRuleParameters InboundNatRule) (*http.Request, error) {
87 pathParameters := map[string]interface{}{
88 "inboundNatRuleName": autorest.Encode("path", inboundNatRuleName),
89 "loadBalancerName": autorest.Encode("path", loadBalancerName),
90 "resourceGroupName": autorest.Encode("path", resourceGroupName),
91 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
92 }
93
94 const APIVersion = "2020-04-01"
95 queryParameters := map[string]interface{}{
96 "api-version": APIVersion,
97 }
98
99 inboundNatRuleParameters.Etag = nil
100 inboundNatRuleParameters.Type = nil
101 preparer := autorest.CreatePreparer(
102 autorest.AsContentType("application/json; charset=utf-8"),
103 autorest.AsPut(),
104 autorest.WithBaseURL(client.BaseURI),
105 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/inboundNatRules/{inboundNatRuleName}", pathParameters),
106 autorest.WithJSON(inboundNatRuleParameters),
107 autorest.WithQueryParameters(queryParameters))
108 return preparer.Prepare((&http.Request{}).WithContext(ctx))
109 }
110
111
112
113 func (client InboundNatRulesClient) CreateOrUpdateSender(req *http.Request) (future InboundNatRulesCreateOrUpdateFuture, err error) {
114 var resp *http.Response
115 future.FutureAPI = &azure.Future{}
116 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
117 if err != nil {
118 return
119 }
120 var azf azure.Future
121 azf, err = azure.NewFutureFromResponse(resp)
122 future.FutureAPI = &azf
123 future.Result = future.result
124 return
125 }
126
127
128
129 func (client InboundNatRulesClient) CreateOrUpdateResponder(resp *http.Response) (result InboundNatRule, err error) {
130 err = autorest.Respond(
131 resp,
132 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
133 autorest.ByUnmarshallingJSON(&result),
134 autorest.ByClosing())
135 result.Response = autorest.Response{Response: resp}
136 return
137 }
138
139
140
141
142
143
144 func (client InboundNatRulesClient) Delete(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string) (result InboundNatRulesDeleteFuture, err error) {
145 if tracing.IsEnabled() {
146 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.Delete")
147 defer func() {
148 sc := -1
149 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
150 sc = result.FutureAPI.Response().StatusCode
151 }
152 tracing.EndSpan(ctx, sc, err)
153 }()
154 }
155 req, err := client.DeletePreparer(ctx, resourceGroupName, loadBalancerName, inboundNatRuleName)
156 if err != nil {
157 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Delete", nil, "Failure preparing request")
158 return
159 }
160
161 result, err = client.DeleteSender(req)
162 if err != nil {
163 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Delete", result.Response(), "Failure sending request")
164 return
165 }
166
167 return
168 }
169
170
171 func (client InboundNatRulesClient) DeletePreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string) (*http.Request, error) {
172 pathParameters := map[string]interface{}{
173 "inboundNatRuleName": autorest.Encode("path", inboundNatRuleName),
174 "loadBalancerName": autorest.Encode("path", loadBalancerName),
175 "resourceGroupName": autorest.Encode("path", resourceGroupName),
176 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
177 }
178
179 const APIVersion = "2020-04-01"
180 queryParameters := map[string]interface{}{
181 "api-version": APIVersion,
182 }
183
184 preparer := autorest.CreatePreparer(
185 autorest.AsDelete(),
186 autorest.WithBaseURL(client.BaseURI),
187 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/inboundNatRules/{inboundNatRuleName}", pathParameters),
188 autorest.WithQueryParameters(queryParameters))
189 return preparer.Prepare((&http.Request{}).WithContext(ctx))
190 }
191
192
193
194 func (client InboundNatRulesClient) DeleteSender(req *http.Request) (future InboundNatRulesDeleteFuture, err error) {
195 var resp *http.Response
196 future.FutureAPI = &azure.Future{}
197 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
198 if err != nil {
199 return
200 }
201 var azf azure.Future
202 azf, err = azure.NewFutureFromResponse(resp)
203 future.FutureAPI = &azf
204 future.Result = future.result
205 return
206 }
207
208
209
210 func (client InboundNatRulesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
211 err = autorest.Respond(
212 resp,
213 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
214 autorest.ByClosing())
215 result.Response = resp
216 return
217 }
218
219
220
221
222
223
224
225 func (client InboundNatRulesClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, expand string) (result InboundNatRule, err error) {
226 if tracing.IsEnabled() {
227 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.Get")
228 defer func() {
229 sc := -1
230 if result.Response.Response != nil {
231 sc = result.Response.Response.StatusCode
232 }
233 tracing.EndSpan(ctx, sc, err)
234 }()
235 }
236 req, err := client.GetPreparer(ctx, resourceGroupName, loadBalancerName, inboundNatRuleName, expand)
237 if err != nil {
238 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Get", nil, "Failure preparing request")
239 return
240 }
241
242 resp, err := client.GetSender(req)
243 if err != nil {
244 result.Response = autorest.Response{Response: resp}
245 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Get", resp, "Failure sending request")
246 return
247 }
248
249 result, err = client.GetResponder(resp)
250 if err != nil {
251 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "Get", resp, "Failure responding to request")
252 return
253 }
254
255 return
256 }
257
258
259 func (client InboundNatRulesClient) GetPreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, inboundNatRuleName string, expand string) (*http.Request, error) {
260 pathParameters := map[string]interface{}{
261 "inboundNatRuleName": autorest.Encode("path", inboundNatRuleName),
262 "loadBalancerName": autorest.Encode("path", loadBalancerName),
263 "resourceGroupName": autorest.Encode("path", resourceGroupName),
264 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
265 }
266
267 const APIVersion = "2020-04-01"
268 queryParameters := map[string]interface{}{
269 "api-version": APIVersion,
270 }
271 if len(expand) > 0 {
272 queryParameters["$expand"] = autorest.Encode("query", expand)
273 }
274
275 preparer := autorest.CreatePreparer(
276 autorest.AsGet(),
277 autorest.WithBaseURL(client.BaseURI),
278 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/inboundNatRules/{inboundNatRuleName}", pathParameters),
279 autorest.WithQueryParameters(queryParameters))
280 return preparer.Prepare((&http.Request{}).WithContext(ctx))
281 }
282
283
284
285 func (client InboundNatRulesClient) GetSender(req *http.Request) (*http.Response, error) {
286 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
287 }
288
289
290
291 func (client InboundNatRulesClient) GetResponder(resp *http.Response) (result InboundNatRule, err error) {
292 err = autorest.Respond(
293 resp,
294 azure.WithErrorUnlessStatusCode(http.StatusOK),
295 autorest.ByUnmarshallingJSON(&result),
296 autorest.ByClosing())
297 result.Response = autorest.Response{Response: resp}
298 return
299 }
300
301
302
303
304
305 func (client InboundNatRulesClient) List(ctx context.Context, resourceGroupName string, loadBalancerName string) (result InboundNatRuleListResultPage, err error) {
306 if tracing.IsEnabled() {
307 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.List")
308 defer func() {
309 sc := -1
310 if result.inrlr.Response.Response != nil {
311 sc = result.inrlr.Response.Response.StatusCode
312 }
313 tracing.EndSpan(ctx, sc, err)
314 }()
315 }
316 result.fn = client.listNextResults
317 req, err := client.ListPreparer(ctx, resourceGroupName, loadBalancerName)
318 if err != nil {
319 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "List", nil, "Failure preparing request")
320 return
321 }
322
323 resp, err := client.ListSender(req)
324 if err != nil {
325 result.inrlr.Response = autorest.Response{Response: resp}
326 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "List", resp, "Failure sending request")
327 return
328 }
329
330 result.inrlr, err = client.ListResponder(resp)
331 if err != nil {
332 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "List", resp, "Failure responding to request")
333 return
334 }
335 if result.inrlr.hasNextLink() && result.inrlr.IsEmpty() {
336 err = result.NextWithContext(ctx)
337 return
338 }
339
340 return
341 }
342
343
344 func (client InboundNatRulesClient) ListPreparer(ctx context.Context, resourceGroupName string, loadBalancerName string) (*http.Request, error) {
345 pathParameters := map[string]interface{}{
346 "loadBalancerName": autorest.Encode("path", loadBalancerName),
347 "resourceGroupName": autorest.Encode("path", resourceGroupName),
348 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
349 }
350
351 const APIVersion = "2020-04-01"
352 queryParameters := map[string]interface{}{
353 "api-version": APIVersion,
354 }
355
356 preparer := autorest.CreatePreparer(
357 autorest.AsGet(),
358 autorest.WithBaseURL(client.BaseURI),
359 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/inboundNatRules", pathParameters),
360 autorest.WithQueryParameters(queryParameters))
361 return preparer.Prepare((&http.Request{}).WithContext(ctx))
362 }
363
364
365
366 func (client InboundNatRulesClient) ListSender(req *http.Request) (*http.Response, error) {
367 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
368 }
369
370
371
372 func (client InboundNatRulesClient) ListResponder(resp *http.Response) (result InboundNatRuleListResult, err error) {
373 err = autorest.Respond(
374 resp,
375 azure.WithErrorUnlessStatusCode(http.StatusOK),
376 autorest.ByUnmarshallingJSON(&result),
377 autorest.ByClosing())
378 result.Response = autorest.Response{Response: resp}
379 return
380 }
381
382
383 func (client InboundNatRulesClient) listNextResults(ctx context.Context, lastResults InboundNatRuleListResult) (result InboundNatRuleListResult, err error) {
384 req, err := lastResults.inboundNatRuleListResultPreparer(ctx)
385 if err != nil {
386 return result, autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "listNextResults", nil, "Failure preparing next results request")
387 }
388 if req == nil {
389 return
390 }
391 resp, err := client.ListSender(req)
392 if err != nil {
393 result.Response = autorest.Response{Response: resp}
394 return result, autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "listNextResults", resp, "Failure sending next results request")
395 }
396 result, err = client.ListResponder(resp)
397 if err != nil {
398 err = autorest.NewErrorWithError(err, "network.InboundNatRulesClient", "listNextResults", resp, "Failure responding to next results request")
399 }
400 return
401 }
402
403
404 func (client InboundNatRulesClient) ListComplete(ctx context.Context, resourceGroupName string, loadBalancerName string) (result InboundNatRuleListResultIterator, err error) {
405 if tracing.IsEnabled() {
406 ctx = tracing.StartSpan(ctx, fqdn+"/InboundNatRulesClient.List")
407 defer func() {
408 sc := -1
409 if result.Response().Response.Response != nil {
410 sc = result.page.Response().Response.Response.StatusCode
411 }
412 tracing.EndSpan(ctx, sc, err)
413 }()
414 }
415 result.page, err = client.List(ctx, resourceGroupName, loadBalancerName)
416 return
417 }
418
View as plain text