...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2018-09-15/dtl/formulas.go

Documentation: github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2018-09-15/dtl

     1  package dtl
     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  // FormulasClient is the the DevTest Labs Client.
    19  type FormulasClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewFormulasClient creates an instance of the FormulasClient client.
    24  func NewFormulasClient(subscriptionID string) FormulasClient {
    25  	return NewFormulasClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewFormulasClientWithBaseURI creates an instance of the FormulasClient client using a custom endpoint.  Use this
    29  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewFormulasClientWithBaseURI(baseURI string, subscriptionID string) FormulasClient {
    31  	return FormulasClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate create or replace an existing formula. This operation can take a while to complete.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // labName - the name of the lab.
    38  // name - the name of the formula.
    39  // formula - a formula for creating a VM, specifying an image base and other parameters
    40  func (client FormulasClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, name string, formula Formula) (result FormulasCreateOrUpdateFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.CreateOrUpdate")
    43  		defer func() {
    44  			sc := -1
    45  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    46  				sc = result.FutureAPI.Response().StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	if err := validation.Validate([]validation.Validation{
    52  		{TargetValue: formula,
    53  			Constraints: []validation.Constraint{{Target: "formula.FormulaProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    54  		return result, validation.NewError("dtl.FormulasClient", "CreateOrUpdate", err.Error())
    55  	}
    56  
    57  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, formula)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "CreateOrUpdate", nil, "Failure preparing request")
    60  		return
    61  	}
    62  
    63  	result, err = client.CreateOrUpdateSender(req)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    66  		return
    67  	}
    68  
    69  	return
    70  }
    71  
    72  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    73  func (client FormulasClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, formula Formula) (*http.Request, error) {
    74  	pathParameters := map[string]interface{}{
    75  		"labName":           autorest.Encode("path", labName),
    76  		"name":              autorest.Encode("path", name),
    77  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    78  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    79  	}
    80  
    81  	const APIVersion = "2018-09-15"
    82  	queryParameters := map[string]interface{}{
    83  		"api-version": APIVersion,
    84  	}
    85  
    86  	preparer := autorest.CreatePreparer(
    87  		autorest.AsContentType("application/json; charset=utf-8"),
    88  		autorest.AsPut(),
    89  		autorest.WithBaseURL(client.BaseURI),
    90  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
    91  		autorest.WithJSON(formula),
    92  		autorest.WithQueryParameters(queryParameters))
    93  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    94  }
    95  
    96  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    97  // http.Response Body if it receives an error.
    98  func (client FormulasClient) CreateOrUpdateSender(req *http.Request) (future FormulasCreateOrUpdateFuture, err error) {
    99  	var resp *http.Response
   100  	future.FutureAPI = &azure.Future{}
   101  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   102  	if err != nil {
   103  		return
   104  	}
   105  	var azf azure.Future
   106  	azf, err = azure.NewFutureFromResponse(resp)
   107  	future.FutureAPI = &azf
   108  	future.Result = future.result
   109  	return
   110  }
   111  
   112  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   113  // closes the http.Response Body.
   114  func (client FormulasClient) CreateOrUpdateResponder(resp *http.Response) (result Formula, err error) {
   115  	err = autorest.Respond(
   116  		resp,
   117  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   118  		autorest.ByUnmarshallingJSON(&result),
   119  		autorest.ByClosing())
   120  	result.Response = autorest.Response{Response: resp}
   121  	return
   122  }
   123  
   124  // Delete delete formula.
   125  // Parameters:
   126  // resourceGroupName - the name of the resource group.
   127  // labName - the name of the lab.
   128  // name - the name of the formula.
   129  func (client FormulasClient) Delete(ctx context.Context, resourceGroupName string, labName string, name string) (result autorest.Response, err error) {
   130  	if tracing.IsEnabled() {
   131  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.Delete")
   132  		defer func() {
   133  			sc := -1
   134  			if result.Response != nil {
   135  				sc = result.Response.StatusCode
   136  			}
   137  			tracing.EndSpan(ctx, sc, err)
   138  		}()
   139  	}
   140  	req, err := client.DeletePreparer(ctx, resourceGroupName, labName, name)
   141  	if err != nil {
   142  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Delete", nil, "Failure preparing request")
   143  		return
   144  	}
   145  
   146  	resp, err := client.DeleteSender(req)
   147  	if err != nil {
   148  		result.Response = resp
   149  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Delete", resp, "Failure sending request")
   150  		return
   151  	}
   152  
   153  	result, err = client.DeleteResponder(resp)
   154  	if err != nil {
   155  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Delete", resp, "Failure responding to request")
   156  		return
   157  	}
   158  
   159  	return
   160  }
   161  
   162  // DeletePreparer prepares the Delete request.
   163  func (client FormulasClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   164  	pathParameters := map[string]interface{}{
   165  		"labName":           autorest.Encode("path", labName),
   166  		"name":              autorest.Encode("path", name),
   167  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   168  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   169  	}
   170  
   171  	const APIVersion = "2018-09-15"
   172  	queryParameters := map[string]interface{}{
   173  		"api-version": APIVersion,
   174  	}
   175  
   176  	preparer := autorest.CreatePreparer(
   177  		autorest.AsDelete(),
   178  		autorest.WithBaseURL(client.BaseURI),
   179  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
   180  		autorest.WithQueryParameters(queryParameters))
   181  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   182  }
   183  
   184  // DeleteSender sends the Delete request. The method will close the
   185  // http.Response Body if it receives an error.
   186  func (client FormulasClient) DeleteSender(req *http.Request) (*http.Response, error) {
   187  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   188  }
   189  
   190  // DeleteResponder handles the response to the Delete request. The method always
   191  // closes the http.Response Body.
   192  func (client FormulasClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   193  	err = autorest.Respond(
   194  		resp,
   195  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   196  		autorest.ByClosing())
   197  	result.Response = resp
   198  	return
   199  }
   200  
   201  // Get get formula.
   202  // Parameters:
   203  // resourceGroupName - the name of the resource group.
   204  // labName - the name of the lab.
   205  // name - the name of the formula.
   206  // expand - specify the $expand query. Example: 'properties($select=description)'
   207  func (client FormulasClient) Get(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (result Formula, err error) {
   208  	if tracing.IsEnabled() {
   209  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.Get")
   210  		defer func() {
   211  			sc := -1
   212  			if result.Response.Response != nil {
   213  				sc = result.Response.Response.StatusCode
   214  			}
   215  			tracing.EndSpan(ctx, sc, err)
   216  		}()
   217  	}
   218  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, name, expand)
   219  	if err != nil {
   220  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Get", nil, "Failure preparing request")
   221  		return
   222  	}
   223  
   224  	resp, err := client.GetSender(req)
   225  	if err != nil {
   226  		result.Response = autorest.Response{Response: resp}
   227  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Get", resp, "Failure sending request")
   228  		return
   229  	}
   230  
   231  	result, err = client.GetResponder(resp)
   232  	if err != nil {
   233  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Get", resp, "Failure responding to request")
   234  		return
   235  	}
   236  
   237  	return
   238  }
   239  
   240  // GetPreparer prepares the Get request.
   241  func (client FormulasClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (*http.Request, error) {
   242  	pathParameters := map[string]interface{}{
   243  		"labName":           autorest.Encode("path", labName),
   244  		"name":              autorest.Encode("path", name),
   245  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   246  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   247  	}
   248  
   249  	const APIVersion = "2018-09-15"
   250  	queryParameters := map[string]interface{}{
   251  		"api-version": APIVersion,
   252  	}
   253  	if len(expand) > 0 {
   254  		queryParameters["$expand"] = autorest.Encode("query", expand)
   255  	}
   256  
   257  	preparer := autorest.CreatePreparer(
   258  		autorest.AsGet(),
   259  		autorest.WithBaseURL(client.BaseURI),
   260  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
   261  		autorest.WithQueryParameters(queryParameters))
   262  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   263  }
   264  
   265  // GetSender sends the Get request. The method will close the
   266  // http.Response Body if it receives an error.
   267  func (client FormulasClient) GetSender(req *http.Request) (*http.Response, error) {
   268  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   269  }
   270  
   271  // GetResponder handles the response to the Get request. The method always
   272  // closes the http.Response Body.
   273  func (client FormulasClient) GetResponder(resp *http.Response) (result Formula, err error) {
   274  	err = autorest.Respond(
   275  		resp,
   276  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   277  		autorest.ByUnmarshallingJSON(&result),
   278  		autorest.ByClosing())
   279  	result.Response = autorest.Response{Response: resp}
   280  	return
   281  }
   282  
   283  // List list formulas in a given lab.
   284  // Parameters:
   285  // resourceGroupName - the name of the resource group.
   286  // labName - the name of the lab.
   287  // expand - specify the $expand query. Example: 'properties($select=description)'
   288  // filter - the filter to apply to the operation. Example: '$filter=contains(name,'myName')
   289  // top - the maximum number of resources to return from the operation. Example: '$top=10'
   290  // orderby - the ordering expression for the results, using OData notation. Example: '$orderby=name desc'
   291  func (client FormulasClient) List(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result FormulaListPage, err error) {
   292  	if tracing.IsEnabled() {
   293  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.List")
   294  		defer func() {
   295  			sc := -1
   296  			if result.fl.Response.Response != nil {
   297  				sc = result.fl.Response.Response.StatusCode
   298  			}
   299  			tracing.EndSpan(ctx, sc, err)
   300  		}()
   301  	}
   302  	result.fn = client.listNextResults
   303  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   304  	if err != nil {
   305  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "List", nil, "Failure preparing request")
   306  		return
   307  	}
   308  
   309  	resp, err := client.ListSender(req)
   310  	if err != nil {
   311  		result.fl.Response = autorest.Response{Response: resp}
   312  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "List", resp, "Failure sending request")
   313  		return
   314  	}
   315  
   316  	result.fl, err = client.ListResponder(resp)
   317  	if err != nil {
   318  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "List", resp, "Failure responding to request")
   319  		return
   320  	}
   321  	if result.fl.hasNextLink() && result.fl.IsEmpty() {
   322  		err = result.NextWithContext(ctx)
   323  		return
   324  	}
   325  
   326  	return
   327  }
   328  
   329  // ListPreparer prepares the List request.
   330  func (client FormulasClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   331  	pathParameters := map[string]interface{}{
   332  		"labName":           autorest.Encode("path", labName),
   333  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   334  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   335  	}
   336  
   337  	const APIVersion = "2018-09-15"
   338  	queryParameters := map[string]interface{}{
   339  		"api-version": APIVersion,
   340  	}
   341  	if len(expand) > 0 {
   342  		queryParameters["$expand"] = autorest.Encode("query", expand)
   343  	}
   344  	if len(filter) > 0 {
   345  		queryParameters["$filter"] = autorest.Encode("query", filter)
   346  	}
   347  	if top != nil {
   348  		queryParameters["$top"] = autorest.Encode("query", *top)
   349  	}
   350  	if len(orderby) > 0 {
   351  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   352  	}
   353  
   354  	preparer := autorest.CreatePreparer(
   355  		autorest.AsGet(),
   356  		autorest.WithBaseURL(client.BaseURI),
   357  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas", pathParameters),
   358  		autorest.WithQueryParameters(queryParameters))
   359  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   360  }
   361  
   362  // ListSender sends the List request. The method will close the
   363  // http.Response Body if it receives an error.
   364  func (client FormulasClient) ListSender(req *http.Request) (*http.Response, error) {
   365  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   366  }
   367  
   368  // ListResponder handles the response to the List request. The method always
   369  // closes the http.Response Body.
   370  func (client FormulasClient) ListResponder(resp *http.Response) (result FormulaList, err error) {
   371  	err = autorest.Respond(
   372  		resp,
   373  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   374  		autorest.ByUnmarshallingJSON(&result),
   375  		autorest.ByClosing())
   376  	result.Response = autorest.Response{Response: resp}
   377  	return
   378  }
   379  
   380  // listNextResults retrieves the next set of results, if any.
   381  func (client FormulasClient) listNextResults(ctx context.Context, lastResults FormulaList) (result FormulaList, err error) {
   382  	req, err := lastResults.formulaListPreparer(ctx)
   383  	if err != nil {
   384  		return result, autorest.NewErrorWithError(err, "dtl.FormulasClient", "listNextResults", nil, "Failure preparing next results request")
   385  	}
   386  	if req == nil {
   387  		return
   388  	}
   389  	resp, err := client.ListSender(req)
   390  	if err != nil {
   391  		result.Response = autorest.Response{Response: resp}
   392  		return result, autorest.NewErrorWithError(err, "dtl.FormulasClient", "listNextResults", resp, "Failure sending next results request")
   393  	}
   394  	result, err = client.ListResponder(resp)
   395  	if err != nil {
   396  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "listNextResults", resp, "Failure responding to next results request")
   397  	}
   398  	return
   399  }
   400  
   401  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   402  func (client FormulasClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result FormulaListIterator, err error) {
   403  	if tracing.IsEnabled() {
   404  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.List")
   405  		defer func() {
   406  			sc := -1
   407  			if result.Response().Response.Response != nil {
   408  				sc = result.page.Response().Response.Response.StatusCode
   409  			}
   410  			tracing.EndSpan(ctx, sc, err)
   411  		}()
   412  	}
   413  	result.page, err = client.List(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   414  	return
   415  }
   416  
   417  // Update allows modifying tags of formulas. All other properties will be ignored.
   418  // Parameters:
   419  // resourceGroupName - the name of the resource group.
   420  // labName - the name of the lab.
   421  // name - the name of the formula.
   422  // formula - a formula for creating a VM, specifying an image base and other parameters
   423  func (client FormulasClient) Update(ctx context.Context, resourceGroupName string, labName string, name string, formula FormulaFragment) (result Formula, err error) {
   424  	if tracing.IsEnabled() {
   425  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.Update")
   426  		defer func() {
   427  			sc := -1
   428  			if result.Response.Response != nil {
   429  				sc = result.Response.Response.StatusCode
   430  			}
   431  			tracing.EndSpan(ctx, sc, err)
   432  		}()
   433  	}
   434  	req, err := client.UpdatePreparer(ctx, resourceGroupName, labName, name, formula)
   435  	if err != nil {
   436  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Update", nil, "Failure preparing request")
   437  		return
   438  	}
   439  
   440  	resp, err := client.UpdateSender(req)
   441  	if err != nil {
   442  		result.Response = autorest.Response{Response: resp}
   443  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Update", resp, "Failure sending request")
   444  		return
   445  	}
   446  
   447  	result, err = client.UpdateResponder(resp)
   448  	if err != nil {
   449  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Update", resp, "Failure responding to request")
   450  		return
   451  	}
   452  
   453  	return
   454  }
   455  
   456  // UpdatePreparer prepares the Update request.
   457  func (client FormulasClient) UpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, formula FormulaFragment) (*http.Request, error) {
   458  	pathParameters := map[string]interface{}{
   459  		"labName":           autorest.Encode("path", labName),
   460  		"name":              autorest.Encode("path", name),
   461  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   462  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   463  	}
   464  
   465  	const APIVersion = "2018-09-15"
   466  	queryParameters := map[string]interface{}{
   467  		"api-version": APIVersion,
   468  	}
   469  
   470  	preparer := autorest.CreatePreparer(
   471  		autorest.AsContentType("application/json; charset=utf-8"),
   472  		autorest.AsPatch(),
   473  		autorest.WithBaseURL(client.BaseURI),
   474  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
   475  		autorest.WithJSON(formula),
   476  		autorest.WithQueryParameters(queryParameters))
   477  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   478  }
   479  
   480  // UpdateSender sends the Update request. The method will close the
   481  // http.Response Body if it receives an error.
   482  func (client FormulasClient) UpdateSender(req *http.Request) (*http.Response, error) {
   483  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   484  }
   485  
   486  // UpdateResponder handles the response to the Update request. The method always
   487  // closes the http.Response Body.
   488  func (client FormulasClient) UpdateResponder(resp *http.Response) (result Formula, err error) {
   489  	err = autorest.Respond(
   490  		resp,
   491  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   492  		autorest.ByUnmarshallingJSON(&result),
   493  		autorest.ByClosing())
   494  	result.Response = autorest.Response{Response: resp}
   495  	return
   496  }
   497  

View as plain text