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/tracing" 25 "net/http" 26) 27 28// VirtualHubBgpConnectionsClient is the network Client 29type VirtualHubBgpConnectionsClient struct { 30 BaseClient 31} 32 33// NewVirtualHubBgpConnectionsClient creates an instance of the VirtualHubBgpConnectionsClient client. 34func NewVirtualHubBgpConnectionsClient(subscriptionID string) VirtualHubBgpConnectionsClient { 35 return NewVirtualHubBgpConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewVirtualHubBgpConnectionsClientWithBaseURI creates an instance of the VirtualHubBgpConnectionsClient client using 39// a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 40// clouds, Azure stack). 41func NewVirtualHubBgpConnectionsClientWithBaseURI(baseURI string, subscriptionID string) VirtualHubBgpConnectionsClient { 42 return VirtualHubBgpConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// List retrieves the details of all VirtualHubBgpConnections. 46// Parameters: 47// resourceGroupName - the resource group name of the VirtualHub. 48// virtualHubName - the name of the VirtualHub. 49func (client VirtualHubBgpConnectionsClient) List(ctx context.Context, resourceGroupName string, virtualHubName string) (result ListVirtualHubBgpConnectionResultsPage, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubBgpConnectionsClient.List") 52 defer func() { 53 sc := -1 54 if result.lvhbcr.Response.Response != nil { 55 sc = result.lvhbcr.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 result.fn = client.listNextResults 61 req, err := client.ListPreparer(ctx, resourceGroupName, virtualHubName) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "List", nil, "Failure preparing request") 64 return 65 } 66 67 resp, err := client.ListSender(req) 68 if err != nil { 69 result.lvhbcr.Response = autorest.Response{Response: resp} 70 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "List", resp, "Failure sending request") 71 return 72 } 73 74 result.lvhbcr, err = client.ListResponder(resp) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "List", resp, "Failure responding to request") 77 return 78 } 79 if result.lvhbcr.hasNextLink() && result.lvhbcr.IsEmpty() { 80 err = result.NextWithContext(ctx) 81 return 82 } 83 84 return 85} 86 87// ListPreparer prepares the List request. 88func (client VirtualHubBgpConnectionsClient) ListPreparer(ctx context.Context, resourceGroupName string, virtualHubName string) (*http.Request, error) { 89 pathParameters := map[string]interface{}{ 90 "resourceGroupName": autorest.Encode("path", resourceGroupName), 91 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 92 "virtualHubName": autorest.Encode("path", virtualHubName), 93 } 94 95 const APIVersion = "2020-07-01" 96 queryParameters := map[string]interface{}{ 97 "api-version": APIVersion, 98 } 99 100 preparer := autorest.CreatePreparer( 101 autorest.AsGet(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/bgpConnections", pathParameters), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// ListSender sends the List request. The method will close the 109// http.Response Body if it receives an error. 110func (client VirtualHubBgpConnectionsClient) ListSender(req *http.Request) (*http.Response, error) { 111 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 112} 113 114// ListResponder handles the response to the List request. The method always 115// closes the http.Response Body. 116func (client VirtualHubBgpConnectionsClient) ListResponder(resp *http.Response) (result ListVirtualHubBgpConnectionResults, err error) { 117 err = autorest.Respond( 118 resp, 119 azure.WithErrorUnlessStatusCode(http.StatusOK), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// listNextResults retrieves the next set of results, if any. 127func (client VirtualHubBgpConnectionsClient) listNextResults(ctx context.Context, lastResults ListVirtualHubBgpConnectionResults) (result ListVirtualHubBgpConnectionResults, err error) { 128 req, err := lastResults.listVirtualHubBgpConnectionResultsPreparer(ctx) 129 if err != nil { 130 return result, autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "listNextResults", nil, "Failure preparing next results request") 131 } 132 if req == nil { 133 return 134 } 135 resp, err := client.ListSender(req) 136 if err != nil { 137 result.Response = autorest.Response{Response: resp} 138 return result, autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "listNextResults", resp, "Failure sending next results request") 139 } 140 result, err = client.ListResponder(resp) 141 if err != nil { 142 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "listNextResults", resp, "Failure responding to next results request") 143 } 144 return 145} 146 147// ListComplete enumerates all values, automatically crossing page boundaries as required. 148func (client VirtualHubBgpConnectionsClient) ListComplete(ctx context.Context, resourceGroupName string, virtualHubName string) (result ListVirtualHubBgpConnectionResultsIterator, err error) { 149 if tracing.IsEnabled() { 150 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubBgpConnectionsClient.List") 151 defer func() { 152 sc := -1 153 if result.Response().Response.Response != nil { 154 sc = result.page.Response().Response.Response.StatusCode 155 } 156 tracing.EndSpan(ctx, sc, err) 157 }() 158 } 159 result.page, err = client.List(ctx, resourceGroupName, virtualHubName) 160 return 161} 162 163// ListAdvertisedRoutes retrieves a list of routes the virtual hub bgp connection is advertising to the specified peer. 164// Parameters: 165// resourceGroupName - the name of the resource group. 166// hubName - the name of the virtual hub. 167// connectionName - the name of the virtual hub bgp connection. 168func (client VirtualHubBgpConnectionsClient) ListAdvertisedRoutes(ctx context.Context, resourceGroupName string, hubName string, connectionName string) (result VirtualHubBgpConnectionsListAdvertisedRoutesFuture, err error) { 169 if tracing.IsEnabled() { 170 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubBgpConnectionsClient.ListAdvertisedRoutes") 171 defer func() { 172 sc := -1 173 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 174 sc = result.FutureAPI.Response().StatusCode 175 } 176 tracing.EndSpan(ctx, sc, err) 177 }() 178 } 179 req, err := client.ListAdvertisedRoutesPreparer(ctx, resourceGroupName, hubName, connectionName) 180 if err != nil { 181 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "ListAdvertisedRoutes", nil, "Failure preparing request") 182 return 183 } 184 185 result, err = client.ListAdvertisedRoutesSender(req) 186 if err != nil { 187 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "ListAdvertisedRoutes", nil, "Failure sending request") 188 return 189 } 190 191 return 192} 193 194// ListAdvertisedRoutesPreparer prepares the ListAdvertisedRoutes request. 195func (client VirtualHubBgpConnectionsClient) ListAdvertisedRoutesPreparer(ctx context.Context, resourceGroupName string, hubName string, connectionName string) (*http.Request, error) { 196 pathParameters := map[string]interface{}{ 197 "connectionName": autorest.Encode("path", connectionName), 198 "hubName": autorest.Encode("path", hubName), 199 "resourceGroupName": autorest.Encode("path", resourceGroupName), 200 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 201 } 202 203 const APIVersion = "2020-07-01" 204 queryParameters := map[string]interface{}{ 205 "api-version": APIVersion, 206 } 207 208 preparer := autorest.CreatePreparer( 209 autorest.AsPost(), 210 autorest.WithBaseURL(client.BaseURI), 211 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{hubName}/bgpConnections/{connectionName}/advertisedRoutes", pathParameters), 212 autorest.WithQueryParameters(queryParameters)) 213 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 214} 215 216// ListAdvertisedRoutesSender sends the ListAdvertisedRoutes request. The method will close the 217// http.Response Body if it receives an error. 218func (client VirtualHubBgpConnectionsClient) ListAdvertisedRoutesSender(req *http.Request) (future VirtualHubBgpConnectionsListAdvertisedRoutesFuture, err error) { 219 var resp *http.Response 220 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 221 if err != nil { 222 return 223 } 224 var azf azure.Future 225 azf, err = azure.NewFutureFromResponse(resp) 226 future.FutureAPI = &azf 227 future.Result = func(client VirtualHubBgpConnectionsClient) (prl PeerRouteList, err error) { 228 var done bool 229 done, err = future.DoneWithContext(context.Background(), client) 230 if err != nil { 231 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsListAdvertisedRoutesFuture", "Result", future.Response(), "Polling failure") 232 return 233 } 234 if !done { 235 err = azure.NewAsyncOpIncompleteError("network.VirtualHubBgpConnectionsListAdvertisedRoutesFuture") 236 return 237 } 238 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 239 prl.Response.Response, err = future.GetResult(sender) 240 if prl.Response.Response == nil && err == nil { 241 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsListAdvertisedRoutesFuture", "Result", nil, "received nil response and error") 242 } 243 if err == nil && prl.Response.Response.StatusCode != http.StatusNoContent { 244 prl, err = client.ListAdvertisedRoutesResponder(prl.Response.Response) 245 if err != nil { 246 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsListAdvertisedRoutesFuture", "Result", prl.Response.Response, "Failure responding to request") 247 } 248 } 249 return 250 } 251 return 252} 253 254// ListAdvertisedRoutesResponder handles the response to the ListAdvertisedRoutes request. The method always 255// closes the http.Response Body. 256func (client VirtualHubBgpConnectionsClient) ListAdvertisedRoutesResponder(resp *http.Response) (result PeerRouteList, err error) { 257 err = autorest.Respond( 258 resp, 259 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 260 autorest.ByUnmarshallingJSON(&result), 261 autorest.ByClosing()) 262 result.Response = autorest.Response{Response: resp} 263 return 264} 265 266// ListLearnedRoutes retrieves a list of routes the virtual hub bgp connection has learned. 267// Parameters: 268// resourceGroupName - the name of the resource group. 269// hubName - the name of the virtual hub. 270// connectionName - the name of the virtual hub bgp connection. 271func (client VirtualHubBgpConnectionsClient) ListLearnedRoutes(ctx context.Context, resourceGroupName string, hubName string, connectionName string) (result VirtualHubBgpConnectionsListLearnedRoutesFuture, err error) { 272 if tracing.IsEnabled() { 273 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubBgpConnectionsClient.ListLearnedRoutes") 274 defer func() { 275 sc := -1 276 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 277 sc = result.FutureAPI.Response().StatusCode 278 } 279 tracing.EndSpan(ctx, sc, err) 280 }() 281 } 282 req, err := client.ListLearnedRoutesPreparer(ctx, resourceGroupName, hubName, connectionName) 283 if err != nil { 284 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "ListLearnedRoutes", nil, "Failure preparing request") 285 return 286 } 287 288 result, err = client.ListLearnedRoutesSender(req) 289 if err != nil { 290 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsClient", "ListLearnedRoutes", nil, "Failure sending request") 291 return 292 } 293 294 return 295} 296 297// ListLearnedRoutesPreparer prepares the ListLearnedRoutes request. 298func (client VirtualHubBgpConnectionsClient) ListLearnedRoutesPreparer(ctx context.Context, resourceGroupName string, hubName string, connectionName string) (*http.Request, error) { 299 pathParameters := map[string]interface{}{ 300 "connectionName": autorest.Encode("path", connectionName), 301 "hubName": autorest.Encode("path", hubName), 302 "resourceGroupName": autorest.Encode("path", resourceGroupName), 303 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 304 } 305 306 const APIVersion = "2020-07-01" 307 queryParameters := map[string]interface{}{ 308 "api-version": APIVersion, 309 } 310 311 preparer := autorest.CreatePreparer( 312 autorest.AsPost(), 313 autorest.WithBaseURL(client.BaseURI), 314 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{hubName}/bgpConnections/{connectionName}/learnedRoutes", pathParameters), 315 autorest.WithQueryParameters(queryParameters)) 316 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 317} 318 319// ListLearnedRoutesSender sends the ListLearnedRoutes request. The method will close the 320// http.Response Body if it receives an error. 321func (client VirtualHubBgpConnectionsClient) ListLearnedRoutesSender(req *http.Request) (future VirtualHubBgpConnectionsListLearnedRoutesFuture, err error) { 322 var resp *http.Response 323 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 324 if err != nil { 325 return 326 } 327 var azf azure.Future 328 azf, err = azure.NewFutureFromResponse(resp) 329 future.FutureAPI = &azf 330 future.Result = func(client VirtualHubBgpConnectionsClient) (prl PeerRouteList, err error) { 331 var done bool 332 done, err = future.DoneWithContext(context.Background(), client) 333 if err != nil { 334 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsListLearnedRoutesFuture", "Result", future.Response(), "Polling failure") 335 return 336 } 337 if !done { 338 err = azure.NewAsyncOpIncompleteError("network.VirtualHubBgpConnectionsListLearnedRoutesFuture") 339 return 340 } 341 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 342 prl.Response.Response, err = future.GetResult(sender) 343 if prl.Response.Response == nil && err == nil { 344 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsListLearnedRoutesFuture", "Result", nil, "received nil response and error") 345 } 346 if err == nil && prl.Response.Response.StatusCode != http.StatusNoContent { 347 prl, err = client.ListLearnedRoutesResponder(prl.Response.Response) 348 if err != nil { 349 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionsListLearnedRoutesFuture", "Result", prl.Response.Response, "Failure responding to request") 350 } 351 } 352 return 353 } 354 return 355} 356 357// ListLearnedRoutesResponder handles the response to the ListLearnedRoutes request. The method always 358// closes the http.Response Body. 359func (client VirtualHubBgpConnectionsClient) ListLearnedRoutesResponder(resp *http.Response) (result PeerRouteList, err error) { 360 err = autorest.Respond( 361 resp, 362 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 363 autorest.ByUnmarshallingJSON(&result), 364 autorest.ByClosing()) 365 result.Response = autorest.Response{Response: resp} 366 return 367} 368