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