1package machinelearningservices
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// ComputeClient is the these APIs allow end users to operate on Azure Machine Learning Workspace resources.
19type ComputeClient struct {
20	BaseClient
21}
22
23// NewComputeClient creates an instance of the ComputeClient client.
24func NewComputeClient(subscriptionID string) ComputeClient {
25	return NewComputeClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewComputeClientWithBaseURI creates an instance of the ComputeClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewComputeClientWithBaseURI(baseURI string, subscriptionID string) ComputeClient {
31	return ComputeClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate creates or updates compute. This call will overwrite a compute if it exists. This is a nonrecoverable
35// operation. If your intent is to create a new compute, do a GET first to verify that it does not exist yet.
36// Parameters:
37// resourceGroupName - the name of the resource group. The name is case insensitive.
38// workspaceName - name of Azure Machine Learning workspace.
39// computeName - name of the Azure Machine Learning compute.
40// parameters - payload with Machine Learning compute definition.
41func (client ComputeClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, parameters ComputeResource) (result ComputeCreateOrUpdateFuture, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47				sc = result.FutureAPI.Response().StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: client.SubscriptionID,
54			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
55		{TargetValue: resourceGroupName,
56			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
57				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
58		return result, validation.NewError("machinelearningservices.ComputeClient", "CreateOrUpdate", err.Error())
59	}
60
61	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, computeName, parameters)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "CreateOrUpdate", nil, "Failure preparing request")
64		return
65	}
66
67	result, err = client.CreateOrUpdateSender(req)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "CreateOrUpdate", nil, "Failure sending request")
70		return
71	}
72
73	return
74}
75
76// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
77func (client ComputeClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, parameters ComputeResource) (*http.Request, error) {
78	pathParameters := map[string]interface{}{
79		"computeName":       autorest.Encode("path", computeName),
80		"resourceGroupName": autorest.Encode("path", resourceGroupName),
81		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
82		"workspaceName":     autorest.Encode("path", workspaceName),
83	}
84
85	const APIVersion = "2021-07-01"
86	queryParameters := map[string]interface{}{
87		"api-version": APIVersion,
88	}
89
90	preparer := autorest.CreatePreparer(
91		autorest.AsContentType("application/json; charset=utf-8"),
92		autorest.AsPut(),
93		autorest.WithBaseURL(client.BaseURI),
94		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}", pathParameters),
95		autorest.WithJSON(parameters),
96		autorest.WithQueryParameters(queryParameters))
97	return preparer.Prepare((&http.Request{}).WithContext(ctx))
98}
99
100// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
101// http.Response Body if it receives an error.
102func (client ComputeClient) CreateOrUpdateSender(req *http.Request) (future ComputeCreateOrUpdateFuture, err error) {
103	var resp *http.Response
104	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
105	if err != nil {
106		return
107	}
108	var azf azure.Future
109	azf, err = azure.NewFutureFromResponse(resp)
110	future.FutureAPI = &azf
111	future.Result = future.result
112	return
113}
114
115// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
116// closes the http.Response Body.
117func (client ComputeClient) CreateOrUpdateResponder(resp *http.Response) (result ComputeResource, err error) {
118	err = autorest.Respond(
119		resp,
120		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
121		autorest.ByUnmarshallingJSON(&result),
122		autorest.ByClosing())
123	result.Response = autorest.Response{Response: resp}
124	return
125}
126
127// Delete deletes specified Machine Learning compute.
128// Parameters:
129// resourceGroupName - the name of the resource group. The name is case insensitive.
130// workspaceName - name of Azure Machine Learning workspace.
131// computeName - name of the Azure Machine Learning compute.
132// underlyingResourceAction - delete the underlying compute if 'Delete', or detach the underlying compute from
133// workspace if 'Detach'.
134func (client ComputeClient) Delete(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, underlyingResourceAction UnderlyingResourceAction) (result ComputeDeleteFuture, err error) {
135	if tracing.IsEnabled() {
136		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.Delete")
137		defer func() {
138			sc := -1
139			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
140				sc = result.FutureAPI.Response().StatusCode
141			}
142			tracing.EndSpan(ctx, sc, err)
143		}()
144	}
145	if err := validation.Validate([]validation.Validation{
146		{TargetValue: client.SubscriptionID,
147			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
148		{TargetValue: resourceGroupName,
149			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
150				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
151		return result, validation.NewError("machinelearningservices.ComputeClient", "Delete", err.Error())
152	}
153
154	req, err := client.DeletePreparer(ctx, resourceGroupName, workspaceName, computeName, underlyingResourceAction)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Delete", nil, "Failure preparing request")
157		return
158	}
159
160	result, err = client.DeleteSender(req)
161	if err != nil {
162		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Delete", nil, "Failure sending request")
163		return
164	}
165
166	return
167}
168
169// DeletePreparer prepares the Delete request.
170func (client ComputeClient) DeletePreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, underlyingResourceAction UnderlyingResourceAction) (*http.Request, error) {
171	pathParameters := map[string]interface{}{
172		"computeName":       autorest.Encode("path", computeName),
173		"resourceGroupName": autorest.Encode("path", resourceGroupName),
174		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
175		"workspaceName":     autorest.Encode("path", workspaceName),
176	}
177
178	const APIVersion = "2021-07-01"
179	queryParameters := map[string]interface{}{
180		"api-version":              APIVersion,
181		"underlyingResourceAction": autorest.Encode("query", underlyingResourceAction),
182	}
183
184	preparer := autorest.CreatePreparer(
185		autorest.AsDelete(),
186		autorest.WithBaseURL(client.BaseURI),
187		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}", pathParameters),
188		autorest.WithQueryParameters(queryParameters))
189	return preparer.Prepare((&http.Request{}).WithContext(ctx))
190}
191
192// DeleteSender sends the Delete request. The method will close the
193// http.Response Body if it receives an error.
194func (client ComputeClient) DeleteSender(req *http.Request) (future ComputeDeleteFuture, err error) {
195	var resp *http.Response
196	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
197	if err != nil {
198		return
199	}
200	var azf azure.Future
201	azf, err = azure.NewFutureFromResponse(resp)
202	future.FutureAPI = &azf
203	future.Result = future.result
204	return
205}
206
207// DeleteResponder handles the response to the Delete request. The method always
208// closes the http.Response Body.
209func (client ComputeClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
210	err = autorest.Respond(
211		resp,
212		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
213		autorest.ByClosing())
214	result.Response = resp
215	return
216}
217
218// Get gets compute definition by its name. Any secrets (storage keys, service credentials, etc) are not returned - use
219// 'keys' nested resource to get them.
220// Parameters:
221// resourceGroupName - the name of the resource group. The name is case insensitive.
222// workspaceName - name of Azure Machine Learning workspace.
223// computeName - name of the Azure Machine Learning compute.
224func (client ComputeClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result ComputeResource, err error) {
225	if tracing.IsEnabled() {
226		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.Get")
227		defer func() {
228			sc := -1
229			if result.Response.Response != nil {
230				sc = result.Response.Response.StatusCode
231			}
232			tracing.EndSpan(ctx, sc, err)
233		}()
234	}
235	if err := validation.Validate([]validation.Validation{
236		{TargetValue: client.SubscriptionID,
237			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
238		{TargetValue: resourceGroupName,
239			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
240				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
241		return result, validation.NewError("machinelearningservices.ComputeClient", "Get", err.Error())
242	}
243
244	req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, computeName)
245	if err != nil {
246		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "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, "machinelearningservices.ComputeClient", "Get", resp, "Failure sending request")
254		return
255	}
256
257	result, err = client.GetResponder(resp)
258	if err != nil {
259		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Get", resp, "Failure responding to request")
260		return
261	}
262
263	return
264}
265
266// GetPreparer prepares the Get request.
267func (client ComputeClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (*http.Request, error) {
268	pathParameters := map[string]interface{}{
269		"computeName":       autorest.Encode("path", computeName),
270		"resourceGroupName": autorest.Encode("path", resourceGroupName),
271		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
272		"workspaceName":     autorest.Encode("path", workspaceName),
273	}
274
275	const APIVersion = "2021-07-01"
276	queryParameters := map[string]interface{}{
277		"api-version": APIVersion,
278	}
279
280	preparer := autorest.CreatePreparer(
281		autorest.AsGet(),
282		autorest.WithBaseURL(client.BaseURI),
283		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}", pathParameters),
284		autorest.WithQueryParameters(queryParameters))
285	return preparer.Prepare((&http.Request{}).WithContext(ctx))
286}
287
288// GetSender sends the Get request. The method will close the
289// http.Response Body if it receives an error.
290func (client ComputeClient) GetSender(req *http.Request) (*http.Response, error) {
291	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
292}
293
294// GetResponder handles the response to the Get request. The method always
295// closes the http.Response Body.
296func (client ComputeClient) GetResponder(resp *http.Response) (result ComputeResource, err error) {
297	err = autorest.Respond(
298		resp,
299		azure.WithErrorUnlessStatusCode(http.StatusOK),
300		autorest.ByUnmarshallingJSON(&result),
301		autorest.ByClosing())
302	result.Response = autorest.Response{Response: resp}
303	return
304}
305
306// List gets computes in specified workspace.
307// Parameters:
308// resourceGroupName - the name of the resource group. The name is case insensitive.
309// workspaceName - name of Azure Machine Learning workspace.
310// skip - continuation token for pagination.
311func (client ComputeClient) List(ctx context.Context, resourceGroupName string, workspaceName string, skip string) (result PaginatedComputeResourcesListPage, err error) {
312	if tracing.IsEnabled() {
313		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.List")
314		defer func() {
315			sc := -1
316			if result.pcrl.Response.Response != nil {
317				sc = result.pcrl.Response.Response.StatusCode
318			}
319			tracing.EndSpan(ctx, sc, err)
320		}()
321	}
322	if err := validation.Validate([]validation.Validation{
323		{TargetValue: client.SubscriptionID,
324			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
325		{TargetValue: resourceGroupName,
326			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
327				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
328		return result, validation.NewError("machinelearningservices.ComputeClient", "List", err.Error())
329	}
330
331	result.fn = client.listNextResults
332	req, err := client.ListPreparer(ctx, resourceGroupName, workspaceName, skip)
333	if err != nil {
334		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "List", nil, "Failure preparing request")
335		return
336	}
337
338	resp, err := client.ListSender(req)
339	if err != nil {
340		result.pcrl.Response = autorest.Response{Response: resp}
341		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "List", resp, "Failure sending request")
342		return
343	}
344
345	result.pcrl, err = client.ListResponder(resp)
346	if err != nil {
347		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "List", resp, "Failure responding to request")
348		return
349	}
350	if result.pcrl.hasNextLink() && result.pcrl.IsEmpty() {
351		err = result.NextWithContext(ctx)
352		return
353	}
354
355	return
356}
357
358// ListPreparer prepares the List request.
359func (client ComputeClient) ListPreparer(ctx context.Context, resourceGroupName string, workspaceName string, skip string) (*http.Request, error) {
360	pathParameters := map[string]interface{}{
361		"resourceGroupName": autorest.Encode("path", resourceGroupName),
362		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
363		"workspaceName":     autorest.Encode("path", workspaceName),
364	}
365
366	const APIVersion = "2021-07-01"
367	queryParameters := map[string]interface{}{
368		"api-version": APIVersion,
369	}
370	if len(skip) > 0 {
371		queryParameters["$skip"] = autorest.Encode("query", skip)
372	}
373
374	preparer := autorest.CreatePreparer(
375		autorest.AsGet(),
376		autorest.WithBaseURL(client.BaseURI),
377		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes", pathParameters),
378		autorest.WithQueryParameters(queryParameters))
379	return preparer.Prepare((&http.Request{}).WithContext(ctx))
380}
381
382// ListSender sends the List request. The method will close the
383// http.Response Body if it receives an error.
384func (client ComputeClient) ListSender(req *http.Request) (*http.Response, error) {
385	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
386}
387
388// ListResponder handles the response to the List request. The method always
389// closes the http.Response Body.
390func (client ComputeClient) ListResponder(resp *http.Response) (result PaginatedComputeResourcesList, err error) {
391	err = autorest.Respond(
392		resp,
393		azure.WithErrorUnlessStatusCode(http.StatusOK),
394		autorest.ByUnmarshallingJSON(&result),
395		autorest.ByClosing())
396	result.Response = autorest.Response{Response: resp}
397	return
398}
399
400// listNextResults retrieves the next set of results, if any.
401func (client ComputeClient) listNextResults(ctx context.Context, lastResults PaginatedComputeResourcesList) (result PaginatedComputeResourcesList, err error) {
402	req, err := lastResults.paginatedComputeResourcesListPreparer(ctx)
403	if err != nil {
404		return result, autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "listNextResults", nil, "Failure preparing next results request")
405	}
406	if req == nil {
407		return
408	}
409	resp, err := client.ListSender(req)
410	if err != nil {
411		result.Response = autorest.Response{Response: resp}
412		return result, autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "listNextResults", resp, "Failure sending next results request")
413	}
414	result, err = client.ListResponder(resp)
415	if err != nil {
416		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "listNextResults", resp, "Failure responding to next results request")
417	}
418	return
419}
420
421// ListComplete enumerates all values, automatically crossing page boundaries as required.
422func (client ComputeClient) ListComplete(ctx context.Context, resourceGroupName string, workspaceName string, skip string) (result PaginatedComputeResourcesListIterator, err error) {
423	if tracing.IsEnabled() {
424		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.List")
425		defer func() {
426			sc := -1
427			if result.Response().Response.Response != nil {
428				sc = result.page.Response().Response.Response.StatusCode
429			}
430			tracing.EndSpan(ctx, sc, err)
431		}()
432	}
433	result.page, err = client.List(ctx, resourceGroupName, workspaceName, skip)
434	return
435}
436
437// ListKeys gets secrets related to Machine Learning compute (storage keys, service credentials, etc).
438// Parameters:
439// resourceGroupName - the name of the resource group. The name is case insensitive.
440// workspaceName - name of Azure Machine Learning workspace.
441// computeName - name of the Azure Machine Learning compute.
442func (client ComputeClient) ListKeys(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result ComputeSecretsModel, err error) {
443	if tracing.IsEnabled() {
444		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.ListKeys")
445		defer func() {
446			sc := -1
447			if result.Response.Response != nil {
448				sc = result.Response.Response.StatusCode
449			}
450			tracing.EndSpan(ctx, sc, err)
451		}()
452	}
453	if err := validation.Validate([]validation.Validation{
454		{TargetValue: client.SubscriptionID,
455			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
456		{TargetValue: resourceGroupName,
457			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
458				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
459		return result, validation.NewError("machinelearningservices.ComputeClient", "ListKeys", err.Error())
460	}
461
462	req, err := client.ListKeysPreparer(ctx, resourceGroupName, workspaceName, computeName)
463	if err != nil {
464		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "ListKeys", nil, "Failure preparing request")
465		return
466	}
467
468	resp, err := client.ListKeysSender(req)
469	if err != nil {
470		result.Response = autorest.Response{Response: resp}
471		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "ListKeys", resp, "Failure sending request")
472		return
473	}
474
475	result, err = client.ListKeysResponder(resp)
476	if err != nil {
477		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "ListKeys", resp, "Failure responding to request")
478		return
479	}
480
481	return
482}
483
484// ListKeysPreparer prepares the ListKeys request.
485func (client ComputeClient) ListKeysPreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (*http.Request, error) {
486	pathParameters := map[string]interface{}{
487		"computeName":       autorest.Encode("path", computeName),
488		"resourceGroupName": autorest.Encode("path", resourceGroupName),
489		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
490		"workspaceName":     autorest.Encode("path", workspaceName),
491	}
492
493	const APIVersion = "2021-07-01"
494	queryParameters := map[string]interface{}{
495		"api-version": APIVersion,
496	}
497
498	preparer := autorest.CreatePreparer(
499		autorest.AsPost(),
500		autorest.WithBaseURL(client.BaseURI),
501		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}/listKeys", pathParameters),
502		autorest.WithQueryParameters(queryParameters))
503	return preparer.Prepare((&http.Request{}).WithContext(ctx))
504}
505
506// ListKeysSender sends the ListKeys request. The method will close the
507// http.Response Body if it receives an error.
508func (client ComputeClient) ListKeysSender(req *http.Request) (*http.Response, error) {
509	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
510}
511
512// ListKeysResponder handles the response to the ListKeys request. The method always
513// closes the http.Response Body.
514func (client ComputeClient) ListKeysResponder(resp *http.Response) (result ComputeSecretsModel, err error) {
515	err = autorest.Respond(
516		resp,
517		azure.WithErrorUnlessStatusCode(http.StatusOK),
518		autorest.ByUnmarshallingJSON(&result),
519		autorest.ByClosing())
520	result.Response = autorest.Response{Response: resp}
521	return
522}
523
524// ListNodes get the details (e.g IP address, port etc) of all the compute nodes in the compute.
525// Parameters:
526// resourceGroupName - the name of the resource group. The name is case insensitive.
527// workspaceName - name of Azure Machine Learning workspace.
528// computeName - name of the Azure Machine Learning compute.
529func (client ComputeClient) ListNodes(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result AmlComputeNodesInformationPage, err error) {
530	if tracing.IsEnabled() {
531		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.ListNodes")
532		defer func() {
533			sc := -1
534			if result.acni.Response.Response != nil {
535				sc = result.acni.Response.Response.StatusCode
536			}
537			tracing.EndSpan(ctx, sc, err)
538		}()
539	}
540	if err := validation.Validate([]validation.Validation{
541		{TargetValue: client.SubscriptionID,
542			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
543		{TargetValue: resourceGroupName,
544			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
545				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
546		return result, validation.NewError("machinelearningservices.ComputeClient", "ListNodes", err.Error())
547	}
548
549	result.fn = client.listNodesNextResults
550	req, err := client.ListNodesPreparer(ctx, resourceGroupName, workspaceName, computeName)
551	if err != nil {
552		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "ListNodes", nil, "Failure preparing request")
553		return
554	}
555
556	resp, err := client.ListNodesSender(req)
557	if err != nil {
558		result.acni.Response = autorest.Response{Response: resp}
559		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "ListNodes", resp, "Failure sending request")
560		return
561	}
562
563	result.acni, err = client.ListNodesResponder(resp)
564	if err != nil {
565		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "ListNodes", resp, "Failure responding to request")
566		return
567	}
568	if result.acni.hasNextLink() && result.acni.IsEmpty() {
569		err = result.NextWithContext(ctx)
570		return
571	}
572
573	return
574}
575
576// ListNodesPreparer prepares the ListNodes request.
577func (client ComputeClient) ListNodesPreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (*http.Request, error) {
578	pathParameters := map[string]interface{}{
579		"computeName":       autorest.Encode("path", computeName),
580		"resourceGroupName": autorest.Encode("path", resourceGroupName),
581		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
582		"workspaceName":     autorest.Encode("path", workspaceName),
583	}
584
585	const APIVersion = "2021-07-01"
586	queryParameters := map[string]interface{}{
587		"api-version": APIVersion,
588	}
589
590	preparer := autorest.CreatePreparer(
591		autorest.AsPost(),
592		autorest.WithBaseURL(client.BaseURI),
593		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}/listNodes", pathParameters),
594		autorest.WithQueryParameters(queryParameters))
595	return preparer.Prepare((&http.Request{}).WithContext(ctx))
596}
597
598// ListNodesSender sends the ListNodes request. The method will close the
599// http.Response Body if it receives an error.
600func (client ComputeClient) ListNodesSender(req *http.Request) (*http.Response, error) {
601	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
602}
603
604// ListNodesResponder handles the response to the ListNodes request. The method always
605// closes the http.Response Body.
606func (client ComputeClient) ListNodesResponder(resp *http.Response) (result AmlComputeNodesInformation, err error) {
607	err = autorest.Respond(
608		resp,
609		azure.WithErrorUnlessStatusCode(http.StatusOK),
610		autorest.ByUnmarshallingJSON(&result),
611		autorest.ByClosing())
612	result.Response = autorest.Response{Response: resp}
613	return
614}
615
616// listNodesNextResults retrieves the next set of results, if any.
617func (client ComputeClient) listNodesNextResults(ctx context.Context, lastResults AmlComputeNodesInformation) (result AmlComputeNodesInformation, err error) {
618	req, err := lastResults.amlComputeNodesInformationPreparer(ctx)
619	if err != nil {
620		return result, autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "listNodesNextResults", nil, "Failure preparing next results request")
621	}
622	if req == nil {
623		return
624	}
625	resp, err := client.ListNodesSender(req)
626	if err != nil {
627		result.Response = autorest.Response{Response: resp}
628		return result, autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "listNodesNextResults", resp, "Failure sending next results request")
629	}
630	result, err = client.ListNodesResponder(resp)
631	if err != nil {
632		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "listNodesNextResults", resp, "Failure responding to next results request")
633	}
634	return
635}
636
637// ListNodesComplete enumerates all values, automatically crossing page boundaries as required.
638func (client ComputeClient) ListNodesComplete(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result AmlComputeNodesInformationIterator, err error) {
639	if tracing.IsEnabled() {
640		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.ListNodes")
641		defer func() {
642			sc := -1
643			if result.Response().Response.Response != nil {
644				sc = result.page.Response().Response.Response.StatusCode
645			}
646			tracing.EndSpan(ctx, sc, err)
647		}()
648	}
649	result.page, err = client.ListNodes(ctx, resourceGroupName, workspaceName, computeName)
650	return
651}
652
653// Restart posts a restart action to a compute instance
654// Parameters:
655// resourceGroupName - the name of the resource group. The name is case insensitive.
656// workspaceName - name of Azure Machine Learning workspace.
657// computeName - name of the Azure Machine Learning compute.
658func (client ComputeClient) Restart(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result ComputeRestartFuture, err error) {
659	if tracing.IsEnabled() {
660		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.Restart")
661		defer func() {
662			sc := -1
663			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
664				sc = result.FutureAPI.Response().StatusCode
665			}
666			tracing.EndSpan(ctx, sc, err)
667		}()
668	}
669	if err := validation.Validate([]validation.Validation{
670		{TargetValue: client.SubscriptionID,
671			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
672		{TargetValue: resourceGroupName,
673			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
674				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
675		return result, validation.NewError("machinelearningservices.ComputeClient", "Restart", err.Error())
676	}
677
678	req, err := client.RestartPreparer(ctx, resourceGroupName, workspaceName, computeName)
679	if err != nil {
680		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Restart", nil, "Failure preparing request")
681		return
682	}
683
684	result, err = client.RestartSender(req)
685	if err != nil {
686		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Restart", nil, "Failure sending request")
687		return
688	}
689
690	return
691}
692
693// RestartPreparer prepares the Restart request.
694func (client ComputeClient) RestartPreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (*http.Request, error) {
695	pathParameters := map[string]interface{}{
696		"computeName":       autorest.Encode("path", computeName),
697		"resourceGroupName": autorest.Encode("path", resourceGroupName),
698		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
699		"workspaceName":     autorest.Encode("path", workspaceName),
700	}
701
702	const APIVersion = "2021-07-01"
703	queryParameters := map[string]interface{}{
704		"api-version": APIVersion,
705	}
706
707	preparer := autorest.CreatePreparer(
708		autorest.AsPost(),
709		autorest.WithBaseURL(client.BaseURI),
710		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}/restart", pathParameters),
711		autorest.WithQueryParameters(queryParameters))
712	return preparer.Prepare((&http.Request{}).WithContext(ctx))
713}
714
715// RestartSender sends the Restart request. The method will close the
716// http.Response Body if it receives an error.
717func (client ComputeClient) RestartSender(req *http.Request) (future ComputeRestartFuture, err error) {
718	var resp *http.Response
719	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
720	if err != nil {
721		return
722	}
723	var azf azure.Future
724	azf, err = azure.NewFutureFromResponse(resp)
725	future.FutureAPI = &azf
726	future.Result = future.result
727	return
728}
729
730// RestartResponder handles the response to the Restart request. The method always
731// closes the http.Response Body.
732func (client ComputeClient) RestartResponder(resp *http.Response) (result autorest.Response, err error) {
733	err = autorest.Respond(
734		resp,
735		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
736		autorest.ByClosing())
737	result.Response = resp
738	return
739}
740
741// Start posts a start action to a compute instance
742// Parameters:
743// resourceGroupName - the name of the resource group. The name is case insensitive.
744// workspaceName - name of Azure Machine Learning workspace.
745// computeName - name of the Azure Machine Learning compute.
746func (client ComputeClient) Start(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result ComputeStartFuture, err error) {
747	if tracing.IsEnabled() {
748		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.Start")
749		defer func() {
750			sc := -1
751			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
752				sc = result.FutureAPI.Response().StatusCode
753			}
754			tracing.EndSpan(ctx, sc, err)
755		}()
756	}
757	if err := validation.Validate([]validation.Validation{
758		{TargetValue: client.SubscriptionID,
759			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
760		{TargetValue: resourceGroupName,
761			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
762				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
763		return result, validation.NewError("machinelearningservices.ComputeClient", "Start", err.Error())
764	}
765
766	req, err := client.StartPreparer(ctx, resourceGroupName, workspaceName, computeName)
767	if err != nil {
768		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Start", nil, "Failure preparing request")
769		return
770	}
771
772	result, err = client.StartSender(req)
773	if err != nil {
774		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Start", nil, "Failure sending request")
775		return
776	}
777
778	return
779}
780
781// StartPreparer prepares the Start request.
782func (client ComputeClient) StartPreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (*http.Request, error) {
783	pathParameters := map[string]interface{}{
784		"computeName":       autorest.Encode("path", computeName),
785		"resourceGroupName": autorest.Encode("path", resourceGroupName),
786		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
787		"workspaceName":     autorest.Encode("path", workspaceName),
788	}
789
790	const APIVersion = "2021-07-01"
791	queryParameters := map[string]interface{}{
792		"api-version": APIVersion,
793	}
794
795	preparer := autorest.CreatePreparer(
796		autorest.AsPost(),
797		autorest.WithBaseURL(client.BaseURI),
798		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}/start", pathParameters),
799		autorest.WithQueryParameters(queryParameters))
800	return preparer.Prepare((&http.Request{}).WithContext(ctx))
801}
802
803// StartSender sends the Start request. The method will close the
804// http.Response Body if it receives an error.
805func (client ComputeClient) StartSender(req *http.Request) (future ComputeStartFuture, err error) {
806	var resp *http.Response
807	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
808	if err != nil {
809		return
810	}
811	var azf azure.Future
812	azf, err = azure.NewFutureFromResponse(resp)
813	future.FutureAPI = &azf
814	future.Result = future.result
815	return
816}
817
818// StartResponder handles the response to the Start request. The method always
819// closes the http.Response Body.
820func (client ComputeClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
821	err = autorest.Respond(
822		resp,
823		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
824		autorest.ByClosing())
825	result.Response = resp
826	return
827}
828
829// Stop posts a stop action to a compute instance
830// Parameters:
831// resourceGroupName - the name of the resource group. The name is case insensitive.
832// workspaceName - name of Azure Machine Learning workspace.
833// computeName - name of the Azure Machine Learning compute.
834func (client ComputeClient) Stop(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (result ComputeStopFuture, err error) {
835	if tracing.IsEnabled() {
836		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.Stop")
837		defer func() {
838			sc := -1
839			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
840				sc = result.FutureAPI.Response().StatusCode
841			}
842			tracing.EndSpan(ctx, sc, err)
843		}()
844	}
845	if err := validation.Validate([]validation.Validation{
846		{TargetValue: client.SubscriptionID,
847			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
848		{TargetValue: resourceGroupName,
849			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
850				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
851		return result, validation.NewError("machinelearningservices.ComputeClient", "Stop", err.Error())
852	}
853
854	req, err := client.StopPreparer(ctx, resourceGroupName, workspaceName, computeName)
855	if err != nil {
856		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Stop", nil, "Failure preparing request")
857		return
858	}
859
860	result, err = client.StopSender(req)
861	if err != nil {
862		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Stop", nil, "Failure sending request")
863		return
864	}
865
866	return
867}
868
869// StopPreparer prepares the Stop request.
870func (client ComputeClient) StopPreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string) (*http.Request, error) {
871	pathParameters := map[string]interface{}{
872		"computeName":       autorest.Encode("path", computeName),
873		"resourceGroupName": autorest.Encode("path", resourceGroupName),
874		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
875		"workspaceName":     autorest.Encode("path", workspaceName),
876	}
877
878	const APIVersion = "2021-07-01"
879	queryParameters := map[string]interface{}{
880		"api-version": APIVersion,
881	}
882
883	preparer := autorest.CreatePreparer(
884		autorest.AsPost(),
885		autorest.WithBaseURL(client.BaseURI),
886		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}/stop", pathParameters),
887		autorest.WithQueryParameters(queryParameters))
888	return preparer.Prepare((&http.Request{}).WithContext(ctx))
889}
890
891// StopSender sends the Stop request. The method will close the
892// http.Response Body if it receives an error.
893func (client ComputeClient) StopSender(req *http.Request) (future ComputeStopFuture, err error) {
894	var resp *http.Response
895	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
896	if err != nil {
897		return
898	}
899	var azf azure.Future
900	azf, err = azure.NewFutureFromResponse(resp)
901	future.FutureAPI = &azf
902	future.Result = future.result
903	return
904}
905
906// StopResponder handles the response to the Stop request. The method always
907// closes the http.Response Body.
908func (client ComputeClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
909	err = autorest.Respond(
910		resp,
911		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
912		autorest.ByClosing())
913	result.Response = resp
914	return
915}
916
917// Update updates properties of a compute. This call will overwrite a compute if it exists. This is a nonrecoverable
918// operation.
919// Parameters:
920// resourceGroupName - the name of the resource group. The name is case insensitive.
921// workspaceName - name of Azure Machine Learning workspace.
922// computeName - name of the Azure Machine Learning compute.
923// parameters - additional parameters for cluster update.
924func (client ComputeClient) Update(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, parameters ClusterUpdateParameters) (result ComputeUpdateFuture, err error) {
925	if tracing.IsEnabled() {
926		ctx = tracing.StartSpan(ctx, fqdn+"/ComputeClient.Update")
927		defer func() {
928			sc := -1
929			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
930				sc = result.FutureAPI.Response().StatusCode
931			}
932			tracing.EndSpan(ctx, sc, err)
933		}()
934	}
935	if err := validation.Validate([]validation.Validation{
936		{TargetValue: client.SubscriptionID,
937			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
938		{TargetValue: resourceGroupName,
939			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
940				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
941		return result, validation.NewError("machinelearningservices.ComputeClient", "Update", err.Error())
942	}
943
944	req, err := client.UpdatePreparer(ctx, resourceGroupName, workspaceName, computeName, parameters)
945	if err != nil {
946		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Update", nil, "Failure preparing request")
947		return
948	}
949
950	result, err = client.UpdateSender(req)
951	if err != nil {
952		err = autorest.NewErrorWithError(err, "machinelearningservices.ComputeClient", "Update", nil, "Failure sending request")
953		return
954	}
955
956	return
957}
958
959// UpdatePreparer prepares the Update request.
960func (client ComputeClient) UpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, computeName string, parameters ClusterUpdateParameters) (*http.Request, error) {
961	pathParameters := map[string]interface{}{
962		"computeName":       autorest.Encode("path", computeName),
963		"resourceGroupName": autorest.Encode("path", resourceGroupName),
964		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
965		"workspaceName":     autorest.Encode("path", workspaceName),
966	}
967
968	const APIVersion = "2021-07-01"
969	queryParameters := map[string]interface{}{
970		"api-version": APIVersion,
971	}
972
973	preparer := autorest.CreatePreparer(
974		autorest.AsContentType("application/json; charset=utf-8"),
975		autorest.AsPatch(),
976		autorest.WithBaseURL(client.BaseURI),
977		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/computes/{computeName}", pathParameters),
978		autorest.WithJSON(parameters),
979		autorest.WithQueryParameters(queryParameters))
980	return preparer.Prepare((&http.Request{}).WithContext(ctx))
981}
982
983// UpdateSender sends the Update request. The method will close the
984// http.Response Body if it receives an error.
985func (client ComputeClient) UpdateSender(req *http.Request) (future ComputeUpdateFuture, err error) {
986	var resp *http.Response
987	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
988	if err != nil {
989		return
990	}
991	var azf azure.Future
992	azf, err = azure.NewFutureFromResponse(resp)
993	future.FutureAPI = &azf
994	future.Result = future.result
995	return
996}
997
998// UpdateResponder handles the response to the Update request. The method always
999// closes the http.Response Body.
1000func (client ComputeClient) UpdateResponder(resp *http.Response) (result ComputeResource, err error) {
1001	err = autorest.Respond(
1002		resp,
1003		azure.WithErrorUnlessStatusCode(http.StatusOK),
1004		autorest.ByUnmarshallingJSON(&result),
1005		autorest.ByClosing())
1006	result.Response = autorest.Response{Response: resp}
1007	return
1008}
1009