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