...

Source file src/github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple/backupschedules.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  // BackupSchedulesClient is the client for the BackupSchedules methods of the Storsimple service.
    19  type BackupSchedulesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewBackupSchedulesClient creates an instance of the BackupSchedulesClient client.
    24  func NewBackupSchedulesClient(subscriptionID string) BackupSchedulesClient {
    25  	return NewBackupSchedulesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewBackupSchedulesClientWithBaseURI creates an instance of the BackupSchedulesClient 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 NewBackupSchedulesClientWithBaseURI(baseURI string, subscriptionID string) BackupSchedulesClient {
    31  	return BackupSchedulesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates or updates the backup schedule.
    35  // Parameters:
    36  // deviceName - the device name
    37  // backupPolicyName - the backup policy name.
    38  // backupScheduleName - the backup schedule name.
    39  // parameters - the backup schedule.
    40  // resourceGroupName - the resource group name
    41  // managerName - the manager name
    42  func (client BackupSchedulesClient) CreateOrUpdate(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, parameters BackupSchedule, resourceGroupName string, managerName string) (result BackupSchedulesCreateOrUpdateFuture, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupSchedulesClient.CreateOrUpdate")
    45  		defer func() {
    46  			sc := -1
    47  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    48  				sc = result.FutureAPI.Response().StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	if err := validation.Validate([]validation.Validation{
    54  		{TargetValue: parameters,
    55  			Constraints: []validation.Constraint{{Target: "parameters.BackupScheduleProperties", Name: validation.Null, Rule: true,
    56  				Chain: []validation.Constraint{{Target: "parameters.BackupScheduleProperties.ScheduleRecurrence", Name: validation.Null, Rule: true,
    57  					Chain: []validation.Constraint{{Target: "parameters.BackupScheduleProperties.ScheduleRecurrence.RecurrenceValue", Name: validation.Null, Rule: true, Chain: nil}}},
    58  					{Target: "parameters.BackupScheduleProperties.RetentionCount", Name: validation.Null, Rule: true, Chain: nil},
    59  					{Target: "parameters.BackupScheduleProperties.StartTime", Name: validation.Null, Rule: true, Chain: nil},
    60  				}}}},
    61  		{TargetValue: managerName,
    62  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    63  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
    64  		return result, validation.NewError("storsimple.BackupSchedulesClient", "CreateOrUpdate", err.Error())
    65  	}
    66  
    67  	req, err := client.CreateOrUpdatePreparer(ctx, deviceName, backupPolicyName, backupScheduleName, parameters, resourceGroupName, managerName)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "CreateOrUpdate", nil, "Failure preparing request")
    70  		return
    71  	}
    72  
    73  	result, err = client.CreateOrUpdateSender(req)
    74  	if err != nil {
    75  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    76  		return
    77  	}
    78  
    79  	return
    80  }
    81  
    82  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    83  func (client BackupSchedulesClient) CreateOrUpdatePreparer(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, parameters BackupSchedule, resourceGroupName string, managerName string) (*http.Request, error) {
    84  	pathParameters := map[string]interface{}{
    85  		"backupPolicyName":   backupPolicyName,
    86  		"backupScheduleName": backupScheduleName,
    87  		"deviceName":         deviceName,
    88  		"managerName":        managerName,
    89  		"resourceGroupName":  resourceGroupName,
    90  		"subscriptionId":     client.SubscriptionID,
    91  	}
    92  
    93  	const APIVersion = "2017-06-01"
    94  	queryParameters := map[string]interface{}{
    95  		"api-version": APIVersion,
    96  	}
    97  
    98  	preparer := autorest.CreatePreparer(
    99  		autorest.AsContentType("application/json; charset=utf-8"),
   100  		autorest.AsPut(),
   101  		autorest.WithBaseURL(client.BaseURI),
   102  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/schedules/{backupScheduleName}", pathParameters),
   103  		autorest.WithJSON(parameters),
   104  		autorest.WithQueryParameters(queryParameters))
   105  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   106  }
   107  
   108  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   109  // http.Response Body if it receives an error.
   110  func (client BackupSchedulesClient) CreateOrUpdateSender(req *http.Request) (future BackupSchedulesCreateOrUpdateFuture, err error) {
   111  	var resp *http.Response
   112  	future.FutureAPI = &azure.Future{}
   113  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   114  	if err != nil {
   115  		return
   116  	}
   117  	var azf azure.Future
   118  	azf, err = azure.NewFutureFromResponse(resp)
   119  	future.FutureAPI = &azf
   120  	future.Result = future.result
   121  	return
   122  }
   123  
   124  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   125  // closes the http.Response Body.
   126  func (client BackupSchedulesClient) CreateOrUpdateResponder(resp *http.Response) (result BackupSchedule, err error) {
   127  	err = autorest.Respond(
   128  		resp,
   129  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   130  		autorest.ByUnmarshallingJSON(&result),
   131  		autorest.ByClosing())
   132  	result.Response = autorest.Response{Response: resp}
   133  	return
   134  }
   135  
   136  // Delete deletes the backup schedule.
   137  // Parameters:
   138  // deviceName - the device name
   139  // backupPolicyName - the backup policy name.
   140  // backupScheduleName - the name the backup schedule.
   141  // resourceGroupName - the resource group name
   142  // managerName - the manager name
   143  func (client BackupSchedulesClient) Delete(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, resourceGroupName string, managerName string) (result BackupSchedulesDeleteFuture, err error) {
   144  	if tracing.IsEnabled() {
   145  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupSchedulesClient.Delete")
   146  		defer func() {
   147  			sc := -1
   148  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   149  				sc = result.FutureAPI.Response().StatusCode
   150  			}
   151  			tracing.EndSpan(ctx, sc, err)
   152  		}()
   153  	}
   154  	if err := validation.Validate([]validation.Validation{
   155  		{TargetValue: managerName,
   156  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   157  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   158  		return result, validation.NewError("storsimple.BackupSchedulesClient", "Delete", err.Error())
   159  	}
   160  
   161  	req, err := client.DeletePreparer(ctx, deviceName, backupPolicyName, backupScheduleName, resourceGroupName, managerName)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Delete", nil, "Failure preparing request")
   164  		return
   165  	}
   166  
   167  	result, err = client.DeleteSender(req)
   168  	if err != nil {
   169  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Delete", result.Response(), "Failure sending request")
   170  		return
   171  	}
   172  
   173  	return
   174  }
   175  
   176  // DeletePreparer prepares the Delete request.
   177  func (client BackupSchedulesClient) DeletePreparer(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, resourceGroupName string, managerName string) (*http.Request, error) {
   178  	pathParameters := map[string]interface{}{
   179  		"backupPolicyName":   backupPolicyName,
   180  		"backupScheduleName": backupScheduleName,
   181  		"deviceName":         deviceName,
   182  		"managerName":        managerName,
   183  		"resourceGroupName":  resourceGroupName,
   184  		"subscriptionId":     client.SubscriptionID,
   185  	}
   186  
   187  	const APIVersion = "2017-06-01"
   188  	queryParameters := map[string]interface{}{
   189  		"api-version": APIVersion,
   190  	}
   191  
   192  	preparer := autorest.CreatePreparer(
   193  		autorest.AsDelete(),
   194  		autorest.WithBaseURL(client.BaseURI),
   195  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/schedules/{backupScheduleName}", pathParameters),
   196  		autorest.WithQueryParameters(queryParameters))
   197  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   198  }
   199  
   200  // DeleteSender sends the Delete request. The method will close the
   201  // http.Response Body if it receives an error.
   202  func (client BackupSchedulesClient) DeleteSender(req *http.Request) (future BackupSchedulesDeleteFuture, err error) {
   203  	var resp *http.Response
   204  	future.FutureAPI = &azure.Future{}
   205  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   206  	if err != nil {
   207  		return
   208  	}
   209  	var azf azure.Future
   210  	azf, err = azure.NewFutureFromResponse(resp)
   211  	future.FutureAPI = &azf
   212  	future.Result = future.result
   213  	return
   214  }
   215  
   216  // DeleteResponder handles the response to the Delete request. The method always
   217  // closes the http.Response Body.
   218  func (client BackupSchedulesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   219  	err = autorest.Respond(
   220  		resp,
   221  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   222  		autorest.ByClosing())
   223  	result.Response = resp
   224  	return
   225  }
   226  
   227  // Get gets the properties of the specified backup schedule name.
   228  // Parameters:
   229  // deviceName - the device name
   230  // backupPolicyName - the backup policy name.
   231  // backupScheduleName - the name of the backup schedule to be fetched
   232  // resourceGroupName - the resource group name
   233  // managerName - the manager name
   234  func (client BackupSchedulesClient) Get(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, resourceGroupName string, managerName string) (result BackupSchedule, err error) {
   235  	if tracing.IsEnabled() {
   236  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupSchedulesClient.Get")
   237  		defer func() {
   238  			sc := -1
   239  			if result.Response.Response != nil {
   240  				sc = result.Response.Response.StatusCode
   241  			}
   242  			tracing.EndSpan(ctx, sc, err)
   243  		}()
   244  	}
   245  	if err := validation.Validate([]validation.Validation{
   246  		{TargetValue: managerName,
   247  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   248  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   249  		return result, validation.NewError("storsimple.BackupSchedulesClient", "Get", err.Error())
   250  	}
   251  
   252  	req, err := client.GetPreparer(ctx, deviceName, backupPolicyName, backupScheduleName, resourceGroupName, managerName)
   253  	if err != nil {
   254  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Get", nil, "Failure preparing request")
   255  		return
   256  	}
   257  
   258  	resp, err := client.GetSender(req)
   259  	if err != nil {
   260  		result.Response = autorest.Response{Response: resp}
   261  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Get", resp, "Failure sending request")
   262  		return
   263  	}
   264  
   265  	result, err = client.GetResponder(resp)
   266  	if err != nil {
   267  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Get", resp, "Failure responding to request")
   268  		return
   269  	}
   270  
   271  	return
   272  }
   273  
   274  // GetPreparer prepares the Get request.
   275  func (client BackupSchedulesClient) GetPreparer(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, resourceGroupName string, managerName string) (*http.Request, error) {
   276  	pathParameters := map[string]interface{}{
   277  		"backupPolicyName":   backupPolicyName,
   278  		"backupScheduleName": backupScheduleName,
   279  		"deviceName":         deviceName,
   280  		"managerName":        managerName,
   281  		"resourceGroupName":  resourceGroupName,
   282  		"subscriptionId":     client.SubscriptionID,
   283  	}
   284  
   285  	const APIVersion = "2017-06-01"
   286  	queryParameters := map[string]interface{}{
   287  		"api-version": APIVersion,
   288  	}
   289  
   290  	preparer := autorest.CreatePreparer(
   291  		autorest.AsGet(),
   292  		autorest.WithBaseURL(client.BaseURI),
   293  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/schedules/{backupScheduleName}", pathParameters),
   294  		autorest.WithQueryParameters(queryParameters))
   295  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   296  }
   297  
   298  // GetSender sends the Get request. The method will close the
   299  // http.Response Body if it receives an error.
   300  func (client BackupSchedulesClient) GetSender(req *http.Request) (*http.Response, error) {
   301  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   302  }
   303  
   304  // GetResponder handles the response to the Get request. The method always
   305  // closes the http.Response Body.
   306  func (client BackupSchedulesClient) GetResponder(resp *http.Response) (result BackupSchedule, err error) {
   307  	err = autorest.Respond(
   308  		resp,
   309  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   310  		autorest.ByUnmarshallingJSON(&result),
   311  		autorest.ByClosing())
   312  	result.Response = autorest.Response{Response: resp}
   313  	return
   314  }
   315  
   316  // ListByBackupPolicy gets all the backup schedules in a backup policy.
   317  // Parameters:
   318  // deviceName - the device name
   319  // backupPolicyName - the backup policy name.
   320  // resourceGroupName - the resource group name
   321  // managerName - the manager name
   322  func (client BackupSchedulesClient) ListByBackupPolicy(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (result BackupScheduleList, err error) {
   323  	if tracing.IsEnabled() {
   324  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupSchedulesClient.ListByBackupPolicy")
   325  		defer func() {
   326  			sc := -1
   327  			if result.Response.Response != nil {
   328  				sc = result.Response.Response.StatusCode
   329  			}
   330  			tracing.EndSpan(ctx, sc, err)
   331  		}()
   332  	}
   333  	if err := validation.Validate([]validation.Validation{
   334  		{TargetValue: managerName,
   335  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   336  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   337  		return result, validation.NewError("storsimple.BackupSchedulesClient", "ListByBackupPolicy", err.Error())
   338  	}
   339  
   340  	req, err := client.ListByBackupPolicyPreparer(ctx, deviceName, backupPolicyName, resourceGroupName, managerName)
   341  	if err != nil {
   342  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "ListByBackupPolicy", nil, "Failure preparing request")
   343  		return
   344  	}
   345  
   346  	resp, err := client.ListByBackupPolicySender(req)
   347  	if err != nil {
   348  		result.Response = autorest.Response{Response: resp}
   349  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "ListByBackupPolicy", resp, "Failure sending request")
   350  		return
   351  	}
   352  
   353  	result, err = client.ListByBackupPolicyResponder(resp)
   354  	if err != nil {
   355  		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "ListByBackupPolicy", resp, "Failure responding to request")
   356  		return
   357  	}
   358  
   359  	return
   360  }
   361  
   362  // ListByBackupPolicyPreparer prepares the ListByBackupPolicy request.
   363  func (client BackupSchedulesClient) ListByBackupPolicyPreparer(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (*http.Request, error) {
   364  	pathParameters := map[string]interface{}{
   365  		"backupPolicyName":  backupPolicyName,
   366  		"deviceName":        deviceName,
   367  		"managerName":       managerName,
   368  		"resourceGroupName": resourceGroupName,
   369  		"subscriptionId":    client.SubscriptionID,
   370  	}
   371  
   372  	const APIVersion = "2017-06-01"
   373  	queryParameters := map[string]interface{}{
   374  		"api-version": APIVersion,
   375  	}
   376  
   377  	preparer := autorest.CreatePreparer(
   378  		autorest.AsGet(),
   379  		autorest.WithBaseURL(client.BaseURI),
   380  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/schedules", pathParameters),
   381  		autorest.WithQueryParameters(queryParameters))
   382  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   383  }
   384  
   385  // ListByBackupPolicySender sends the ListByBackupPolicy request. The method will close the
   386  // http.Response Body if it receives an error.
   387  func (client BackupSchedulesClient) ListByBackupPolicySender(req *http.Request) (*http.Response, error) {
   388  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   389  }
   390  
   391  // ListByBackupPolicyResponder handles the response to the ListByBackupPolicy request. The method always
   392  // closes the http.Response Body.
   393  func (client BackupSchedulesClient) ListByBackupPolicyResponder(resp *http.Response) (result BackupScheduleList, err error) {
   394  	err = autorest.Respond(
   395  		resp,
   396  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   397  		autorest.ByUnmarshallingJSON(&result),
   398  		autorest.ByClosing())
   399  	result.Response = autorest.Response{Response: resp}
   400  	return
   401  }
   402  

View as plain text