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// VirtualRouterPeeringsClient is the network Client 30type VirtualRouterPeeringsClient struct { 31 BaseClient 32} 33 34// NewVirtualRouterPeeringsClient creates an instance of the VirtualRouterPeeringsClient client. 35func NewVirtualRouterPeeringsClient(subscriptionID string) VirtualRouterPeeringsClient { 36 return NewVirtualRouterPeeringsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewVirtualRouterPeeringsClientWithBaseURI creates an instance of the VirtualRouterPeeringsClient client using a 40// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, 41// Azure stack). 42func NewVirtualRouterPeeringsClientWithBaseURI(baseURI string, subscriptionID string) VirtualRouterPeeringsClient { 43 return VirtualRouterPeeringsClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// CreateOrUpdate creates or updates the specified Virtual Router Peering. 47// Parameters: 48// resourceGroupName - the name of the resource group. 49// virtualRouterName - the name of the Virtual Router. 50// peeringName - the name of the Virtual Router Peering. 51// parameters - parameters supplied to the create or update Virtual Router Peering operation. 52func (client VirtualRouterPeeringsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string, parameters VirtualRouterPeering) (result VirtualRouterPeeringsCreateOrUpdateFuture, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualRouterPeeringsClient.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: parameters, 65 Constraints: []validation.Constraint{{Target: "parameters.VirtualRouterPeeringProperties", Name: validation.Null, Rule: false, 66 Chain: []validation.Constraint{{Target: "parameters.VirtualRouterPeeringProperties.PeerAsn", Name: validation.Null, Rule: false, 67 Chain: []validation.Constraint{{Target: "parameters.VirtualRouterPeeringProperties.PeerAsn", Name: validation.InclusiveMaximum, Rule: int64(4294967295), Chain: nil}, 68 {Target: "parameters.VirtualRouterPeeringProperties.PeerAsn", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}, 69 }}, 70 }}}}}); err != nil { 71 return result, validation.NewError("network.VirtualRouterPeeringsClient", "CreateOrUpdate", err.Error()) 72 } 73 74 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, virtualRouterName, peeringName, parameters) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "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.VirtualRouterPeeringsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 83 return 84 } 85 86 return 87} 88 89// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 90func (client VirtualRouterPeeringsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string, parameters VirtualRouterPeering) (*http.Request, error) { 91 pathParameters := map[string]interface{}{ 92 "peeringName": autorest.Encode("path", peeringName), 93 "resourceGroupName": autorest.Encode("path", resourceGroupName), 94 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 95 "virtualRouterName": autorest.Encode("path", virtualRouterName), 96 } 97 98 const APIVersion = "2019-11-01" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 parameters.Etag = nil 104 parameters.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/virtualRouters/{virtualRouterName}/peerings/{peeringName}", pathParameters), 110 autorest.WithJSON(parameters), 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 VirtualRouterPeeringsClient) CreateOrUpdateSender(req *http.Request) (future VirtualRouterPeeringsCreateOrUpdateFuture, 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 future.Future, err = azure.NewFutureFromResponse(resp) 124 return 125} 126 127// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 128// closes the http.Response Body. 129func (client VirtualRouterPeeringsClient) CreateOrUpdateResponder(resp *http.Response) (result VirtualRouterPeering, err error) { 130 err = autorest.Respond( 131 resp, 132 client.ByInspecting(), 133 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 134 autorest.ByUnmarshallingJSON(&result), 135 autorest.ByClosing()) 136 result.Response = autorest.Response{Response: resp} 137 return 138} 139 140// Delete deletes the specified peering from a Virtual Router. 141// Parameters: 142// resourceGroupName - the name of the resource group. 143// virtualRouterName - the name of the Virtual Router. 144// peeringName - the name of the peering. 145func (client VirtualRouterPeeringsClient) Delete(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string) (result VirtualRouterPeeringsDeleteFuture, err error) { 146 if tracing.IsEnabled() { 147 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualRouterPeeringsClient.Delete") 148 defer func() { 149 sc := -1 150 if result.Response() != nil { 151 sc = result.Response().StatusCode 152 } 153 tracing.EndSpan(ctx, sc, err) 154 }() 155 } 156 req, err := client.DeletePreparer(ctx, resourceGroupName, virtualRouterName, peeringName) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "Delete", nil, "Failure preparing request") 159 return 160 } 161 162 result, err = client.DeleteSender(req) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "Delete", result.Response(), "Failure sending request") 165 return 166 } 167 168 return 169} 170 171// DeletePreparer prepares the Delete request. 172func (client VirtualRouterPeeringsClient) DeletePreparer(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string) (*http.Request, error) { 173 pathParameters := map[string]interface{}{ 174 "peeringName": autorest.Encode("path", peeringName), 175 "resourceGroupName": autorest.Encode("path", resourceGroupName), 176 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 177 "virtualRouterName": autorest.Encode("path", virtualRouterName), 178 } 179 180 const APIVersion = "2019-11-01" 181 queryParameters := map[string]interface{}{ 182 "api-version": APIVersion, 183 } 184 185 preparer := autorest.CreatePreparer( 186 autorest.AsDelete(), 187 autorest.WithBaseURL(client.BaseURI), 188 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualRouters/{virtualRouterName}/peerings/{peeringName}", pathParameters), 189 autorest.WithQueryParameters(queryParameters)) 190 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 191} 192 193// DeleteSender sends the Delete request. The method will close the 194// http.Response Body if it receives an error. 195func (client VirtualRouterPeeringsClient) DeleteSender(req *http.Request) (future VirtualRouterPeeringsDeleteFuture, err error) { 196 var resp *http.Response 197 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 198 if err != nil { 199 return 200 } 201 future.Future, err = azure.NewFutureFromResponse(resp) 202 return 203} 204 205// DeleteResponder handles the response to the Delete request. The method always 206// closes the http.Response Body. 207func (client VirtualRouterPeeringsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 208 err = autorest.Respond( 209 resp, 210 client.ByInspecting(), 211 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 212 autorest.ByClosing()) 213 result.Response = resp 214 return 215} 216 217// Get gets the specified Virtual Router Peering. 218// Parameters: 219// resourceGroupName - the name of the resource group. 220// virtualRouterName - the name of the Virtual Router. 221// peeringName - the name of the Virtual Router Peering. 222func (client VirtualRouterPeeringsClient) Get(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string) (result VirtualRouterPeering, err error) { 223 if tracing.IsEnabled() { 224 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualRouterPeeringsClient.Get") 225 defer func() { 226 sc := -1 227 if result.Response.Response != nil { 228 sc = result.Response.Response.StatusCode 229 } 230 tracing.EndSpan(ctx, sc, err) 231 }() 232 } 233 req, err := client.GetPreparer(ctx, resourceGroupName, virtualRouterName, peeringName) 234 if err != nil { 235 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "Get", nil, "Failure preparing request") 236 return 237 } 238 239 resp, err := client.GetSender(req) 240 if err != nil { 241 result.Response = autorest.Response{Response: resp} 242 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "Get", resp, "Failure sending request") 243 return 244 } 245 246 result, err = client.GetResponder(resp) 247 if err != nil { 248 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "Get", resp, "Failure responding to request") 249 } 250 251 return 252} 253 254// GetPreparer prepares the Get request. 255func (client VirtualRouterPeeringsClient) GetPreparer(ctx context.Context, resourceGroupName string, virtualRouterName string, peeringName string) (*http.Request, error) { 256 pathParameters := map[string]interface{}{ 257 "peeringName": autorest.Encode("path", peeringName), 258 "resourceGroupName": autorest.Encode("path", resourceGroupName), 259 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 260 "virtualRouterName": autorest.Encode("path", virtualRouterName), 261 } 262 263 const APIVersion = "2019-11-01" 264 queryParameters := map[string]interface{}{ 265 "api-version": APIVersion, 266 } 267 268 preparer := autorest.CreatePreparer( 269 autorest.AsGet(), 270 autorest.WithBaseURL(client.BaseURI), 271 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualRouters/{virtualRouterName}/peerings/{peeringName}", pathParameters), 272 autorest.WithQueryParameters(queryParameters)) 273 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 274} 275 276// GetSender sends the Get request. The method will close the 277// http.Response Body if it receives an error. 278func (client VirtualRouterPeeringsClient) GetSender(req *http.Request) (*http.Response, error) { 279 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 280} 281 282// GetResponder handles the response to the Get request. The method always 283// closes the http.Response Body. 284func (client VirtualRouterPeeringsClient) GetResponder(resp *http.Response) (result VirtualRouterPeering, err error) { 285 err = autorest.Respond( 286 resp, 287 client.ByInspecting(), 288 azure.WithErrorUnlessStatusCode(http.StatusOK), 289 autorest.ByUnmarshallingJSON(&result), 290 autorest.ByClosing()) 291 result.Response = autorest.Response{Response: resp} 292 return 293} 294 295// List lists all Virtual Router Peerings in a Virtual Router resource. 296// Parameters: 297// resourceGroupName - the name of the resource group. 298// virtualRouterName - the name of the Virtual Router. 299func (client VirtualRouterPeeringsClient) List(ctx context.Context, resourceGroupName string, virtualRouterName string) (result VirtualRouterPeeringListResultPage, err error) { 300 if tracing.IsEnabled() { 301 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualRouterPeeringsClient.List") 302 defer func() { 303 sc := -1 304 if result.vrplr.Response.Response != nil { 305 sc = result.vrplr.Response.Response.StatusCode 306 } 307 tracing.EndSpan(ctx, sc, err) 308 }() 309 } 310 result.fn = client.listNextResults 311 req, err := client.ListPreparer(ctx, resourceGroupName, virtualRouterName) 312 if err != nil { 313 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "List", nil, "Failure preparing request") 314 return 315 } 316 317 resp, err := client.ListSender(req) 318 if err != nil { 319 result.vrplr.Response = autorest.Response{Response: resp} 320 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "List", resp, "Failure sending request") 321 return 322 } 323 324 result.vrplr, err = client.ListResponder(resp) 325 if err != nil { 326 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "List", resp, "Failure responding to request") 327 } 328 329 return 330} 331 332// ListPreparer prepares the List request. 333func (client VirtualRouterPeeringsClient) ListPreparer(ctx context.Context, resourceGroupName string, virtualRouterName string) (*http.Request, error) { 334 pathParameters := map[string]interface{}{ 335 "resourceGroupName": autorest.Encode("path", resourceGroupName), 336 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 337 "virtualRouterName": autorest.Encode("path", virtualRouterName), 338 } 339 340 const APIVersion = "2019-11-01" 341 queryParameters := map[string]interface{}{ 342 "api-version": APIVersion, 343 } 344 345 preparer := autorest.CreatePreparer( 346 autorest.AsGet(), 347 autorest.WithBaseURL(client.BaseURI), 348 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualRouters/{virtualRouterName}/peerings", pathParameters), 349 autorest.WithQueryParameters(queryParameters)) 350 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 351} 352 353// ListSender sends the List request. The method will close the 354// http.Response Body if it receives an error. 355func (client VirtualRouterPeeringsClient) ListSender(req *http.Request) (*http.Response, error) { 356 return client.Send(req, 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 VirtualRouterPeeringsClient) ListResponder(resp *http.Response) (result VirtualRouterPeeringListResult, 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 VirtualRouterPeeringsClient) listNextResults(ctx context.Context, lastResults VirtualRouterPeeringListResult) (result VirtualRouterPeeringListResult, err error) { 374 req, err := lastResults.virtualRouterPeeringListResultPreparer(ctx) 375 if err != nil { 376 return result, autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "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.VirtualRouterPeeringsClient", "listNextResults", resp, "Failure sending next results request") 385 } 386 result, err = client.ListResponder(resp) 387 if err != nil { 388 err = autorest.NewErrorWithError(err, "network.VirtualRouterPeeringsClient", "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 VirtualRouterPeeringsClient) ListComplete(ctx context.Context, resourceGroupName string, virtualRouterName string) (result VirtualRouterPeeringListResultIterator, err error) { 395 if tracing.IsEnabled() { 396 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualRouterPeeringsClient.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, virtualRouterName) 406 return 407} 408