...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-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/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 = "2018-08-01"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  
    92  	peeringParameters.Etag = nil
    93  	preparer := autorest.CreatePreparer(
    94  		autorest.AsContentType("application/json; charset=utf-8"),
    95  		autorest.AsPut(),
    96  		autorest.WithBaseURL(client.BaseURI),
    97  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}", pathParameters),
    98  		autorest.WithJSON(peeringParameters),
    99  		autorest.WithQueryParameters(queryParameters))
   100  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   101  }
   102  
   103  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   104  // http.Response Body if it receives an error.
   105  func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdateSender(req *http.Request) (future ExpressRouteCircuitPeeringsCreateOrUpdateFuture, err error) {
   106  	var resp *http.Response
   107  	future.FutureAPI = &azure.Future{}
   108  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   109  	if err != nil {
   110  		return
   111  	}
   112  	var azf azure.Future
   113  	azf, err = azure.NewFutureFromResponse(resp)
   114  	future.FutureAPI = &azf
   115  	future.Result = future.result
   116  	return
   117  }
   118  
   119  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   120  // closes the http.Response Body.
   121  func (client ExpressRouteCircuitPeeringsClient) CreateOrUpdateResponder(resp *http.Response) (result ExpressRouteCircuitPeering, err error) {
   122  	err = autorest.Respond(
   123  		resp,
   124  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   125  		autorest.ByUnmarshallingJSON(&result),
   126  		autorest.ByClosing())
   127  	result.Response = autorest.Response{Response: resp}
   128  	return
   129  }
   130  
   131  // Delete deletes the specified peering from the specified express route circuit.
   132  // Parameters:
   133  // resourceGroupName - the name of the resource group.
   134  // circuitName - the name of the express route circuit.
   135  // peeringName - the name of the peering.
   136  func (client ExpressRouteCircuitPeeringsClient) Delete(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitPeeringsDeleteFuture, err error) {
   137  	if tracing.IsEnabled() {
   138  		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.Delete")
   139  		defer func() {
   140  			sc := -1
   141  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   142  				sc = result.FutureAPI.Response().StatusCode
   143  			}
   144  			tracing.EndSpan(ctx, sc, err)
   145  		}()
   146  	}
   147  	req, err := client.DeletePreparer(ctx, resourceGroupName, circuitName, peeringName)
   148  	if err != nil {
   149  		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Delete", nil, "Failure preparing request")
   150  		return
   151  	}
   152  
   153  	result, err = client.DeleteSender(req)
   154  	if err != nil {
   155  		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Delete", result.Response(), "Failure sending request")
   156  		return
   157  	}
   158  
   159  	return
   160  }
   161  
   162  // DeletePreparer prepares the Delete request.
   163  func (client ExpressRouteCircuitPeeringsClient) DeletePreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) {
   164  	pathParameters := map[string]interface{}{
   165  		"circuitName":       autorest.Encode("path", circuitName),
   166  		"peeringName":       autorest.Encode("path", peeringName),
   167  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   168  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   169  	}
   170  
   171  	const APIVersion = "2018-08-01"
   172  	queryParameters := map[string]interface{}{
   173  		"api-version": APIVersion,
   174  	}
   175  
   176  	preparer := autorest.CreatePreparer(
   177  		autorest.AsDelete(),
   178  		autorest.WithBaseURL(client.BaseURI),
   179  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}", pathParameters),
   180  		autorest.WithQueryParameters(queryParameters))
   181  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   182  }
   183  
   184  // DeleteSender sends the Delete request. The method will close the
   185  // http.Response Body if it receives an error.
   186  func (client ExpressRouteCircuitPeeringsClient) DeleteSender(req *http.Request) (future ExpressRouteCircuitPeeringsDeleteFuture, err error) {
   187  	var resp *http.Response
   188  	future.FutureAPI = &azure.Future{}
   189  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   190  	if err != nil {
   191  		return
   192  	}
   193  	var azf azure.Future
   194  	azf, err = azure.NewFutureFromResponse(resp)
   195  	future.FutureAPI = &azf
   196  	future.Result = future.result
   197  	return
   198  }
   199  
   200  // DeleteResponder handles the response to the Delete request. The method always
   201  // closes the http.Response Body.
   202  func (client ExpressRouteCircuitPeeringsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   203  	err = autorest.Respond(
   204  		resp,
   205  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   206  		autorest.ByClosing())
   207  	result.Response = resp
   208  	return
   209  }
   210  
   211  // Get gets the specified peering for the express route circuit.
   212  // Parameters:
   213  // resourceGroupName - the name of the resource group.
   214  // circuitName - the name of the express route circuit.
   215  // peeringName - the name of the peering.
   216  func (client ExpressRouteCircuitPeeringsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (result ExpressRouteCircuitPeering, err error) {
   217  	if tracing.IsEnabled() {
   218  		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.Get")
   219  		defer func() {
   220  			sc := -1
   221  			if result.Response.Response != nil {
   222  				sc = result.Response.Response.StatusCode
   223  			}
   224  			tracing.EndSpan(ctx, sc, err)
   225  		}()
   226  	}
   227  	req, err := client.GetPreparer(ctx, resourceGroupName, circuitName, peeringName)
   228  	if err != nil {
   229  		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Get", nil, "Failure preparing request")
   230  		return
   231  	}
   232  
   233  	resp, err := client.GetSender(req)
   234  	if err != nil {
   235  		result.Response = autorest.Response{Response: resp}
   236  		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Get", resp, "Failure sending request")
   237  		return
   238  	}
   239  
   240  	result, err = client.GetResponder(resp)
   241  	if err != nil {
   242  		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "Get", resp, "Failure responding to request")
   243  		return
   244  	}
   245  
   246  	return
   247  }
   248  
   249  // GetPreparer prepares the Get request.
   250  func (client ExpressRouteCircuitPeeringsClient) GetPreparer(ctx context.Context, resourceGroupName string, circuitName string, peeringName string) (*http.Request, error) {
   251  	pathParameters := map[string]interface{}{
   252  		"circuitName":       autorest.Encode("path", circuitName),
   253  		"peeringName":       autorest.Encode("path", peeringName),
   254  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   255  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   256  	}
   257  
   258  	const APIVersion = "2018-08-01"
   259  	queryParameters := map[string]interface{}{
   260  		"api-version": APIVersion,
   261  	}
   262  
   263  	preparer := autorest.CreatePreparer(
   264  		autorest.AsGet(),
   265  		autorest.WithBaseURL(client.BaseURI),
   266  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}", pathParameters),
   267  		autorest.WithQueryParameters(queryParameters))
   268  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   269  }
   270  
   271  // GetSender sends the Get request. The method will close the
   272  // http.Response Body if it receives an error.
   273  func (client ExpressRouteCircuitPeeringsClient) GetSender(req *http.Request) (*http.Response, error) {
   274  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   275  }
   276  
   277  // GetResponder handles the response to the Get request. The method always
   278  // closes the http.Response Body.
   279  func (client ExpressRouteCircuitPeeringsClient) GetResponder(resp *http.Response) (result ExpressRouteCircuitPeering, err error) {
   280  	err = autorest.Respond(
   281  		resp,
   282  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   283  		autorest.ByUnmarshallingJSON(&result),
   284  		autorest.ByClosing())
   285  	result.Response = autorest.Response{Response: resp}
   286  	return
   287  }
   288  
   289  // List gets all peerings in a specified express route circuit.
   290  // Parameters:
   291  // resourceGroupName - the name of the resource group.
   292  // circuitName - the name of the express route circuit.
   293  func (client ExpressRouteCircuitPeeringsClient) List(ctx context.Context, resourceGroupName string, circuitName string) (result ExpressRouteCircuitPeeringListResultPage, err error) {
   294  	if tracing.IsEnabled() {
   295  		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.List")
   296  		defer func() {
   297  			sc := -1
   298  			if result.ercplr.Response.Response != nil {
   299  				sc = result.ercplr.Response.Response.StatusCode
   300  			}
   301  			tracing.EndSpan(ctx, sc, err)
   302  		}()
   303  	}
   304  	result.fn = client.listNextResults
   305  	req, err := client.ListPreparer(ctx, resourceGroupName, circuitName)
   306  	if err != nil {
   307  		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", nil, "Failure preparing request")
   308  		return
   309  	}
   310  
   311  	resp, err := client.ListSender(req)
   312  	if err != nil {
   313  		result.ercplr.Response = autorest.Response{Response: resp}
   314  		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure sending request")
   315  		return
   316  	}
   317  
   318  	result.ercplr, err = client.ListResponder(resp)
   319  	if err != nil {
   320  		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "List", resp, "Failure responding to request")
   321  		return
   322  	}
   323  	if result.ercplr.hasNextLink() && result.ercplr.IsEmpty() {
   324  		err = result.NextWithContext(ctx)
   325  		return
   326  	}
   327  
   328  	return
   329  }
   330  
   331  // ListPreparer prepares the List request.
   332  func (client ExpressRouteCircuitPeeringsClient) ListPreparer(ctx context.Context, resourceGroupName string, circuitName string) (*http.Request, error) {
   333  	pathParameters := map[string]interface{}{
   334  		"circuitName":       autorest.Encode("path", circuitName),
   335  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   336  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   337  	}
   338  
   339  	const APIVersion = "2018-08-01"
   340  	queryParameters := map[string]interface{}{
   341  		"api-version": APIVersion,
   342  	}
   343  
   344  	preparer := autorest.CreatePreparer(
   345  		autorest.AsGet(),
   346  		autorest.WithBaseURL(client.BaseURI),
   347  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings", pathParameters),
   348  		autorest.WithQueryParameters(queryParameters))
   349  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   350  }
   351  
   352  // ListSender sends the List request. The method will close the
   353  // http.Response Body if it receives an error.
   354  func (client ExpressRouteCircuitPeeringsClient) ListSender(req *http.Request) (*http.Response, error) {
   355  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   356  }
   357  
   358  // ListResponder handles the response to the List request. The method always
   359  // closes the http.Response Body.
   360  func (client ExpressRouteCircuitPeeringsClient) ListResponder(resp *http.Response) (result ExpressRouteCircuitPeeringListResult, err error) {
   361  	err = autorest.Respond(
   362  		resp,
   363  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   364  		autorest.ByUnmarshallingJSON(&result),
   365  		autorest.ByClosing())
   366  	result.Response = autorest.Response{Response: resp}
   367  	return
   368  }
   369  
   370  // listNextResults retrieves the next set of results, if any.
   371  func (client ExpressRouteCircuitPeeringsClient) listNextResults(ctx context.Context, lastResults ExpressRouteCircuitPeeringListResult) (result ExpressRouteCircuitPeeringListResult, err error) {
   372  	req, err := lastResults.expressRouteCircuitPeeringListResultPreparer(ctx)
   373  	if err != nil {
   374  		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "listNextResults", nil, "Failure preparing next results request")
   375  	}
   376  	if req == nil {
   377  		return
   378  	}
   379  	resp, err := client.ListSender(req)
   380  	if err != nil {
   381  		result.Response = autorest.Response{Response: resp}
   382  		return result, autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "listNextResults", resp, "Failure sending next results request")
   383  	}
   384  	result, err = client.ListResponder(resp)
   385  	if err != nil {
   386  		err = autorest.NewErrorWithError(err, "network.ExpressRouteCircuitPeeringsClient", "listNextResults", resp, "Failure responding to next results request")
   387  	}
   388  	return
   389  }
   390  
   391  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   392  func (client ExpressRouteCircuitPeeringsClient) ListComplete(ctx context.Context, resourceGroupName string, circuitName string) (result ExpressRouteCircuitPeeringListResultIterator, err error) {
   393  	if tracing.IsEnabled() {
   394  		ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteCircuitPeeringsClient.List")
   395  		defer func() {
   396  			sc := -1
   397  			if result.Response().Response.Response != nil {
   398  				sc = result.page.Response().Response.Response.StatusCode
   399  			}
   400  			tracing.EndSpan(ctx, sc, err)
   401  		}()
   402  	}
   403  	result.page, err = client.List(ctx, resourceGroupName, circuitName)
   404  	return
   405  }
   406  

View as plain text