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