...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/backup/jobs.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/backup

     1  package backup
     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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // JobsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type JobsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewJobsClient creates an instance of the JobsClient client.
    23  func NewJobsClient(subscriptionID string) JobsClient {
    24  	return NewJobsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewJobsClientWithBaseURI creates an instance of the JobsClient client using a custom endpoint.  Use this when
    28  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewJobsClientWithBaseURI(baseURI string, subscriptionID string) JobsClient {
    30  	return JobsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Export exports all jobs for a given Shared Access Signatures (SAS) URL. The SAS URL expires within 15 minutes of its
    34  // creation.
    35  // Parameters:
    36  // vaultName - the name of the Recovery Services vault.
    37  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
    38  // filter - the OData filter options. status eq { InProgress , Completed , Failed , CompletedWithWarnings ,
    39  // Cancelled , Cancelling } and backupManagementType eq {AzureIaasVM, MAB, DPM, AzureBackupServer, AzureSql }
    40  // and operation eq { ConfigureBackup , Backup , Restore , DisableBackup , DeleteBackupData } and jobId eq
    41  // {guid} and startTime eq { yyyy-mm-dd hh:mm:ss PM } and endTime eq { yyyy-mm-dd hh:mm:ss PM }.
    42  func (client JobsClient) Export(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result autorest.Response, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Export")
    45  		defer func() {
    46  			sc := -1
    47  			if result.Response != nil {
    48  				sc = result.Response.StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	req, err := client.ExportPreparer(ctx, vaultName, resourceGroupName, filter)
    54  	if err != nil {
    55  		err = autorest.NewErrorWithError(err, "backup.JobsClient", "Export", nil, "Failure preparing request")
    56  		return
    57  	}
    58  
    59  	resp, err := client.ExportSender(req)
    60  	if err != nil {
    61  		result.Response = resp
    62  		err = autorest.NewErrorWithError(err, "backup.JobsClient", "Export", resp, "Failure sending request")
    63  		return
    64  	}
    65  
    66  	result, err = client.ExportResponder(resp)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "backup.JobsClient", "Export", resp, "Failure responding to request")
    69  		return
    70  	}
    71  
    72  	return
    73  }
    74  
    75  // ExportPreparer prepares the Export request.
    76  func (client JobsClient) ExportPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string) (*http.Request, error) {
    77  	pathParameters := map[string]interface{}{
    78  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    79  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    80  		"vaultName":         autorest.Encode("path", vaultName),
    81  	}
    82  
    83  	const APIVersion = "2016-06-01"
    84  	queryParameters := map[string]interface{}{
    85  		"api-version": APIVersion,
    86  	}
    87  	if len(filter) > 0 {
    88  		queryParameters["$filter"] = autorest.Encode("query", filter)
    89  	}
    90  
    91  	preparer := autorest.CreatePreparer(
    92  		autorest.AsPost(),
    93  		autorest.WithBaseURL(client.BaseURI),
    94  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupJobsExport", pathParameters),
    95  		autorest.WithQueryParameters(queryParameters))
    96  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    97  }
    98  
    99  // ExportSender sends the Export request. The method will close the
   100  // http.Response Body if it receives an error.
   101  func (client JobsClient) ExportSender(req *http.Request) (*http.Response, error) {
   102  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   103  }
   104  
   105  // ExportResponder handles the response to the Export request. The method always
   106  // closes the http.Response Body.
   107  func (client JobsClient) ExportResponder(resp *http.Response) (result autorest.Response, err error) {
   108  	err = autorest.Respond(
   109  		resp,
   110  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   111  		autorest.ByClosing())
   112  	result.Response = resp
   113  	return
   114  }
   115  
   116  // List provides a pageable list of jobs.
   117  // Parameters:
   118  // vaultName - the name of the Recovery Services vault.
   119  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
   120  // filter - the following equation can be used to filter the list of jobs based on status, type, start date,
   121  // and end date. status eq { InProgress , Completed , Failed , CompletedWithWarnings , Cancelled , Cancelling }
   122  // and backupManagementType eq {AzureIaasVM, MAB, DPM, AzureBackupServer, AzureSql } and operation eq {
   123  // ConfigureBackup , Backup , Restore , DisableBackup , DeleteBackupData } and jobId eq {guid} and startTime eq
   124  // { yyyy-mm-dd hh:mm:ss PM } and endTime eq { yyyy-mm-dd hh:mm:ss PM }.
   125  // skipToken - the Skip Token filter.
   126  func (client JobsClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (result JobResourceListPage, err error) {
   127  	if tracing.IsEnabled() {
   128  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List")
   129  		defer func() {
   130  			sc := -1
   131  			if result.jrl.Response.Response != nil {
   132  				sc = result.jrl.Response.Response.StatusCode
   133  			}
   134  			tracing.EndSpan(ctx, sc, err)
   135  		}()
   136  	}
   137  	result.fn = client.listNextResults
   138  	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter, skipToken)
   139  	if err != nil {
   140  		err = autorest.NewErrorWithError(err, "backup.JobsClient", "List", nil, "Failure preparing request")
   141  		return
   142  	}
   143  
   144  	resp, err := client.ListSender(req)
   145  	if err != nil {
   146  		result.jrl.Response = autorest.Response{Response: resp}
   147  		err = autorest.NewErrorWithError(err, "backup.JobsClient", "List", resp, "Failure sending request")
   148  		return
   149  	}
   150  
   151  	result.jrl, err = client.ListResponder(resp)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "backup.JobsClient", "List", resp, "Failure responding to request")
   154  		return
   155  	}
   156  	if result.jrl.hasNextLink() && result.jrl.IsEmpty() {
   157  		err = result.NextWithContext(ctx)
   158  		return
   159  	}
   160  
   161  	return
   162  }
   163  
   164  // ListPreparer prepares the List request.
   165  func (client JobsClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (*http.Request, error) {
   166  	pathParameters := map[string]interface{}{
   167  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   168  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   169  		"vaultName":         autorest.Encode("path", vaultName),
   170  	}
   171  
   172  	const APIVersion = "2016-06-01"
   173  	queryParameters := map[string]interface{}{
   174  		"api-version": APIVersion,
   175  	}
   176  	if len(filter) > 0 {
   177  		queryParameters["$filter"] = autorest.Encode("query", filter)
   178  	}
   179  	if len(skipToken) > 0 {
   180  		queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
   181  	}
   182  
   183  	preparer := autorest.CreatePreparer(
   184  		autorest.AsGet(),
   185  		autorest.WithBaseURL(client.BaseURI),
   186  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupJobs", pathParameters),
   187  		autorest.WithQueryParameters(queryParameters))
   188  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   189  }
   190  
   191  // ListSender sends the List request. The method will close the
   192  // http.Response Body if it receives an error.
   193  func (client JobsClient) ListSender(req *http.Request) (*http.Response, error) {
   194  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   195  }
   196  
   197  // ListResponder handles the response to the List request. The method always
   198  // closes the http.Response Body.
   199  func (client JobsClient) ListResponder(resp *http.Response) (result JobResourceList, err error) {
   200  	err = autorest.Respond(
   201  		resp,
   202  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   203  		autorest.ByUnmarshallingJSON(&result),
   204  		autorest.ByClosing())
   205  	result.Response = autorest.Response{Response: resp}
   206  	return
   207  }
   208  
   209  // listNextResults retrieves the next set of results, if any.
   210  func (client JobsClient) listNextResults(ctx context.Context, lastResults JobResourceList) (result JobResourceList, err error) {
   211  	req, err := lastResults.jobResourceListPreparer(ctx)
   212  	if err != nil {
   213  		return result, autorest.NewErrorWithError(err, "backup.JobsClient", "listNextResults", nil, "Failure preparing next results request")
   214  	}
   215  	if req == nil {
   216  		return
   217  	}
   218  	resp, err := client.ListSender(req)
   219  	if err != nil {
   220  		result.Response = autorest.Response{Response: resp}
   221  		return result, autorest.NewErrorWithError(err, "backup.JobsClient", "listNextResults", resp, "Failure sending next results request")
   222  	}
   223  	result, err = client.ListResponder(resp)
   224  	if err != nil {
   225  		err = autorest.NewErrorWithError(err, "backup.JobsClient", "listNextResults", resp, "Failure responding to next results request")
   226  	}
   227  	return
   228  }
   229  
   230  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   231  func (client JobsClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (result JobResourceListIterator, err error) {
   232  	if tracing.IsEnabled() {
   233  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List")
   234  		defer func() {
   235  			sc := -1
   236  			if result.Response().Response.Response != nil {
   237  				sc = result.page.Response().Response.Response.StatusCode
   238  			}
   239  			tracing.EndSpan(ctx, sc, err)
   240  		}()
   241  	}
   242  	result.page, err = client.List(ctx, vaultName, resourceGroupName, filter, skipToken)
   243  	return
   244  }
   245  

View as plain text