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