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