...

Source file src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-08-01/network/vpnconnections.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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // VpnConnectionsClient is the network Client
    18  type VpnConnectionsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewVpnConnectionsClient creates an instance of the VpnConnectionsClient client.
    23  func NewVpnConnectionsClient(subscriptionID string) VpnConnectionsClient {
    24  	return NewVpnConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewVpnConnectionsClientWithBaseURI creates an instance of the VpnConnectionsClient 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 NewVpnConnectionsClientWithBaseURI(baseURI string, subscriptionID string) VpnConnectionsClient {
    30  	return VpnConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate creates a vpn connection to a scalable vpn gateway if it doesn't exist else updates the existing
    34  // connection.
    35  // Parameters:
    36  // resourceGroupName - the resource group name of the VpnGateway.
    37  // gatewayName - the name of the gateway.
    38  // connectionName - the name of the connection.
    39  // vpnConnectionParameters - parameters supplied to create or Update a VPN Connection.
    40  func (client VpnConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VpnConnection) (result VpnConnectionsCreateOrUpdateFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.CreateOrUpdate")
    43  		defer func() {
    44  			sc := -1
    45  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    46  				sc = result.FutureAPI.Response().StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, gatewayName, connectionName, vpnConnectionParameters)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	result, err = client.CreateOrUpdateSender(req)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    60  		return
    61  	}
    62  
    63  	return
    64  }
    65  
    66  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    67  func (client VpnConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string, vpnConnectionParameters VpnConnection) (*http.Request, error) {
    68  	pathParameters := map[string]interface{}{
    69  		"connectionName":    autorest.Encode("path", connectionName),
    70  		"gatewayName":       autorest.Encode("path", gatewayName),
    71  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    72  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    73  	}
    74  
    75  	const APIVersion = "2018-08-01"
    76  	queryParameters := map[string]interface{}{
    77  		"api-version": APIVersion,
    78  	}
    79  
    80  	vpnConnectionParameters.Etag = 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/vpnGateways/{gatewayName}/vpnConnections/{connectionName}", pathParameters),
    86  		autorest.WithJSON(vpnConnectionParameters),
    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 VpnConnectionsClient) CreateOrUpdateSender(req *http.Request) (future VpnConnectionsCreateOrUpdateFuture, 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 VpnConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result VpnConnection, 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 vpn connection.
   120  // Parameters:
   121  // resourceGroupName - the resource group name of the VpnGateway.
   122  // gatewayName - the name of the gateway.
   123  // connectionName - the name of the connection.
   124  func (client VpnConnectionsClient) Delete(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result VpnConnectionsDeleteFuture, err error) {
   125  	if tracing.IsEnabled() {
   126  		ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.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, gatewayName, connectionName)
   136  	if err != nil {
   137  		err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "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.VpnConnectionsClient", "Delete", result.Response(), "Failure sending request")
   144  		return
   145  	}
   146  
   147  	return
   148  }
   149  
   150  // DeletePreparer prepares the Delete request.
   151  func (client VpnConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (*http.Request, error) {
   152  	pathParameters := map[string]interface{}{
   153  		"connectionName":    autorest.Encode("path", connectionName),
   154  		"gatewayName":       autorest.Encode("path", gatewayName),
   155  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   156  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   157  	}
   158  
   159  	const APIVersion = "2018-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/vpnGateways/{gatewayName}/vpnConnections/{connectionName}", 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 VpnConnectionsClient) DeleteSender(req *http.Request) (future VpnConnectionsDeleteFuture, 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 VpnConnectionsClient) 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 vpn connection.
   200  // Parameters:
   201  // resourceGroupName - the resource group name of the VpnGateway.
   202  // gatewayName - the name of the gateway.
   203  // connectionName - the name of the vpn connection.
   204  func (client VpnConnectionsClient) Get(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (result VpnConnection, err error) {
   205  	if tracing.IsEnabled() {
   206  		ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.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, gatewayName, connectionName)
   216  	if err != nil {
   217  		err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "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.VpnConnectionsClient", "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.VpnConnectionsClient", "Get", resp, "Failure responding to request")
   231  		return
   232  	}
   233  
   234  	return
   235  }
   236  
   237  // GetPreparer prepares the Get request.
   238  func (client VpnConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, gatewayName string, connectionName string) (*http.Request, error) {
   239  	pathParameters := map[string]interface{}{
   240  		"connectionName":    autorest.Encode("path", connectionName),
   241  		"gatewayName":       autorest.Encode("path", gatewayName),
   242  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   243  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   244  	}
   245  
   246  	const APIVersion = "2018-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/vpnGateways/{gatewayName}/vpnConnections/{connectionName}", 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 VpnConnectionsClient) 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 VpnConnectionsClient) GetResponder(resp *http.Response) (result VpnConnection, 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  // ListByVpnGateway retrieves all vpn connections for a particular virtual wan vpn gateway.
   278  // Parameters:
   279  // resourceGroupName - the resource group name of the VpnGateway.
   280  // gatewayName - the name of the gateway.
   281  func (client VpnConnectionsClient) ListByVpnGateway(ctx context.Context, resourceGroupName string, gatewayName string) (result ListVpnConnectionsResultPage, err error) {
   282  	if tracing.IsEnabled() {
   283  		ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.ListByVpnGateway")
   284  		defer func() {
   285  			sc := -1
   286  			if result.lvcr.Response.Response != nil {
   287  				sc = result.lvcr.Response.Response.StatusCode
   288  			}
   289  			tracing.EndSpan(ctx, sc, err)
   290  		}()
   291  	}
   292  	result.fn = client.listByVpnGatewayNextResults
   293  	req, err := client.ListByVpnGatewayPreparer(ctx, resourceGroupName, gatewayName)
   294  	if err != nil {
   295  		err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "ListByVpnGateway", nil, "Failure preparing request")
   296  		return
   297  	}
   298  
   299  	resp, err := client.ListByVpnGatewaySender(req)
   300  	if err != nil {
   301  		result.lvcr.Response = autorest.Response{Response: resp}
   302  		err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "ListByVpnGateway", resp, "Failure sending request")
   303  		return
   304  	}
   305  
   306  	result.lvcr, err = client.ListByVpnGatewayResponder(resp)
   307  	if err != nil {
   308  		err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "ListByVpnGateway", resp, "Failure responding to request")
   309  		return
   310  	}
   311  	if result.lvcr.hasNextLink() && result.lvcr.IsEmpty() {
   312  		err = result.NextWithContext(ctx)
   313  		return
   314  	}
   315  
   316  	return
   317  }
   318  
   319  // ListByVpnGatewayPreparer prepares the ListByVpnGateway request.
   320  func (client VpnConnectionsClient) ListByVpnGatewayPreparer(ctx context.Context, resourceGroupName string, gatewayName string) (*http.Request, error) {
   321  	pathParameters := map[string]interface{}{
   322  		"gatewayName":       autorest.Encode("path", gatewayName),
   323  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   324  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   325  	}
   326  
   327  	const APIVersion = "2018-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/vpnGateways/{gatewayName}/vpnConnections", pathParameters),
   336  		autorest.WithQueryParameters(queryParameters))
   337  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   338  }
   339  
   340  // ListByVpnGatewaySender sends the ListByVpnGateway request. The method will close the
   341  // http.Response Body if it receives an error.
   342  func (client VpnConnectionsClient) ListByVpnGatewaySender(req *http.Request) (*http.Response, error) {
   343  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   344  }
   345  
   346  // ListByVpnGatewayResponder handles the response to the ListByVpnGateway request. The method always
   347  // closes the http.Response Body.
   348  func (client VpnConnectionsClient) ListByVpnGatewayResponder(resp *http.Response) (result ListVpnConnectionsResult, 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  // listByVpnGatewayNextResults retrieves the next set of results, if any.
   359  func (client VpnConnectionsClient) listByVpnGatewayNextResults(ctx context.Context, lastResults ListVpnConnectionsResult) (result ListVpnConnectionsResult, err error) {
   360  	req, err := lastResults.listVpnConnectionsResultPreparer(ctx)
   361  	if err != nil {
   362  		return result, autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "listByVpnGatewayNextResults", nil, "Failure preparing next results request")
   363  	}
   364  	if req == nil {
   365  		return
   366  	}
   367  	resp, err := client.ListByVpnGatewaySender(req)
   368  	if err != nil {
   369  		result.Response = autorest.Response{Response: resp}
   370  		return result, autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "listByVpnGatewayNextResults", resp, "Failure sending next results request")
   371  	}
   372  	result, err = client.ListByVpnGatewayResponder(resp)
   373  	if err != nil {
   374  		err = autorest.NewErrorWithError(err, "network.VpnConnectionsClient", "listByVpnGatewayNextResults", resp, "Failure responding to next results request")
   375  	}
   376  	return
   377  }
   378  
   379  // ListByVpnGatewayComplete enumerates all values, automatically crossing page boundaries as required.
   380  func (client VpnConnectionsClient) ListByVpnGatewayComplete(ctx context.Context, resourceGroupName string, gatewayName string) (result ListVpnConnectionsResultIterator, err error) {
   381  	if tracing.IsEnabled() {
   382  		ctx = tracing.StartSpan(ctx, fqdn+"/VpnConnectionsClient.ListByVpnGateway")
   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.ListByVpnGateway(ctx, resourceGroupName, gatewayName)
   392  	return
   393  }
   394  

View as plain text