...

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

View as plain text