...

Source file src/github.com/Azure/azure-sdk-for-go/services/hybriddatamanager/mgmt/2019-06-01/hybriddata/datastores.go

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

     1  package hybriddata
     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  // DataStoresClient is the client for the DataStores methods of the Hybriddata service.
    19  type DataStoresClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewDataStoresClient creates an instance of the DataStoresClient client.
    24  func NewDataStoresClient(subscriptionID string) DataStoresClient {
    25  	return NewDataStoresClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewDataStoresClientWithBaseURI creates an instance of the DataStoresClient client using a custom endpoint.  Use this
    29  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewDataStoresClientWithBaseURI(baseURI string, subscriptionID string) DataStoresClient {
    31  	return DataStoresClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates or updates the data store/repository in the data manager.
    35  // Parameters:
    36  // dataStoreName - the data store/repository name to be created or updated.
    37  // dataStore - the data store/repository object to be created or updated.
    38  // resourceGroupName - the Resource Group Name
    39  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
    40  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
    41  func (client DataStoresClient) CreateOrUpdate(ctx context.Context, dataStoreName string, dataStore DataStore, resourceGroupName string, dataManagerName string) (result DataStoresCreateOrUpdateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/DataStoresClient.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: dataStore,
    54  			Constraints: []validation.Constraint{{Target: "dataStore.DataStoreProperties", Name: validation.Null, Rule: true,
    55  				Chain: []validation.Constraint{{Target: "dataStore.DataStoreProperties.DataStoreTypeID", Name: validation.Null, Rule: true, Chain: nil}}}}},
    56  		{TargetValue: dataManagerName,
    57  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
    58  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
    59  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
    60  		return result, validation.NewError("hybriddata.DataStoresClient", "CreateOrUpdate", err.Error())
    61  	}
    62  
    63  	req, err := client.CreateOrUpdatePreparer(ctx, dataStoreName, dataStore, resourceGroupName, dataManagerName)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "CreateOrUpdate", nil, "Failure preparing request")
    66  		return
    67  	}
    68  
    69  	result, err = client.CreateOrUpdateSender(req)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    79  func (client DataStoresClient) CreateOrUpdatePreparer(ctx context.Context, dataStoreName string, dataStore DataStore, resourceGroupName string, dataManagerName string) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"dataManagerName":   autorest.Encode("path", dataManagerName),
    82  		"dataStoreName":     autorest.Encode("path", dataStoreName),
    83  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    84  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    85  	}
    86  
    87  	const APIVersion = "2019-06-01"
    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.AsPut(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/dataStores/{dataStoreName}", pathParameters),
    97  		autorest.WithJSON(dataStore),
    98  		autorest.WithQueryParameters(queryParameters))
    99  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   100  }
   101  
   102  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   103  // http.Response Body if it receives an error.
   104  func (client DataStoresClient) CreateOrUpdateSender(req *http.Request) (future DataStoresCreateOrUpdateFuture, err error) {
   105  	var resp *http.Response
   106  	future.FutureAPI = &azure.Future{}
   107  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   108  	if err != nil {
   109  		return
   110  	}
   111  	var azf azure.Future
   112  	azf, err = azure.NewFutureFromResponse(resp)
   113  	future.FutureAPI = &azf
   114  	future.Result = future.result
   115  	return
   116  }
   117  
   118  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   119  // closes the http.Response Body.
   120  func (client DataStoresClient) CreateOrUpdateResponder(resp *http.Response) (result DataStore, err error) {
   121  	err = autorest.Respond(
   122  		resp,
   123  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   124  		autorest.ByUnmarshallingJSON(&result),
   125  		autorest.ByClosing())
   126  	result.Response = autorest.Response{Response: resp}
   127  	return
   128  }
   129  
   130  // Delete this method deletes the given data store/repository.
   131  // Parameters:
   132  // dataStoreName - the data store/repository name to be deleted.
   133  // resourceGroupName - the Resource Group Name
   134  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
   135  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
   136  func (client DataStoresClient) Delete(ctx context.Context, dataStoreName string, resourceGroupName string, dataManagerName string) (result DataStoresDeleteFuture, err error) {
   137  	if tracing.IsEnabled() {
   138  		ctx = tracing.StartSpan(ctx, fqdn+"/DataStoresClient.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  	if err := validation.Validate([]validation.Validation{
   148  		{TargetValue: dataManagerName,
   149  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   150  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
   151  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
   152  		return result, validation.NewError("hybriddata.DataStoresClient", "Delete", err.Error())
   153  	}
   154  
   155  	req, err := client.DeletePreparer(ctx, dataStoreName, resourceGroupName, dataManagerName)
   156  	if err != nil {
   157  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "Delete", nil, "Failure preparing request")
   158  		return
   159  	}
   160  
   161  	result, err = client.DeleteSender(req)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "Delete", result.Response(), "Failure sending request")
   164  		return
   165  	}
   166  
   167  	return
   168  }
   169  
   170  // DeletePreparer prepares the Delete request.
   171  func (client DataStoresClient) DeletePreparer(ctx context.Context, dataStoreName string, resourceGroupName string, dataManagerName string) (*http.Request, error) {
   172  	pathParameters := map[string]interface{}{
   173  		"dataManagerName":   autorest.Encode("path", dataManagerName),
   174  		"dataStoreName":     autorest.Encode("path", dataStoreName),
   175  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   176  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   177  	}
   178  
   179  	const APIVersion = "2019-06-01"
   180  	queryParameters := map[string]interface{}{
   181  		"api-version": APIVersion,
   182  	}
   183  
   184  	preparer := autorest.CreatePreparer(
   185  		autorest.AsDelete(),
   186  		autorest.WithBaseURL(client.BaseURI),
   187  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/dataStores/{dataStoreName}", pathParameters),
   188  		autorest.WithQueryParameters(queryParameters))
   189  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   190  }
   191  
   192  // DeleteSender sends the Delete request. The method will close the
   193  // http.Response Body if it receives an error.
   194  func (client DataStoresClient) DeleteSender(req *http.Request) (future DataStoresDeleteFuture, err error) {
   195  	var resp *http.Response
   196  	future.FutureAPI = &azure.Future{}
   197  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   198  	if err != nil {
   199  		return
   200  	}
   201  	var azf azure.Future
   202  	azf, err = azure.NewFutureFromResponse(resp)
   203  	future.FutureAPI = &azf
   204  	future.Result = future.result
   205  	return
   206  }
   207  
   208  // DeleteResponder handles the response to the Delete request. The method always
   209  // closes the http.Response Body.
   210  func (client DataStoresClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   211  	err = autorest.Respond(
   212  		resp,
   213  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   214  		autorest.ByClosing())
   215  	result.Response = resp
   216  	return
   217  }
   218  
   219  // Get this method gets the data store/repository by name.
   220  // Parameters:
   221  // dataStoreName - the data store/repository name queried.
   222  // resourceGroupName - the Resource Group Name
   223  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
   224  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
   225  func (client DataStoresClient) Get(ctx context.Context, dataStoreName string, resourceGroupName string, dataManagerName string) (result DataStore, err error) {
   226  	if tracing.IsEnabled() {
   227  		ctx = tracing.StartSpan(ctx, fqdn+"/DataStoresClient.Get")
   228  		defer func() {
   229  			sc := -1
   230  			if result.Response.Response != nil {
   231  				sc = result.Response.Response.StatusCode
   232  			}
   233  			tracing.EndSpan(ctx, sc, err)
   234  		}()
   235  	}
   236  	if err := validation.Validate([]validation.Validation{
   237  		{TargetValue: dataManagerName,
   238  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   239  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
   240  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
   241  		return result, validation.NewError("hybriddata.DataStoresClient", "Get", err.Error())
   242  	}
   243  
   244  	req, err := client.GetPreparer(ctx, dataStoreName, resourceGroupName, dataManagerName)
   245  	if err != nil {
   246  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "Get", nil, "Failure preparing request")
   247  		return
   248  	}
   249  
   250  	resp, err := client.GetSender(req)
   251  	if err != nil {
   252  		result.Response = autorest.Response{Response: resp}
   253  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "Get", resp, "Failure sending request")
   254  		return
   255  	}
   256  
   257  	result, err = client.GetResponder(resp)
   258  	if err != nil {
   259  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "Get", resp, "Failure responding to request")
   260  		return
   261  	}
   262  
   263  	return
   264  }
   265  
   266  // GetPreparer prepares the Get request.
   267  func (client DataStoresClient) GetPreparer(ctx context.Context, dataStoreName string, resourceGroupName string, dataManagerName string) (*http.Request, error) {
   268  	pathParameters := map[string]interface{}{
   269  		"dataManagerName":   autorest.Encode("path", dataManagerName),
   270  		"dataStoreName":     autorest.Encode("path", dataStoreName),
   271  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   272  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   273  	}
   274  
   275  	const APIVersion = "2019-06-01"
   276  	queryParameters := map[string]interface{}{
   277  		"api-version": APIVersion,
   278  	}
   279  
   280  	preparer := autorest.CreatePreparer(
   281  		autorest.AsGet(),
   282  		autorest.WithBaseURL(client.BaseURI),
   283  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/dataStores/{dataStoreName}", pathParameters),
   284  		autorest.WithQueryParameters(queryParameters))
   285  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   286  }
   287  
   288  // GetSender sends the Get request. The method will close the
   289  // http.Response Body if it receives an error.
   290  func (client DataStoresClient) GetSender(req *http.Request) (*http.Response, error) {
   291  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   292  }
   293  
   294  // GetResponder handles the response to the Get request. The method always
   295  // closes the http.Response Body.
   296  func (client DataStoresClient) GetResponder(resp *http.Response) (result DataStore, err error) {
   297  	err = autorest.Respond(
   298  		resp,
   299  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   300  		autorest.ByUnmarshallingJSON(&result),
   301  		autorest.ByClosing())
   302  	result.Response = autorest.Response{Response: resp}
   303  	return
   304  }
   305  
   306  // ListByDataManager gets all the data stores/repositories in the given resource.
   307  // Parameters:
   308  // resourceGroupName - the Resource Group Name
   309  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
   310  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
   311  // filter - oData Filter options
   312  func (client DataStoresClient) ListByDataManager(ctx context.Context, resourceGroupName string, dataManagerName string, filter string) (result DataStoreListPage, err error) {
   313  	if tracing.IsEnabled() {
   314  		ctx = tracing.StartSpan(ctx, fqdn+"/DataStoresClient.ListByDataManager")
   315  		defer func() {
   316  			sc := -1
   317  			if result.dsl.Response.Response != nil {
   318  				sc = result.dsl.Response.Response.StatusCode
   319  			}
   320  			tracing.EndSpan(ctx, sc, err)
   321  		}()
   322  	}
   323  	if err := validation.Validate([]validation.Validation{
   324  		{TargetValue: dataManagerName,
   325  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   326  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
   327  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
   328  		return result, validation.NewError("hybriddata.DataStoresClient", "ListByDataManager", err.Error())
   329  	}
   330  
   331  	result.fn = client.listByDataManagerNextResults
   332  	req, err := client.ListByDataManagerPreparer(ctx, resourceGroupName, dataManagerName, filter)
   333  	if err != nil {
   334  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "ListByDataManager", nil, "Failure preparing request")
   335  		return
   336  	}
   337  
   338  	resp, err := client.ListByDataManagerSender(req)
   339  	if err != nil {
   340  		result.dsl.Response = autorest.Response{Response: resp}
   341  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "ListByDataManager", resp, "Failure sending request")
   342  		return
   343  	}
   344  
   345  	result.dsl, err = client.ListByDataManagerResponder(resp)
   346  	if err != nil {
   347  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "ListByDataManager", resp, "Failure responding to request")
   348  		return
   349  	}
   350  	if result.dsl.hasNextLink() && result.dsl.IsEmpty() {
   351  		err = result.NextWithContext(ctx)
   352  		return
   353  	}
   354  
   355  	return
   356  }
   357  
   358  // ListByDataManagerPreparer prepares the ListByDataManager request.
   359  func (client DataStoresClient) ListByDataManagerPreparer(ctx context.Context, resourceGroupName string, dataManagerName string, filter string) (*http.Request, error) {
   360  	pathParameters := map[string]interface{}{
   361  		"dataManagerName":   autorest.Encode("path", dataManagerName),
   362  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   363  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   364  	}
   365  
   366  	const APIVersion = "2019-06-01"
   367  	queryParameters := map[string]interface{}{
   368  		"api-version": APIVersion,
   369  	}
   370  	if len(filter) > 0 {
   371  		queryParameters["$filter"] = autorest.Encode("query", filter)
   372  	}
   373  
   374  	preparer := autorest.CreatePreparer(
   375  		autorest.AsGet(),
   376  		autorest.WithBaseURL(client.BaseURI),
   377  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/dataStores", pathParameters),
   378  		autorest.WithQueryParameters(queryParameters))
   379  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   380  }
   381  
   382  // ListByDataManagerSender sends the ListByDataManager request. The method will close the
   383  // http.Response Body if it receives an error.
   384  func (client DataStoresClient) ListByDataManagerSender(req *http.Request) (*http.Response, error) {
   385  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   386  }
   387  
   388  // ListByDataManagerResponder handles the response to the ListByDataManager request. The method always
   389  // closes the http.Response Body.
   390  func (client DataStoresClient) ListByDataManagerResponder(resp *http.Response) (result DataStoreList, err error) {
   391  	err = autorest.Respond(
   392  		resp,
   393  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   394  		autorest.ByUnmarshallingJSON(&result),
   395  		autorest.ByClosing())
   396  	result.Response = autorest.Response{Response: resp}
   397  	return
   398  }
   399  
   400  // listByDataManagerNextResults retrieves the next set of results, if any.
   401  func (client DataStoresClient) listByDataManagerNextResults(ctx context.Context, lastResults DataStoreList) (result DataStoreList, err error) {
   402  	req, err := lastResults.dataStoreListPreparer(ctx)
   403  	if err != nil {
   404  		return result, autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "listByDataManagerNextResults", nil, "Failure preparing next results request")
   405  	}
   406  	if req == nil {
   407  		return
   408  	}
   409  	resp, err := client.ListByDataManagerSender(req)
   410  	if err != nil {
   411  		result.Response = autorest.Response{Response: resp}
   412  		return result, autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "listByDataManagerNextResults", resp, "Failure sending next results request")
   413  	}
   414  	result, err = client.ListByDataManagerResponder(resp)
   415  	if err != nil {
   416  		err = autorest.NewErrorWithError(err, "hybriddata.DataStoresClient", "listByDataManagerNextResults", resp, "Failure responding to next results request")
   417  	}
   418  	return
   419  }
   420  
   421  // ListByDataManagerComplete enumerates all values, automatically crossing page boundaries as required.
   422  func (client DataStoresClient) ListByDataManagerComplete(ctx context.Context, resourceGroupName string, dataManagerName string, filter string) (result DataStoreListIterator, err error) {
   423  	if tracing.IsEnabled() {
   424  		ctx = tracing.StartSpan(ctx, fqdn+"/DataStoresClient.ListByDataManager")
   425  		defer func() {
   426  			sc := -1
   427  			if result.Response().Response.Response != nil {
   428  				sc = result.page.Response().Response.Response.StatusCode
   429  			}
   430  			tracing.EndSpan(ctx, sc, err)
   431  		}()
   432  	}
   433  	result.page, err = client.ListByDataManager(ctx, resourceGroupName, dataManagerName, filter)
   434  	return
   435  }
   436  

View as plain text