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