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