...

Source file src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-01-01/network/expressroutecircuitpeerings.go

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

View as plain text