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/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// ExpressRouteCircuitPeeringsClient is the network Client 30type ExpressRouteCircuitPeeringsClient struct { 31 BaseClient 32} 33 34// NewExpressRouteCircuitPeeringsClient creates an instance of the ExpressRouteCircuitPeeringsClient client. 35func NewExpressRouteCircuitPeeringsClient(subscriptionID string) ExpressRouteCircuitPeeringsClient { 36 return NewExpressRouteCircuitPeeringsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewExpressRouteCircuitPeeringsClientWithBaseURI creates an instance of the ExpressRouteCircuitPeeringsClient client 40// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 41// clouds, Azure stack). 42func NewExpressRouteCircuitPeeringsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteCircuitPeeringsClient { 43 return ExpressRouteCircuitPeeringsClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// CreateOrUpdate creates or updates a peering in the specified express route circuits. 47// Parameters: 48// resourceGroupName - the name of the resource group. 49// circuitName - the name of the express route circuit. 50// peeringName - the name of the peering. 51// peeringParameters - parameters supplied to the create or update express route circuit peering operation. 52func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, peeringParameters ExpressRouteCircuitPeering) (result ExpressRouteCircuitPeeringsCreateOrUpdateFuture, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.CreateOrUpdate") 55 defer func() { 56 sc := -1 57 if result.Response() != nil { 58 sc = result.Response().StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: peeringParameters, 65 Constraints: []validation.Constraint{{Target: "peeringParameters.ExpressRouteCircuitPeeringPropertiesFormat", Name: validation.Null, Rule: false, 66 Chain: []validation.Constraint{{Target: "peeringParameters.ExpressRouteCircuitPeeringPropertiesFormat.PeerASN", Name: validation.Null, Rule: false, 67 Chain: []validation.Constraint{{Target: "peeringParameters.ExpressRouteCircuitPeeringPropertiesFormat.PeerASN", Name: validation.InclusiveMaximum, Rule: int64(4294967295), Chain: nil}, 68 {Target: "peeringParameters.ExpressRouteCircuitPeeringPropertiesFormat.PeerASN", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, 69 }}, 70 }}}}}); err != nil { 71 return result, validation.NewError("network.ExpressRouteCircuitPeeringsClient", "CreateOrUpdate", err.Error()) 72 } 73 74 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, circuitName, peeringName, peeringParameters) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "CreateOrUpdate", nil, "Failure preparing request") 77 return 78 } 79 80 result, err = client.CreateOrUpdateSender(req) 81 if err != nil { 82 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "CreateOrUpdate", nil, "Failure sending request") 83 return 84 } 85 86 return 87} 88 89// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 90func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, peeringParameters ExpressRouteCircuitPeering) (*http.Request, error) { 91 pathParameters := map[string]interface{}{ 92 "circuitName": autorest.Encode("path", circuitName), 93 "peeringName": autorest.Encode("path", peeringName), 94 "resourceGroupName": autorest.Encode("path", resourceGroupName), 95 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 96 } 97 98 const APIVersion = "2019-07-01" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 peeringParameters.Etag = nil 104 peeringParameters.Type = nil 105 preparer := autorest.CreatePreparer( 106 autorest.AsContentType("application/json; charset=utf-8"), 107 autorest.AsPut(), 108 autorest.WithBaseURL(client.BaseURI), 109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}", pathParameters), 110 autorest.WithJSON(peeringParameters), 111 autorest.WithQueryParameters(queryParameters)) 112 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 113} 114 115// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 116// http.Response Body if it receives an error. 117func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCircuitPeeringsCreateOrUpdateFuture, err error) { 118 var resp *http.Response 119 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 120 if err != nil { 121 return 122 } 123 var azf azure.Future 124 azf, err = azure.NewFutureFromResponse(resp) 125 future.FutureAPI = &azf 126 future.Result = func(client ExpressRouteCircuitPeeringsClient) (ercp ExpressRouteCircuitPeering, err error) { 127 var done bool 128 done, err = future.DoneWithContext(context.Background(), client) 129 if err != nil { 130 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") 131 return 132 } 133 if !done { 134 err = azure.NewAsyncOpIncompleteError("network.ExpressRouteCircuitPeeringsCreateOrUpdateFuture") 135 return 136 } 137 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 138 if ercp.Response.Response, err = future.GetResult(sender); err == nil && ercp.Response.Response.StatusCode != http.StatusNoContent { 139 ercp, err = client.CreateOrUpdateResponder(ercp.Response.Response) 140 if err != nil { 141 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsCreateOrUpdateFuture", "Result", ercp.Response.Response, "Failure responding to request") 142 } 143 } 144 return 145 } 146 return 147} 148 149// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 150// closes the http.Response Body. 151func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteCircuitPeering, err error) { 152 err = autorest.Respond( 153 resp, 154 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 155 autorest.ByUnmarshallingJSON(&result), 156 autorest.ByClosing()) 157 result.Response = autorest.Response{Response: resp} 158 return 159} 160 161// Delete deletes the specified peering from the specified express route circuit. 162// Parameters: 163// resourceGroupName - the name of the resource group. 164// circuitName - the name of the express route circuit. 165// peeringName - the name of the peering. 166func (client ExpressRouteCircuitPeeringsClient) Delete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitPeeringsDeleteFuture, err error) { 167 if tracing.IsEnabled() { 168 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.Delete") 169 defer func() { 170 sc := -1 171 if result.Response() != nil { 172 sc = result.Response().StatusCode 173 } 174 tracing.EndSpan(ctx, sc, err) 175 }() 176 } 177 req, err := client.DeletePreparer(ctx, resourceGroupName, circuitName, peeringName) 178 if err != nil { 179 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Delete", nil, "Failure preparing request") 180 return 181 } 182 183 result, err = client.DeleteSender(req) 184 if err != nil { 185 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Delete", nil, "Failure sending request") 186 return 187 } 188 189 return 190} 191 192// DeletePreparer prepares the Delete request. 193func (client ExpressRouteCircuitPeeringsClient) DeletePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) { 194 pathParameters := map[string]interface{}{ 195 "circuitName": autorest.Encode("path", circuitName), 196 "peeringName": autorest.Encode("path", peeringName), 197 "resourceGroupName": autorest.Encode("path", resourceGroupName), 198 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 199 } 200 201 const APIVersion = "2019-07-01" 202 queryParameters := map[string]interface{}{ 203 "api-version": APIVersion, 204 } 205 206 preparer := autorest.CreatePreparer( 207 autorest.AsDelete(), 208 autorest.WithBaseURL(client.BaseURI), 209 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}", pathParameters), 210 autorest.WithQueryParameters(queryParameters)) 211 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 212} 213 214// DeleteSender sends the Delete request. The method will close the 215// http.Response Body if it receives an error. 216func (client ExpressRouteCircuitPeeringsClient) DeleteSender(req *http.Request) (future ExpressRouteCircuitPeeringsDeleteFuture, err error) { 217 var resp *http.Response 218 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 219 if err != nil { 220 return 221 } 222 var azf azure.Future 223 azf, err = azure.NewFutureFromResponse(resp) 224 future.FutureAPI = &azf 225 future.Result = func(client ExpressRouteCircuitPeeringsClient) (ar autorest.Response, err error) { 226 var done bool 227 done, err = future.DoneWithContext(context.Background(), client) 228 if err != nil { 229 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsDeleteFuture", "Result", future.Response(), "Polling failure") 230 return 231 } 232 if !done { 233 err = azure.NewAsyncOpIncompleteError("network.ExpressRouteCircuitPeeringsDeleteFuture") 234 return 235 } 236 ar.Response = future.Response() 237 return 238 } 239 return 240} 241 242// DeleteResponder handles the response to the Delete request. The method always 243// closes the http.Response Body. 244func (client ExpressRouteCircuitPeeringsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 245 err = autorest.Respond( 246 resp, 247 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 248 autorest.ByClosing()) 249 result.Response = resp 250 return 251} 252 253// Get gets the specified peering for the express route circuit. 254// Parameters: 255// resourceGroupName - the name of the resource group. 256// circuitName - the name of the express route circuit. 257// peeringName - the name of the peering. 258func (client ExpressRouteCircuitPeeringsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitPeering, err error) { 259 if tracing.IsEnabled() { 260 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.Get") 261 defer func() { 262 sc := -1 263 if result.Response.Response != nil { 264 sc = result.Response.Response.StatusCode 265 } 266 tracing.EndSpan(ctx, sc, err) 267 }() 268 } 269 req, err := client.GetPreparer(ctx, resourceGroupName, circuitName, peeringName) 270 if err != nil { 271 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Get", nil, "Failure preparing request") 272 return 273 } 274 275 resp, err := client.GetSender(req) 276 if err != nil { 277 result.Response = autorest.Response{Response: resp} 278 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Get", resp, "Failure sending request") 279 return 280 } 281 282 result, err = client.GetResponder(resp) 283 if err != nil { 284 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Get", resp, "Failure responding to request") 285 return 286 } 287 288 return 289} 290 291// GetPreparer prepares the Get request. 292func (client ExpressRouteCircuitPeeringsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) { 293 pathParameters := map[string]interface{}{ 294 "circuitName": autorest.Encode("path", circuitName), 295 "peeringName": autorest.Encode("path", peeringName), 296 "resourceGroupName": autorest.Encode("path", resourceGroupName), 297 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 298 } 299 300 const APIVersion = "2019-07-01" 301 queryParameters := map[string]interface{}{ 302 "api-version": APIVersion, 303 } 304 305 preparer := autorest.CreatePreparer( 306 autorest.AsGet(), 307 autorest.WithBaseURL(client.BaseURI), 308 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}", pathParameters), 309 autorest.WithQueryParameters(queryParameters)) 310 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 311} 312 313// GetSender sends the Get request. The method will close the 314// http.Response Body if it receives an error. 315func (client ExpressRouteCircuitPeeringsClient) GetSender(req *http.Request) (*http.Response, error) { 316 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 317} 318 319// GetResponder handles the response to the Get request. The method always 320// closes the http.Response Body. 321func (client ExpressRouteCircuitPeeringsClient) GetResponder(resp *http.Response) (result ExpressRouteCircuitPeering, err error) { 322 err = autorest.Respond( 323 resp, 324 azure.WithErrorUnlessStatusCode(http.StatusOK), 325 autorest.ByUnmarshallingJSON(&result), 326 autorest.ByClosing()) 327 result.Response = autorest.Response{Response: resp} 328 return 329} 330 331// List gets all peerings in a specified express route circuit. 332// Parameters: 333// resourceGroupName - the name of the resource group. 334// circuitName - the name of the express route circuit. 335func (client ExpressRouteCircuitPeeringsClient) List(ctx context.Context, resourceGroupName string, circuitName string) (result ExpressRouteCircuitPeeringListResultPage, err error) { 336 if tracing.IsEnabled() { 337 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.List") 338 defer func() { 339 sc := -1 340 if result.ercplr.Response.Response != nil { 341 sc = result.ercplr.Response.Response.StatusCode 342 } 343 tracing.EndSpan(ctx, sc, err) 344 }() 345 } 346 result.fn = client.listNextResults 347 req, err := client.ListPreparer(ctx, resourceGroupName, circuitName) 348 if err != nil { 349 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", nil, "Failure preparing request") 350 return 351 } 352 353 resp, err := client.ListSender(req) 354 if err != nil { 355 result.ercplr.Response = autorest.Response{Response: resp} 356 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure sending request") 357 return 358 } 359 360 result.ercplr, err = client.ListResponder(resp) 361 if err != nil { 362 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure responding to request") 363 return 364 } 365 if result.ercplr.hasNextLink() && result.ercplr.IsEmpty() { 366 err = result.NextWithContext(ctx) 367 return 368 } 369 370 return 371} 372 373// ListPreparer prepares the List request. 374func (client ExpressRouteCircuitPeeringsClient) ListPreparer(ctx context.Context, resourceGroupName string, circuitName string) (*http.Request, error) { 375 pathParameters := map[string]interface{}{ 376 "circuitName": autorest.Encode("path", circuitName), 377 "resourceGroupName": autorest.Encode("path", resourceGroupName), 378 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 379 } 380 381 const APIVersion = "2019-07-01" 382 queryParameters := map[string]interface{}{ 383 "api-version": APIVersion, 384 } 385 386 preparer := autorest.CreatePreparer( 387 autorest.AsGet(), 388 autorest.WithBaseURL(client.BaseURI), 389 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings", pathParameters), 390 autorest.WithQueryParameters(queryParameters)) 391 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 392} 393 394// ListSender sends the List request. The method will close the 395// http.Response Body if it receives an error. 396func (client ExpressRouteCircuitPeeringsClient) ListSender(req *http.Request) (*http.Response, error) { 397 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 398} 399 400// ListResponder handles the response to the List request. The method always 401// closes the http.Response Body. 402func (client ExpressRouteCircuitPeeringsClient) ListResponder(resp *http.Response) (result ExpressRouteCircuitPeeringListResult, err error) { 403 err = autorest.Respond( 404 resp, 405 azure.WithErrorUnlessStatusCode(http.StatusOK), 406 autorest.ByUnmarshallingJSON(&result), 407 autorest.ByClosing()) 408 result.Response = autorest.Response{Response: resp} 409 return 410} 411 412// listNextResults retrieves the next set of results, if any. 413func (client ExpressRouteCircuitPeeringsClient) listNextResults(ctx context.Context, lastResults ExpressRouteCircuitPeeringListResult) (result ExpressRouteCircuitPeeringListResult, err error) { 414 req, err := lastResults.expressRouteCircuitPeeringListResultPreparer(ctx) 415 if err != nil { 416 return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "listNextResults", nil, "Failure preparing next results request") 417 } 418 if req == nil { 419 return 420 } 421 resp, err := client.ListSender(req) 422 if err != nil { 423 result.Response = autorest.Response{Response: resp} 424 return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "listNextResults", resp, "Failure sending next results request") 425 } 426 result, err = client.ListResponder(resp) 427 if err != nil { 428 err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "listNextResults", resp, "Failure responding to next results request") 429 } 430 return 431} 432 433// ListComplete enumerates all values, automatically crossing page boundaries as required. 434func (client ExpressRouteCircuitPeeringsClient) ListComplete(ctx context.Context, resourceGroupName string, circuitName string) (result ExpressRouteCircuitPeeringListResultIterator, err error) { 435 if tracing.IsEnabled() { 436 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.List") 437 defer func() { 438 sc := -1 439 if result.Response().Response.Response != nil { 440 sc = result.page.Response().Response.Response.StatusCode 441 } 442 tracing.EndSpan(ctx, sc, err) 443 }() 444 } 445 result.page, err = client.List(ctx, resourceGroupName, circuitName) 446 return 447} 448