...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-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,
    54  				Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent", Name: validation.Null, Rule: false,
    55  					Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties", Name: validation.Null, Rule: false,
    56  						Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule", Name: validation.Null, Rule: false,
    57  							Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties", Name: validation.Null, Rule: true,
    58  								Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsShutdown", Name: validation.Null, Rule: false,
    59  									Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsShutdown.ScheduleProperties", Name: validation.Null, Rule: true, Chain: nil}}},
    60  									{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsStartup", Name: validation.Null, Rule: false,
    61  										Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsStartup.ScheduleProperties", Name: validation.Null, Rule: true, Chain: nil}}},
    62  								}},
    63  							}},
    64  						}},
    65  					}},
    66  				}}}}}); err != nil {
    67  		return result, validation.NewError("dtl.FormulasClient", "CreateOrUpdate", err.Error())
    68  	}
    69  
    70  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, formula)
    71  	if err != nil {
    72  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "CreateOrUpdate", nil, "Failure preparing request")
    73  		return
    74  	}
    75  
    76  	result, err = client.CreateOrUpdateSender(req)
    77  	if err != nil {
    78  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    79  		return
    80  	}
    81  
    82  	return
    83  }
    84  
    85  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    86  func (client FormulasClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, formula Formula) (*http.Request, error) {
    87  	pathParameters := map[string]interface{}{
    88  		"labName":           autorest.Encode("path", labName),
    89  		"name":              autorest.Encode("path", name),
    90  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    91  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    92  	}
    93  
    94  	const APIVersion = "2016-05-15"
    95  	queryParameters := map[string]interface{}{
    96  		"api-version": APIVersion,
    97  	}
    98  
    99  	preparer := autorest.CreatePreparer(
   100  		autorest.AsContentType("application/json; charset=utf-8"),
   101  		autorest.AsPut(),
   102  		autorest.WithBaseURL(client.BaseURI),
   103  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
   104  		autorest.WithJSON(formula),
   105  		autorest.WithQueryParameters(queryParameters))
   106  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   107  }
   108  
   109  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   110  // http.Response Body if it receives an error.
   111  func (client FormulasClient) CreateOrUpdateSender(req *http.Request) (future FormulasCreateOrUpdateFuture, err error) {
   112  	var resp *http.Response
   113  	future.FutureAPI = &azure.Future{}
   114  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   115  	if err != nil {
   116  		return
   117  	}
   118  	var azf azure.Future
   119  	azf, err = azure.NewFutureFromResponse(resp)
   120  	future.FutureAPI = &azf
   121  	future.Result = future.result
   122  	return
   123  }
   124  
   125  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   126  // closes the http.Response Body.
   127  func (client FormulasClient) CreateOrUpdateResponder(resp *http.Response) (result Formula, err error) {
   128  	err = autorest.Respond(
   129  		resp,
   130  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   131  		autorest.ByUnmarshallingJSON(&result),
   132  		autorest.ByClosing())
   133  	result.Response = autorest.Response{Response: resp}
   134  	return
   135  }
   136  
   137  // Delete delete formula.
   138  // Parameters:
   139  // resourceGroupName - the name of the resource group.
   140  // labName - the name of the lab.
   141  // name - the name of the formula.
   142  func (client FormulasClient) Delete(ctx context.Context, resourceGroupName string, labName string, name string) (result autorest.Response, err error) {
   143  	if tracing.IsEnabled() {
   144  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.Delete")
   145  		defer func() {
   146  			sc := -1
   147  			if result.Response != nil {
   148  				sc = result.Response.StatusCode
   149  			}
   150  			tracing.EndSpan(ctx, sc, err)
   151  		}()
   152  	}
   153  	req, err := client.DeletePreparer(ctx, resourceGroupName, labName, name)
   154  	if err != nil {
   155  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Delete", nil, "Failure preparing request")
   156  		return
   157  	}
   158  
   159  	resp, err := client.DeleteSender(req)
   160  	if err != nil {
   161  		result.Response = resp
   162  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Delete", resp, "Failure sending request")
   163  		return
   164  	}
   165  
   166  	result, err = client.DeleteResponder(resp)
   167  	if err != nil {
   168  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Delete", resp, "Failure responding to request")
   169  		return
   170  	}
   171  
   172  	return
   173  }
   174  
   175  // DeletePreparer prepares the Delete request.
   176  func (client FormulasClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   177  	pathParameters := map[string]interface{}{
   178  		"labName":           autorest.Encode("path", labName),
   179  		"name":              autorest.Encode("path", name),
   180  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   181  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   182  	}
   183  
   184  	const APIVersion = "2016-05-15"
   185  	queryParameters := map[string]interface{}{
   186  		"api-version": APIVersion,
   187  	}
   188  
   189  	preparer := autorest.CreatePreparer(
   190  		autorest.AsDelete(),
   191  		autorest.WithBaseURL(client.BaseURI),
   192  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
   193  		autorest.WithQueryParameters(queryParameters))
   194  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   195  }
   196  
   197  // DeleteSender sends the Delete request. The method will close the
   198  // http.Response Body if it receives an error.
   199  func (client FormulasClient) DeleteSender(req *http.Request) (*http.Response, error) {
   200  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   201  }
   202  
   203  // DeleteResponder handles the response to the Delete request. The method always
   204  // closes the http.Response Body.
   205  func (client FormulasClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   206  	err = autorest.Respond(
   207  		resp,
   208  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   209  		autorest.ByClosing())
   210  	result.Response = resp
   211  	return
   212  }
   213  
   214  // Get get formula.
   215  // Parameters:
   216  // resourceGroupName - the name of the resource group.
   217  // labName - the name of the lab.
   218  // name - the name of the formula.
   219  // expand - specify the $expand query. Example: 'properties($select=description)'
   220  func (client FormulasClient) Get(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (result Formula, err error) {
   221  	if tracing.IsEnabled() {
   222  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.Get")
   223  		defer func() {
   224  			sc := -1
   225  			if result.Response.Response != nil {
   226  				sc = result.Response.Response.StatusCode
   227  			}
   228  			tracing.EndSpan(ctx, sc, err)
   229  		}()
   230  	}
   231  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, name, expand)
   232  	if err != nil {
   233  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Get", nil, "Failure preparing request")
   234  		return
   235  	}
   236  
   237  	resp, err := client.GetSender(req)
   238  	if err != nil {
   239  		result.Response = autorest.Response{Response: resp}
   240  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Get", resp, "Failure sending request")
   241  		return
   242  	}
   243  
   244  	result, err = client.GetResponder(resp)
   245  	if err != nil {
   246  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Get", resp, "Failure responding to request")
   247  		return
   248  	}
   249  
   250  	return
   251  }
   252  
   253  // GetPreparer prepares the Get request.
   254  func (client FormulasClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (*http.Request, error) {
   255  	pathParameters := map[string]interface{}{
   256  		"labName":           autorest.Encode("path", labName),
   257  		"name":              autorest.Encode("path", name),
   258  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   259  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   260  	}
   261  
   262  	const APIVersion = "2016-05-15"
   263  	queryParameters := map[string]interface{}{
   264  		"api-version": APIVersion,
   265  	}
   266  	if len(expand) > 0 {
   267  		queryParameters["$expand"] = autorest.Encode("query", expand)
   268  	}
   269  
   270  	preparer := autorest.CreatePreparer(
   271  		autorest.AsGet(),
   272  		autorest.WithBaseURL(client.BaseURI),
   273  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
   274  		autorest.WithQueryParameters(queryParameters))
   275  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   276  }
   277  
   278  // GetSender sends the Get request. The method will close the
   279  // http.Response Body if it receives an error.
   280  func (client FormulasClient) GetSender(req *http.Request) (*http.Response, error) {
   281  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   282  }
   283  
   284  // GetResponder handles the response to the Get request. The method always
   285  // closes the http.Response Body.
   286  func (client FormulasClient) GetResponder(resp *http.Response) (result Formula, err error) {
   287  	err = autorest.Respond(
   288  		resp,
   289  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   290  		autorest.ByUnmarshallingJSON(&result),
   291  		autorest.ByClosing())
   292  	result.Response = autorest.Response{Response: resp}
   293  	return
   294  }
   295  
   296  // List list formulas in a given lab.
   297  // Parameters:
   298  // resourceGroupName - the name of the resource group.
   299  // labName - the name of the lab.
   300  // expand - specify the $expand query. Example: 'properties($select=description)'
   301  // filter - the filter to apply to the operation.
   302  // top - the maximum number of resources to return from the operation.
   303  // orderby - the ordering expression for the results, using OData notation.
   304  func (client FormulasClient) List(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationFormulaPage, err error) {
   305  	if tracing.IsEnabled() {
   306  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.List")
   307  		defer func() {
   308  			sc := -1
   309  			if result.rwcf.Response.Response != nil {
   310  				sc = result.rwcf.Response.Response.StatusCode
   311  			}
   312  			tracing.EndSpan(ctx, sc, err)
   313  		}()
   314  	}
   315  	result.fn = client.listNextResults
   316  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   317  	if err != nil {
   318  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "List", nil, "Failure preparing request")
   319  		return
   320  	}
   321  
   322  	resp, err := client.ListSender(req)
   323  	if err != nil {
   324  		result.rwcf.Response = autorest.Response{Response: resp}
   325  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "List", resp, "Failure sending request")
   326  		return
   327  	}
   328  
   329  	result.rwcf, err = client.ListResponder(resp)
   330  	if err != nil {
   331  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "List", resp, "Failure responding to request")
   332  		return
   333  	}
   334  	if result.rwcf.hasNextLink() && result.rwcf.IsEmpty() {
   335  		err = result.NextWithContext(ctx)
   336  		return
   337  	}
   338  
   339  	return
   340  }
   341  
   342  // ListPreparer prepares the List request.
   343  func (client FormulasClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   344  	pathParameters := map[string]interface{}{
   345  		"labName":           autorest.Encode("path", labName),
   346  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   347  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   348  	}
   349  
   350  	const APIVersion = "2016-05-15"
   351  	queryParameters := map[string]interface{}{
   352  		"api-version": APIVersion,
   353  	}
   354  	if len(expand) > 0 {
   355  		queryParameters["$expand"] = autorest.Encode("query", expand)
   356  	}
   357  	if len(filter) > 0 {
   358  		queryParameters["$filter"] = autorest.Encode("query", filter)
   359  	}
   360  	if top != nil {
   361  		queryParameters["$top"] = autorest.Encode("query", *top)
   362  	}
   363  	if len(orderby) > 0 {
   364  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   365  	}
   366  
   367  	preparer := autorest.CreatePreparer(
   368  		autorest.AsGet(),
   369  		autorest.WithBaseURL(client.BaseURI),
   370  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas", pathParameters),
   371  		autorest.WithQueryParameters(queryParameters))
   372  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   373  }
   374  
   375  // ListSender sends the List request. The method will close the
   376  // http.Response Body if it receives an error.
   377  func (client FormulasClient) ListSender(req *http.Request) (*http.Response, error) {
   378  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   379  }
   380  
   381  // ListResponder handles the response to the List request. The method always
   382  // closes the http.Response Body.
   383  func (client FormulasClient) ListResponder(resp *http.Response) (result ResponseWithContinuationFormula, err error) {
   384  	err = autorest.Respond(
   385  		resp,
   386  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   387  		autorest.ByUnmarshallingJSON(&result),
   388  		autorest.ByClosing())
   389  	result.Response = autorest.Response{Response: resp}
   390  	return
   391  }
   392  
   393  // listNextResults retrieves the next set of results, if any.
   394  func (client FormulasClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationFormula) (result ResponseWithContinuationFormula, err error) {
   395  	req, err := lastResults.responseWithContinuationFormulaPreparer(ctx)
   396  	if err != nil {
   397  		return result, autorest.NewErrorWithError(err, "dtl.FormulasClient", "listNextResults", nil, "Failure preparing next results request")
   398  	}
   399  	if req == nil {
   400  		return
   401  	}
   402  	resp, err := client.ListSender(req)
   403  	if err != nil {
   404  		result.Response = autorest.Response{Response: resp}
   405  		return result, autorest.NewErrorWithError(err, "dtl.FormulasClient", "listNextResults", resp, "Failure sending next results request")
   406  	}
   407  	result, err = client.ListResponder(resp)
   408  	if err != nil {
   409  		err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "listNextResults", resp, "Failure responding to next results request")
   410  	}
   411  	return
   412  }
   413  
   414  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   415  func (client FormulasClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationFormulaIterator, err error) {
   416  	if tracing.IsEnabled() {
   417  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.List")
   418  		defer func() {
   419  			sc := -1
   420  			if result.Response().Response.Response != nil {
   421  				sc = result.page.Response().Response.Response.StatusCode
   422  			}
   423  			tracing.EndSpan(ctx, sc, err)
   424  		}()
   425  	}
   426  	result.page, err = client.List(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   427  	return
   428  }
   429  

View as plain text