1package network 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 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// NatGatewaysClient is the network Client 18type NatGatewaysClient struct { 19 BaseClient 20} 21 22// NewNatGatewaysClient creates an instance of the NatGatewaysClient client. 23func NewNatGatewaysClient(subscriptionID string) NatGatewaysClient { 24 return NewNatGatewaysClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewNatGatewaysClientWithBaseURI creates an instance of the NatGatewaysClient client using a custom endpoint. Use 28// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewNatGatewaysClientWithBaseURI(baseURI string, subscriptionID string) NatGatewaysClient { 30 return NatGatewaysClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// CreateOrUpdate creates or updates a nat gateway. 34// Parameters: 35// resourceGroupName - the name of the resource group. 36// natGatewayName - the name of the nat gateway. 37// parameters - parameters supplied to the create or update nat gateway operation. 38func (client NatGatewaysClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, natGatewayName string, parameters NatGateway) (result NatGatewaysCreateOrUpdateFuture, err error) { 39 if tracing.IsEnabled() { 40 ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.CreateOrUpdate") 41 defer func() { 42 sc := -1 43 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 44 sc = result.FutureAPI.Response().StatusCode 45 } 46 tracing.EndSpan(ctx, sc, err) 47 }() 48 } 49 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, natGatewayName, parameters) 50 if err != nil { 51 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "CreateOrUpdate", nil, "Failure preparing request") 52 return 53 } 54 55 result, err = client.CreateOrUpdateSender(req) 56 if err != nil { 57 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "CreateOrUpdate", nil, "Failure sending request") 58 return 59 } 60 61 return 62} 63 64// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 65func (client NatGatewaysClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, natGatewayName string, parameters NatGateway) (*http.Request, error) { 66 pathParameters := map[string]interface{}{ 67 "natGatewayName": autorest.Encode("path", natGatewayName), 68 "resourceGroupName": autorest.Encode("path", resourceGroupName), 69 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 70 } 71 72 const APIVersion = "2020-07-01" 73 queryParameters := map[string]interface{}{ 74 "api-version": APIVersion, 75 } 76 77 parameters.Etag = nil 78 preparer := autorest.CreatePreparer( 79 autorest.AsContentType("application/json; charset=utf-8"), 80 autorest.AsPut(), 81 autorest.WithBaseURL(client.BaseURI), 82 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways/{natGatewayName}", pathParameters), 83 autorest.WithJSON(parameters), 84 autorest.WithQueryParameters(queryParameters)) 85 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 86} 87 88// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 89// http.Response Body if it receives an error. 90func (client NatGatewaysClient) CreateOrUpdateSender(req *http.Request) (future NatGatewaysCreateOrUpdateFuture, err error) { 91 var resp *http.Response 92 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 93 if err != nil { 94 return 95 } 96 var azf azure.Future 97 azf, err = azure.NewFutureFromResponse(resp) 98 future.FutureAPI = &azf 99 future.Result = future.result 100 return 101} 102 103// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 104// closes the http.Response Body. 105func (client NatGatewaysClient) CreateOrUpdateResponder(resp *http.Response) (result NatGateway, err error) { 106 err = autorest.Respond( 107 resp, 108 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted), 109 autorest.ByUnmarshallingJSON(&result), 110 autorest.ByClosing()) 111 result.Response = autorest.Response{Response: resp} 112 return 113} 114 115// Delete deletes the specified nat gateway. 116// Parameters: 117// resourceGroupName - the name of the resource group. 118// natGatewayName - the name of the nat gateway. 119func (client NatGatewaysClient) Delete(ctx context.Context, resourceGroupName string, natGatewayName string) (result NatGatewaysDeleteFuture, err error) { 120 if tracing.IsEnabled() { 121 ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.Delete") 122 defer func() { 123 sc := -1 124 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 125 sc = result.FutureAPI.Response().StatusCode 126 } 127 tracing.EndSpan(ctx, sc, err) 128 }() 129 } 130 req, err := client.DeletePreparer(ctx, resourceGroupName, natGatewayName) 131 if err != nil { 132 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Delete", nil, "Failure preparing request") 133 return 134 } 135 136 result, err = client.DeleteSender(req) 137 if err != nil { 138 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Delete", nil, "Failure sending request") 139 return 140 } 141 142 return 143} 144 145// DeletePreparer prepares the Delete request. 146func (client NatGatewaysClient) DeletePreparer(ctx context.Context, resourceGroupName string, natGatewayName string) (*http.Request, error) { 147 pathParameters := map[string]interface{}{ 148 "natGatewayName": autorest.Encode("path", natGatewayName), 149 "resourceGroupName": autorest.Encode("path", resourceGroupName), 150 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 151 } 152 153 const APIVersion = "2020-07-01" 154 queryParameters := map[string]interface{}{ 155 "api-version": APIVersion, 156 } 157 158 preparer := autorest.CreatePreparer( 159 autorest.AsDelete(), 160 autorest.WithBaseURL(client.BaseURI), 161 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways/{natGatewayName}", pathParameters), 162 autorest.WithQueryParameters(queryParameters)) 163 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 164} 165 166// DeleteSender sends the Delete request. The method will close the 167// http.Response Body if it receives an error. 168func (client NatGatewaysClient) DeleteSender(req *http.Request) (future NatGatewaysDeleteFuture, err error) { 169 var resp *http.Response 170 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 171 if err != nil { 172 return 173 } 174 var azf azure.Future 175 azf, err = azure.NewFutureFromResponse(resp) 176 future.FutureAPI = &azf 177 future.Result = future.result 178 return 179} 180 181// DeleteResponder handles the response to the Delete request. The method always 182// closes the http.Response Body. 183func (client NatGatewaysClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 184 err = autorest.Respond( 185 resp, 186 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 187 autorest.ByClosing()) 188 result.Response = resp 189 return 190} 191 192// Get gets the specified nat gateway in a specified resource group. 193// Parameters: 194// resourceGroupName - the name of the resource group. 195// natGatewayName - the name of the nat gateway. 196// expand - expands referenced resources. 197func (client NatGatewaysClient) Get(ctx context.Context, resourceGroupName string, natGatewayName string, expand string) (result NatGateway, err error) { 198 if tracing.IsEnabled() { 199 ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.Get") 200 defer func() { 201 sc := -1 202 if result.Response.Response != nil { 203 sc = result.Response.Response.StatusCode 204 } 205 tracing.EndSpan(ctx, sc, err) 206 }() 207 } 208 req, err := client.GetPreparer(ctx, resourceGroupName, natGatewayName, expand) 209 if err != nil { 210 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Get", nil, "Failure preparing request") 211 return 212 } 213 214 resp, err := client.GetSender(req) 215 if err != nil { 216 result.Response = autorest.Response{Response: resp} 217 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Get", resp, "Failure sending request") 218 return 219 } 220 221 result, err = client.GetResponder(resp) 222 if err != nil { 223 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "Get", resp, "Failure responding to request") 224 return 225 } 226 227 return 228} 229 230// GetPreparer prepares the Get request. 231func (client NatGatewaysClient) GetPreparer(ctx context.Context, resourceGroupName string, natGatewayName string, expand string) (*http.Request, error) { 232 pathParameters := map[string]interface{}{ 233 "natGatewayName": autorest.Encode("path", natGatewayName), 234 "resourceGroupName": autorest.Encode("path", resourceGroupName), 235 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 236 } 237 238 const APIVersion = "2020-07-01" 239 queryParameters := map[string]interface{}{ 240 "api-version": APIVersion, 241 } 242 if len(expand) > 0 { 243 queryParameters["$expand"] = autorest.Encode("query", expand) 244 } 245 246 preparer := autorest.CreatePreparer( 247 autorest.AsGet(), 248 autorest.WithBaseURL(client.BaseURI), 249 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways/{natGatewayName}", pathParameters), 250 autorest.WithQueryParameters(queryParameters)) 251 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 252} 253 254// GetSender sends the Get request. The method will close the 255// http.Response Body if it receives an error. 256func (client NatGatewaysClient) GetSender(req *http.Request) (*http.Response, error) { 257 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 258} 259 260// GetResponder handles the response to the Get request. The method always 261// closes the http.Response Body. 262func (client NatGatewaysClient) GetResponder(resp *http.Response) (result NatGateway, err error) { 263 err = autorest.Respond( 264 resp, 265 azure.WithErrorUnlessStatusCode(http.StatusOK), 266 autorest.ByUnmarshallingJSON(&result), 267 autorest.ByClosing()) 268 result.Response = autorest.Response{Response: resp} 269 return 270} 271 272// List gets all nat gateways in a resource group. 273// Parameters: 274// resourceGroupName - the name of the resource group. 275func (client NatGatewaysClient) List(ctx context.Context, resourceGroupName string) (result NatGatewayListResultPage, err error) { 276 if tracing.IsEnabled() { 277 ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.List") 278 defer func() { 279 sc := -1 280 if result.nglr.Response.Response != nil { 281 sc = result.nglr.Response.Response.StatusCode 282 } 283 tracing.EndSpan(ctx, sc, err) 284 }() 285 } 286 result.fn = client.listNextResults 287 req, err := client.ListPreparer(ctx, resourceGroupName) 288 if err != nil { 289 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "List", nil, "Failure preparing request") 290 return 291 } 292 293 resp, err := client.ListSender(req) 294 if err != nil { 295 result.nglr.Response = autorest.Response{Response: resp} 296 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "List", resp, "Failure sending request") 297 return 298 } 299 300 result.nglr, err = client.ListResponder(resp) 301 if err != nil { 302 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "List", resp, "Failure responding to request") 303 return 304 } 305 if result.nglr.hasNextLink() && result.nglr.IsEmpty() { 306 err = result.NextWithContext(ctx) 307 return 308 } 309 310 return 311} 312 313// ListPreparer prepares the List request. 314func (client NatGatewaysClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 315 pathParameters := map[string]interface{}{ 316 "resourceGroupName": autorest.Encode("path", resourceGroupName), 317 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 318 } 319 320 const APIVersion = "2020-07-01" 321 queryParameters := map[string]interface{}{ 322 "api-version": APIVersion, 323 } 324 325 preparer := autorest.CreatePreparer( 326 autorest.AsGet(), 327 autorest.WithBaseURL(client.BaseURI), 328 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways", pathParameters), 329 autorest.WithQueryParameters(queryParameters)) 330 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 331} 332 333// ListSender sends the List request. The method will close the 334// http.Response Body if it receives an error. 335func (client NatGatewaysClient) ListSender(req *http.Request) (*http.Response, error) { 336 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 337} 338 339// ListResponder handles the response to the List request. The method always 340// closes the http.Response Body. 341func (client NatGatewaysClient) ListResponder(resp *http.Response) (result NatGatewayListResult, err error) { 342 err = autorest.Respond( 343 resp, 344 azure.WithErrorUnlessStatusCode(http.StatusOK), 345 autorest.ByUnmarshallingJSON(&result), 346 autorest.ByClosing()) 347 result.Response = autorest.Response{Response: resp} 348 return 349} 350 351// listNextResults retrieves the next set of results, if any. 352func (client NatGatewaysClient) listNextResults(ctx context.Context, lastResults NatGatewayListResult) (result NatGatewayListResult, err error) { 353 req, err := lastResults.natGatewayListResultPreparer(ctx) 354 if err != nil { 355 return result, autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listNextResults", nil, "Failure preparing next results request") 356 } 357 if req == nil { 358 return 359 } 360 resp, err := client.ListSender(req) 361 if err != nil { 362 result.Response = autorest.Response{Response: resp} 363 return result, autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listNextResults", resp, "Failure sending next results request") 364 } 365 result, err = client.ListResponder(resp) 366 if err != nil { 367 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listNextResults", resp, "Failure responding to next results request") 368 } 369 return 370} 371 372// ListComplete enumerates all values, automatically crossing page boundaries as required. 373func (client NatGatewaysClient) ListComplete(ctx context.Context, resourceGroupName string) (result NatGatewayListResultIterator, err error) { 374 if tracing.IsEnabled() { 375 ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.List") 376 defer func() { 377 sc := -1 378 if result.Response().Response.Response != nil { 379 sc = result.page.Response().Response.Response.StatusCode 380 } 381 tracing.EndSpan(ctx, sc, err) 382 }() 383 } 384 result.page, err = client.List(ctx, resourceGroupName) 385 return 386} 387 388// ListAll gets all the Nat Gateways in a subscription. 389func (client NatGatewaysClient) ListAll(ctx context.Context) (result NatGatewayListResultPage, err error) { 390 if tracing.IsEnabled() { 391 ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.ListAll") 392 defer func() { 393 sc := -1 394 if result.nglr.Response.Response != nil { 395 sc = result.nglr.Response.Response.StatusCode 396 } 397 tracing.EndSpan(ctx, sc, err) 398 }() 399 } 400 result.fn = client.listAllNextResults 401 req, err := client.ListAllPreparer(ctx) 402 if err != nil { 403 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "ListAll", nil, "Failure preparing request") 404 return 405 } 406 407 resp, err := client.ListAllSender(req) 408 if err != nil { 409 result.nglr.Response = autorest.Response{Response: resp} 410 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "ListAll", resp, "Failure sending request") 411 return 412 } 413 414 result.nglr, err = client.ListAllResponder(resp) 415 if err != nil { 416 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "ListAll", resp, "Failure responding to request") 417 return 418 } 419 if result.nglr.hasNextLink() && result.nglr.IsEmpty() { 420 err = result.NextWithContext(ctx) 421 return 422 } 423 424 return 425} 426 427// ListAllPreparer prepares the ListAll request. 428func (client NatGatewaysClient) ListAllPreparer(ctx context.Context) (*http.Request, error) { 429 pathParameters := map[string]interface{}{ 430 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 431 } 432 433 const APIVersion = "2020-07-01" 434 queryParameters := map[string]interface{}{ 435 "api-version": APIVersion, 436 } 437 438 preparer := autorest.CreatePreparer( 439 autorest.AsGet(), 440 autorest.WithBaseURL(client.BaseURI), 441 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/natGateways", pathParameters), 442 autorest.WithQueryParameters(queryParameters)) 443 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 444} 445 446// ListAllSender sends the ListAll request. The method will close the 447// http.Response Body if it receives an error. 448func (client NatGatewaysClient) ListAllSender(req *http.Request) (*http.Response, error) { 449 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 450} 451 452// ListAllResponder handles the response to the ListAll request. The method always 453// closes the http.Response Body. 454func (client NatGatewaysClient) ListAllResponder(resp *http.Response) (result NatGatewayListResult, err error) { 455 err = autorest.Respond( 456 resp, 457 azure.WithErrorUnlessStatusCode(http.StatusOK), 458 autorest.ByUnmarshallingJSON(&result), 459 autorest.ByClosing()) 460 result.Response = autorest.Response{Response: resp} 461 return 462} 463 464// listAllNextResults retrieves the next set of results, if any. 465func (client NatGatewaysClient) listAllNextResults(ctx context.Context, lastResults NatGatewayListResult) (result NatGatewayListResult, err error) { 466 req, err := lastResults.natGatewayListResultPreparer(ctx) 467 if err != nil { 468 return result, autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listAllNextResults", nil, "Failure preparing next results request") 469 } 470 if req == nil { 471 return 472 } 473 resp, err := client.ListAllSender(req) 474 if err != nil { 475 result.Response = autorest.Response{Response: resp} 476 return result, autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listAllNextResults", resp, "Failure sending next results request") 477 } 478 result, err = client.ListAllResponder(resp) 479 if err != nil { 480 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "listAllNextResults", resp, "Failure responding to next results request") 481 } 482 return 483} 484 485// ListAllComplete enumerates all values, automatically crossing page boundaries as required. 486func (client NatGatewaysClient) ListAllComplete(ctx context.Context) (result NatGatewayListResultIterator, err error) { 487 if tracing.IsEnabled() { 488 ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.ListAll") 489 defer func() { 490 sc := -1 491 if result.Response().Response.Response != nil { 492 sc = result.page.Response().Response.Response.StatusCode 493 } 494 tracing.EndSpan(ctx, sc, err) 495 }() 496 } 497 result.page, err = client.ListAll(ctx) 498 return 499} 500 501// UpdateTags updates nat gateway tags. 502// Parameters: 503// resourceGroupName - the name of the resource group. 504// natGatewayName - the name of the nat gateway. 505// parameters - parameters supplied to update nat gateway tags. 506func (client NatGatewaysClient) UpdateTags(ctx context.Context, resourceGroupName string, natGatewayName string, parameters TagsObject) (result NatGateway, err error) { 507 if tracing.IsEnabled() { 508 ctx = tracing.StartSpan(ctx, fqdn+"/NatGatewaysClient.UpdateTags") 509 defer func() { 510 sc := -1 511 if result.Response.Response != nil { 512 sc = result.Response.Response.StatusCode 513 } 514 tracing.EndSpan(ctx, sc, err) 515 }() 516 } 517 req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, natGatewayName, parameters) 518 if err != nil { 519 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "UpdateTags", nil, "Failure preparing request") 520 return 521 } 522 523 resp, err := client.UpdateTagsSender(req) 524 if err != nil { 525 result.Response = autorest.Response{Response: resp} 526 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "UpdateTags", resp, "Failure sending request") 527 return 528 } 529 530 result, err = client.UpdateTagsResponder(resp) 531 if err != nil { 532 err = autorest.NewErrorWithError(err, "network.NatGatewaysClient", "UpdateTags", resp, "Failure responding to request") 533 return 534 } 535 536 return 537} 538 539// UpdateTagsPreparer prepares the UpdateTags request. 540func (client NatGatewaysClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, natGatewayName string, parameters TagsObject) (*http.Request, error) { 541 pathParameters := map[string]interface{}{ 542 "natGatewayName": autorest.Encode("path", natGatewayName), 543 "resourceGroupName": autorest.Encode("path", resourceGroupName), 544 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 545 } 546 547 const APIVersion = "2020-07-01" 548 queryParameters := map[string]interface{}{ 549 "api-version": APIVersion, 550 } 551 552 preparer := autorest.CreatePreparer( 553 autorest.AsContentType("application/json; charset=utf-8"), 554 autorest.AsPatch(), 555 autorest.WithBaseURL(client.BaseURI), 556 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/natGateways/{natGatewayName}", pathParameters), 557 autorest.WithJSON(parameters), 558 autorest.WithQueryParameters(queryParameters)) 559 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 560} 561 562// UpdateTagsSender sends the UpdateTags request. The method will close the 563// http.Response Body if it receives an error. 564func (client NatGatewaysClient) UpdateTagsSender(req *http.Request) (*http.Response, error) { 565 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 566} 567 568// UpdateTagsResponder handles the response to the UpdateTags request. The method always 569// closes the http.Response Body. 570func (client NatGatewaysClient) UpdateTagsResponder(resp *http.Response) (result NatGateway, err error) { 571 err = autorest.Respond( 572 resp, 573 azure.WithErrorUnlessStatusCode(http.StatusOK), 574 autorest.ByUnmarshallingJSON(&result), 575 autorest.ByClosing()) 576 result.Response = autorest.Response{Response: resp} 577 return 578} 579