...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/postgresql/mgmt/2020-11-05-preview/postgresqlflexibleservers/virtualnetworksubnetusage.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/postgresql/mgmt/2020-11-05-preview/postgresqlflexibleservers

     1  package postgresqlflexibleservers
     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  // VirtualNetworkSubnetUsageClient is the the Microsoft Azure management API provides create, read, update, and delete
    19  // functionality for Azure PostgreSQL resources including servers, databases, firewall rules, VNET rules, security
    20  // alert policies, log files and configurations with new business model.
    21  type VirtualNetworkSubnetUsageClient struct {
    22  	BaseClient
    23  }
    24  
    25  // NewVirtualNetworkSubnetUsageClient creates an instance of the VirtualNetworkSubnetUsageClient client.
    26  func NewVirtualNetworkSubnetUsageClient(subscriptionID string) VirtualNetworkSubnetUsageClient {
    27  	return NewVirtualNetworkSubnetUsageClientWithBaseURI(DefaultBaseURI, subscriptionID)
    28  }
    29  
    30  // NewVirtualNetworkSubnetUsageClientWithBaseURI creates an instance of the VirtualNetworkSubnetUsageClient client
    31  // using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    32  // clouds, Azure stack).
    33  func NewVirtualNetworkSubnetUsageClientWithBaseURI(baseURI string, subscriptionID string) VirtualNetworkSubnetUsageClient {
    34  	return VirtualNetworkSubnetUsageClient{NewWithBaseURI(baseURI, subscriptionID)}
    35  }
    36  
    37  // Execute get virtual network subnet usage for a given vNet resource id.
    38  // Parameters:
    39  // locationName - the name of the location.
    40  // parameters - the required parameters for creating or updating a server.
    41  func (client VirtualNetworkSubnetUsageClient) Execute(ctx context.Context, locationName string, parameters VirtualNetworkSubnetUsageParameter) (result VirtualNetworkSubnetUsageResult, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworkSubnetUsageClient.Execute")
    44  		defer func() {
    45  			sc := -1
    46  			if result.Response.Response != nil {
    47  				sc = result.Response.Response.StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: client.SubscriptionID,
    54  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    55  		return result, validation.NewError("postgresqlflexibleservers.VirtualNetworkSubnetUsageClient", "Execute", err.Error())
    56  	}
    57  
    58  	req, err := client.ExecutePreparer(ctx, locationName, parameters)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.VirtualNetworkSubnetUsageClient", "Execute", nil, "Failure preparing request")
    61  		return
    62  	}
    63  
    64  	resp, err := client.ExecuteSender(req)
    65  	if err != nil {
    66  		result.Response = autorest.Response{Response: resp}
    67  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.VirtualNetworkSubnetUsageClient", "Execute", resp, "Failure sending request")
    68  		return
    69  	}
    70  
    71  	result, err = client.ExecuteResponder(resp)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.VirtualNetworkSubnetUsageClient", "Execute", resp, "Failure responding to request")
    74  		return
    75  	}
    76  
    77  	return
    78  }
    79  
    80  // ExecutePreparer prepares the Execute request.
    81  func (client VirtualNetworkSubnetUsageClient) ExecutePreparer(ctx context.Context, locationName string, parameters VirtualNetworkSubnetUsageParameter) (*http.Request, error) {
    82  	pathParameters := map[string]interface{}{
    83  		"locationName":   autorest.Encode("path", locationName),
    84  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    85  	}
    86  
    87  	const APIVersion = "2020-02-14-preview"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  
    92  	preparer := autorest.CreatePreparer(
    93  		autorest.AsContentType("application/json; charset=utf-8"),
    94  		autorest.AsPost(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBForPostgreSql/locations/{locationName}/checkVirtualNetworkSubnetUsage", pathParameters),
    97  		autorest.WithJSON(parameters),
    98  		autorest.WithQueryParameters(queryParameters))
    99  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   100  }
   101  
   102  // ExecuteSender sends the Execute request. The method will close the
   103  // http.Response Body if it receives an error.
   104  func (client VirtualNetworkSubnetUsageClient) ExecuteSender(req *http.Request) (*http.Response, error) {
   105  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   106  }
   107  
   108  // ExecuteResponder handles the response to the Execute request. The method always
   109  // closes the http.Response Body.
   110  func (client VirtualNetworkSubnetUsageClient) ExecuteResponder(resp *http.Response) (result VirtualNetworkSubnetUsageResult, err error) {
   111  	err = autorest.Respond(
   112  		resp,
   113  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   114  		autorest.ByUnmarshallingJSON(&result),
   115  		autorest.ByClosing())
   116  	result.Response = autorest.Response{Response: resp}
   117  	return
   118  }
   119  

View as plain text