...

Source file src/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-06-30/compute/disks.go

Documentation: github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-06-30/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  // DisksClient is the compute Client
    19  type DisksClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewDisksClient creates an instance of the DisksClient client.
    24  func NewDisksClient(subscriptionID string) DisksClient {
    25  	return NewDisksClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewDisksClientWithBaseURI creates an instance of the DisksClient client using a custom endpoint.  Use this when
    29  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewDisksClientWithBaseURI(baseURI string, subscriptionID string) DisksClient {
    31  	return DisksClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates or updates a disk.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // diskName - the name of the managed disk that is being created. The name can't be changed after the disk is
    38  // created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80
    39  // characters.
    40  // disk - disk object supplied in the body of the Put disk operation.
    41  func (client DisksClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, diskName string, disk Disk) (result DisksCreateOrUpdateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.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: disk,
    54  			Constraints: []validation.Constraint{{Target: "disk.DiskProperties", Name: validation.Null, Rule: false,
    55  				Chain: []validation.Constraint{{Target: "disk.DiskProperties.CreationData", Name: validation.Null, Rule: true,
    56  					Chain: []validation.Constraint{{Target: "disk.DiskProperties.CreationData.ImageReference", Name: validation.Null, Rule: false,
    57  						Chain: []validation.Constraint{{Target: "disk.DiskProperties.CreationData.ImageReference.ID", Name: validation.Null, Rule: true, Chain: nil}}},
    58  						{Target: "disk.DiskProperties.CreationData.GalleryImageReference", Name: validation.Null, Rule: false,
    59  							Chain: []validation.Constraint{{Target: "disk.DiskProperties.CreationData.GalleryImageReference.ID", Name: validation.Null, Rule: true, Chain: nil}}},
    60  					}},
    61  					{Target: "disk.DiskProperties.EncryptionSettingsCollection", Name: validation.Null, Rule: false,
    62  						Chain: []validation.Constraint{{Target: "disk.DiskProperties.EncryptionSettingsCollection.Enabled", Name: validation.Null, Rule: true, Chain: nil}}},
    63  				}}}}}); err != nil {
    64  		return result, validation.NewError("compute.DisksClient", "CreateOrUpdate", err.Error())
    65  	}
    66  
    67  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, diskName, disk)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "CreateOrUpdate", nil, "Failure preparing request")
    70  		return
    71  	}
    72  
    73  	result, err = client.CreateOrUpdateSender(req)
    74  	if err != nil {
    75  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    76  		return
    77  	}
    78  
    79  	return
    80  }
    81  
    82  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    83  func (client DisksClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, diskName string, disk Disk) (*http.Request, error) {
    84  	pathParameters := map[string]interface{}{
    85  		"diskName":          autorest.Encode("path", diskName),
    86  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    87  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    88  	}
    89  
    90  	const APIVersion = "2020-06-30"
    91  	queryParameters := map[string]interface{}{
    92  		"api-version": APIVersion,
    93  	}
    94  
    95  	disk.ManagedBy = nil
    96  	disk.ManagedByExtended = nil
    97  	preparer := autorest.CreatePreparer(
    98  		autorest.AsContentType("application/json; charset=utf-8"),
    99  		autorest.AsPut(),
   100  		autorest.WithBaseURL(client.BaseURI),
   101  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters),
   102  		autorest.WithJSON(disk),
   103  		autorest.WithQueryParameters(queryParameters))
   104  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   105  }
   106  
   107  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   108  // http.Response Body if it receives an error.
   109  func (client DisksClient) CreateOrUpdateSender(req *http.Request) (future DisksCreateOrUpdateFuture, err error) {
   110  	var resp *http.Response
   111  	future.FutureAPI = &azure.Future{}
   112  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   113  	if err != nil {
   114  		return
   115  	}
   116  	var azf azure.Future
   117  	azf, err = azure.NewFutureFromResponse(resp)
   118  	future.FutureAPI = &azf
   119  	future.Result = future.result
   120  	return
   121  }
   122  
   123  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   124  // closes the http.Response Body.
   125  func (client DisksClient) CreateOrUpdateResponder(resp *http.Response) (result Disk, err error) {
   126  	err = autorest.Respond(
   127  		resp,
   128  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   129  		autorest.ByUnmarshallingJSON(&result),
   130  		autorest.ByClosing())
   131  	result.Response = autorest.Response{Response: resp}
   132  	return
   133  }
   134  
   135  // Delete deletes a disk.
   136  // Parameters:
   137  // resourceGroupName - the name of the resource group.
   138  // diskName - the name of the managed disk that is being created. The name can't be changed after the disk is
   139  // created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80
   140  // characters.
   141  func (client DisksClient) Delete(ctx context.Context, resourceGroupName string, diskName string) (result DisksDeleteFuture, err error) {
   142  	if tracing.IsEnabled() {
   143  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.Delete")
   144  		defer func() {
   145  			sc := -1
   146  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   147  				sc = result.FutureAPI.Response().StatusCode
   148  			}
   149  			tracing.EndSpan(ctx, sc, err)
   150  		}()
   151  	}
   152  	req, err := client.DeletePreparer(ctx, resourceGroupName, diskName)
   153  	if err != nil {
   154  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "Delete", nil, "Failure preparing request")
   155  		return
   156  	}
   157  
   158  	result, err = client.DeleteSender(req)
   159  	if err != nil {
   160  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "Delete", result.Response(), "Failure sending request")
   161  		return
   162  	}
   163  
   164  	return
   165  }
   166  
   167  // DeletePreparer prepares the Delete request.
   168  func (client DisksClient) DeletePreparer(ctx context.Context, resourceGroupName string, diskName string) (*http.Request, error) {
   169  	pathParameters := map[string]interface{}{
   170  		"diskName":          autorest.Encode("path", diskName),
   171  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   172  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   173  	}
   174  
   175  	const APIVersion = "2020-06-30"
   176  	queryParameters := map[string]interface{}{
   177  		"api-version": APIVersion,
   178  	}
   179  
   180  	preparer := autorest.CreatePreparer(
   181  		autorest.AsDelete(),
   182  		autorest.WithBaseURL(client.BaseURI),
   183  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters),
   184  		autorest.WithQueryParameters(queryParameters))
   185  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   186  }
   187  
   188  // DeleteSender sends the Delete request. The method will close the
   189  // http.Response Body if it receives an error.
   190  func (client DisksClient) DeleteSender(req *http.Request) (future DisksDeleteFuture, err error) {
   191  	var resp *http.Response
   192  	future.FutureAPI = &azure.Future{}
   193  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   194  	if err != nil {
   195  		return
   196  	}
   197  	var azf azure.Future
   198  	azf, err = azure.NewFutureFromResponse(resp)
   199  	future.FutureAPI = &azf
   200  	future.Result = future.result
   201  	return
   202  }
   203  
   204  // DeleteResponder handles the response to the Delete request. The method always
   205  // closes the http.Response Body.
   206  func (client DisksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   207  	err = autorest.Respond(
   208  		resp,
   209  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   210  		autorest.ByClosing())
   211  	result.Response = resp
   212  	return
   213  }
   214  
   215  // Get gets information about a disk.
   216  // Parameters:
   217  // resourceGroupName - the name of the resource group.
   218  // diskName - the name of the managed disk that is being created. The name can't be changed after the disk is
   219  // created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80
   220  // characters.
   221  func (client DisksClient) Get(ctx context.Context, resourceGroupName string, diskName string) (result Disk, err error) {
   222  	if tracing.IsEnabled() {
   223  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.Get")
   224  		defer func() {
   225  			sc := -1
   226  			if result.Response.Response != nil {
   227  				sc = result.Response.Response.StatusCode
   228  			}
   229  			tracing.EndSpan(ctx, sc, err)
   230  		}()
   231  	}
   232  	req, err := client.GetPreparer(ctx, resourceGroupName, diskName)
   233  	if err != nil {
   234  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "Get", nil, "Failure preparing request")
   235  		return
   236  	}
   237  
   238  	resp, err := client.GetSender(req)
   239  	if err != nil {
   240  		result.Response = autorest.Response{Response: resp}
   241  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "Get", resp, "Failure sending request")
   242  		return
   243  	}
   244  
   245  	result, err = client.GetResponder(resp)
   246  	if err != nil {
   247  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "Get", resp, "Failure responding to request")
   248  		return
   249  	}
   250  
   251  	return
   252  }
   253  
   254  // GetPreparer prepares the Get request.
   255  func (client DisksClient) GetPreparer(ctx context.Context, resourceGroupName string, diskName string) (*http.Request, error) {
   256  	pathParameters := map[string]interface{}{
   257  		"diskName":          autorest.Encode("path", diskName),
   258  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   259  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   260  	}
   261  
   262  	const APIVersion = "2020-06-30"
   263  	queryParameters := map[string]interface{}{
   264  		"api-version": APIVersion,
   265  	}
   266  
   267  	preparer := autorest.CreatePreparer(
   268  		autorest.AsGet(),
   269  		autorest.WithBaseURL(client.BaseURI),
   270  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters),
   271  		autorest.WithQueryParameters(queryParameters))
   272  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   273  }
   274  
   275  // GetSender sends the Get request. The method will close the
   276  // http.Response Body if it receives an error.
   277  func (client DisksClient) GetSender(req *http.Request) (*http.Response, error) {
   278  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   279  }
   280  
   281  // GetResponder handles the response to the Get request. The method always
   282  // closes the http.Response Body.
   283  func (client DisksClient) GetResponder(resp *http.Response) (result Disk, err error) {
   284  	err = autorest.Respond(
   285  		resp,
   286  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   287  		autorest.ByUnmarshallingJSON(&result),
   288  		autorest.ByClosing())
   289  	result.Response = autorest.Response{Response: resp}
   290  	return
   291  }
   292  
   293  // GrantAccess grants access to a disk.
   294  // Parameters:
   295  // resourceGroupName - the name of the resource group.
   296  // diskName - the name of the managed disk that is being created. The name can't be changed after the disk is
   297  // created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80
   298  // characters.
   299  // grantAccessData - access data object supplied in the body of the get disk access operation.
   300  func (client DisksClient) GrantAccess(ctx context.Context, resourceGroupName string, diskName string, grantAccessData GrantAccessData) (result DisksGrantAccessFuture, err error) {
   301  	if tracing.IsEnabled() {
   302  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.GrantAccess")
   303  		defer func() {
   304  			sc := -1
   305  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   306  				sc = result.FutureAPI.Response().StatusCode
   307  			}
   308  			tracing.EndSpan(ctx, sc, err)
   309  		}()
   310  	}
   311  	if err := validation.Validate([]validation.Validation{
   312  		{TargetValue: grantAccessData,
   313  			Constraints: []validation.Constraint{{Target: "grantAccessData.DurationInSeconds", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   314  		return result, validation.NewError("compute.DisksClient", "GrantAccess", err.Error())
   315  	}
   316  
   317  	req, err := client.GrantAccessPreparer(ctx, resourceGroupName, diskName, grantAccessData)
   318  	if err != nil {
   319  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "GrantAccess", nil, "Failure preparing request")
   320  		return
   321  	}
   322  
   323  	result, err = client.GrantAccessSender(req)
   324  	if err != nil {
   325  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "GrantAccess", result.Response(), "Failure sending request")
   326  		return
   327  	}
   328  
   329  	return
   330  }
   331  
   332  // GrantAccessPreparer prepares the GrantAccess request.
   333  func (client DisksClient) GrantAccessPreparer(ctx context.Context, resourceGroupName string, diskName string, grantAccessData GrantAccessData) (*http.Request, error) {
   334  	pathParameters := map[string]interface{}{
   335  		"diskName":          autorest.Encode("path", diskName),
   336  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   337  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   338  	}
   339  
   340  	const APIVersion = "2020-06-30"
   341  	queryParameters := map[string]interface{}{
   342  		"api-version": APIVersion,
   343  	}
   344  
   345  	preparer := autorest.CreatePreparer(
   346  		autorest.AsContentType("application/json; charset=utf-8"),
   347  		autorest.AsPost(),
   348  		autorest.WithBaseURL(client.BaseURI),
   349  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}/beginGetAccess", pathParameters),
   350  		autorest.WithJSON(grantAccessData),
   351  		autorest.WithQueryParameters(queryParameters))
   352  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   353  }
   354  
   355  // GrantAccessSender sends the GrantAccess request. The method will close the
   356  // http.Response Body if it receives an error.
   357  func (client DisksClient) GrantAccessSender(req *http.Request) (future DisksGrantAccessFuture, err error) {
   358  	var resp *http.Response
   359  	future.FutureAPI = &azure.Future{}
   360  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   361  	if err != nil {
   362  		return
   363  	}
   364  	var azf azure.Future
   365  	azf, err = azure.NewFutureFromResponse(resp)
   366  	future.FutureAPI = &azf
   367  	future.Result = future.result
   368  	return
   369  }
   370  
   371  // GrantAccessResponder handles the response to the GrantAccess request. The method always
   372  // closes the http.Response Body.
   373  func (client DisksClient) GrantAccessResponder(resp *http.Response) (result AccessURI, err error) {
   374  	err = autorest.Respond(
   375  		resp,
   376  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   377  		autorest.ByUnmarshallingJSON(&result),
   378  		autorest.ByClosing())
   379  	result.Response = autorest.Response{Response: resp}
   380  	return
   381  }
   382  
   383  // List lists all the disks under a subscription.
   384  func (client DisksClient) List(ctx context.Context) (result DiskListPage, err error) {
   385  	if tracing.IsEnabled() {
   386  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.List")
   387  		defer func() {
   388  			sc := -1
   389  			if result.dl.Response.Response != nil {
   390  				sc = result.dl.Response.Response.StatusCode
   391  			}
   392  			tracing.EndSpan(ctx, sc, err)
   393  		}()
   394  	}
   395  	result.fn = client.listNextResults
   396  	req, err := client.ListPreparer(ctx)
   397  	if err != nil {
   398  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "List", nil, "Failure preparing request")
   399  		return
   400  	}
   401  
   402  	resp, err := client.ListSender(req)
   403  	if err != nil {
   404  		result.dl.Response = autorest.Response{Response: resp}
   405  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "List", resp, "Failure sending request")
   406  		return
   407  	}
   408  
   409  	result.dl, err = client.ListResponder(resp)
   410  	if err != nil {
   411  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "List", resp, "Failure responding to request")
   412  		return
   413  	}
   414  	if result.dl.hasNextLink() && result.dl.IsEmpty() {
   415  		err = result.NextWithContext(ctx)
   416  		return
   417  	}
   418  
   419  	return
   420  }
   421  
   422  // ListPreparer prepares the List request.
   423  func (client DisksClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   424  	pathParameters := map[string]interface{}{
   425  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   426  	}
   427  
   428  	const APIVersion = "2020-06-30"
   429  	queryParameters := map[string]interface{}{
   430  		"api-version": APIVersion,
   431  	}
   432  
   433  	preparer := autorest.CreatePreparer(
   434  		autorest.AsGet(),
   435  		autorest.WithBaseURL(client.BaseURI),
   436  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/disks", pathParameters),
   437  		autorest.WithQueryParameters(queryParameters))
   438  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   439  }
   440  
   441  // ListSender sends the List request. The method will close the
   442  // http.Response Body if it receives an error.
   443  func (client DisksClient) ListSender(req *http.Request) (*http.Response, error) {
   444  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   445  }
   446  
   447  // ListResponder handles the response to the List request. The method always
   448  // closes the http.Response Body.
   449  func (client DisksClient) ListResponder(resp *http.Response) (result DiskList, err error) {
   450  	err = autorest.Respond(
   451  		resp,
   452  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   453  		autorest.ByUnmarshallingJSON(&result),
   454  		autorest.ByClosing())
   455  	result.Response = autorest.Response{Response: resp}
   456  	return
   457  }
   458  
   459  // listNextResults retrieves the next set of results, if any.
   460  func (client DisksClient) listNextResults(ctx context.Context, lastResults DiskList) (result DiskList, err error) {
   461  	req, err := lastResults.diskListPreparer(ctx)
   462  	if err != nil {
   463  		return result, autorest.NewErrorWithError(err, "compute.DisksClient", "listNextResults", nil, "Failure preparing next results request")
   464  	}
   465  	if req == nil {
   466  		return
   467  	}
   468  	resp, err := client.ListSender(req)
   469  	if err != nil {
   470  		result.Response = autorest.Response{Response: resp}
   471  		return result, autorest.NewErrorWithError(err, "compute.DisksClient", "listNextResults", resp, "Failure sending next results request")
   472  	}
   473  	result, err = client.ListResponder(resp)
   474  	if err != nil {
   475  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "listNextResults", resp, "Failure responding to next results request")
   476  	}
   477  	return
   478  }
   479  
   480  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   481  func (client DisksClient) ListComplete(ctx context.Context) (result DiskListIterator, err error) {
   482  	if tracing.IsEnabled() {
   483  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.List")
   484  		defer func() {
   485  			sc := -1
   486  			if result.Response().Response.Response != nil {
   487  				sc = result.page.Response().Response.Response.StatusCode
   488  			}
   489  			tracing.EndSpan(ctx, sc, err)
   490  		}()
   491  	}
   492  	result.page, err = client.List(ctx)
   493  	return
   494  }
   495  
   496  // ListByResourceGroup lists all the disks under a resource group.
   497  // Parameters:
   498  // resourceGroupName - the name of the resource group.
   499  func (client DisksClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result DiskListPage, err error) {
   500  	if tracing.IsEnabled() {
   501  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.ListByResourceGroup")
   502  		defer func() {
   503  			sc := -1
   504  			if result.dl.Response.Response != nil {
   505  				sc = result.dl.Response.Response.StatusCode
   506  			}
   507  			tracing.EndSpan(ctx, sc, err)
   508  		}()
   509  	}
   510  	result.fn = client.listByResourceGroupNextResults
   511  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
   512  	if err != nil {
   513  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "ListByResourceGroup", nil, "Failure preparing request")
   514  		return
   515  	}
   516  
   517  	resp, err := client.ListByResourceGroupSender(req)
   518  	if err != nil {
   519  		result.dl.Response = autorest.Response{Response: resp}
   520  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "ListByResourceGroup", resp, "Failure sending request")
   521  		return
   522  	}
   523  
   524  	result.dl, err = client.ListByResourceGroupResponder(resp)
   525  	if err != nil {
   526  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "ListByResourceGroup", resp, "Failure responding to request")
   527  		return
   528  	}
   529  	if result.dl.hasNextLink() && result.dl.IsEmpty() {
   530  		err = result.NextWithContext(ctx)
   531  		return
   532  	}
   533  
   534  	return
   535  }
   536  
   537  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   538  func (client DisksClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   539  	pathParameters := map[string]interface{}{
   540  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   541  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   542  	}
   543  
   544  	const APIVersion = "2020-06-30"
   545  	queryParameters := map[string]interface{}{
   546  		"api-version": APIVersion,
   547  	}
   548  
   549  	preparer := autorest.CreatePreparer(
   550  		autorest.AsGet(),
   551  		autorest.WithBaseURL(client.BaseURI),
   552  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks", pathParameters),
   553  		autorest.WithQueryParameters(queryParameters))
   554  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   555  }
   556  
   557  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   558  // http.Response Body if it receives an error.
   559  func (client DisksClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   560  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   561  }
   562  
   563  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   564  // closes the http.Response Body.
   565  func (client DisksClient) ListByResourceGroupResponder(resp *http.Response) (result DiskList, err error) {
   566  	err = autorest.Respond(
   567  		resp,
   568  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   569  		autorest.ByUnmarshallingJSON(&result),
   570  		autorest.ByClosing())
   571  	result.Response = autorest.Response{Response: resp}
   572  	return
   573  }
   574  
   575  // listByResourceGroupNextResults retrieves the next set of results, if any.
   576  func (client DisksClient) listByResourceGroupNextResults(ctx context.Context, lastResults DiskList) (result DiskList, err error) {
   577  	req, err := lastResults.diskListPreparer(ctx)
   578  	if err != nil {
   579  		return result, autorest.NewErrorWithError(err, "compute.DisksClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
   580  	}
   581  	if req == nil {
   582  		return
   583  	}
   584  	resp, err := client.ListByResourceGroupSender(req)
   585  	if err != nil {
   586  		result.Response = autorest.Response{Response: resp}
   587  		return result, autorest.NewErrorWithError(err, "compute.DisksClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
   588  	}
   589  	result, err = client.ListByResourceGroupResponder(resp)
   590  	if err != nil {
   591  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
   592  	}
   593  	return
   594  }
   595  
   596  // ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
   597  func (client DisksClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result DiskListIterator, err error) {
   598  	if tracing.IsEnabled() {
   599  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.ListByResourceGroup")
   600  		defer func() {
   601  			sc := -1
   602  			if result.Response().Response.Response != nil {
   603  				sc = result.page.Response().Response.Response.StatusCode
   604  			}
   605  			tracing.EndSpan(ctx, sc, err)
   606  		}()
   607  	}
   608  	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
   609  	return
   610  }
   611  
   612  // RevokeAccess revokes access to a disk.
   613  // Parameters:
   614  // resourceGroupName - the name of the resource group.
   615  // diskName - the name of the managed disk that is being created. The name can't be changed after the disk is
   616  // created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80
   617  // characters.
   618  func (client DisksClient) RevokeAccess(ctx context.Context, resourceGroupName string, diskName string) (result DisksRevokeAccessFuture, err error) {
   619  	if tracing.IsEnabled() {
   620  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.RevokeAccess")
   621  		defer func() {
   622  			sc := -1
   623  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   624  				sc = result.FutureAPI.Response().StatusCode
   625  			}
   626  			tracing.EndSpan(ctx, sc, err)
   627  		}()
   628  	}
   629  	req, err := client.RevokeAccessPreparer(ctx, resourceGroupName, diskName)
   630  	if err != nil {
   631  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "RevokeAccess", nil, "Failure preparing request")
   632  		return
   633  	}
   634  
   635  	result, err = client.RevokeAccessSender(req)
   636  	if err != nil {
   637  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "RevokeAccess", result.Response(), "Failure sending request")
   638  		return
   639  	}
   640  
   641  	return
   642  }
   643  
   644  // RevokeAccessPreparer prepares the RevokeAccess request.
   645  func (client DisksClient) RevokeAccessPreparer(ctx context.Context, resourceGroupName string, diskName string) (*http.Request, error) {
   646  	pathParameters := map[string]interface{}{
   647  		"diskName":          autorest.Encode("path", diskName),
   648  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   649  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   650  	}
   651  
   652  	const APIVersion = "2020-06-30"
   653  	queryParameters := map[string]interface{}{
   654  		"api-version": APIVersion,
   655  	}
   656  
   657  	preparer := autorest.CreatePreparer(
   658  		autorest.AsPost(),
   659  		autorest.WithBaseURL(client.BaseURI),
   660  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}/endGetAccess", pathParameters),
   661  		autorest.WithQueryParameters(queryParameters))
   662  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   663  }
   664  
   665  // RevokeAccessSender sends the RevokeAccess request. The method will close the
   666  // http.Response Body if it receives an error.
   667  func (client DisksClient) RevokeAccessSender(req *http.Request) (future DisksRevokeAccessFuture, err error) {
   668  	var resp *http.Response
   669  	future.FutureAPI = &azure.Future{}
   670  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   671  	if err != nil {
   672  		return
   673  	}
   674  	var azf azure.Future
   675  	azf, err = azure.NewFutureFromResponse(resp)
   676  	future.FutureAPI = &azf
   677  	future.Result = future.result
   678  	return
   679  }
   680  
   681  // RevokeAccessResponder handles the response to the RevokeAccess request. The method always
   682  // closes the http.Response Body.
   683  func (client DisksClient) RevokeAccessResponder(resp *http.Response) (result autorest.Response, err error) {
   684  	err = autorest.Respond(
   685  		resp,
   686  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   687  		autorest.ByClosing())
   688  	result.Response = resp
   689  	return
   690  }
   691  
   692  // Update updates (patches) a disk.
   693  // Parameters:
   694  // resourceGroupName - the name of the resource group.
   695  // diskName - the name of the managed disk that is being created. The name can't be changed after the disk is
   696  // created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80
   697  // characters.
   698  // disk - disk object supplied in the body of the Patch disk operation.
   699  func (client DisksClient) Update(ctx context.Context, resourceGroupName string, diskName string, disk DiskUpdate) (result DisksUpdateFuture, err error) {
   700  	if tracing.IsEnabled() {
   701  		ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.Update")
   702  		defer func() {
   703  			sc := -1
   704  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   705  				sc = result.FutureAPI.Response().StatusCode
   706  			}
   707  			tracing.EndSpan(ctx, sc, err)
   708  		}()
   709  	}
   710  	req, err := client.UpdatePreparer(ctx, resourceGroupName, diskName, disk)
   711  	if err != nil {
   712  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "Update", nil, "Failure preparing request")
   713  		return
   714  	}
   715  
   716  	result, err = client.UpdateSender(req)
   717  	if err != nil {
   718  		err = autorest.NewErrorWithError(err, "compute.DisksClient", "Update", result.Response(), "Failure sending request")
   719  		return
   720  	}
   721  
   722  	return
   723  }
   724  
   725  // UpdatePreparer prepares the Update request.
   726  func (client DisksClient) UpdatePreparer(ctx context.Context, resourceGroupName string, diskName string, disk DiskUpdate) (*http.Request, error) {
   727  	pathParameters := map[string]interface{}{
   728  		"diskName":          autorest.Encode("path", diskName),
   729  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   730  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   731  	}
   732  
   733  	const APIVersion = "2020-06-30"
   734  	queryParameters := map[string]interface{}{
   735  		"api-version": APIVersion,
   736  	}
   737  
   738  	preparer := autorest.CreatePreparer(
   739  		autorest.AsContentType("application/json; charset=utf-8"),
   740  		autorest.AsPatch(),
   741  		autorest.WithBaseURL(client.BaseURI),
   742  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters),
   743  		autorest.WithJSON(disk),
   744  		autorest.WithQueryParameters(queryParameters))
   745  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   746  }
   747  
   748  // UpdateSender sends the Update request. The method will close the
   749  // http.Response Body if it receives an error.
   750  func (client DisksClient) UpdateSender(req *http.Request) (future DisksUpdateFuture, err error) {
   751  	var resp *http.Response
   752  	future.FutureAPI = &azure.Future{}
   753  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   754  	if err != nil {
   755  		return
   756  	}
   757  	var azf azure.Future
   758  	azf, err = azure.NewFutureFromResponse(resp)
   759  	future.FutureAPI = &azf
   760  	future.Result = future.result
   761  	return
   762  }
   763  
   764  // UpdateResponder handles the response to the Update request. The method always
   765  // closes the http.Response Body.
   766  func (client DisksClient) UpdateResponder(resp *http.Response) (result Disk, err error) {
   767  	err = autorest.Respond(
   768  		resp,
   769  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   770  		autorest.ByUnmarshallingJSON(&result),
   771  		autorest.ByClosing())
   772  	result.Response = autorest.Response{Response: resp}
   773  	return
   774  }
   775  

View as plain text