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