...

Source file src/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-07-01/compute/diskrestorepoint.go

Documentation: github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-07-01/compute

     1  package compute
     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  // DiskRestorePointClient is the compute Client
    19  type DiskRestorePointClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewDiskRestorePointClient creates an instance of the DiskRestorePointClient client.
    24  func NewDiskRestorePointClient(subscriptionID string) DiskRestorePointClient {
    25  	return NewDiskRestorePointClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewDiskRestorePointClientWithBaseURI creates an instance of the DiskRestorePointClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewDiskRestorePointClientWithBaseURI(baseURI string, subscriptionID string) DiskRestorePointClient {
    32  	return DiskRestorePointClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // Get get disk restorePoint resource
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group.
    38  // restorePointCollectionName - the name of the restore point collection that the disk restore point belongs.
    39  // VMRestorePointName - the name of the vm restore point that the disk disk restore point belongs.
    40  // diskRestorePointName - the name of the disk restore point created.
    41  func (client DiskRestorePointClient) Get(ctx context.Context, resourceGroupName string, restorePointCollectionName string, VMRestorePointName string, diskRestorePointName string) (result DiskRestorePoint, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/DiskRestorePointClient.Get")
    44  		defer func() {
    45  			sc := -1
    46  			if result.Response.Response != nil {
    47  				sc = result.Response.Response.StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	req, err := client.GetPreparer(ctx, resourceGroupName, restorePointCollectionName, VMRestorePointName, diskRestorePointName)
    53  	if err != nil {
    54  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "Get", nil, "Failure preparing request")
    55  		return
    56  	}
    57  
    58  	resp, err := client.GetSender(req)
    59  	if err != nil {
    60  		result.Response = autorest.Response{Response: resp}
    61  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "Get", resp, "Failure sending request")
    62  		return
    63  	}
    64  
    65  	result, err = client.GetResponder(resp)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "Get", resp, "Failure responding to request")
    68  		return
    69  	}
    70  
    71  	return
    72  }
    73  
    74  // GetPreparer prepares the Get request.
    75  func (client DiskRestorePointClient) GetPreparer(ctx context.Context, resourceGroupName string, restorePointCollectionName string, VMRestorePointName string, diskRestorePointName string) (*http.Request, error) {
    76  	pathParameters := map[string]interface{}{
    77  		"diskRestorePointName":       autorest.Encode("path", diskRestorePointName),
    78  		"resourceGroupName":          autorest.Encode("path", resourceGroupName),
    79  		"restorePointCollectionName": autorest.Encode("path", restorePointCollectionName),
    80  		"subscriptionId":             autorest.Encode("path", client.SubscriptionID),
    81  		"vmRestorePointName":         autorest.Encode("path", VMRestorePointName),
    82  	}
    83  
    84  	const APIVersion = "2021-04-01"
    85  	queryParameters := map[string]interface{}{
    86  		"api-version": APIVersion,
    87  	}
    88  
    89  	preparer := autorest.CreatePreparer(
    90  		autorest.AsGet(),
    91  		autorest.WithBaseURL(client.BaseURI),
    92  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/restorePointCollections/{restorePointCollectionName}/restorePoints/{vmRestorePointName}/diskRestorePoints/{diskRestorePointName}", pathParameters),
    93  		autorest.WithQueryParameters(queryParameters))
    94  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    95  }
    96  
    97  // GetSender sends the Get request. The method will close the
    98  // http.Response Body if it receives an error.
    99  func (client DiskRestorePointClient) GetSender(req *http.Request) (*http.Response, error) {
   100  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   101  }
   102  
   103  // GetResponder handles the response to the Get request. The method always
   104  // closes the http.Response Body.
   105  func (client DiskRestorePointClient) GetResponder(resp *http.Response) (result DiskRestorePoint, err error) {
   106  	err = autorest.Respond(
   107  		resp,
   108  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   109  		autorest.ByUnmarshallingJSON(&result),
   110  		autorest.ByClosing())
   111  	result.Response = autorest.Response{Response: resp}
   112  	return
   113  }
   114  
   115  // GrantAccess grants access to a diskRestorePoint.
   116  // Parameters:
   117  // resourceGroupName - the name of the resource group.
   118  // restorePointCollectionName - the name of the restore point collection that the disk restore point belongs.
   119  // VMRestorePointName - the name of the vm restore point that the disk disk restore point belongs.
   120  // diskRestorePointName - the name of the disk restore point created.
   121  // grantAccessData - access data object supplied in the body of the get disk access operation.
   122  func (client DiskRestorePointClient) GrantAccess(ctx context.Context, resourceGroupName string, restorePointCollectionName string, VMRestorePointName string, diskRestorePointName string, grantAccessData GrantAccessData) (result DiskRestorePointGrantAccessFuture, err error) {
   123  	if tracing.IsEnabled() {
   124  		ctx = tracing.StartSpan(ctx, fqdn+"/DiskRestorePointClient.GrantAccess")
   125  		defer func() {
   126  			sc := -1
   127  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   128  				sc = result.FutureAPI.Response().StatusCode
   129  			}
   130  			tracing.EndSpan(ctx, sc, err)
   131  		}()
   132  	}
   133  	if err := validation.Validate([]validation.Validation{
   134  		{TargetValue: grantAccessData,
   135  			Constraints: []validation.Constraint{{Target: "grantAccessData.DurationInSeconds", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   136  		return result, validation.NewError("compute.DiskRestorePointClient", "GrantAccess", err.Error())
   137  	}
   138  
   139  	req, err := client.GrantAccessPreparer(ctx, resourceGroupName, restorePointCollectionName, VMRestorePointName, diskRestorePointName, grantAccessData)
   140  	if err != nil {
   141  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "GrantAccess", nil, "Failure preparing request")
   142  		return
   143  	}
   144  
   145  	result, err = client.GrantAccessSender(req)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "GrantAccess", result.Response(), "Failure sending request")
   148  		return
   149  	}
   150  
   151  	return
   152  }
   153  
   154  // GrantAccessPreparer prepares the GrantAccess request.
   155  func (client DiskRestorePointClient) GrantAccessPreparer(ctx context.Context, resourceGroupName string, restorePointCollectionName string, VMRestorePointName string, diskRestorePointName string, grantAccessData GrantAccessData) (*http.Request, error) {
   156  	pathParameters := map[string]interface{}{
   157  		"diskRestorePointName":       autorest.Encode("path", diskRestorePointName),
   158  		"resourceGroupName":          autorest.Encode("path", resourceGroupName),
   159  		"restorePointCollectionName": autorest.Encode("path", restorePointCollectionName),
   160  		"subscriptionId":             autorest.Encode("path", client.SubscriptionID),
   161  		"vmRestorePointName":         autorest.Encode("path", VMRestorePointName),
   162  	}
   163  
   164  	const APIVersion = "2021-04-01"
   165  	queryParameters := map[string]interface{}{
   166  		"api-version": APIVersion,
   167  	}
   168  
   169  	preparer := autorest.CreatePreparer(
   170  		autorest.AsContentType("application/json; charset=utf-8"),
   171  		autorest.AsPost(),
   172  		autorest.WithBaseURL(client.BaseURI),
   173  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/restorePointCollections/{restorePointCollectionName}/restorePoints/{vmRestorePointName}/diskRestorePoints/{diskRestorePointName}/beginGetAccess", pathParameters),
   174  		autorest.WithJSON(grantAccessData),
   175  		autorest.WithQueryParameters(queryParameters))
   176  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   177  }
   178  
   179  // GrantAccessSender sends the GrantAccess request. The method will close the
   180  // http.Response Body if it receives an error.
   181  func (client DiskRestorePointClient) GrantAccessSender(req *http.Request) (future DiskRestorePointGrantAccessFuture, err error) {
   182  	var resp *http.Response
   183  	future.FutureAPI = &azure.Future{}
   184  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   185  	if err != nil {
   186  		return
   187  	}
   188  	var azf azure.Future
   189  	azf, err = azure.NewFutureFromResponse(resp)
   190  	future.FutureAPI = &azf
   191  	future.Result = future.result
   192  	return
   193  }
   194  
   195  // GrantAccessResponder handles the response to the GrantAccess request. The method always
   196  // closes the http.Response Body.
   197  func (client DiskRestorePointClient) GrantAccessResponder(resp *http.Response) (result AccessURI, err error) {
   198  	err = autorest.Respond(
   199  		resp,
   200  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   201  		autorest.ByUnmarshallingJSON(&result),
   202  		autorest.ByClosing())
   203  	result.Response = autorest.Response{Response: resp}
   204  	return
   205  }
   206  
   207  // ListByRestorePoint lists diskRestorePoints under a vmRestorePoint.
   208  // Parameters:
   209  // resourceGroupName - the name of the resource group.
   210  // restorePointCollectionName - the name of the restore point collection that the disk restore point belongs.
   211  // VMRestorePointName - the name of the vm restore point that the disk disk restore point belongs.
   212  func (client DiskRestorePointClient) ListByRestorePoint(ctx context.Context, resourceGroupName string, restorePointCollectionName string, VMRestorePointName string) (result DiskRestorePointListPage, err error) {
   213  	if tracing.IsEnabled() {
   214  		ctx = tracing.StartSpan(ctx, fqdn+"/DiskRestorePointClient.ListByRestorePoint")
   215  		defer func() {
   216  			sc := -1
   217  			if result.drpl.Response.Response != nil {
   218  				sc = result.drpl.Response.Response.StatusCode
   219  			}
   220  			tracing.EndSpan(ctx, sc, err)
   221  		}()
   222  	}
   223  	result.fn = client.listByRestorePointNextResults
   224  	req, err := client.ListByRestorePointPreparer(ctx, resourceGroupName, restorePointCollectionName, VMRestorePointName)
   225  	if err != nil {
   226  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "ListByRestorePoint", nil, "Failure preparing request")
   227  		return
   228  	}
   229  
   230  	resp, err := client.ListByRestorePointSender(req)
   231  	if err != nil {
   232  		result.drpl.Response = autorest.Response{Response: resp}
   233  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "ListByRestorePoint", resp, "Failure sending request")
   234  		return
   235  	}
   236  
   237  	result.drpl, err = client.ListByRestorePointResponder(resp)
   238  	if err != nil {
   239  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "ListByRestorePoint", resp, "Failure responding to request")
   240  		return
   241  	}
   242  	if result.drpl.hasNextLink() && result.drpl.IsEmpty() {
   243  		err = result.NextWithContext(ctx)
   244  		return
   245  	}
   246  
   247  	return
   248  }
   249  
   250  // ListByRestorePointPreparer prepares the ListByRestorePoint request.
   251  func (client DiskRestorePointClient) ListByRestorePointPreparer(ctx context.Context, resourceGroupName string, restorePointCollectionName string, VMRestorePointName string) (*http.Request, error) {
   252  	pathParameters := map[string]interface{}{
   253  		"resourceGroupName":          autorest.Encode("path", resourceGroupName),
   254  		"restorePointCollectionName": autorest.Encode("path", restorePointCollectionName),
   255  		"subscriptionId":             autorest.Encode("path", client.SubscriptionID),
   256  		"vmRestorePointName":         autorest.Encode("path", VMRestorePointName),
   257  	}
   258  
   259  	const APIVersion = "2021-04-01"
   260  	queryParameters := map[string]interface{}{
   261  		"api-version": APIVersion,
   262  	}
   263  
   264  	preparer := autorest.CreatePreparer(
   265  		autorest.AsGet(),
   266  		autorest.WithBaseURL(client.BaseURI),
   267  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/restorePointCollections/{restorePointCollectionName}/restorePoints/{vmRestorePointName}/diskRestorePoints", pathParameters),
   268  		autorest.WithQueryParameters(queryParameters))
   269  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   270  }
   271  
   272  // ListByRestorePointSender sends the ListByRestorePoint request. The method will close the
   273  // http.Response Body if it receives an error.
   274  func (client DiskRestorePointClient) ListByRestorePointSender(req *http.Request) (*http.Response, error) {
   275  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   276  }
   277  
   278  // ListByRestorePointResponder handles the response to the ListByRestorePoint request. The method always
   279  // closes the http.Response Body.
   280  func (client DiskRestorePointClient) ListByRestorePointResponder(resp *http.Response) (result DiskRestorePointList, err error) {
   281  	err = autorest.Respond(
   282  		resp,
   283  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   284  		autorest.ByUnmarshallingJSON(&result),
   285  		autorest.ByClosing())
   286  	result.Response = autorest.Response{Response: resp}
   287  	return
   288  }
   289  
   290  // listByRestorePointNextResults retrieves the next set of results, if any.
   291  func (client DiskRestorePointClient) listByRestorePointNextResults(ctx context.Context, lastResults DiskRestorePointList) (result DiskRestorePointList, err error) {
   292  	req, err := lastResults.diskRestorePointListPreparer(ctx)
   293  	if err != nil {
   294  		return result, autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "listByRestorePointNextResults", nil, "Failure preparing next results request")
   295  	}
   296  	if req == nil {
   297  		return
   298  	}
   299  	resp, err := client.ListByRestorePointSender(req)
   300  	if err != nil {
   301  		result.Response = autorest.Response{Response: resp}
   302  		return result, autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "listByRestorePointNextResults", resp, "Failure sending next results request")
   303  	}
   304  	result, err = client.ListByRestorePointResponder(resp)
   305  	if err != nil {
   306  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "listByRestorePointNextResults", resp, "Failure responding to next results request")
   307  	}
   308  	return
   309  }
   310  
   311  // ListByRestorePointComplete enumerates all values, automatically crossing page boundaries as required.
   312  func (client DiskRestorePointClient) ListByRestorePointComplete(ctx context.Context, resourceGroupName string, restorePointCollectionName string, VMRestorePointName string) (result DiskRestorePointListIterator, err error) {
   313  	if tracing.IsEnabled() {
   314  		ctx = tracing.StartSpan(ctx, fqdn+"/DiskRestorePointClient.ListByRestorePoint")
   315  		defer func() {
   316  			sc := -1
   317  			if result.Response().Response.Response != nil {
   318  				sc = result.page.Response().Response.Response.StatusCode
   319  			}
   320  			tracing.EndSpan(ctx, sc, err)
   321  		}()
   322  	}
   323  	result.page, err = client.ListByRestorePoint(ctx, resourceGroupName, restorePointCollectionName, VMRestorePointName)
   324  	return
   325  }
   326  
   327  // RevokeAccess revokes access to a diskRestorePoint.
   328  // Parameters:
   329  // resourceGroupName - the name of the resource group.
   330  // restorePointCollectionName - the name of the restore point collection that the disk restore point belongs.
   331  // VMRestorePointName - the name of the vm restore point that the disk disk restore point belongs.
   332  // diskRestorePointName - the name of the disk restore point created.
   333  func (client DiskRestorePointClient) RevokeAccess(ctx context.Context, resourceGroupName string, restorePointCollectionName string, VMRestorePointName string, diskRestorePointName string) (result DiskRestorePointRevokeAccessFuture, err error) {
   334  	if tracing.IsEnabled() {
   335  		ctx = tracing.StartSpan(ctx, fqdn+"/DiskRestorePointClient.RevokeAccess")
   336  		defer func() {
   337  			sc := -1
   338  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   339  				sc = result.FutureAPI.Response().StatusCode
   340  			}
   341  			tracing.EndSpan(ctx, sc, err)
   342  		}()
   343  	}
   344  	req, err := client.RevokeAccessPreparer(ctx, resourceGroupName, restorePointCollectionName, VMRestorePointName, diskRestorePointName)
   345  	if err != nil {
   346  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "RevokeAccess", nil, "Failure preparing request")
   347  		return
   348  	}
   349  
   350  	result, err = client.RevokeAccessSender(req)
   351  	if err != nil {
   352  		err = autorest.NewErrorWithError(err, "compute.DiskRestorePointClient", "RevokeAccess", result.Response(), "Failure sending request")
   353  		return
   354  	}
   355  
   356  	return
   357  }
   358  
   359  // RevokeAccessPreparer prepares the RevokeAccess request.
   360  func (client DiskRestorePointClient) RevokeAccessPreparer(ctx context.Context, resourceGroupName string, restorePointCollectionName string, VMRestorePointName string, diskRestorePointName string) (*http.Request, error) {
   361  	pathParameters := map[string]interface{}{
   362  		"diskRestorePointName":       autorest.Encode("path", diskRestorePointName),
   363  		"resourceGroupName":          autorest.Encode("path", resourceGroupName),
   364  		"restorePointCollectionName": autorest.Encode("path", restorePointCollectionName),
   365  		"subscriptionId":             autorest.Encode("path", client.SubscriptionID),
   366  		"vmRestorePointName":         autorest.Encode("path", VMRestorePointName),
   367  	}
   368  
   369  	const APIVersion = "2021-04-01"
   370  	queryParameters := map[string]interface{}{
   371  		"api-version": APIVersion,
   372  	}
   373  
   374  	preparer := autorest.CreatePreparer(
   375  		autorest.AsPost(),
   376  		autorest.WithBaseURL(client.BaseURI),
   377  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/restorePointCollections/{restorePointCollectionName}/restorePoints/{vmRestorePointName}/diskRestorePoints/{diskRestorePointName}/endGetAccess", pathParameters),
   378  		autorest.WithQueryParameters(queryParameters))
   379  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   380  }
   381  
   382  // RevokeAccessSender sends the RevokeAccess request. The method will close the
   383  // http.Response Body if it receives an error.
   384  func (client DiskRestorePointClient) RevokeAccessSender(req *http.Request) (future DiskRestorePointRevokeAccessFuture, err error) {
   385  	var resp *http.Response
   386  	future.FutureAPI = &azure.Future{}
   387  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   388  	if err != nil {
   389  		return
   390  	}
   391  	var azf azure.Future
   392  	azf, err = azure.NewFutureFromResponse(resp)
   393  	future.FutureAPI = &azf
   394  	future.Result = future.result
   395  	return
   396  }
   397  
   398  // RevokeAccessResponder handles the response to the RevokeAccess request. The method always
   399  // closes the http.Response Body.
   400  func (client DiskRestorePointClient) RevokeAccessResponder(resp *http.Response) (result autorest.Response, err error) {
   401  	err = autorest.Respond(
   402  		resp,
   403  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   404  		autorest.ByClosing())
   405  	result.Response = resp
   406  	return
   407  }
   408  

View as plain text