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