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