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