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/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// PublicIPAddressesClient is the network Client 19type PublicIPAddressesClient struct { 20 BaseClient 21} 22 23// NewPublicIPAddressesClient creates an instance of the PublicIPAddressesClient client. 24func NewPublicIPAddressesClient(subscriptionID string) PublicIPAddressesClient { 25 return NewPublicIPAddressesClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewPublicIPAddressesClientWithBaseURI creates an instance of the PublicIPAddressesClient client using a custom 29// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 30// stack). 31func NewPublicIPAddressesClientWithBaseURI(baseURI string, subscriptionID string) PublicIPAddressesClient { 32 return PublicIPAddressesClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// CreateOrUpdate creates or updates a static or dynamic public IP address. 36// Parameters: 37// resourceGroupName - the name of the resource group. 38// publicIPAddressName - the name of the public IP address. 39// parameters - parameters supplied to the create or update public IP address operation. 40func (client PublicIPAddressesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters PublicIPAddress) (result PublicIPAddressesCreateOrUpdateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/PublicIPAddressesClient.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: parameters, 53 Constraints: []validation.Constraint{{Target: "parameters.PublicIPAddressPropertiesFormat", Name: validation.Null, Rule: false, 54 Chain: []validation.Constraint{{Target: "parameters.PublicIPAddressPropertiesFormat.IPConfiguration", Name: validation.Null, Rule: false, 55 Chain: []validation.Constraint{{Target: "parameters.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat", Name: validation.Null, Rule: false, 56 Chain: []validation.Constraint{{Target: "parameters.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat.PublicIPAddress", Name: validation.Null, Rule: false, Chain: nil}}}, 57 }}, 58 }}}}}); err != nil { 59 return result, validation.NewError("network.PublicIPAddressesClient", "CreateOrUpdate", err.Error()) 60 } 61 62 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, publicIPAddressName, parameters) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "CreateOrUpdate", nil, "Failure preparing request") 65 return 66 } 67 68 result, err = client.CreateOrUpdateSender(req) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "CreateOrUpdate", nil, "Failure sending request") 71 return 72 } 73 74 return 75} 76 77// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 78func (client PublicIPAddressesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters PublicIPAddress) (*http.Request, error) { 79 pathParameters := map[string]interface{}{ 80 "publicIpAddressName": autorest.Encode("path", publicIPAddressName), 81 "resourceGroupName": autorest.Encode("path", resourceGroupName), 82 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 83 } 84 85 const APIVersion = "2015-06-15" 86 queryParameters := map[string]interface{}{ 87 "api-version": APIVersion, 88 } 89 90 preparer := autorest.CreatePreparer( 91 autorest.AsContentType("application/json; charset=utf-8"), 92 autorest.AsPut(), 93 autorest.WithBaseURL(client.BaseURI), 94 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}", pathParameters), 95 autorest.WithJSON(parameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 101// http.Response Body if it receives an error. 102func (client PublicIPAddressesClient) CreateOrUpdateSender(req *http.Request) (future PublicIPAddressesCreateOrUpdateFuture, err error) { 103 var resp *http.Response 104 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 105 if err != nil { 106 return 107 } 108 var azf azure.Future 109 azf, err = azure.NewFutureFromResponse(resp) 110 future.FutureAPI = &azf 111 future.Result = future.result 112 return 113} 114 115// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 116// closes the http.Response Body. 117func (client PublicIPAddressesClient) CreateOrUpdateResponder(resp *http.Response) (result PublicIPAddress, err error) { 118 err = autorest.Respond( 119 resp, 120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// Delete deletes the specified public IP address. 128// Parameters: 129// resourceGroupName - the name of the resource group. 130// publicIPAddressName - the name of the subnet. 131func (client PublicIPAddressesClient) Delete(ctx context.Context, resourceGroupName string, publicIPAddressName string) (result PublicIPAddressesDeleteFuture, err error) { 132 if tracing.IsEnabled() { 133 ctx = tracing.StartSpan(ctx, fqdn+"/PublicIPAddressesClient.Delete") 134 defer func() { 135 sc := -1 136 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 137 sc = result.FutureAPI.Response().StatusCode 138 } 139 tracing.EndSpan(ctx, sc, err) 140 }() 141 } 142 req, err := client.DeletePreparer(ctx, resourceGroupName, publicIPAddressName) 143 if err != nil { 144 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Delete", nil, "Failure preparing request") 145 return 146 } 147 148 result, err = client.DeleteSender(req) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Delete", nil, "Failure sending request") 151 return 152 } 153 154 return 155} 156 157// DeletePreparer prepares the Delete request. 158func (client PublicIPAddressesClient) DeletePreparer(ctx context.Context, resourceGroupName string, publicIPAddressName string) (*http.Request, error) { 159 pathParameters := map[string]interface{}{ 160 "publicIpAddressName": autorest.Encode("path", publicIPAddressName), 161 "resourceGroupName": autorest.Encode("path", resourceGroupName), 162 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 163 } 164 165 const APIVersion = "2015-06-15" 166 queryParameters := map[string]interface{}{ 167 "api-version": APIVersion, 168 } 169 170 preparer := autorest.CreatePreparer( 171 autorest.AsDelete(), 172 autorest.WithBaseURL(client.BaseURI), 173 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}", pathParameters), 174 autorest.WithQueryParameters(queryParameters)) 175 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 176} 177 178// DeleteSender sends the Delete request. The method will close the 179// http.Response Body if it receives an error. 180func (client PublicIPAddressesClient) DeleteSender(req *http.Request) (future PublicIPAddressesDeleteFuture, 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 var azf azure.Future 187 azf, err = azure.NewFutureFromResponse(resp) 188 future.FutureAPI = &azf 189 future.Result = future.result 190 return 191} 192 193// DeleteResponder handles the response to the Delete request. The method always 194// closes the http.Response Body. 195func (client PublicIPAddressesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 196 err = autorest.Respond( 197 resp, 198 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 199 autorest.ByClosing()) 200 result.Response = resp 201 return 202} 203 204// Get gets the specified public IP address in a specified resource group. 205// Parameters: 206// resourceGroupName - the name of the resource group. 207// publicIPAddressName - the name of the subnet. 208// expand - expands referenced resources. 209func (client PublicIPAddressesClient) Get(ctx context.Context, resourceGroupName string, publicIPAddressName string, expand string) (result PublicIPAddress, err error) { 210 if tracing.IsEnabled() { 211 ctx = tracing.StartSpan(ctx, fqdn+"/PublicIPAddressesClient.Get") 212 defer func() { 213 sc := -1 214 if result.Response.Response != nil { 215 sc = result.Response.Response.StatusCode 216 } 217 tracing.EndSpan(ctx, sc, err) 218 }() 219 } 220 req, err := client.GetPreparer(ctx, resourceGroupName, publicIPAddressName, expand) 221 if err != nil { 222 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Get", nil, "Failure preparing request") 223 return 224 } 225 226 resp, err := client.GetSender(req) 227 if err != nil { 228 result.Response = autorest.Response{Response: resp} 229 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Get", resp, "Failure sending request") 230 return 231 } 232 233 result, err = client.GetResponder(resp) 234 if err != nil { 235 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "Get", resp, "Failure responding to request") 236 return 237 } 238 239 return 240} 241 242// GetPreparer prepares the Get request. 243func (client PublicIPAddressesClient) GetPreparer(ctx context.Context, resourceGroupName string, publicIPAddressName string, expand string) (*http.Request, error) { 244 pathParameters := map[string]interface{}{ 245 "publicIpAddressName": autorest.Encode("path", publicIPAddressName), 246 "resourceGroupName": autorest.Encode("path", resourceGroupName), 247 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 248 } 249 250 const APIVersion = "2015-06-15" 251 queryParameters := map[string]interface{}{ 252 "api-version": APIVersion, 253 } 254 if len(expand) > 0 { 255 queryParameters["$expand"] = autorest.Encode("query", expand) 256 } 257 258 preparer := autorest.CreatePreparer( 259 autorest.AsGet(), 260 autorest.WithBaseURL(client.BaseURI), 261 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}", pathParameters), 262 autorest.WithQueryParameters(queryParameters)) 263 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 264} 265 266// GetSender sends the Get request. The method will close the 267// http.Response Body if it receives an error. 268func (client PublicIPAddressesClient) GetSender(req *http.Request) (*http.Response, error) { 269 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 270} 271 272// GetResponder handles the response to the Get request. The method always 273// closes the http.Response Body. 274func (client PublicIPAddressesClient) GetResponder(resp *http.Response) (result PublicIPAddress, err error) { 275 err = autorest.Respond( 276 resp, 277 azure.WithErrorUnlessStatusCode(http.StatusOK), 278 autorest.ByUnmarshallingJSON(&result), 279 autorest.ByClosing()) 280 result.Response = autorest.Response{Response: resp} 281 return 282} 283 284// List gets all public IP addresses in a resource group. 285// Parameters: 286// resourceGroupName - the name of the resource group. 287func (client PublicIPAddressesClient) List(ctx context.Context, resourceGroupName string) (result PublicIPAddressListResultPage, err error) { 288 if tracing.IsEnabled() { 289 ctx = tracing.StartSpan(ctx, fqdn+"/PublicIPAddressesClient.List") 290 defer func() { 291 sc := -1 292 if result.pialr.Response.Response != nil { 293 sc = result.pialr.Response.Response.StatusCode 294 } 295 tracing.EndSpan(ctx, sc, err) 296 }() 297 } 298 result.fn = client.listNextResults 299 req, err := client.ListPreparer(ctx, resourceGroupName) 300 if err != nil { 301 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", nil, "Failure preparing request") 302 return 303 } 304 305 resp, err := client.ListSender(req) 306 if err != nil { 307 result.pialr.Response = autorest.Response{Response: resp} 308 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", resp, "Failure sending request") 309 return 310 } 311 312 result.pialr, err = client.ListResponder(resp) 313 if err != nil { 314 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "List", resp, "Failure responding to request") 315 return 316 } 317 if result.pialr.hasNextLink() && result.pialr.IsEmpty() { 318 err = result.NextWithContext(ctx) 319 return 320 } 321 322 return 323} 324 325// ListPreparer prepares the List request. 326func (client PublicIPAddressesClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 327 pathParameters := map[string]interface{}{ 328 "resourceGroupName": autorest.Encode("path", resourceGroupName), 329 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 330 } 331 332 const APIVersion = "2015-06-15" 333 queryParameters := map[string]interface{}{ 334 "api-version": APIVersion, 335 } 336 337 preparer := autorest.CreatePreparer( 338 autorest.AsGet(), 339 autorest.WithBaseURL(client.BaseURI), 340 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses", pathParameters), 341 autorest.WithQueryParameters(queryParameters)) 342 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 343} 344 345// ListSender sends the List request. The method will close the 346// http.Response Body if it receives an error. 347func (client PublicIPAddressesClient) ListSender(req *http.Request) (*http.Response, error) { 348 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 349} 350 351// ListResponder handles the response to the List request. The method always 352// closes the http.Response Body. 353func (client PublicIPAddressesClient) ListResponder(resp *http.Response) (result PublicIPAddressListResult, err error) { 354 err = autorest.Respond( 355 resp, 356 azure.WithErrorUnlessStatusCode(http.StatusOK), 357 autorest.ByUnmarshallingJSON(&result), 358 autorest.ByClosing()) 359 result.Response = autorest.Response{Response: resp} 360 return 361} 362 363// listNextResults retrieves the next set of results, if any. 364func (client PublicIPAddressesClient) listNextResults(ctx context.Context, lastResults PublicIPAddressListResult) (result PublicIPAddressListResult, err error) { 365 req, err := lastResults.publicIPAddressListResultPreparer(ctx) 366 if err != nil { 367 return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listNextResults", nil, "Failure preparing next results request") 368 } 369 if req == nil { 370 return 371 } 372 resp, err := client.ListSender(req) 373 if err != nil { 374 result.Response = autorest.Response{Response: resp} 375 return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listNextResults", resp, "Failure sending next results request") 376 } 377 result, err = client.ListResponder(resp) 378 if err != nil { 379 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listNextResults", resp, "Failure responding to next results request") 380 } 381 return 382} 383 384// ListComplete enumerates all values, automatically crossing page boundaries as required. 385func (client PublicIPAddressesClient) ListComplete(ctx context.Context, resourceGroupName string) (result PublicIPAddressListResultIterator, err error) { 386 if tracing.IsEnabled() { 387 ctx = tracing.StartSpan(ctx, fqdn+"/PublicIPAddressesClient.List") 388 defer func() { 389 sc := -1 390 if result.Response().Response.Response != nil { 391 sc = result.page.Response().Response.Response.StatusCode 392 } 393 tracing.EndSpan(ctx, sc, err) 394 }() 395 } 396 result.page, err = client.List(ctx, resourceGroupName) 397 return 398} 399 400// ListAll gets all the public IP addresses in a subscription. 401func (client PublicIPAddressesClient) ListAll(ctx context.Context) (result PublicIPAddressListResultPage, err error) { 402 if tracing.IsEnabled() { 403 ctx = tracing.StartSpan(ctx, fqdn+"/PublicIPAddressesClient.ListAll") 404 defer func() { 405 sc := -1 406 if result.pialr.Response.Response != nil { 407 sc = result.pialr.Response.Response.StatusCode 408 } 409 tracing.EndSpan(ctx, sc, err) 410 }() 411 } 412 result.fn = client.listAllNextResults 413 req, err := client.ListAllPreparer(ctx) 414 if err != nil { 415 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", nil, "Failure preparing request") 416 return 417 } 418 419 resp, err := client.ListAllSender(req) 420 if err != nil { 421 result.pialr.Response = autorest.Response{Response: resp} 422 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", resp, "Failure sending request") 423 return 424 } 425 426 result.pialr, err = client.ListAllResponder(resp) 427 if err != nil { 428 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "ListAll", resp, "Failure responding to request") 429 return 430 } 431 if result.pialr.hasNextLink() && result.pialr.IsEmpty() { 432 err = result.NextWithContext(ctx) 433 return 434 } 435 436 return 437} 438 439// ListAllPreparer prepares the ListAll request. 440func (client PublicIPAddressesClient) ListAllPreparer(ctx context.Context) (*http.Request, error) { 441 pathParameters := map[string]interface{}{ 442 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 443 } 444 445 const APIVersion = "2015-06-15" 446 queryParameters := map[string]interface{}{ 447 "api-version": APIVersion, 448 } 449 450 preparer := autorest.CreatePreparer( 451 autorest.AsGet(), 452 autorest.WithBaseURL(client.BaseURI), 453 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/publicIPAddresses", pathParameters), 454 autorest.WithQueryParameters(queryParameters)) 455 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 456} 457 458// ListAllSender sends the ListAll request. The method will close the 459// http.Response Body if it receives an error. 460func (client PublicIPAddressesClient) ListAllSender(req *http.Request) (*http.Response, error) { 461 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 462} 463 464// ListAllResponder handles the response to the ListAll request. The method always 465// closes the http.Response Body. 466func (client PublicIPAddressesClient) ListAllResponder(resp *http.Response) (result PublicIPAddressListResult, err error) { 467 err = autorest.Respond( 468 resp, 469 azure.WithErrorUnlessStatusCode(http.StatusOK), 470 autorest.ByUnmarshallingJSON(&result), 471 autorest.ByClosing()) 472 result.Response = autorest.Response{Response: resp} 473 return 474} 475 476// listAllNextResults retrieves the next set of results, if any. 477func (client PublicIPAddressesClient) listAllNextResults(ctx context.Context, lastResults PublicIPAddressListResult) (result PublicIPAddressListResult, err error) { 478 req, err := lastResults.publicIPAddressListResultPreparer(ctx) 479 if err != nil { 480 return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listAllNextResults", nil, "Failure preparing next results request") 481 } 482 if req == nil { 483 return 484 } 485 resp, err := client.ListAllSender(req) 486 if err != nil { 487 result.Response = autorest.Response{Response: resp} 488 return result, autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listAllNextResults", resp, "Failure sending next results request") 489 } 490 result, err = client.ListAllResponder(resp) 491 if err != nil { 492 err = autorest.NewErrorWithError(err, "network.PublicIPAddressesClient", "listAllNextResults", resp, "Failure responding to next results request") 493 } 494 return 495} 496 497// ListAllComplete enumerates all values, automatically crossing page boundaries as required. 498func (client PublicIPAddressesClient) ListAllComplete(ctx context.Context) (result PublicIPAddressListResultIterator, err error) { 499 if tracing.IsEnabled() { 500 ctx = tracing.StartSpan(ctx, fqdn+"/PublicIPAddressesClient.ListAll") 501 defer func() { 502 sc := -1 503 if result.Response().Response.Response != nil { 504 sc = result.page.Response().Response.Response.StatusCode 505 } 506 tracing.EndSpan(ctx, sc, err) 507 }() 508 } 509 result.page, err = client.ListAll(ctx) 510 return 511} 512