1package network 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// VirtualNetworksClient is the network Client 29type VirtualNetworksClient struct { 30 BaseClient 31} 32 33// NewVirtualNetworksClient creates an instance of the VirtualNetworksClient client. 34func NewVirtualNetworksClient(subscriptionID string) VirtualNetworksClient { 35 return NewVirtualNetworksClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewVirtualNetworksClientWithBaseURI creates an instance of the VirtualNetworksClient client using a custom endpoint. 39// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 40func NewVirtualNetworksClientWithBaseURI(baseURI string, subscriptionID string) VirtualNetworksClient { 41 return VirtualNetworksClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// CheckIPAddressAvailability checks whether a private IP address is available for use. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// virtualNetworkName - the name of the virtual network. 48// IPAddress - the private IP address to be verified. 49func (client VirtualNetworksClient) CheckIPAddressAvailability(ctx context.Context, resourceGroupName string, virtualNetworkName string, IPAddress string) (result IPAddressAvailabilityResult, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.CheckIPAddressAvailability") 52 defer func() { 53 sc := -1 54 if result.Response.Response != nil { 55 sc = result.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 req, err := client.CheckIPAddressAvailabilityPreparer(ctx, resourceGroupName, virtualNetworkName, IPAddress) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "CheckIPAddressAvailability", nil, "Failure preparing request") 63 return 64 } 65 66 resp, err := client.CheckIPAddressAvailabilitySender(req) 67 if err != nil { 68 result.Response = autorest.Response{Response: resp} 69 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "CheckIPAddressAvailability", resp, "Failure sending request") 70 return 71 } 72 73 result, err = client.CheckIPAddressAvailabilityResponder(resp) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "CheckIPAddressAvailability", resp, "Failure responding to request") 76 } 77 78 return 79} 80 81// CheckIPAddressAvailabilityPreparer prepares the CheckIPAddressAvailability request. 82func (client VirtualNetworksClient) CheckIPAddressAvailabilityPreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string, IPAddress string) (*http.Request, error) { 83 pathParameters := map[string]interface{}{ 84 "resourceGroupName": autorest.Encode("path", resourceGroupName), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 "virtualNetworkName": autorest.Encode("path", virtualNetworkName), 87 } 88 89 const APIVersion = "2017-03-01" 90 queryParameters := map[string]interface{}{ 91 "api-version": APIVersion, 92 } 93 if len(IPAddress) > 0 { 94 queryParameters["ipAddress"] = autorest.Encode("query", IPAddress) 95 } 96 97 preparer := autorest.CreatePreparer( 98 autorest.AsGet(), 99 autorest.WithBaseURL(client.BaseURI), 100 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/CheckIPAddressAvailability", pathParameters), 101 autorest.WithQueryParameters(queryParameters)) 102 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 103} 104 105// CheckIPAddressAvailabilitySender sends the CheckIPAddressAvailability request. The method will close the 106// http.Response Body if it receives an error. 107func (client VirtualNetworksClient) CheckIPAddressAvailabilitySender(req *http.Request) (*http.Response, error) { 108 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 109} 110 111// CheckIPAddressAvailabilityResponder handles the response to the CheckIPAddressAvailability request. The method always 112// closes the http.Response Body. 113func (client VirtualNetworksClient) CheckIPAddressAvailabilityResponder(resp *http.Response) (result IPAddressAvailabilityResult, 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// CreateOrUpdate creates or updates a virtual network in the specified resource group. 125// Parameters: 126// resourceGroupName - the name of the resource group. 127// virtualNetworkName - the name of the virtual network. 128// parameters - parameters supplied to the create or update virtual network operation 129func (client VirtualNetworksClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters VirtualNetwork) (result VirtualNetworksCreateOrUpdateFuture, err error) { 130 if tracing.IsEnabled() { 131 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.CreateOrUpdate") 132 defer func() { 133 sc := -1 134 if result.Response() != nil { 135 sc = result.Response().StatusCode 136 } 137 tracing.EndSpan(ctx, sc, err) 138 }() 139 } 140 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, virtualNetworkName, parameters) 141 if err != nil { 142 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "CreateOrUpdate", nil, "Failure preparing request") 143 return 144 } 145 146 result, err = client.CreateOrUpdateSender(req) 147 if err != nil { 148 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "CreateOrUpdate", result.Response(), "Failure sending request") 149 return 150 } 151 152 return 153} 154 155// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 156func (client VirtualNetworksClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters VirtualNetwork) (*http.Request, error) { 157 pathParameters := map[string]interface{}{ 158 "resourceGroupName": autorest.Encode("path", resourceGroupName), 159 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 160 "virtualNetworkName": autorest.Encode("path", virtualNetworkName), 161 } 162 163 const APIVersion = "2017-03-01" 164 queryParameters := map[string]interface{}{ 165 "api-version": APIVersion, 166 } 167 168 preparer := autorest.CreatePreparer( 169 autorest.AsContentType("application/json; charset=utf-8"), 170 autorest.AsPut(), 171 autorest.WithBaseURL(client.BaseURI), 172 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}", pathParameters), 173 autorest.WithJSON(parameters), 174 autorest.WithQueryParameters(queryParameters)) 175 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 176} 177 178// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 179// http.Response Body if it receives an error. 180func (client VirtualNetworksClient) CreateOrUpdateSender(req *http.Request) (future VirtualNetworksCreateOrUpdateFuture, err error) { 181 var resp *http.Response 182 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 183 if err != nil { 184 return 185 } 186 future.Future, err = azure.NewFutureFromResponse(resp) 187 return 188} 189 190// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 191// closes the http.Response Body. 192func (client VirtualNetworksClient) CreateOrUpdateResponder(resp *http.Response) (result VirtualNetwork, err error) { 193 err = autorest.Respond( 194 resp, 195 client.ByInspecting(), 196 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 197 autorest.ByUnmarshallingJSON(&result), 198 autorest.ByClosing()) 199 result.Response = autorest.Response{Response: resp} 200 return 201} 202 203// Delete deletes the specified virtual network. 204// Parameters: 205// resourceGroupName - the name of the resource group. 206// virtualNetworkName - the name of the virtual network. 207func (client VirtualNetworksClient) Delete(ctx context.Context, resourceGroupName string, virtualNetworkName string) (result VirtualNetworksDeleteFuture, err error) { 208 if tracing.IsEnabled() { 209 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.Delete") 210 defer func() { 211 sc := -1 212 if result.Response() != nil { 213 sc = result.Response().StatusCode 214 } 215 tracing.EndSpan(ctx, sc, err) 216 }() 217 } 218 req, err := client.DeletePreparer(ctx, resourceGroupName, virtualNetworkName) 219 if err != nil { 220 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "Delete", nil, "Failure preparing request") 221 return 222 } 223 224 result, err = client.DeleteSender(req) 225 if err != nil { 226 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "Delete", result.Response(), "Failure sending request") 227 return 228 } 229 230 return 231} 232 233// DeletePreparer prepares the Delete request. 234func (client VirtualNetworksClient) DeletePreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string) (*http.Request, error) { 235 pathParameters := map[string]interface{}{ 236 "resourceGroupName": autorest.Encode("path", resourceGroupName), 237 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 238 "virtualNetworkName": autorest.Encode("path", virtualNetworkName), 239 } 240 241 const APIVersion = "2017-03-01" 242 queryParameters := map[string]interface{}{ 243 "api-version": APIVersion, 244 } 245 246 preparer := autorest.CreatePreparer( 247 autorest.AsDelete(), 248 autorest.WithBaseURL(client.BaseURI), 249 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}", pathParameters), 250 autorest.WithQueryParameters(queryParameters)) 251 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 252} 253 254// DeleteSender sends the Delete request. The method will close the 255// http.Response Body if it receives an error. 256func (client VirtualNetworksClient) DeleteSender(req *http.Request) (future VirtualNetworksDeleteFuture, err error) { 257 var resp *http.Response 258 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 259 if err != nil { 260 return 261 } 262 future.Future, err = azure.NewFutureFromResponse(resp) 263 return 264} 265 266// DeleteResponder handles the response to the Delete request. The method always 267// closes the http.Response Body. 268func (client VirtualNetworksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 269 err = autorest.Respond( 270 resp, 271 client.ByInspecting(), 272 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 273 autorest.ByClosing()) 274 result.Response = resp 275 return 276} 277 278// Get gets the specified virtual network by resource group. 279// Parameters: 280// resourceGroupName - the name of the resource group. 281// virtualNetworkName - the name of the virtual network. 282// expand - expands referenced resources. 283func (client VirtualNetworksClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, expand string) (result VirtualNetwork, err error) { 284 if tracing.IsEnabled() { 285 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.Get") 286 defer func() { 287 sc := -1 288 if result.Response.Response != nil { 289 sc = result.Response.Response.StatusCode 290 } 291 tracing.EndSpan(ctx, sc, err) 292 }() 293 } 294 req, err := client.GetPreparer(ctx, resourceGroupName, virtualNetworkName, expand) 295 if err != nil { 296 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "Get", nil, "Failure preparing request") 297 return 298 } 299 300 resp, err := client.GetSender(req) 301 if err != nil { 302 result.Response = autorest.Response{Response: resp} 303 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "Get", resp, "Failure sending request") 304 return 305 } 306 307 result, err = client.GetResponder(resp) 308 if err != nil { 309 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "Get", resp, "Failure responding to request") 310 } 311 312 return 313} 314 315// GetPreparer prepares the Get request. 316func (client VirtualNetworksClient) GetPreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string, expand string) (*http.Request, error) { 317 pathParameters := map[string]interface{}{ 318 "resourceGroupName": autorest.Encode("path", resourceGroupName), 319 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 320 "virtualNetworkName": autorest.Encode("path", virtualNetworkName), 321 } 322 323 const APIVersion = "2017-03-01" 324 queryParameters := map[string]interface{}{ 325 "api-version": APIVersion, 326 } 327 if len(expand) > 0 { 328 queryParameters["$expand"] = autorest.Encode("query", expand) 329 } 330 331 preparer := autorest.CreatePreparer( 332 autorest.AsGet(), 333 autorest.WithBaseURL(client.BaseURI), 334 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}", pathParameters), 335 autorest.WithQueryParameters(queryParameters)) 336 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 337} 338 339// GetSender sends the Get request. The method will close the 340// http.Response Body if it receives an error. 341func (client VirtualNetworksClient) GetSender(req *http.Request) (*http.Response, error) { 342 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 343} 344 345// GetResponder handles the response to the Get request. The method always 346// closes the http.Response Body. 347func (client VirtualNetworksClient) GetResponder(resp *http.Response) (result VirtualNetwork, err error) { 348 err = autorest.Respond( 349 resp, 350 client.ByInspecting(), 351 azure.WithErrorUnlessStatusCode(http.StatusOK), 352 autorest.ByUnmarshallingJSON(&result), 353 autorest.ByClosing()) 354 result.Response = autorest.Response{Response: resp} 355 return 356} 357 358// List gets all virtual networks in a resource group. 359// Parameters: 360// resourceGroupName - the name of the resource group. 361func (client VirtualNetworksClient) List(ctx context.Context, resourceGroupName string) (result VirtualNetworkListResultPage, err error) { 362 if tracing.IsEnabled() { 363 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.List") 364 defer func() { 365 sc := -1 366 if result.vnlr.Response.Response != nil { 367 sc = result.vnlr.Response.Response.StatusCode 368 } 369 tracing.EndSpan(ctx, sc, err) 370 }() 371 } 372 result.fn = client.listNextResults 373 req, err := client.ListPreparer(ctx, resourceGroupName) 374 if err != nil { 375 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "List", nil, "Failure preparing request") 376 return 377 } 378 379 resp, err := client.ListSender(req) 380 if err != nil { 381 result.vnlr.Response = autorest.Response{Response: resp} 382 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "List", resp, "Failure sending request") 383 return 384 } 385 386 result.vnlr, err = client.ListResponder(resp) 387 if err != nil { 388 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "List", resp, "Failure responding to request") 389 } 390 391 return 392} 393 394// ListPreparer prepares the List request. 395func (client VirtualNetworksClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 396 pathParameters := map[string]interface{}{ 397 "resourceGroupName": autorest.Encode("path", resourceGroupName), 398 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 399 } 400 401 const APIVersion = "2017-03-01" 402 queryParameters := map[string]interface{}{ 403 "api-version": APIVersion, 404 } 405 406 preparer := autorest.CreatePreparer( 407 autorest.AsGet(), 408 autorest.WithBaseURL(client.BaseURI), 409 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks", pathParameters), 410 autorest.WithQueryParameters(queryParameters)) 411 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 412} 413 414// ListSender sends the List request. The method will close the 415// http.Response Body if it receives an error. 416func (client VirtualNetworksClient) ListSender(req *http.Request) (*http.Response, error) { 417 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 418} 419 420// ListResponder handles the response to the List request. The method always 421// closes the http.Response Body. 422func (client VirtualNetworksClient) ListResponder(resp *http.Response) (result VirtualNetworkListResult, err error) { 423 err = autorest.Respond( 424 resp, 425 client.ByInspecting(), 426 azure.WithErrorUnlessStatusCode(http.StatusOK), 427 autorest.ByUnmarshallingJSON(&result), 428 autorest.ByClosing()) 429 result.Response = autorest.Response{Response: resp} 430 return 431} 432 433// listNextResults retrieves the next set of results, if any. 434func (client VirtualNetworksClient) listNextResults(ctx context.Context, lastResults VirtualNetworkListResult) (result VirtualNetworkListResult, err error) { 435 req, err := lastResults.virtualNetworkListResultPreparer(ctx) 436 if err != nil { 437 return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "listNextResults", nil, "Failure preparing next results request") 438 } 439 if req == nil { 440 return 441 } 442 resp, err := client.ListSender(req) 443 if err != nil { 444 result.Response = autorest.Response{Response: resp} 445 return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "listNextResults", resp, "Failure sending next results request") 446 } 447 result, err = client.ListResponder(resp) 448 if err != nil { 449 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "listNextResults", resp, "Failure responding to next results request") 450 } 451 return 452} 453 454// ListComplete enumerates all values, automatically crossing page boundaries as required. 455func (client VirtualNetworksClient) ListComplete(ctx context.Context, resourceGroupName string) (result VirtualNetworkListResultIterator, err error) { 456 if tracing.IsEnabled() { 457 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.List") 458 defer func() { 459 sc := -1 460 if result.Response().Response.Response != nil { 461 sc = result.page.Response().Response.Response.StatusCode 462 } 463 tracing.EndSpan(ctx, sc, err) 464 }() 465 } 466 result.page, err = client.List(ctx, resourceGroupName) 467 return 468} 469 470// ListAll gets all virtual networks in a subscription. 471func (client VirtualNetworksClient) ListAll(ctx context.Context) (result VirtualNetworkListResultPage, err error) { 472 if tracing.IsEnabled() { 473 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.ListAll") 474 defer func() { 475 sc := -1 476 if result.vnlr.Response.Response != nil { 477 sc = result.vnlr.Response.Response.StatusCode 478 } 479 tracing.EndSpan(ctx, sc, err) 480 }() 481 } 482 result.fn = client.listAllNextResults 483 req, err := client.ListAllPreparer(ctx) 484 if err != nil { 485 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListAll", nil, "Failure preparing request") 486 return 487 } 488 489 resp, err := client.ListAllSender(req) 490 if err != nil { 491 result.vnlr.Response = autorest.Response{Response: resp} 492 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListAll", resp, "Failure sending request") 493 return 494 } 495 496 result.vnlr, err = client.ListAllResponder(resp) 497 if err != nil { 498 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListAll", resp, "Failure responding to request") 499 } 500 501 return 502} 503 504// ListAllPreparer prepares the ListAll request. 505func (client VirtualNetworksClient) ListAllPreparer(ctx context.Context) (*http.Request, error) { 506 pathParameters := map[string]interface{}{ 507 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 508 } 509 510 const APIVersion = "2017-03-01" 511 queryParameters := map[string]interface{}{ 512 "api-version": APIVersion, 513 } 514 515 preparer := autorest.CreatePreparer( 516 autorest.AsGet(), 517 autorest.WithBaseURL(client.BaseURI), 518 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/virtualNetworks", pathParameters), 519 autorest.WithQueryParameters(queryParameters)) 520 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 521} 522 523// ListAllSender sends the ListAll request. The method will close the 524// http.Response Body if it receives an error. 525func (client VirtualNetworksClient) ListAllSender(req *http.Request) (*http.Response, error) { 526 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 527} 528 529// ListAllResponder handles the response to the ListAll request. The method always 530// closes the http.Response Body. 531func (client VirtualNetworksClient) ListAllResponder(resp *http.Response) (result VirtualNetworkListResult, err error) { 532 err = autorest.Respond( 533 resp, 534 client.ByInspecting(), 535 azure.WithErrorUnlessStatusCode(http.StatusOK), 536 autorest.ByUnmarshallingJSON(&result), 537 autorest.ByClosing()) 538 result.Response = autorest.Response{Response: resp} 539 return 540} 541 542// listAllNextResults retrieves the next set of results, if any. 543func (client VirtualNetworksClient) listAllNextResults(ctx context.Context, lastResults VirtualNetworkListResult) (result VirtualNetworkListResult, err error) { 544 req, err := lastResults.virtualNetworkListResultPreparer(ctx) 545 if err != nil { 546 return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "listAllNextResults", nil, "Failure preparing next results request") 547 } 548 if req == nil { 549 return 550 } 551 resp, err := client.ListAllSender(req) 552 if err != nil { 553 result.Response = autorest.Response{Response: resp} 554 return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "listAllNextResults", resp, "Failure sending next results request") 555 } 556 result, err = client.ListAllResponder(resp) 557 if err != nil { 558 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "listAllNextResults", resp, "Failure responding to next results request") 559 } 560 return 561} 562 563// ListAllComplete enumerates all values, automatically crossing page boundaries as required. 564func (client VirtualNetworksClient) ListAllComplete(ctx context.Context) (result VirtualNetworkListResultIterator, err error) { 565 if tracing.IsEnabled() { 566 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.ListAll") 567 defer func() { 568 sc := -1 569 if result.Response().Response.Response != nil { 570 sc = result.page.Response().Response.Response.StatusCode 571 } 572 tracing.EndSpan(ctx, sc, err) 573 }() 574 } 575 result.page, err = client.ListAll(ctx) 576 return 577} 578 579// ListUsage lists usage stats. 580// Parameters: 581// resourceGroupName - the name of the resource group. 582// virtualNetworkName - the name of the virtual network. 583func (client VirtualNetworksClient) ListUsage(ctx context.Context, resourceGroupName string, virtualNetworkName string) (result VirtualNetworkListUsageResultPage, err error) { 584 if tracing.IsEnabled() { 585 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.ListUsage") 586 defer func() { 587 sc := -1 588 if result.vnlur.Response.Response != nil { 589 sc = result.vnlur.Response.Response.StatusCode 590 } 591 tracing.EndSpan(ctx, sc, err) 592 }() 593 } 594 result.fn = client.listUsageNextResults 595 req, err := client.ListUsagePreparer(ctx, resourceGroupName, virtualNetworkName) 596 if err != nil { 597 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListUsage", nil, "Failure preparing request") 598 return 599 } 600 601 resp, err := client.ListUsageSender(req) 602 if err != nil { 603 result.vnlur.Response = autorest.Response{Response: resp} 604 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListUsage", resp, "Failure sending request") 605 return 606 } 607 608 result.vnlur, err = client.ListUsageResponder(resp) 609 if err != nil { 610 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "ListUsage", resp, "Failure responding to request") 611 } 612 613 return 614} 615 616// ListUsagePreparer prepares the ListUsage request. 617func (client VirtualNetworksClient) ListUsagePreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string) (*http.Request, error) { 618 pathParameters := map[string]interface{}{ 619 "resourceGroupName": autorest.Encode("path", resourceGroupName), 620 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 621 "virtualNetworkName": autorest.Encode("path", virtualNetworkName), 622 } 623 624 const APIVersion = "2017-03-01" 625 queryParameters := map[string]interface{}{ 626 "api-version": APIVersion, 627 } 628 629 preparer := autorest.CreatePreparer( 630 autorest.AsGet(), 631 autorest.WithBaseURL(client.BaseURI), 632 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/usages", pathParameters), 633 autorest.WithQueryParameters(queryParameters)) 634 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 635} 636 637// ListUsageSender sends the ListUsage request. The method will close the 638// http.Response Body if it receives an error. 639func (client VirtualNetworksClient) ListUsageSender(req *http.Request) (*http.Response, error) { 640 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 641} 642 643// ListUsageResponder handles the response to the ListUsage request. The method always 644// closes the http.Response Body. 645func (client VirtualNetworksClient) ListUsageResponder(resp *http.Response) (result VirtualNetworkListUsageResult, err error) { 646 err = autorest.Respond( 647 resp, 648 client.ByInspecting(), 649 azure.WithErrorUnlessStatusCode(http.StatusOK), 650 autorest.ByUnmarshallingJSON(&result), 651 autorest.ByClosing()) 652 result.Response = autorest.Response{Response: resp} 653 return 654} 655 656// listUsageNextResults retrieves the next set of results, if any. 657func (client VirtualNetworksClient) listUsageNextResults(ctx context.Context, lastResults VirtualNetworkListUsageResult) (result VirtualNetworkListUsageResult, err error) { 658 req, err := lastResults.virtualNetworkListUsageResultPreparer(ctx) 659 if err != nil { 660 return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "listUsageNextResults", nil, "Failure preparing next results request") 661 } 662 if req == nil { 663 return 664 } 665 resp, err := client.ListUsageSender(req) 666 if err != nil { 667 result.Response = autorest.Response{Response: resp} 668 return result, autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "listUsageNextResults", resp, "Failure sending next results request") 669 } 670 result, err = client.ListUsageResponder(resp) 671 if err != nil { 672 err = autorest.NewErrorWithError(err, "network.VirtualNetworksClient", "listUsageNextResults", resp, "Failure responding to next results request") 673 } 674 return 675} 676 677// ListUsageComplete enumerates all values, automatically crossing page boundaries as required. 678func (client VirtualNetworksClient) ListUsageComplete(ctx context.Context, resourceGroupName string, virtualNetworkName string) (result VirtualNetworkListUsageResultIterator, err error) { 679 if tracing.IsEnabled() { 680 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.ListUsage") 681 defer func() { 682 sc := -1 683 if result.Response().Response.Response != nil { 684 sc = result.page.Response().Response.Response.StatusCode 685 } 686 tracing.EndSpan(ctx, sc, err) 687 }() 688 } 689 result.page, err = client.ListUsage(ctx, resourceGroupName, virtualNetworkName) 690 return 691} 692