...

Source file src/github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple/backuppolicies.go

Documentation: github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple

     1  package storsimple
     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  // BackupPoliciesClient is the client for the BackupPolicies methods of the Storsimple service.
    19  type BackupPoliciesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewBackupPoliciesClient creates an instance of the BackupPoliciesClient client.
    24  func NewBackupPoliciesClient(subscriptionID string) BackupPoliciesClient {
    25  	return NewBackupPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewBackupPoliciesClientWithBaseURI creates an instance of the BackupPoliciesClient 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 NewBackupPoliciesClientWithBaseURI(baseURI string, subscriptionID string) BackupPoliciesClient {
    31  	return BackupPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // BackupNow backup the backup policy now.
    35  // Parameters:
    36  // deviceName - the device name
    37  // backupPolicyName - the backup policy name.
    38  // backupType - the backup Type. This can be cloudSnapshot or localSnapshot.
    39  // resourceGroupName - the resource group name
    40  // managerName - the manager name
    41  func (client BackupPoliciesClient) BackupNow(ctx context.Context, deviceName string, backupPolicyName string, backupType string, resourceGroupName string, managerName string) (result BackupPoliciesBackupNowFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.BackupNow")
    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: managerName,
    54  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    55  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
    56  		return result, validation.NewError("storsimple.BackupPoliciesClient", "BackupNow", err.Error())
    57  	}
    58  
    59  	req, err := client.BackupNowPreparer(ctx, deviceName, backupPolicyName, backupType, resourceGroupName, managerName)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "BackupNow", nil, "Failure preparing request")
    62  		return
    63  	}
    64  
    65  	result, err = client.BackupNowSender(req)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "BackupNow", result.Response(), "Failure sending request")
    68  		return
    69  	}
    70  
    71  	return
    72  }
    73  
    74  // BackupNowPreparer prepares the BackupNow request.
    75  func (client BackupPoliciesClient) BackupNowPreparer(ctx context.Context, deviceName string, backupPolicyName string, backupType string, resourceGroupName string, managerName string) (*http.Request, error) {
    76  	pathParameters := map[string]interface{}{
    77  		"backupPolicyName":  backupPolicyName,
    78  		"deviceName":        deviceName,
    79  		"managerName":       managerName,
    80  		"resourceGroupName": resourceGroupName,
    81  		"subscriptionId":    client.SubscriptionID,
    82  	}
    83  
    84  	const APIVersion = "2017-06-01"
    85  	queryParameters := map[string]interface{}{
    86  		"api-version": APIVersion,
    87  		"backupType":  backupType,
    88  	}
    89  
    90  	preparer := autorest.CreatePreparer(
    91  		autorest.AsPost(),
    92  		autorest.WithBaseURL(client.BaseURI),
    93  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/backup", pathParameters),
    94  		autorest.WithQueryParameters(queryParameters))
    95  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    96  }
    97  
    98  // BackupNowSender sends the BackupNow request. The method will close the
    99  // http.Response Body if it receives an error.
   100  func (client BackupPoliciesClient) BackupNowSender(req *http.Request) (future BackupPoliciesBackupNowFuture, err error) {
   101  	var resp *http.Response
   102  	future.FutureAPI = &azure.Future{}
   103  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   104  	if err != nil {
   105  		return
   106  	}
   107  	var azf azure.Future
   108  	azf, err = azure.NewFutureFromResponse(resp)
   109  	future.FutureAPI = &azf
   110  	future.Result = future.result
   111  	return
   112  }
   113  
   114  // BackupNowResponder handles the response to the BackupNow request. The method always
   115  // closes the http.Response Body.
   116  func (client BackupPoliciesClient) BackupNowResponder(resp *http.Response) (result autorest.Response, err error) {
   117  	err = autorest.Respond(
   118  		resp,
   119  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   120  		autorest.ByClosing())
   121  	result.Response = resp
   122  	return
   123  }
   124  
   125  // CreateOrUpdate creates or updates the backup policy.
   126  // Parameters:
   127  // deviceName - the device name
   128  // backupPolicyName - the name of the backup policy to be created/updated.
   129  // parameters - the backup policy.
   130  // resourceGroupName - the resource group name
   131  // managerName - the manager name
   132  func (client BackupPoliciesClient) CreateOrUpdate(ctx context.Context, deviceName string, backupPolicyName string, parameters BackupPolicy, resourceGroupName string, managerName string) (result BackupPoliciesCreateOrUpdateFuture, err error) {
   133  	if tracing.IsEnabled() {
   134  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.CreateOrUpdate")
   135  		defer func() {
   136  			sc := -1
   137  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   138  				sc = result.FutureAPI.Response().StatusCode
   139  			}
   140  			tracing.EndSpan(ctx, sc, err)
   141  		}()
   142  	}
   143  	if err := validation.Validate([]validation.Validation{
   144  		{TargetValue: parameters,
   145  			Constraints: []validation.Constraint{{Target: "parameters.BackupPolicyProperties", Name: validation.Null, Rule: true,
   146  				Chain: []validation.Constraint{{Target: "parameters.BackupPolicyProperties.VolumeIds", Name: validation.Null, Rule: true, Chain: nil}}}}},
   147  		{TargetValue: managerName,
   148  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   149  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   150  		return result, validation.NewError("storsimple.BackupPoliciesClient", "CreateOrUpdate", err.Error())
   151  	}
   152  
   153  	req, err := client.CreateOrUpdatePreparer(ctx, deviceName, backupPolicyName, parameters, resourceGroupName, managerName)
   154  	if err != nil {
   155  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request")
   156  		return
   157  	}
   158  
   159  	result, err = client.CreateOrUpdateSender(req)
   160  	if err != nil {
   161  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
   162  		return
   163  	}
   164  
   165  	return
   166  }
   167  
   168  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
   169  func (client BackupPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, deviceName string, backupPolicyName string, parameters BackupPolicy, resourceGroupName string, managerName string) (*http.Request, error) {
   170  	pathParameters := map[string]interface{}{
   171  		"backupPolicyName":  backupPolicyName,
   172  		"deviceName":        deviceName,
   173  		"managerName":       managerName,
   174  		"resourceGroupName": resourceGroupName,
   175  		"subscriptionId":    client.SubscriptionID,
   176  	}
   177  
   178  	const APIVersion = "2017-06-01"
   179  	queryParameters := map[string]interface{}{
   180  		"api-version": APIVersion,
   181  	}
   182  
   183  	preparer := autorest.CreatePreparer(
   184  		autorest.AsContentType("application/json; charset=utf-8"),
   185  		autorest.AsPut(),
   186  		autorest.WithBaseURL(client.BaseURI),
   187  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}", pathParameters),
   188  		autorest.WithJSON(parameters),
   189  		autorest.WithQueryParameters(queryParameters))
   190  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   191  }
   192  
   193  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   194  // http.Response Body if it receives an error.
   195  func (client BackupPoliciesClient) CreateOrUpdateSender(req *http.Request) (future BackupPoliciesCreateOrUpdateFuture, err error) {
   196  	var resp *http.Response
   197  	future.FutureAPI = &azure.Future{}
   198  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   199  	if err != nil {
   200  		return
   201  	}
   202  	var azf azure.Future
   203  	azf, err = azure.NewFutureFromResponse(resp)
   204  	future.FutureAPI = &azf
   205  	future.Result = future.result
   206  	return
   207  }
   208  
   209  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   210  // closes the http.Response Body.
   211  func (client BackupPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result BackupPolicy, err error) {
   212  	err = autorest.Respond(
   213  		resp,
   214  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   215  		autorest.ByUnmarshallingJSON(&result),
   216  		autorest.ByClosing())
   217  	result.Response = autorest.Response{Response: resp}
   218  	return
   219  }
   220  
   221  // Delete deletes the backup policy.
   222  // Parameters:
   223  // deviceName - the device name
   224  // backupPolicyName - the name of the backup policy.
   225  // resourceGroupName - the resource group name
   226  // managerName - the manager name
   227  func (client BackupPoliciesClient) Delete(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (result BackupPoliciesDeleteFuture, err error) {
   228  	if tracing.IsEnabled() {
   229  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.Delete")
   230  		defer func() {
   231  			sc := -1
   232  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   233  				sc = result.FutureAPI.Response().StatusCode
   234  			}
   235  			tracing.EndSpan(ctx, sc, err)
   236  		}()
   237  	}
   238  	if err := validation.Validate([]validation.Validation{
   239  		{TargetValue: managerName,
   240  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   241  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   242  		return result, validation.NewError("storsimple.BackupPoliciesClient", "Delete", err.Error())
   243  	}
   244  
   245  	req, err := client.DeletePreparer(ctx, deviceName, backupPolicyName, resourceGroupName, managerName)
   246  	if err != nil {
   247  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Delete", nil, "Failure preparing request")
   248  		return
   249  	}
   250  
   251  	result, err = client.DeleteSender(req)
   252  	if err != nil {
   253  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Delete", result.Response(), "Failure sending request")
   254  		return
   255  	}
   256  
   257  	return
   258  }
   259  
   260  // DeletePreparer prepares the Delete request.
   261  func (client BackupPoliciesClient) DeletePreparer(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (*http.Request, error) {
   262  	pathParameters := map[string]interface{}{
   263  		"backupPolicyName":  backupPolicyName,
   264  		"deviceName":        deviceName,
   265  		"managerName":       managerName,
   266  		"resourceGroupName": resourceGroupName,
   267  		"subscriptionId":    client.SubscriptionID,
   268  	}
   269  
   270  	const APIVersion = "2017-06-01"
   271  	queryParameters := map[string]interface{}{
   272  		"api-version": APIVersion,
   273  	}
   274  
   275  	preparer := autorest.CreatePreparer(
   276  		autorest.AsDelete(),
   277  		autorest.WithBaseURL(client.BaseURI),
   278  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}", pathParameters),
   279  		autorest.WithQueryParameters(queryParameters))
   280  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   281  }
   282  
   283  // DeleteSender sends the Delete request. The method will close the
   284  // http.Response Body if it receives an error.
   285  func (client BackupPoliciesClient) DeleteSender(req *http.Request) (future BackupPoliciesDeleteFuture, err error) {
   286  	var resp *http.Response
   287  	future.FutureAPI = &azure.Future{}
   288  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   289  	if err != nil {
   290  		return
   291  	}
   292  	var azf azure.Future
   293  	azf, err = azure.NewFutureFromResponse(resp)
   294  	future.FutureAPI = &azf
   295  	future.Result = future.result
   296  	return
   297  }
   298  
   299  // DeleteResponder handles the response to the Delete request. The method always
   300  // closes the http.Response Body.
   301  func (client BackupPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   302  	err = autorest.Respond(
   303  		resp,
   304  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   305  		autorest.ByClosing())
   306  	result.Response = resp
   307  	return
   308  }
   309  
   310  // Get gets the properties of the specified backup policy name.
   311  // Parameters:
   312  // deviceName - the device name
   313  // backupPolicyName - the name of backup policy to be fetched.
   314  // resourceGroupName - the resource group name
   315  // managerName - the manager name
   316  func (client BackupPoliciesClient) Get(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (result BackupPolicy, err error) {
   317  	if tracing.IsEnabled() {
   318  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.Get")
   319  		defer func() {
   320  			sc := -1
   321  			if result.Response.Response != nil {
   322  				sc = result.Response.Response.StatusCode
   323  			}
   324  			tracing.EndSpan(ctx, sc, err)
   325  		}()
   326  	}
   327  	if err := validation.Validate([]validation.Validation{
   328  		{TargetValue: managerName,
   329  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   330  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   331  		return result, validation.NewError("storsimple.BackupPoliciesClient", "Get", err.Error())
   332  	}
   333  
   334  	req, err := client.GetPreparer(ctx, deviceName, backupPolicyName, resourceGroupName, managerName)
   335  	if err != nil {
   336  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Get", nil, "Failure preparing request")
   337  		return
   338  	}
   339  
   340  	resp, err := client.GetSender(req)
   341  	if err != nil {
   342  		result.Response = autorest.Response{Response: resp}
   343  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Get", resp, "Failure sending request")
   344  		return
   345  	}
   346  
   347  	result, err = client.GetResponder(resp)
   348  	if err != nil {
   349  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Get", resp, "Failure responding to request")
   350  		return
   351  	}
   352  
   353  	return
   354  }
   355  
   356  // GetPreparer prepares the Get request.
   357  func (client BackupPoliciesClient) GetPreparer(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (*http.Request, error) {
   358  	pathParameters := map[string]interface{}{
   359  		"backupPolicyName":  backupPolicyName,
   360  		"deviceName":        deviceName,
   361  		"managerName":       managerName,
   362  		"resourceGroupName": resourceGroupName,
   363  		"subscriptionId":    client.SubscriptionID,
   364  	}
   365  
   366  	const APIVersion = "2017-06-01"
   367  	queryParameters := map[string]interface{}{
   368  		"api-version": APIVersion,
   369  	}
   370  
   371  	preparer := autorest.CreatePreparer(
   372  		autorest.AsGet(),
   373  		autorest.WithBaseURL(client.BaseURI),
   374  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}", pathParameters),
   375  		autorest.WithQueryParameters(queryParameters))
   376  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   377  }
   378  
   379  // GetSender sends the Get request. The method will close the
   380  // http.Response Body if it receives an error.
   381  func (client BackupPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
   382  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   383  }
   384  
   385  // GetResponder handles the response to the Get request. The method always
   386  // closes the http.Response Body.
   387  func (client BackupPoliciesClient) GetResponder(resp *http.Response) (result BackupPolicy, err error) {
   388  	err = autorest.Respond(
   389  		resp,
   390  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   391  		autorest.ByUnmarshallingJSON(&result),
   392  		autorest.ByClosing())
   393  	result.Response = autorest.Response{Response: resp}
   394  	return
   395  }
   396  
   397  // ListByDevice gets all the backup policies in a device.
   398  // Parameters:
   399  // deviceName - the device name
   400  // resourceGroupName - the resource group name
   401  // managerName - the manager name
   402  func (client BackupPoliciesClient) ListByDevice(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (result BackupPolicyList, err error) {
   403  	if tracing.IsEnabled() {
   404  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.ListByDevice")
   405  		defer func() {
   406  			sc := -1
   407  			if result.Response.Response != nil {
   408  				sc = result.Response.Response.StatusCode
   409  			}
   410  			tracing.EndSpan(ctx, sc, err)
   411  		}()
   412  	}
   413  	if err := validation.Validate([]validation.Validation{
   414  		{TargetValue: managerName,
   415  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   416  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   417  		return result, validation.NewError("storsimple.BackupPoliciesClient", "ListByDevice", err.Error())
   418  	}
   419  
   420  	req, err := client.ListByDevicePreparer(ctx, deviceName, resourceGroupName, managerName)
   421  	if err != nil {
   422  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "ListByDevice", nil, "Failure preparing request")
   423  		return
   424  	}
   425  
   426  	resp, err := client.ListByDeviceSender(req)
   427  	if err != nil {
   428  		result.Response = autorest.Response{Response: resp}
   429  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "ListByDevice", resp, "Failure sending request")
   430  		return
   431  	}
   432  
   433  	result, err = client.ListByDeviceResponder(resp)
   434  	if err != nil {
   435  		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "ListByDevice", resp, "Failure responding to request")
   436  		return
   437  	}
   438  
   439  	return
   440  }
   441  
   442  // ListByDevicePreparer prepares the ListByDevice request.
   443  func (client BackupPoliciesClient) ListByDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (*http.Request, error) {
   444  	pathParameters := map[string]interface{}{
   445  		"deviceName":        deviceName,
   446  		"managerName":       managerName,
   447  		"resourceGroupName": resourceGroupName,
   448  		"subscriptionId":    client.SubscriptionID,
   449  	}
   450  
   451  	const APIVersion = "2017-06-01"
   452  	queryParameters := map[string]interface{}{
   453  		"api-version": APIVersion,
   454  	}
   455  
   456  	preparer := autorest.CreatePreparer(
   457  		autorest.AsGet(),
   458  		autorest.WithBaseURL(client.BaseURI),
   459  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies", pathParameters),
   460  		autorest.WithQueryParameters(queryParameters))
   461  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   462  }
   463  
   464  // ListByDeviceSender sends the ListByDevice request. The method will close the
   465  // http.Response Body if it receives an error.
   466  func (client BackupPoliciesClient) ListByDeviceSender(req *http.Request) (*http.Response, error) {
   467  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   468  }
   469  
   470  // ListByDeviceResponder handles the response to the ListByDevice request. The method always
   471  // closes the http.Response Body.
   472  func (client BackupPoliciesClient) ListByDeviceResponder(resp *http.Response) (result BackupPolicyList, err error) {
   473  	err = autorest.Respond(
   474  		resp,
   475  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   476  		autorest.ByUnmarshallingJSON(&result),
   477  		autorest.ByClosing())
   478  	result.Response = autorest.Response{Response: resp}
   479  	return
   480  }
   481  

View as plain text