1package machinelearningservices
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/tracing"
25	"net/http"
26)
27
28// MachineLearningComputeClient is the these APIs allow end users to operate on Azure Machine Learning Workspace
29// resources.
30type MachineLearningComputeClient struct {
31	BaseClient
32}
33
34// NewMachineLearningComputeClient creates an instance of the MachineLearningComputeClient client.
35func NewMachineLearningComputeClient(subscriptionID string) MachineLearningComputeClient {
36	return NewMachineLearningComputeClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewMachineLearningComputeClientWithBaseURI creates an instance of the MachineLearningComputeClient client using a
40// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
41// Azure stack).
42func NewMachineLearningComputeClientWithBaseURI(baseURI string, subscriptionID string) MachineLearningComputeClient {
43	return MachineLearningComputeClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CreateOrUpdate creates or updates compute. This call will overwrite a compute if it exists. This is a nonrecoverable
47// operation. If your intent is to create a new compute, do a GET first to verify that it does not exist yet.
48// Parameters:
49// resourceGroupName - name of the resource group in which workspace is located.
50// workspaceName - name of Azure Machine Learning workspace.
51// computeName - name of the Azure Machine Learning compute.
52// parameters - payload with Machine Learning compute definition.
53func (client MachineLearningComputeClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, parameters ComputeResource) (result MachineLearningComputeCreateOrUpdateFuture, err error) {
54	if tracing.IsEnabled() {
55		ctx = tracing.StartSpan(ctx, fqdn+"/MachineLearningComputeClient.CreateOrUpdate")
56		defer func() {
57			sc := -1
58			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
59				sc = result.FutureAPI.Response().StatusCode
60			}
61			tracing.EndSpan(ctx, sc, err)
62		}()
63	}
64	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, computeName, parameters)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "CreateOrUpdate", nil, "Failure preparing request")
67		return
68	}
69
70	result, err = client.CreateOrUpdateSender(req)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "CreateOrUpdate", nil, "Failure sending request")
73		return
74	}
75
76	return
77}
78
79// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
80func (client MachineLearningComputeClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, parameters ComputeResource) (*http.Request, error) {
81	pathParameters := map[string]interface{}{
82		"computeName":       autorest.Encode("path", computeName),
83		"resourceGroupName": autorest.Encode("path", resourceGroupName),
84		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
85		"workspaceName":     autorest.Encode("path", workspaceName),
86	}
87
88	const APIVersion = "2020-04-01"
89	queryParameters := map[string]interface{}{
90		"api-version": APIVersion,
91	}
92
93	preparer := autorest.CreatePreparer(
94		autorest.AsContentType("application/json; charset=utf-8"),
95		autorest.AsPut(),
96		autorest.WithBaseURL(client.BaseURI),
97		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}", pathParameters),
98		autorest.WithJSON(parameters),
99		autorest.WithQueryParameters(queryParameters))
100	return preparer.Prepare((&http.Request{}).WithContext(ctx))
101}
102
103// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
104// http.Response Body if it receives an error.
105func (client MachineLearningComputeClient) CreateOrUpdateSender(req *http.Request) (future MachineLearningComputeCreateOrUpdateFuture, err error) {
106	var resp *http.Response
107	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
108	if err != nil {
109		return
110	}
111	var azf azure.Future
112	azf, err = azure.NewFutureFromResponse(resp)
113	future.FutureAPI = &azf
114	future.Result = func(client MachineLearningComputeClient) (cr ComputeResource, err error) {
115		var done bool
116		done, err = future.DoneWithContext(context.Background(), client)
117		if err != nil {
118			err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeCreateOrUpdateFuture", "Result", future.Response(), "Polling failure")
119			return
120		}
121		if !done {
122			err = azure.NewAsyncOpIncompleteError("machinelearningservices.MachineLearningComputeCreateOrUpdateFuture")
123			return
124		}
125		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
126		cr.Response.Response, err = future.GetResult(sender)
127		if cr.Response.Response == nil && err == nil {
128			err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeCreateOrUpdateFuture", "Result", nil, "received nil response and error")
129		}
130		if err == nil && cr.Response.Response.StatusCode != http.StatusNoContent {
131			cr, err = client.CreateOrUpdateResponder(cr.Response.Response)
132			if err != nil {
133				err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeCreateOrUpdateFuture", "Result", cr.Response.Response, "Failure responding to request")
134			}
135		}
136		return
137	}
138	return
139}
140
141// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
142// closes the http.Response Body.
143func (client MachineLearningComputeClient) CreateOrUpdateResponder(resp *http.Response) (result ComputeResource, err error) {
144	err = autorest.Respond(
145		resp,
146		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
147		autorest.ByUnmarshallingJSON(&result),
148		autorest.ByClosing())
149	result.Response = autorest.Response{Response: resp}
150	return
151}
152
153// Delete deletes specified Machine Learning compute.
154// Parameters:
155// resourceGroupName - name of the resource group in which workspace is located.
156// workspaceName - name of Azure Machine Learning workspace.
157// computeName - name of the Azure Machine Learning compute.
158// underlyingResourceAction - delete the underlying compute if 'Delete', or detach the underlying compute from
159// workspace if 'Detach'.
160func (client MachineLearningComputeClient) Delete(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, underlyingResourceAction UnderlyingResourceAction) (result MachineLearningComputeDeleteFuture, err error) {
161	if tracing.IsEnabled() {
162		ctx = tracing.StartSpan(ctx, fqdn+"/MachineLearningComputeClient.Delete")
163		defer func() {
164			sc := -1
165			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
166				sc = result.FutureAPI.Response().StatusCode
167			}
168			tracing.EndSpan(ctx, sc, err)
169		}()
170	}
171	req, err := client.DeletePreparer(ctx, resourceGroupName, workspaceName, computeName, underlyingResourceAction)
172	if err != nil {
173		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "Delete", nil, "Failure preparing request")
174		return
175	}
176
177	result, err = client.DeleteSender(req)
178	if err != nil {
179		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "Delete", nil, "Failure sending request")
180		return
181	}
182
183	return
184}
185
186// DeletePreparer prepares the Delete request.
187func (client MachineLearningComputeClient) DeletePreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, underlyingResourceAction UnderlyingResourceAction) (*http.Request, error) {
188	pathParameters := map[string]interface{}{
189		"computeName":       autorest.Encode("path", computeName),
190		"resourceGroupName": autorest.Encode("path", resourceGroupName),
191		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
192		"workspaceName":     autorest.Encode("path", workspaceName),
193	}
194
195	const APIVersion = "2020-04-01"
196	queryParameters := map[string]interface{}{
197		"api-version":              APIVersion,
198		"underlyingResourceAction": autorest.Encode("query", underlyingResourceAction),
199	}
200
201	preparer := autorest.CreatePreparer(
202		autorest.AsDelete(),
203		autorest.WithBaseURL(client.BaseURI),
204		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}", pathParameters),
205		autorest.WithQueryParameters(queryParameters))
206	return preparer.Prepare((&http.Request{}).WithContext(ctx))
207}
208
209// DeleteSender sends the Delete request. The method will close the
210// http.Response Body if it receives an error.
211func (client MachineLearningComputeClient) DeleteSender(req *http.Request) (future MachineLearningComputeDeleteFuture, err error) {
212	var resp *http.Response
213	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
214	if err != nil {
215		return
216	}
217	var azf azure.Future
218	azf, err = azure.NewFutureFromResponse(resp)
219	future.FutureAPI = &azf
220	future.Result = func(client MachineLearningComputeClient) (ar autorest.Response, err error) {
221		var done bool
222		done, err = future.DoneWithContext(context.Background(), client)
223		if err != nil {
224			err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeDeleteFuture", "Result", future.Response(), "Polling failure")
225			return
226		}
227		if !done {
228			err = azure.NewAsyncOpIncompleteError("machinelearningservices.MachineLearningComputeDeleteFuture")
229			return
230		}
231		ar.Response = future.Response()
232		return
233	}
234	return
235}
236
237// DeleteResponder handles the response to the Delete request. The method always
238// closes the http.Response Body.
239func (client MachineLearningComputeClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
240	err = autorest.Respond(
241		resp,
242		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
243		autorest.ByClosing())
244	result.Response = resp
245	return
246}
247
248// Get gets compute definition by its name. Any secrets (storage keys, service credentials, etc) are not returned - use
249// 'keys' nested resource to get them.
250// Parameters:
251// resourceGroupName - name of the resource group in which workspace is located.
252// workspaceName - name of Azure Machine Learning workspace.
253// computeName - name of the Azure Machine Learning compute.
254func (client MachineLearningComputeClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result ComputeResource, err error) {
255	if tracing.IsEnabled() {
256		ctx = tracing.StartSpan(ctx, fqdn+"/MachineLearningComputeClient.Get")
257		defer func() {
258			sc := -1
259			if result.Response.Response != nil {
260				sc = result.Response.Response.StatusCode
261			}
262			tracing.EndSpan(ctx, sc, err)
263		}()
264	}
265	req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, computeName)
266	if err != nil {
267		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "Get", nil, "Failure preparing request")
268		return
269	}
270
271	resp, err := client.GetSender(req)
272	if err != nil {
273		result.Response = autorest.Response{Response: resp}
274		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "Get", resp, "Failure sending request")
275		return
276	}
277
278	result, err = client.GetResponder(resp)
279	if err != nil {
280		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "Get", resp, "Failure responding to request")
281		return
282	}
283
284	return
285}
286
287// GetPreparer prepares the Get request.
288func (client MachineLearningComputeClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (*http.Request, error) {
289	pathParameters := map[string]interface{}{
290		"computeName":       autorest.Encode("path", computeName),
291		"resourceGroupName": autorest.Encode("path", resourceGroupName),
292		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
293		"workspaceName":     autorest.Encode("path", workspaceName),
294	}
295
296	const APIVersion = "2020-04-01"
297	queryParameters := map[string]interface{}{
298		"api-version": APIVersion,
299	}
300
301	preparer := autorest.CreatePreparer(
302		autorest.AsGet(),
303		autorest.WithBaseURL(client.BaseURI),
304		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}", pathParameters),
305		autorest.WithQueryParameters(queryParameters))
306	return preparer.Prepare((&http.Request{}).WithContext(ctx))
307}
308
309// GetSender sends the Get request. The method will close the
310// http.Response Body if it receives an error.
311func (client MachineLearningComputeClient) GetSender(req *http.Request) (*http.Response, error) {
312	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
313}
314
315// GetResponder handles the response to the Get request. The method always
316// closes the http.Response Body.
317func (client MachineLearningComputeClient) GetResponder(resp *http.Response) (result ComputeResource, err error) {
318	err = autorest.Respond(
319		resp,
320		azure.WithErrorUnlessStatusCode(http.StatusOK),
321		autorest.ByUnmarshallingJSON(&result),
322		autorest.ByClosing())
323	result.Response = autorest.Response{Response: resp}
324	return
325}
326
327// ListByWorkspace gets computes in specified workspace.
328// Parameters:
329// resourceGroupName - name of the resource group in which workspace is located.
330// workspaceName - name of Azure Machine Learning workspace.
331// skiptoken - continuation token for pagination.
332func (client MachineLearningComputeClient) ListByWorkspace(ctx context.Context, resourceGroupName string, workspaceName string, skiptoken string) (result PaginatedComputeResourcesListPage, err error) {
333	if tracing.IsEnabled() {
334		ctx = tracing.StartSpan(ctx, fqdn+"/MachineLearningComputeClient.ListByWorkspace")
335		defer func() {
336			sc := -1
337			if result.pcrl.Response.Response != nil {
338				sc = result.pcrl.Response.Response.StatusCode
339			}
340			tracing.EndSpan(ctx, sc, err)
341		}()
342	}
343	result.fn = client.listByWorkspaceNextResults
344	req, err := client.ListByWorkspacePreparer(ctx, resourceGroupName, workspaceName, skiptoken)
345	if err != nil {
346		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "ListByWorkspace", nil, "Failure preparing request")
347		return
348	}
349
350	resp, err := client.ListByWorkspaceSender(req)
351	if err != nil {
352		result.pcrl.Response = autorest.Response{Response: resp}
353		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "ListByWorkspace", resp, "Failure sending request")
354		return
355	}
356
357	result.pcrl, err = client.ListByWorkspaceResponder(resp)
358	if err != nil {
359		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "ListByWorkspace", resp, "Failure responding to request")
360		return
361	}
362	if result.pcrl.hasNextLink() && result.pcrl.IsEmpty() {
363		err = result.NextWithContext(ctx)
364		return
365	}
366
367	return
368}
369
370// ListByWorkspacePreparer prepares the ListByWorkspace request.
371func (client MachineLearningComputeClient) ListByWorkspacePreparer(ctx context.Context, resourceGroupName string, workspaceName string, skiptoken string) (*http.Request, error) {
372	pathParameters := map[string]interface{}{
373		"resourceGroupName": autorest.Encode("path", resourceGroupName),
374		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
375		"workspaceName":     autorest.Encode("path", workspaceName),
376	}
377
378	const APIVersion = "2020-04-01"
379	queryParameters := map[string]interface{}{
380		"api-version": APIVersion,
381	}
382	if len(skiptoken) > 0 {
383		queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken)
384	}
385
386	preparer := autorest.CreatePreparer(
387		autorest.AsGet(),
388		autorest.WithBaseURL(client.BaseURI),
389		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes", pathParameters),
390		autorest.WithQueryParameters(queryParameters))
391	return preparer.Prepare((&http.Request{}).WithContext(ctx))
392}
393
394// ListByWorkspaceSender sends the ListByWorkspace request. The method will close the
395// http.Response Body if it receives an error.
396func (client MachineLearningComputeClient) ListByWorkspaceSender(req *http.Request) (*http.Response, error) {
397	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
398}
399
400// ListByWorkspaceResponder handles the response to the ListByWorkspace request. The method always
401// closes the http.Response Body.
402func (client MachineLearningComputeClient) ListByWorkspaceResponder(resp *http.Response) (result PaginatedComputeResourcesList, err error) {
403	err = autorest.Respond(
404		resp,
405		azure.WithErrorUnlessStatusCode(http.StatusOK),
406		autorest.ByUnmarshallingJSON(&result),
407		autorest.ByClosing())
408	result.Response = autorest.Response{Response: resp}
409	return
410}
411
412// listByWorkspaceNextResults retrieves the next set of results, if any.
413func (client MachineLearningComputeClient) listByWorkspaceNextResults(ctx context.Context, lastResults PaginatedComputeResourcesList) (result PaginatedComputeResourcesList, err error) {
414	req, err := lastResults.paginatedComputeResourcesListPreparer(ctx)
415	if err != nil {
416		return result, autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "listByWorkspaceNextResults", nil, "Failure preparing next results request")
417	}
418	if req == nil {
419		return
420	}
421	resp, err := client.ListByWorkspaceSender(req)
422	if err != nil {
423		result.Response = autorest.Response{Response: resp}
424		return result, autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "listByWorkspaceNextResults", resp, "Failure sending next results request")
425	}
426	result, err = client.ListByWorkspaceResponder(resp)
427	if err != nil {
428		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "listByWorkspaceNextResults", resp, "Failure responding to next results request")
429	}
430	return
431}
432
433// ListByWorkspaceComplete enumerates all values, automatically crossing page boundaries as required.
434func (client MachineLearningComputeClient) ListByWorkspaceComplete(ctx context.Context, resourceGroupName string, workspaceName string, skiptoken string) (result PaginatedComputeResourcesListIterator, err error) {
435	if tracing.IsEnabled() {
436		ctx = tracing.StartSpan(ctx, fqdn+"/MachineLearningComputeClient.ListByWorkspace")
437		defer func() {
438			sc := -1
439			if result.Response().Response.Response != nil {
440				sc = result.page.Response().Response.Response.StatusCode
441			}
442			tracing.EndSpan(ctx, sc, err)
443		}()
444	}
445	result.page, err = client.ListByWorkspace(ctx, resourceGroupName, workspaceName, skiptoken)
446	return
447}
448
449// ListKeys gets secrets related to Machine Learning compute (storage keys, service credentials, etc).
450// Parameters:
451// resourceGroupName - name of the resource group in which workspace is located.
452// workspaceName - name of Azure Machine Learning workspace.
453// computeName - name of the Azure Machine Learning compute.
454func (client MachineLearningComputeClient) ListKeys(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result ComputeSecretsModel, err error) {
455	if tracing.IsEnabled() {
456		ctx = tracing.StartSpan(ctx, fqdn+"/MachineLearningComputeClient.ListKeys")
457		defer func() {
458			sc := -1
459			if result.Response.Response != nil {
460				sc = result.Response.Response.StatusCode
461			}
462			tracing.EndSpan(ctx, sc, err)
463		}()
464	}
465	req, err := client.ListKeysPreparer(ctx, resourceGroupName, workspaceName, computeName)
466	if err != nil {
467		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "ListKeys", nil, "Failure preparing request")
468		return
469	}
470
471	resp, err := client.ListKeysSender(req)
472	if err != nil {
473		result.Response = autorest.Response{Response: resp}
474		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "ListKeys", resp, "Failure sending request")
475		return
476	}
477
478	result, err = client.ListKeysResponder(resp)
479	if err != nil {
480		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "ListKeys", resp, "Failure responding to request")
481		return
482	}
483
484	return
485}
486
487// ListKeysPreparer prepares the ListKeys request.
488func (client MachineLearningComputeClient) ListKeysPreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (*http.Request, error) {
489	pathParameters := map[string]interface{}{
490		"computeName":       autorest.Encode("path", computeName),
491		"resourceGroupName": autorest.Encode("path", resourceGroupName),
492		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
493		"workspaceName":     autorest.Encode("path", workspaceName),
494	}
495
496	const APIVersion = "2020-04-01"
497	queryParameters := map[string]interface{}{
498		"api-version": APIVersion,
499	}
500
501	preparer := autorest.CreatePreparer(
502		autorest.AsPost(),
503		autorest.WithBaseURL(client.BaseURI),
504		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}/listKeys", pathParameters),
505		autorest.WithQueryParameters(queryParameters))
506	return preparer.Prepare((&http.Request{}).WithContext(ctx))
507}
508
509// ListKeysSender sends the ListKeys request. The method will close the
510// http.Response Body if it receives an error.
511func (client MachineLearningComputeClient) ListKeysSender(req *http.Request) (*http.Response, error) {
512	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
513}
514
515// ListKeysResponder handles the response to the ListKeys request. The method always
516// closes the http.Response Body.
517func (client MachineLearningComputeClient) ListKeysResponder(resp *http.Response) (result ComputeSecretsModel, err error) {
518	err = autorest.Respond(
519		resp,
520		azure.WithErrorUnlessStatusCode(http.StatusOK),
521		autorest.ByUnmarshallingJSON(&result),
522		autorest.ByClosing())
523	result.Response = autorest.Response{Response: resp}
524	return
525}
526
527// ListNodes get the details (e.g IP address, port etc) of all the compute nodes in the compute.
528// Parameters:
529// resourceGroupName - name of the resource group in which workspace is located.
530// workspaceName - name of Azure Machine Learning workspace.
531// computeName - name of the Azure Machine Learning compute.
532func (client MachineLearningComputeClient) ListNodes(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result AmlComputeNodesInformation, err error) {
533	if tracing.IsEnabled() {
534		ctx = tracing.StartSpan(ctx, fqdn+"/MachineLearningComputeClient.ListNodes")
535		defer func() {
536			sc := -1
537			if result.Response.Response != nil {
538				sc = result.Response.Response.StatusCode
539			}
540			tracing.EndSpan(ctx, sc, err)
541		}()
542	}
543	req, err := client.ListNodesPreparer(ctx, resourceGroupName, workspaceName, computeName)
544	if err != nil {
545		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "ListNodes", nil, "Failure preparing request")
546		return
547	}
548
549	resp, err := client.ListNodesSender(req)
550	if err != nil {
551		result.Response = autorest.Response{Response: resp}
552		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "ListNodes", resp, "Failure sending request")
553		return
554	}
555
556	result, err = client.ListNodesResponder(resp)
557	if err != nil {
558		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "ListNodes", resp, "Failure responding to request")
559		return
560	}
561
562	return
563}
564
565// ListNodesPreparer prepares the ListNodes request.
566func (client MachineLearningComputeClient) ListNodesPreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (*http.Request, error) {
567	pathParameters := map[string]interface{}{
568		"computeName":       autorest.Encode("path", computeName),
569		"resourceGroupName": autorest.Encode("path", resourceGroupName),
570		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
571		"workspaceName":     autorest.Encode("path", workspaceName),
572	}
573
574	const APIVersion = "2020-04-01"
575	queryParameters := map[string]interface{}{
576		"api-version": APIVersion,
577	}
578
579	preparer := autorest.CreatePreparer(
580		autorest.AsPost(),
581		autorest.WithBaseURL(client.BaseURI),
582		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}/listNodes", pathParameters),
583		autorest.WithQueryParameters(queryParameters))
584	return preparer.Prepare((&http.Request{}).WithContext(ctx))
585}
586
587// ListNodesSender sends the ListNodes request. The method will close the
588// http.Response Body if it receives an error.
589func (client MachineLearningComputeClient) ListNodesSender(req *http.Request) (*http.Response, error) {
590	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
591}
592
593// ListNodesResponder handles the response to the ListNodes request. The method always
594// closes the http.Response Body.
595func (client MachineLearningComputeClient) ListNodesResponder(resp *http.Response) (result AmlComputeNodesInformation, err error) {
596	err = autorest.Respond(
597		resp,
598		azure.WithErrorUnlessStatusCode(http.StatusOK),
599		autorest.ByUnmarshallingJSON(&result),
600		autorest.ByClosing())
601	result.Response = autorest.Response{Response: resp}
602	return
603}
604
605// Update updates properties of a compute. This call will overwrite a compute if it exists. This is a nonrecoverable
606// operation.
607// Parameters:
608// resourceGroupName - name of the resource group in which workspace is located.
609// workspaceName - name of Azure Machine Learning workspace.
610// computeName - name of the Azure Machine Learning compute.
611// parameters - additional parameters for cluster update.
612func (client MachineLearningComputeClient) Update(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, parameters ClusterUpdateParameters) (result MachineLearningComputeUpdateFuture, err error) {
613	if tracing.IsEnabled() {
614		ctx = tracing.StartSpan(ctx, fqdn+"/MachineLearningComputeClient.Update")
615		defer func() {
616			sc := -1
617			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
618				sc = result.FutureAPI.Response().StatusCode
619			}
620			tracing.EndSpan(ctx, sc, err)
621		}()
622	}
623	req, err := client.UpdatePreparer(ctx, resourceGroupName, workspaceName, computeName, parameters)
624	if err != nil {
625		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "Update", nil, "Failure preparing request")
626		return
627	}
628
629	result, err = client.UpdateSender(req)
630	if err != nil {
631		err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeClient", "Update", nil, "Failure sending request")
632		return
633	}
634
635	return
636}
637
638// UpdatePreparer prepares the Update request.
639func (client MachineLearningComputeClient) UpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, parameters ClusterUpdateParameters) (*http.Request, error) {
640	pathParameters := map[string]interface{}{
641		"computeName":       autorest.Encode("path", computeName),
642		"resourceGroupName": autorest.Encode("path", resourceGroupName),
643		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
644		"workspaceName":     autorest.Encode("path", workspaceName),
645	}
646
647	const APIVersion = "2020-04-01"
648	queryParameters := map[string]interface{}{
649		"api-version": APIVersion,
650	}
651
652	preparer := autorest.CreatePreparer(
653		autorest.AsContentType("application/json; charset=utf-8"),
654		autorest.AsPatch(),
655		autorest.WithBaseURL(client.BaseURI),
656		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}", pathParameters),
657		autorest.WithJSON(parameters),
658		autorest.WithQueryParameters(queryParameters))
659	return preparer.Prepare((&http.Request{}).WithContext(ctx))
660}
661
662// UpdateSender sends the Update request. The method will close the
663// http.Response Body if it receives an error.
664func (client MachineLearningComputeClient) UpdateSender(req *http.Request) (future MachineLearningComputeUpdateFuture, err error) {
665	var resp *http.Response
666	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
667	if err != nil {
668		return
669	}
670	var azf azure.Future
671	azf, err = azure.NewFutureFromResponse(resp)
672	future.FutureAPI = &azf
673	future.Result = func(client MachineLearningComputeClient) (cr ComputeResource, err error) {
674		var done bool
675		done, err = future.DoneWithContext(context.Background(), client)
676		if err != nil {
677			err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeUpdateFuture", "Result", future.Response(), "Polling failure")
678			return
679		}
680		if !done {
681			err = azure.NewAsyncOpIncompleteError("machinelearningservices.MachineLearningComputeUpdateFuture")
682			return
683		}
684		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
685		cr.Response.Response, err = future.GetResult(sender)
686		if cr.Response.Response == nil && err == nil {
687			err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeUpdateFuture", "Result", nil, "received nil response and error")
688		}
689		if err == nil && cr.Response.Response.StatusCode != http.StatusNoContent {
690			cr, err = client.UpdateResponder(cr.Response.Response)
691			if err != nil {
692				err = autorest.NewErrorWithError(err, "machinelearningservices.MachineLearningComputeUpdateFuture", "Result", cr.Response.Response, "Failure responding to request")
693			}
694		}
695		return
696	}
697	return
698}
699
700// UpdateResponder handles the response to the Update request. The method always
701// closes the http.Response Body.
702func (client MachineLearningComputeClient) UpdateResponder(resp *http.Response) (result ComputeResource, err error) {
703	err = autorest.Respond(
704		resp,
705		azure.WithErrorUnlessStatusCode(http.StatusOK),
706		autorest.ByUnmarshallingJSON(&result),
707		autorest.ByClosing())
708	result.Response = autorest.Response{Response: resp}
709	return
710}
711