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