...

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

View as plain text