...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/machinelearning/mgmt/2017-05-01-preview/experimentation/workspaces.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/machinelearning/mgmt/2017-05-01-preview/experimentation

     1  package experimentation
     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  
     9  import (
    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  // WorkspacesClient is the these APIs allow end users to operate on Azure Machine Learning Team Account resources. They
    19  // support CRUD operations for Azure Machine Learning Team Accounts.
    20  type WorkspacesClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewWorkspacesClient creates an instance of the WorkspacesClient client.
    25  func NewWorkspacesClient(subscriptionID string) WorkspacesClient {
    26  	return NewWorkspacesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    27  }
    28  
    29  // NewWorkspacesClientWithBaseURI creates an instance of the WorkspacesClient client using a custom endpoint.  Use this
    30  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewWorkspacesClientWithBaseURI(baseURI string, subscriptionID string) WorkspacesClient {
    32  	return WorkspacesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate creates or updates a machine learning workspace with the specified parameters.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group to which the machine learning team account belongs.
    38  // accountName - the name of the machine learning team account.
    39  // workspaceName - the name of the machine learning team account workspace.
    40  // parameters - the parameters for creating or updating a machine learning workspace.
    41  func (client WorkspacesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, accountName string, workspaceName string, parameters Workspace) (result Workspace, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspacesClient.CreateOrUpdate")
    44  		defer func() {
    45  			sc := -1
    46  			if result.Response.Response != nil {
    47  				sc = result.Response.Response.StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: accountName,
    54  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    55  				{Target: "accountName", Name: validation.MinLength, Rule: 5, Chain: nil},
    56  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}},
    57  		{TargetValue: workspaceName,
    58  			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    59  				{Target: "workspaceName", Name: validation.MinLength, Rule: 5, Chain: nil},
    60  				{Target: "workspaceName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}},
    61  		{TargetValue: parameters,
    62  			Constraints: []validation.Constraint{{Target: "parameters.WorkspaceProperties", Name: validation.Null, Rule: false,
    63  				Chain: []validation.Constraint{{Target: "parameters.WorkspaceProperties.FriendlyName", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
    64  		return result, validation.NewError("experimentation.WorkspacesClient", "CreateOrUpdate", err.Error())
    65  	}
    66  
    67  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, accountName, workspaceName, parameters)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "CreateOrUpdate", nil, "Failure preparing request")
    70  		return
    71  	}
    72  
    73  	resp, err := client.CreateOrUpdateSender(req)
    74  	if err != nil {
    75  		result.Response = autorest.Response{Response: resp}
    76  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "CreateOrUpdate", resp, "Failure sending request")
    77  		return
    78  	}
    79  
    80  	result, err = client.CreateOrUpdateResponder(resp)
    81  	if err != nil {
    82  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "CreateOrUpdate", resp, "Failure responding to request")
    83  		return
    84  	}
    85  
    86  	return
    87  }
    88  
    89  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    90  func (client WorkspacesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, workspaceName string, parameters Workspace) (*http.Request, error) {
    91  	pathParameters := map[string]interface{}{
    92  		"accountName":       autorest.Encode("path", accountName),
    93  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    94  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    95  		"workspaceName":     autorest.Encode("path", workspaceName),
    96  	}
    97  
    98  	const APIVersion = "2017-05-01-preview"
    99  	queryParameters := map[string]interface{}{
   100  		"api-version": APIVersion,
   101  	}
   102  
   103  	preparer := autorest.CreatePreparer(
   104  		autorest.AsContentType("application/json; charset=utf-8"),
   105  		autorest.AsPut(),
   106  		autorest.WithBaseURL(client.BaseURI),
   107  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningExperimentation/accounts/{accountName}/workspaces/{workspaceName}", pathParameters),
   108  		autorest.WithJSON(parameters),
   109  		autorest.WithQueryParameters(queryParameters))
   110  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   111  }
   112  
   113  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   114  // http.Response Body if it receives an error.
   115  func (client WorkspacesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   116  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   117  }
   118  
   119  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   120  // closes the http.Response Body.
   121  func (client WorkspacesClient) CreateOrUpdateResponder(resp *http.Response) (result Workspace, err error) {
   122  	err = autorest.Respond(
   123  		resp,
   124  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   125  		autorest.ByUnmarshallingJSON(&result),
   126  		autorest.ByClosing())
   127  	result.Response = autorest.Response{Response: resp}
   128  	return
   129  }
   130  
   131  // Delete deletes a machine learning workspace.
   132  // Parameters:
   133  // resourceGroupName - the name of the resource group to which the machine learning team account belongs.
   134  // accountName - the name of the machine learning team account.
   135  // workspaceName - the name of the machine learning team account workspace.
   136  func (client WorkspacesClient) Delete(ctx context.Context, resourceGroupName string, accountName string, workspaceName string) (result autorest.Response, err error) {
   137  	if tracing.IsEnabled() {
   138  		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspacesClient.Delete")
   139  		defer func() {
   140  			sc := -1
   141  			if result.Response != nil {
   142  				sc = result.Response.StatusCode
   143  			}
   144  			tracing.EndSpan(ctx, sc, err)
   145  		}()
   146  	}
   147  	if err := validation.Validate([]validation.Validation{
   148  		{TargetValue: accountName,
   149  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   150  				{Target: "accountName", Name: validation.MinLength, Rule: 5, Chain: nil},
   151  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}},
   152  		{TargetValue: workspaceName,
   153  			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   154  				{Target: "workspaceName", Name: validation.MinLength, Rule: 5, Chain: nil},
   155  				{Target: "workspaceName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
   156  		return result, validation.NewError("experimentation.WorkspacesClient", "Delete", err.Error())
   157  	}
   158  
   159  	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, workspaceName)
   160  	if err != nil {
   161  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "Delete", nil, "Failure preparing request")
   162  		return
   163  	}
   164  
   165  	resp, err := client.DeleteSender(req)
   166  	if err != nil {
   167  		result.Response = resp
   168  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "Delete", resp, "Failure sending request")
   169  		return
   170  	}
   171  
   172  	result, err = client.DeleteResponder(resp)
   173  	if err != nil {
   174  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "Delete", resp, "Failure responding to request")
   175  		return
   176  	}
   177  
   178  	return
   179  }
   180  
   181  // DeletePreparer prepares the Delete request.
   182  func (client WorkspacesClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, workspaceName string) (*http.Request, error) {
   183  	pathParameters := map[string]interface{}{
   184  		"accountName":       autorest.Encode("path", accountName),
   185  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   186  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   187  		"workspaceName":     autorest.Encode("path", workspaceName),
   188  	}
   189  
   190  	const APIVersion = "2017-05-01-preview"
   191  	queryParameters := map[string]interface{}{
   192  		"api-version": APIVersion,
   193  	}
   194  
   195  	preparer := autorest.CreatePreparer(
   196  		autorest.AsDelete(),
   197  		autorest.WithBaseURL(client.BaseURI),
   198  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningExperimentation/accounts/{accountName}/workspaces/{workspaceName}", pathParameters),
   199  		autorest.WithQueryParameters(queryParameters))
   200  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   201  }
   202  
   203  // DeleteSender sends the Delete request. The method will close the
   204  // http.Response Body if it receives an error.
   205  func (client WorkspacesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   206  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   207  }
   208  
   209  // DeleteResponder handles the response to the Delete request. The method always
   210  // closes the http.Response Body.
   211  func (client WorkspacesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   212  	err = autorest.Respond(
   213  		resp,
   214  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   215  		autorest.ByClosing())
   216  	result.Response = resp
   217  	return
   218  }
   219  
   220  // Get gets the properties of the specified machine learning workspace.
   221  // Parameters:
   222  // resourceGroupName - the name of the resource group to which the machine learning team account belongs.
   223  // accountName - the name of the machine learning team account.
   224  // workspaceName - the name of the machine learning team account workspace.
   225  func (client WorkspacesClient) Get(ctx context.Context, resourceGroupName string, accountName string, workspaceName string) (result Workspace, err error) {
   226  	if tracing.IsEnabled() {
   227  		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspacesClient.Get")
   228  		defer func() {
   229  			sc := -1
   230  			if result.Response.Response != nil {
   231  				sc = result.Response.Response.StatusCode
   232  			}
   233  			tracing.EndSpan(ctx, sc, err)
   234  		}()
   235  	}
   236  	if err := validation.Validate([]validation.Validation{
   237  		{TargetValue: accountName,
   238  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   239  				{Target: "accountName", Name: validation.MinLength, Rule: 5, Chain: nil},
   240  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}},
   241  		{TargetValue: workspaceName,
   242  			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   243  				{Target: "workspaceName", Name: validation.MinLength, Rule: 5, Chain: nil},
   244  				{Target: "workspaceName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
   245  		return result, validation.NewError("experimentation.WorkspacesClient", "Get", err.Error())
   246  	}
   247  
   248  	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, workspaceName)
   249  	if err != nil {
   250  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "Get", nil, "Failure preparing request")
   251  		return
   252  	}
   253  
   254  	resp, err := client.GetSender(req)
   255  	if err != nil {
   256  		result.Response = autorest.Response{Response: resp}
   257  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "Get", resp, "Failure sending request")
   258  		return
   259  	}
   260  
   261  	result, err = client.GetResponder(resp)
   262  	if err != nil {
   263  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "Get", resp, "Failure responding to request")
   264  		return
   265  	}
   266  
   267  	return
   268  }
   269  
   270  // GetPreparer prepares the Get request.
   271  func (client WorkspacesClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, workspaceName string) (*http.Request, error) {
   272  	pathParameters := map[string]interface{}{
   273  		"accountName":       autorest.Encode("path", accountName),
   274  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   275  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   276  		"workspaceName":     autorest.Encode("path", workspaceName),
   277  	}
   278  
   279  	const APIVersion = "2017-05-01-preview"
   280  	queryParameters := map[string]interface{}{
   281  		"api-version": APIVersion,
   282  	}
   283  
   284  	preparer := autorest.CreatePreparer(
   285  		autorest.AsGet(),
   286  		autorest.WithBaseURL(client.BaseURI),
   287  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningExperimentation/accounts/{accountName}/workspaces/{workspaceName}", pathParameters),
   288  		autorest.WithQueryParameters(queryParameters))
   289  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   290  }
   291  
   292  // GetSender sends the Get request. The method will close the
   293  // http.Response Body if it receives an error.
   294  func (client WorkspacesClient) GetSender(req *http.Request) (*http.Response, error) {
   295  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   296  }
   297  
   298  // GetResponder handles the response to the Get request. The method always
   299  // closes the http.Response Body.
   300  func (client WorkspacesClient) GetResponder(resp *http.Response) (result Workspace, err error) {
   301  	err = autorest.Respond(
   302  		resp,
   303  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   304  		autorest.ByUnmarshallingJSON(&result),
   305  		autorest.ByClosing())
   306  	result.Response = autorest.Response{Response: resp}
   307  	return
   308  }
   309  
   310  // ListByAccounts lists all the available machine learning workspaces under the specified team account.
   311  // Parameters:
   312  // accountName - the name of the machine learning team account.
   313  // resourceGroupName - the name of the resource group to which the machine learning team account belongs.
   314  func (client WorkspacesClient) ListByAccounts(ctx context.Context, accountName string, resourceGroupName string) (result WorkspaceListResultPage, err error) {
   315  	if tracing.IsEnabled() {
   316  		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspacesClient.ListByAccounts")
   317  		defer func() {
   318  			sc := -1
   319  			if result.wlr.Response.Response != nil {
   320  				sc = result.wlr.Response.Response.StatusCode
   321  			}
   322  			tracing.EndSpan(ctx, sc, err)
   323  		}()
   324  	}
   325  	if err := validation.Validate([]validation.Validation{
   326  		{TargetValue: accountName,
   327  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   328  				{Target: "accountName", Name: validation.MinLength, Rule: 5, Chain: nil},
   329  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
   330  		return result, validation.NewError("experimentation.WorkspacesClient", "ListByAccounts", err.Error())
   331  	}
   332  
   333  	result.fn = client.listByAccountsNextResults
   334  	req, err := client.ListByAccountsPreparer(ctx, accountName, resourceGroupName)
   335  	if err != nil {
   336  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "ListByAccounts", nil, "Failure preparing request")
   337  		return
   338  	}
   339  
   340  	resp, err := client.ListByAccountsSender(req)
   341  	if err != nil {
   342  		result.wlr.Response = autorest.Response{Response: resp}
   343  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "ListByAccounts", resp, "Failure sending request")
   344  		return
   345  	}
   346  
   347  	result.wlr, err = client.ListByAccountsResponder(resp)
   348  	if err != nil {
   349  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "ListByAccounts", resp, "Failure responding to request")
   350  		return
   351  	}
   352  	if result.wlr.hasNextLink() && result.wlr.IsEmpty() {
   353  		err = result.NextWithContext(ctx)
   354  		return
   355  	}
   356  
   357  	return
   358  }
   359  
   360  // ListByAccountsPreparer prepares the ListByAccounts request.
   361  func (client WorkspacesClient) ListByAccountsPreparer(ctx context.Context, accountName string, resourceGroupName string) (*http.Request, error) {
   362  	pathParameters := map[string]interface{}{
   363  		"accountName":       autorest.Encode("path", accountName),
   364  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   365  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   366  	}
   367  
   368  	const APIVersion = "2017-05-01-preview"
   369  	queryParameters := map[string]interface{}{
   370  		"api-version": APIVersion,
   371  	}
   372  
   373  	preparer := autorest.CreatePreparer(
   374  		autorest.AsGet(),
   375  		autorest.WithBaseURL(client.BaseURI),
   376  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningExperimentation/accounts/{accountName}/workspaces", pathParameters),
   377  		autorest.WithQueryParameters(queryParameters))
   378  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   379  }
   380  
   381  // ListByAccountsSender sends the ListByAccounts request. The method will close the
   382  // http.Response Body if it receives an error.
   383  func (client WorkspacesClient) ListByAccountsSender(req *http.Request) (*http.Response, error) {
   384  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   385  }
   386  
   387  // ListByAccountsResponder handles the response to the ListByAccounts request. The method always
   388  // closes the http.Response Body.
   389  func (client WorkspacesClient) ListByAccountsResponder(resp *http.Response) (result WorkspaceListResult, err error) {
   390  	err = autorest.Respond(
   391  		resp,
   392  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   393  		autorest.ByUnmarshallingJSON(&result),
   394  		autorest.ByClosing())
   395  	result.Response = autorest.Response{Response: resp}
   396  	return
   397  }
   398  
   399  // listByAccountsNextResults retrieves the next set of results, if any.
   400  func (client WorkspacesClient) listByAccountsNextResults(ctx context.Context, lastResults WorkspaceListResult) (result WorkspaceListResult, err error) {
   401  	req, err := lastResults.workspaceListResultPreparer(ctx)
   402  	if err != nil {
   403  		return result, autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "listByAccountsNextResults", nil, "Failure preparing next results request")
   404  	}
   405  	if req == nil {
   406  		return
   407  	}
   408  	resp, err := client.ListByAccountsSender(req)
   409  	if err != nil {
   410  		result.Response = autorest.Response{Response: resp}
   411  		return result, autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "listByAccountsNextResults", resp, "Failure sending next results request")
   412  	}
   413  	result, err = client.ListByAccountsResponder(resp)
   414  	if err != nil {
   415  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "listByAccountsNextResults", resp, "Failure responding to next results request")
   416  	}
   417  	return
   418  }
   419  
   420  // ListByAccountsComplete enumerates all values, automatically crossing page boundaries as required.
   421  func (client WorkspacesClient) ListByAccountsComplete(ctx context.Context, accountName string, resourceGroupName string) (result WorkspaceListResultIterator, err error) {
   422  	if tracing.IsEnabled() {
   423  		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspacesClient.ListByAccounts")
   424  		defer func() {
   425  			sc := -1
   426  			if result.Response().Response.Response != nil {
   427  				sc = result.page.Response().Response.Response.StatusCode
   428  			}
   429  			tracing.EndSpan(ctx, sc, err)
   430  		}()
   431  	}
   432  	result.page, err = client.ListByAccounts(ctx, accountName, resourceGroupName)
   433  	return
   434  }
   435  
   436  // Update updates a machine learning workspace with the specified parameters.
   437  // Parameters:
   438  // resourceGroupName - the name of the resource group to which the machine learning team account belongs.
   439  // accountName - the name of the machine learning team account.
   440  // workspaceName - the name of the machine learning team account workspace.
   441  // parameters - the parameters for updating a machine learning workspace.
   442  func (client WorkspacesClient) Update(ctx context.Context, resourceGroupName string, accountName string, workspaceName string, parameters WorkspaceUpdateParameters) (result Workspace, err error) {
   443  	if tracing.IsEnabled() {
   444  		ctx = tracing.StartSpan(ctx, fqdn+"/WorkspacesClient.Update")
   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: accountName,
   455  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   456  				{Target: "accountName", Name: validation.MinLength, Rule: 5, Chain: nil},
   457  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}},
   458  		{TargetValue: workspaceName,
   459  			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   460  				{Target: "workspaceName", Name: validation.MinLength, Rule: 5, Chain: nil},
   461  				{Target: "workspaceName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]*$`, Chain: nil}}}}); err != nil {
   462  		return result, validation.NewError("experimentation.WorkspacesClient", "Update", err.Error())
   463  	}
   464  
   465  	req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, workspaceName, parameters)
   466  	if err != nil {
   467  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "Update", nil, "Failure preparing request")
   468  		return
   469  	}
   470  
   471  	resp, err := client.UpdateSender(req)
   472  	if err != nil {
   473  		result.Response = autorest.Response{Response: resp}
   474  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "Update", resp, "Failure sending request")
   475  		return
   476  	}
   477  
   478  	result, err = client.UpdateResponder(resp)
   479  	if err != nil {
   480  		err = autorest.NewErrorWithError(err, "experimentation.WorkspacesClient", "Update", resp, "Failure responding to request")
   481  		return
   482  	}
   483  
   484  	return
   485  }
   486  
   487  // UpdatePreparer prepares the Update request.
   488  func (client WorkspacesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, workspaceName string, parameters WorkspaceUpdateParameters) (*http.Request, error) {
   489  	pathParameters := map[string]interface{}{
   490  		"accountName":       autorest.Encode("path", accountName),
   491  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   492  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   493  		"workspaceName":     autorest.Encode("path", workspaceName),
   494  	}
   495  
   496  	const APIVersion = "2017-05-01-preview"
   497  	queryParameters := map[string]interface{}{
   498  		"api-version": APIVersion,
   499  	}
   500  
   501  	preparer := autorest.CreatePreparer(
   502  		autorest.AsContentType("application/json; charset=utf-8"),
   503  		autorest.AsPatch(),
   504  		autorest.WithBaseURL(client.BaseURI),
   505  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningExperimentation/accounts/{accountName}/workspaces/{workspaceName}", pathParameters),
   506  		autorest.WithJSON(parameters),
   507  		autorest.WithQueryParameters(queryParameters))
   508  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   509  }
   510  
   511  // UpdateSender sends the Update request. The method will close the
   512  // http.Response Body if it receives an error.
   513  func (client WorkspacesClient) UpdateSender(req *http.Request) (*http.Response, error) {
   514  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   515  }
   516  
   517  // UpdateResponder handles the response to the Update request. The method always
   518  // closes the http.Response Body.
   519  func (client WorkspacesClient) UpdateResponder(resp *http.Response) (result Workspace, err error) {
   520  	err = autorest.Respond(
   521  		resp,
   522  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   523  		autorest.ByUnmarshallingJSON(&result),
   524  		autorest.ByClosing())
   525  	result.Response = autorest.Response{Response: resp}
   526  	return
   527  }
   528  

View as plain text