...

Source file src/github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp

     1  // Deprecated: Please note, this package has been deprecated. A replacement package is available [github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/netapp/armnetapp](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/netapp/armnetapp). We strongly encourage you to upgrade to continue receiving updates. See [Migration Guide](https://aka.ms/azsdk/golang/t2/migration) for guidance on upgrading. Refer to our [deprecation policy](https://azure.github.io/azure-sdk/policies_support.html) for more details.
     2  //
     3  // Package netapp implements the Azure ARM Netapp service API version 2019-06-01.
     4  //
     5  // Microsoft NetApp Azure Resource Provider specification
     6  package netapp
     7  
     8  // Copyright (c) Microsoft Corporation. All rights reserved.
     9  // Licensed under the MIT License. See License.txt in the project root for license information.
    10  //
    11  // Code generated by Microsoft (R) AutoRest Code Generator.
    12  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
    13  
    14  import (
    15  	"context"
    16  	"github.com/Azure/go-autorest/autorest"
    17  	"github.com/Azure/go-autorest/autorest/azure"
    18  	"github.com/Azure/go-autorest/autorest/validation"
    19  	"github.com/Azure/go-autorest/tracing"
    20  	"net/http"
    21  )
    22  
    23  const (
    24  	// DefaultBaseURI is the default URI used for the service Netapp
    25  	DefaultBaseURI = "https://management.azure.com"
    26  )
    27  
    28  // BaseClient is the base client for Netapp.
    29  type BaseClient struct {
    30  	autorest.Client
    31  	BaseURI        string
    32  	SubscriptionID string
    33  }
    34  
    35  // New creates an instance of the BaseClient client.
    36  func New(subscriptionID string) BaseClient {
    37  	return NewWithBaseURI(DefaultBaseURI, subscriptionID)
    38  }
    39  
    40  // NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint.  Use this when interacting with
    41  // an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    42  func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient {
    43  	return BaseClient{
    44  		Client:         autorest.NewClientWithUserAgent(UserAgent()),
    45  		BaseURI:        baseURI,
    46  		SubscriptionID: subscriptionID,
    47  	}
    48  }
    49  
    50  // CheckFilePathAvailability check if a file path is available.
    51  // Parameters:
    52  // body - file path availability request.
    53  // location - the location
    54  func (client BaseClient) CheckFilePathAvailability(ctx context.Context, body ResourceNameAvailabilityRequest, location string) (result ResourceNameAvailability, err error) {
    55  	if tracing.IsEnabled() {
    56  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckFilePathAvailability")
    57  		defer func() {
    58  			sc := -1
    59  			if result.Response.Response != nil {
    60  				sc = result.Response.Response.StatusCode
    61  			}
    62  			tracing.EndSpan(ctx, sc, err)
    63  		}()
    64  	}
    65  	if err := validation.Validate([]validation.Validation{
    66  		{TargetValue: body,
    67  			Constraints: []validation.Constraint{{Target: "body.Name", Name: validation.Null, Rule: true, Chain: nil},
    68  				{Target: "body.ResourceGroup", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    69  		return result, validation.NewError("netapp.BaseClient", "CheckFilePathAvailability", err.Error())
    70  	}
    71  
    72  	req, err := client.CheckFilePathAvailabilityPreparer(ctx, body, location)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "netapp.BaseClient", "CheckFilePathAvailability", nil, "Failure preparing request")
    75  		return
    76  	}
    77  
    78  	resp, err := client.CheckFilePathAvailabilitySender(req)
    79  	if err != nil {
    80  		result.Response = autorest.Response{Response: resp}
    81  		err = autorest.NewErrorWithError(err, "netapp.BaseClient", "CheckFilePathAvailability", resp, "Failure sending request")
    82  		return
    83  	}
    84  
    85  	result, err = client.CheckFilePathAvailabilityResponder(resp)
    86  	if err != nil {
    87  		err = autorest.NewErrorWithError(err, "netapp.BaseClient", "CheckFilePathAvailability", resp, "Failure responding to request")
    88  		return
    89  	}
    90  
    91  	return
    92  }
    93  
    94  // CheckFilePathAvailabilityPreparer prepares the CheckFilePathAvailability request.
    95  func (client BaseClient) CheckFilePathAvailabilityPreparer(ctx context.Context, body ResourceNameAvailabilityRequest, location string) (*http.Request, error) {
    96  	pathParameters := map[string]interface{}{
    97  		"location":       autorest.Encode("path", location),
    98  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    99  	}
   100  
   101  	const APIVersion = "2019-06-01"
   102  	queryParameters := map[string]interface{}{
   103  		"api-version": APIVersion,
   104  	}
   105  
   106  	preparer := autorest.CreatePreparer(
   107  		autorest.AsContentType("application/json; charset=utf-8"),
   108  		autorest.AsPost(),
   109  		autorest.WithBaseURL(client.BaseURI),
   110  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.NetApp/locations/{location}/checkFilePathAvailability", pathParameters),
   111  		autorest.WithJSON(body),
   112  		autorest.WithQueryParameters(queryParameters))
   113  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   114  }
   115  
   116  // CheckFilePathAvailabilitySender sends the CheckFilePathAvailability request. The method will close the
   117  // http.Response Body if it receives an error.
   118  func (client BaseClient) CheckFilePathAvailabilitySender(req *http.Request) (*http.Response, error) {
   119  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   120  }
   121  
   122  // CheckFilePathAvailabilityResponder handles the response to the CheckFilePathAvailability request. The method always
   123  // closes the http.Response Body.
   124  func (client BaseClient) CheckFilePathAvailabilityResponder(resp *http.Response) (result ResourceNameAvailability, err error) {
   125  	err = autorest.Respond(
   126  		resp,
   127  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   128  		autorest.ByUnmarshallingJSON(&result),
   129  		autorest.ByClosing())
   130  	result.Response = autorest.Response{Response: resp}
   131  	return
   132  }
   133  
   134  // CheckNameAvailability check if a resource name is available.
   135  // Parameters:
   136  // body - name availability request.
   137  // location - the location
   138  func (client BaseClient) CheckNameAvailability(ctx context.Context, body ResourceNameAvailabilityRequest, location string) (result ResourceNameAvailability, err error) {
   139  	if tracing.IsEnabled() {
   140  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckNameAvailability")
   141  		defer func() {
   142  			sc := -1
   143  			if result.Response.Response != nil {
   144  				sc = result.Response.Response.StatusCode
   145  			}
   146  			tracing.EndSpan(ctx, sc, err)
   147  		}()
   148  	}
   149  	if err := validation.Validate([]validation.Validation{
   150  		{TargetValue: body,
   151  			Constraints: []validation.Constraint{{Target: "body.Name", Name: validation.Null, Rule: true, Chain: nil},
   152  				{Target: "body.ResourceGroup", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   153  		return result, validation.NewError("netapp.BaseClient", "CheckNameAvailability", err.Error())
   154  	}
   155  
   156  	req, err := client.CheckNameAvailabilityPreparer(ctx, body, location)
   157  	if err != nil {
   158  		err = autorest.NewErrorWithError(err, "netapp.BaseClient", "CheckNameAvailability", nil, "Failure preparing request")
   159  		return
   160  	}
   161  
   162  	resp, err := client.CheckNameAvailabilitySender(req)
   163  	if err != nil {
   164  		result.Response = autorest.Response{Response: resp}
   165  		err = autorest.NewErrorWithError(err, "netapp.BaseClient", "CheckNameAvailability", resp, "Failure sending request")
   166  		return
   167  	}
   168  
   169  	result, err = client.CheckNameAvailabilityResponder(resp)
   170  	if err != nil {
   171  		err = autorest.NewErrorWithError(err, "netapp.BaseClient", "CheckNameAvailability", resp, "Failure responding to request")
   172  		return
   173  	}
   174  
   175  	return
   176  }
   177  
   178  // CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
   179  func (client BaseClient) CheckNameAvailabilityPreparer(ctx context.Context, body ResourceNameAvailabilityRequest, location string) (*http.Request, error) {
   180  	pathParameters := map[string]interface{}{
   181  		"location":       autorest.Encode("path", location),
   182  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   183  	}
   184  
   185  	const APIVersion = "2019-06-01"
   186  	queryParameters := map[string]interface{}{
   187  		"api-version": APIVersion,
   188  	}
   189  
   190  	preparer := autorest.CreatePreparer(
   191  		autorest.AsContentType("application/json; charset=utf-8"),
   192  		autorest.AsPost(),
   193  		autorest.WithBaseURL(client.BaseURI),
   194  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.NetApp/locations/{location}/checkNameAvailability", pathParameters),
   195  		autorest.WithJSON(body),
   196  		autorest.WithQueryParameters(queryParameters))
   197  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   198  }
   199  
   200  // CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
   201  // http.Response Body if it receives an error.
   202  func (client BaseClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
   203  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   204  }
   205  
   206  // CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
   207  // closes the http.Response Body.
   208  func (client BaseClient) CheckNameAvailabilityResponder(resp *http.Response) (result ResourceNameAvailability, err error) {
   209  	err = autorest.Respond(
   210  		resp,
   211  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   212  		autorest.ByUnmarshallingJSON(&result),
   213  		autorest.ByClosing())
   214  	result.Response = autorest.Response{Response: resp}
   215  	return
   216  }
   217  

View as plain text