...

Source file src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network/routes.go

Documentation: github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network

     1  package 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  
     9  import (
    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
    18  type RoutesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewRoutesClient creates an instance of the RoutesClient client.
    23  func 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).
    29  func NewRoutesClientWithBaseURI(baseURI string, subscriptionID string) RoutesClient {
    30  	return RoutesClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate creates or 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 or update route operation.
    39  func (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", result.Response(), "Failure sending request")
    59  		return
    60  	}
    61  
    62  	return
    63  }
    64  
    65  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    66  func (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 = "2021-08-01"
    75  	queryParameters := map[string]interface{}{
    76  		"api-version": APIVersion,
    77  	}
    78  
    79  	routeParameters.Etag = nil
    80  	preparer := autorest.CreatePreparer(
    81  		autorest.AsContentType("application/json; charset=utf-8"),
    82  		autorest.AsPut(),
    83  		autorest.WithBaseURL(client.BaseURI),
    84  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}/routes/{routeName}", pathParameters),
    85  		autorest.WithJSON(routeParameters),
    86  		autorest.WithQueryParameters(queryParameters))
    87  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    88  }
    89  
    90  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    91  // http.Response Body if it receives an error.
    92  func (client RoutesClient) CreateOrUpdateSender(req *http.Request) (future RoutesCreateOrUpdateFuture, err error) {
    93  	var resp *http.Response
    94  	future.FutureAPI = &azure.Future{}
    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.
   108  func (client RoutesClient) CreateOrUpdateResponder(resp *http.Response) (result Route, 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 route from a route table.
   119  // Parameters:
   120  // resourceGroupName - the name of the resource group.
   121  // routeTableName - the name of the route table.
   122  // routeName - the name of the route.
   123  func (client RoutesClient) Delete(ctx context.Context, resourceGroupName string, routeTableName string, routeName string) (result RoutesDeleteFuture, err error) {
   124  	if tracing.IsEnabled() {
   125  		ctx = tracing.StartSpan(ctx, fqdn+"/RoutesClient.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, routeTableName, routeName)
   135  	if err != nil {
   136  		err = autorest.NewErrorWithError(err, "network.RoutesClient", "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.RoutesClient", "Delete", result.Response(), "Failure sending request")
   143  		return
   144  	}
   145  
   146  	return
   147  }
   148  
   149  // DeletePreparer prepares the Delete request.
   150  func (client RoutesClient) DeletePreparer(ctx context.Context, resourceGroupName string, routeTableName string, routeName string) (*http.Request, error) {
   151  	pathParameters := map[string]interface{}{
   152  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   153  		"routeName":         autorest.Encode("path", routeName),
   154  		"routeTableName":    autorest.Encode("path", routeTableName),
   155  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   156  	}
   157  
   158  	const APIVersion = "2021-08-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/routeTables/{routeTableName}/routes/{routeName}", 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.
   173  func (client RoutesClient) DeleteSender(req *http.Request) (future RoutesDeleteFuture, err error) {
   174  	var resp *http.Response
   175  	future.FutureAPI = &azure.Future{}
   176  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   177  	if err != nil {
   178  		return
   179  	}
   180  	var azf azure.Future
   181  	azf, err = azure.NewFutureFromResponse(resp)
   182  	future.FutureAPI = &azf
   183  	future.Result = future.result
   184  	return
   185  }
   186  
   187  // DeleteResponder handles the response to the Delete request. The method always
   188  // closes the http.Response Body.
   189  func (client RoutesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   190  	err = autorest.Respond(
   191  		resp,
   192  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   193  		autorest.ByClosing())
   194  	result.Response = resp
   195  	return
   196  }
   197  
   198  // Get gets the specified route from a route table.
   199  // Parameters:
   200  // resourceGroupName - the name of the resource group.
   201  // routeTableName - the name of the route table.
   202  // routeName - the name of the route.
   203  func (client RoutesClient) Get(ctx context.Context, resourceGroupName string, routeTableName string, routeName string) (result Route, err error) {
   204  	if tracing.IsEnabled() {
   205  		ctx = tracing.StartSpan(ctx, fqdn+"/RoutesClient.Get")
   206  		defer func() {
   207  			sc := -1
   208  			if result.Response.Response != nil {
   209  				sc = result.Response.Response.StatusCode
   210  			}
   211  			tracing.EndSpan(ctx, sc, err)
   212  		}()
   213  	}
   214  	req, err := client.GetPreparer(ctx, resourceGroupName, routeTableName, routeName)
   215  	if err != nil {
   216  		err = autorest.NewErrorWithError(err, "network.RoutesClient", "Get", nil, "Failure preparing request")
   217  		return
   218  	}
   219  
   220  	resp, err := client.GetSender(req)
   221  	if err != nil {
   222  		result.Response = autorest.Response{Response: resp}
   223  		err = autorest.NewErrorWithError(err, "network.RoutesClient", "Get", resp, "Failure sending request")
   224  		return
   225  	}
   226  
   227  	result, err = client.GetResponder(resp)
   228  	if err != nil {
   229  		err = autorest.NewErrorWithError(err, "network.RoutesClient", "Get", resp, "Failure responding to request")
   230  		return
   231  	}
   232  
   233  	return
   234  }
   235  
   236  // GetPreparer prepares the Get request.
   237  func (client RoutesClient) GetPreparer(ctx context.Context, resourceGroupName string, routeTableName string, routeName string) (*http.Request, error) {
   238  	pathParameters := map[string]interface{}{
   239  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   240  		"routeName":         autorest.Encode("path", routeName),
   241  		"routeTableName":    autorest.Encode("path", routeTableName),
   242  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   243  	}
   244  
   245  	const APIVersion = "2021-08-01"
   246  	queryParameters := map[string]interface{}{
   247  		"api-version": APIVersion,
   248  	}
   249  
   250  	preparer := autorest.CreatePreparer(
   251  		autorest.AsGet(),
   252  		autorest.WithBaseURL(client.BaseURI),
   253  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}/routes/{routeName}", pathParameters),
   254  		autorest.WithQueryParameters(queryParameters))
   255  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   256  }
   257  
   258  // GetSender sends the Get request. The method will close the
   259  // http.Response Body if it receives an error.
   260  func (client RoutesClient) GetSender(req *http.Request) (*http.Response, error) {
   261  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   262  }
   263  
   264  // GetResponder handles the response to the Get request. The method always
   265  // closes the http.Response Body.
   266  func (client RoutesClient) GetResponder(resp *http.Response) (result Route, err error) {
   267  	err = autorest.Respond(
   268  		resp,
   269  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   270  		autorest.ByUnmarshallingJSON(&result),
   271  		autorest.ByClosing())
   272  	result.Response = autorest.Response{Response: resp}
   273  	return
   274  }
   275  
   276  // List gets all routes in a route table.
   277  // Parameters:
   278  // resourceGroupName - the name of the resource group.
   279  // routeTableName - the name of the route table.
   280  func (client RoutesClient) List(ctx context.Context, resourceGroupName string, routeTableName string) (result RouteListResultPage, err error) {
   281  	if tracing.IsEnabled() {
   282  		ctx = tracing.StartSpan(ctx, fqdn+"/RoutesClient.List")
   283  		defer func() {
   284  			sc := -1
   285  			if result.rlr.Response.Response != nil {
   286  				sc = result.rlr.Response.Response.StatusCode
   287  			}
   288  			tracing.EndSpan(ctx, sc, err)
   289  		}()
   290  	}
   291  	result.fn = client.listNextResults
   292  	req, err := client.ListPreparer(ctx, resourceGroupName, routeTableName)
   293  	if err != nil {
   294  		err = autorest.NewErrorWithError(err, "network.RoutesClient", "List", nil, "Failure preparing request")
   295  		return
   296  	}
   297  
   298  	resp, err := client.ListSender(req)
   299  	if err != nil {
   300  		result.rlr.Response = autorest.Response{Response: resp}
   301  		err = autorest.NewErrorWithError(err, "network.RoutesClient", "List", resp, "Failure sending request")
   302  		return
   303  	}
   304  
   305  	result.rlr, err = client.ListResponder(resp)
   306  	if err != nil {
   307  		err = autorest.NewErrorWithError(err, "network.RoutesClient", "List", resp, "Failure responding to request")
   308  		return
   309  	}
   310  	if result.rlr.hasNextLink() && result.rlr.IsEmpty() {
   311  		err = result.NextWithContext(ctx)
   312  		return
   313  	}
   314  
   315  	return
   316  }
   317  
   318  // ListPreparer prepares the List request.
   319  func (client RoutesClient) ListPreparer(ctx context.Context, resourceGroupName string, routeTableName string) (*http.Request, error) {
   320  	pathParameters := map[string]interface{}{
   321  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   322  		"routeTableName":    autorest.Encode("path", routeTableName),
   323  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   324  	}
   325  
   326  	const APIVersion = "2021-08-01"
   327  	queryParameters := map[string]interface{}{
   328  		"api-version": APIVersion,
   329  	}
   330  
   331  	preparer := autorest.CreatePreparer(
   332  		autorest.AsGet(),
   333  		autorest.WithBaseURL(client.BaseURI),
   334  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}/routes", pathParameters),
   335  		autorest.WithQueryParameters(queryParameters))
   336  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   337  }
   338  
   339  // ListSender sends the List request. The method will close the
   340  // http.Response Body if it receives an error.
   341  func (client RoutesClient) ListSender(req *http.Request) (*http.Response, error) {
   342  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   343  }
   344  
   345  // ListResponder handles the response to the List request. The method always
   346  // closes the http.Response Body.
   347  func (client RoutesClient) ListResponder(resp *http.Response) (result RouteListResult, err error) {
   348  	err = autorest.Respond(
   349  		resp,
   350  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   351  		autorest.ByUnmarshallingJSON(&result),
   352  		autorest.ByClosing())
   353  	result.Response = autorest.Response{Response: resp}
   354  	return
   355  }
   356  
   357  // listNextResults retrieves the next set of results, if any.
   358  func (client RoutesClient) listNextResults(ctx context.Context, lastResults RouteListResult) (result RouteListResult, err error) {
   359  	req, err := lastResults.routeListResultPreparer(ctx)
   360  	if err != nil {
   361  		return result, autorest.NewErrorWithError(err, "network.RoutesClient", "listNextResults", nil, "Failure preparing next results request")
   362  	}
   363  	if req == nil {
   364  		return
   365  	}
   366  	resp, err := client.ListSender(req)
   367  	if err != nil {
   368  		result.Response = autorest.Response{Response: resp}
   369  		return result, autorest.NewErrorWithError(err, "network.RoutesClient", "listNextResults", resp, "Failure sending next results request")
   370  	}
   371  	result, err = client.ListResponder(resp)
   372  	if err != nil {
   373  		err = autorest.NewErrorWithError(err, "network.RoutesClient", "listNextResults", resp, "Failure responding to next results request")
   374  	}
   375  	return
   376  }
   377  
   378  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   379  func (client RoutesClient) ListComplete(ctx context.Context, resourceGroupName string, routeTableName string) (result RouteListResultIterator, err error) {
   380  	if tracing.IsEnabled() {
   381  		ctx = tracing.StartSpan(ctx, fqdn+"/RoutesClient.List")
   382  		defer func() {
   383  			sc := -1
   384  			if result.Response().Response.Response != nil {
   385  				sc = result.page.Response().Response.Response.StatusCode
   386  			}
   387  			tracing.EndSpan(ctx, sc, err)
   388  		}()
   389  	}
   390  	result.page, err = client.List(ctx, resourceGroupName, routeTableName)
   391  	return
   392  }
   393  

View as plain text