...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/devtestlabs/mgmt/2015-05-21-preview/dtl/formula.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/devtestlabs/mgmt/2015-05-21-preview/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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // FormulaClient is the azure DevTest Labs REST API version 2015-05-21-preview.
    18  type FormulaClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewFormulaClient creates an instance of the FormulaClient client.
    23  func NewFormulaClient(subscriptionID string) FormulaClient {
    24  	return NewFormulaClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewFormulaClientWithBaseURI creates an instance of the FormulaClient client using a custom endpoint.  Use this when
    28  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewFormulaClientWithBaseURI(baseURI string, subscriptionID string) FormulaClient {
    30  	return FormulaClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdateResource create or replace an existing Formula. This operation can take a while to complete.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group.
    36  // labName - the name of the lab.
    37  // name - the name of the formula.
    38  func (client FormulaClient) CreateOrUpdateResource(ctx context.Context, resourceGroupName string, labName string, name string, formula Formula) (result FormulaCreateOrUpdateResourceFuture, err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulaClient.CreateOrUpdateResource")
    41  		defer func() {
    42  			sc := -1
    43  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    44  				sc = result.FutureAPI.Response().StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	req, err := client.CreateOrUpdateResourcePreparer(ctx, resourceGroupName, labName, name, formula)
    50  	if err != nil {
    51  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "CreateOrUpdateResource", nil, "Failure preparing request")
    52  		return
    53  	}
    54  
    55  	result, err = client.CreateOrUpdateResourceSender(req)
    56  	if err != nil {
    57  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "CreateOrUpdateResource", result.Response(), "Failure sending request")
    58  		return
    59  	}
    60  
    61  	return
    62  }
    63  
    64  // CreateOrUpdateResourcePreparer prepares the CreateOrUpdateResource request.
    65  func (client FormulaClient) CreateOrUpdateResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string, formula Formula) (*http.Request, error) {
    66  	pathParameters := map[string]interface{}{
    67  		"labName":           autorest.Encode("path", labName),
    68  		"name":              autorest.Encode("path", name),
    69  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    70  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    71  	}
    72  
    73  	const APIVersion = "2015-05-21-preview"
    74  	queryParameters := map[string]interface{}{
    75  		"api-version": APIVersion,
    76  	}
    77  
    78  	preparer := autorest.CreatePreparer(
    79  		autorest.AsContentType("application/json; charset=utf-8"),
    80  		autorest.AsPut(),
    81  		autorest.WithBaseURL(client.BaseURI),
    82  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
    83  		autorest.WithJSON(formula),
    84  		autorest.WithQueryParameters(queryParameters))
    85  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    86  }
    87  
    88  // CreateOrUpdateResourceSender sends the CreateOrUpdateResource request. The method will close the
    89  // http.Response Body if it receives an error.
    90  func (client FormulaClient) CreateOrUpdateResourceSender(req *http.Request) (future FormulaCreateOrUpdateResourceFuture, err error) {
    91  	var resp *http.Response
    92  	future.FutureAPI = &azure.Future{}
    93  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
    94  	if err != nil {
    95  		return
    96  	}
    97  	var azf azure.Future
    98  	azf, err = azure.NewFutureFromResponse(resp)
    99  	future.FutureAPI = &azf
   100  	future.Result = future.result
   101  	return
   102  }
   103  
   104  // CreateOrUpdateResourceResponder handles the response to the CreateOrUpdateResource request. The method always
   105  // closes the http.Response Body.
   106  func (client FormulaClient) CreateOrUpdateResourceResponder(resp *http.Response) (result Formula, err error) {
   107  	err = autorest.Respond(
   108  		resp,
   109  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   110  		autorest.ByUnmarshallingJSON(&result),
   111  		autorest.ByClosing())
   112  	result.Response = autorest.Response{Response: resp}
   113  	return
   114  }
   115  
   116  // DeleteResource delete formula.
   117  // Parameters:
   118  // resourceGroupName - the name of the resource group.
   119  // labName - the name of the lab.
   120  // name - the name of the formula.
   121  func (client FormulaClient) DeleteResource(ctx context.Context, resourceGroupName string, labName string, name string) (result autorest.Response, err error) {
   122  	if tracing.IsEnabled() {
   123  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulaClient.DeleteResource")
   124  		defer func() {
   125  			sc := -1
   126  			if result.Response != nil {
   127  				sc = result.Response.StatusCode
   128  			}
   129  			tracing.EndSpan(ctx, sc, err)
   130  		}()
   131  	}
   132  	req, err := client.DeleteResourcePreparer(ctx, resourceGroupName, labName, name)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "DeleteResource", nil, "Failure preparing request")
   135  		return
   136  	}
   137  
   138  	resp, err := client.DeleteResourceSender(req)
   139  	if err != nil {
   140  		result.Response = resp
   141  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "DeleteResource", resp, "Failure sending request")
   142  		return
   143  	}
   144  
   145  	result, err = client.DeleteResourceResponder(resp)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "DeleteResource", resp, "Failure responding to request")
   148  		return
   149  	}
   150  
   151  	return
   152  }
   153  
   154  // DeleteResourcePreparer prepares the DeleteResource request.
   155  func (client FormulaClient) DeleteResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   156  	pathParameters := map[string]interface{}{
   157  		"labName":           autorest.Encode("path", labName),
   158  		"name":              autorest.Encode("path", name),
   159  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   160  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   161  	}
   162  
   163  	const APIVersion = "2015-05-21-preview"
   164  	queryParameters := map[string]interface{}{
   165  		"api-version": APIVersion,
   166  	}
   167  
   168  	preparer := autorest.CreatePreparer(
   169  		autorest.AsDelete(),
   170  		autorest.WithBaseURL(client.BaseURI),
   171  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
   172  		autorest.WithQueryParameters(queryParameters))
   173  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   174  }
   175  
   176  // DeleteResourceSender sends the DeleteResource request. The method will close the
   177  // http.Response Body if it receives an error.
   178  func (client FormulaClient) DeleteResourceSender(req *http.Request) (*http.Response, error) {
   179  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   180  }
   181  
   182  // DeleteResourceResponder handles the response to the DeleteResource request. The method always
   183  // closes the http.Response Body.
   184  func (client FormulaClient) DeleteResourceResponder(resp *http.Response) (result autorest.Response, err error) {
   185  	err = autorest.Respond(
   186  		resp,
   187  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   188  		autorest.ByClosing())
   189  	result.Response = resp
   190  	return
   191  }
   192  
   193  // GetResource get formula.
   194  // Parameters:
   195  // resourceGroupName - the name of the resource group.
   196  // labName - the name of the lab.
   197  // name - the name of the formula.
   198  func (client FormulaClient) GetResource(ctx context.Context, resourceGroupName string, labName string, name string) (result Formula, err error) {
   199  	if tracing.IsEnabled() {
   200  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulaClient.GetResource")
   201  		defer func() {
   202  			sc := -1
   203  			if result.Response.Response != nil {
   204  				sc = result.Response.Response.StatusCode
   205  			}
   206  			tracing.EndSpan(ctx, sc, err)
   207  		}()
   208  	}
   209  	req, err := client.GetResourcePreparer(ctx, resourceGroupName, labName, name)
   210  	if err != nil {
   211  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "GetResource", nil, "Failure preparing request")
   212  		return
   213  	}
   214  
   215  	resp, err := client.GetResourceSender(req)
   216  	if err != nil {
   217  		result.Response = autorest.Response{Response: resp}
   218  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "GetResource", resp, "Failure sending request")
   219  		return
   220  	}
   221  
   222  	result, err = client.GetResourceResponder(resp)
   223  	if err != nil {
   224  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "GetResource", resp, "Failure responding to request")
   225  		return
   226  	}
   227  
   228  	return
   229  }
   230  
   231  // GetResourcePreparer prepares the GetResource request.
   232  func (client FormulaClient) GetResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   233  	pathParameters := map[string]interface{}{
   234  		"labName":           autorest.Encode("path", labName),
   235  		"name":              autorest.Encode("path", name),
   236  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   237  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   238  	}
   239  
   240  	const APIVersion = "2015-05-21-preview"
   241  	queryParameters := map[string]interface{}{
   242  		"api-version": APIVersion,
   243  	}
   244  
   245  	preparer := autorest.CreatePreparer(
   246  		autorest.AsGet(),
   247  		autorest.WithBaseURL(client.BaseURI),
   248  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
   249  		autorest.WithQueryParameters(queryParameters))
   250  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   251  }
   252  
   253  // GetResourceSender sends the GetResource request. The method will close the
   254  // http.Response Body if it receives an error.
   255  func (client FormulaClient) GetResourceSender(req *http.Request) (*http.Response, error) {
   256  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   257  }
   258  
   259  // GetResourceResponder handles the response to the GetResource request. The method always
   260  // closes the http.Response Body.
   261  func (client FormulaClient) GetResourceResponder(resp *http.Response) (result Formula, err error) {
   262  	err = autorest.Respond(
   263  		resp,
   264  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   265  		autorest.ByUnmarshallingJSON(&result),
   266  		autorest.ByClosing())
   267  	result.Response = autorest.Response{Response: resp}
   268  	return
   269  }
   270  
   271  // List list formulas.
   272  // Parameters:
   273  // resourceGroupName - the name of the resource group.
   274  // labName - the name of the lab.
   275  // filter - the filter to apply on the operation.
   276  func (client FormulaClient) List(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationFormulaPage, err error) {
   277  	if tracing.IsEnabled() {
   278  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulaClient.List")
   279  		defer func() {
   280  			sc := -1
   281  			if result.rwcf.Response.Response != nil {
   282  				sc = result.rwcf.Response.Response.StatusCode
   283  			}
   284  			tracing.EndSpan(ctx, sc, err)
   285  		}()
   286  	}
   287  	result.fn = client.listNextResults
   288  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, filter, top, orderBy)
   289  	if err != nil {
   290  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "List", nil, "Failure preparing request")
   291  		return
   292  	}
   293  
   294  	resp, err := client.ListSender(req)
   295  	if err != nil {
   296  		result.rwcf.Response = autorest.Response{Response: resp}
   297  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "List", resp, "Failure sending request")
   298  		return
   299  	}
   300  
   301  	result.rwcf, err = client.ListResponder(resp)
   302  	if err != nil {
   303  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "List", resp, "Failure responding to request")
   304  		return
   305  	}
   306  	if result.rwcf.hasNextLink() && result.rwcf.IsEmpty() {
   307  		err = result.NextWithContext(ctx)
   308  		return
   309  	}
   310  
   311  	return
   312  }
   313  
   314  // ListPreparer prepares the List request.
   315  func (client FormulaClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (*http.Request, error) {
   316  	pathParameters := map[string]interface{}{
   317  		"labName":           autorest.Encode("path", labName),
   318  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   319  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   320  	}
   321  
   322  	const APIVersion = "2015-05-21-preview"
   323  	queryParameters := map[string]interface{}{
   324  		"api-version": APIVersion,
   325  	}
   326  	if len(filter) > 0 {
   327  		queryParameters["$filter"] = autorest.Encode("query", filter)
   328  	}
   329  	if top != nil {
   330  		queryParameters["$top"] = autorest.Encode("query", *top)
   331  	}
   332  	if len(orderBy) > 0 {
   333  		queryParameters["$orderBy"] = autorest.Encode("query", orderBy)
   334  	}
   335  
   336  	preparer := autorest.CreatePreparer(
   337  		autorest.AsGet(),
   338  		autorest.WithBaseURL(client.BaseURI),
   339  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas", pathParameters),
   340  		autorest.WithQueryParameters(queryParameters))
   341  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   342  }
   343  
   344  // ListSender sends the List request. The method will close the
   345  // http.Response Body if it receives an error.
   346  func (client FormulaClient) ListSender(req *http.Request) (*http.Response, error) {
   347  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   348  }
   349  
   350  // ListResponder handles the response to the List request. The method always
   351  // closes the http.Response Body.
   352  func (client FormulaClient) ListResponder(resp *http.Response) (result ResponseWithContinuationFormula, err error) {
   353  	err = autorest.Respond(
   354  		resp,
   355  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   356  		autorest.ByUnmarshallingJSON(&result),
   357  		autorest.ByClosing())
   358  	result.Response = autorest.Response{Response: resp}
   359  	return
   360  }
   361  
   362  // listNextResults retrieves the next set of results, if any.
   363  func (client FormulaClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationFormula) (result ResponseWithContinuationFormula, err error) {
   364  	req, err := lastResults.responseWithContinuationFormulaPreparer(ctx)
   365  	if err != nil {
   366  		return result, autorest.NewErrorWithError(err, "dtl.FormulaClient", "listNextResults", nil, "Failure preparing next results request")
   367  	}
   368  	if req == nil {
   369  		return
   370  	}
   371  	resp, err := client.ListSender(req)
   372  	if err != nil {
   373  		result.Response = autorest.Response{Response: resp}
   374  		return result, autorest.NewErrorWithError(err, "dtl.FormulaClient", "listNextResults", resp, "Failure sending next results request")
   375  	}
   376  	result, err = client.ListResponder(resp)
   377  	if err != nil {
   378  		err = autorest.NewErrorWithError(err, "dtl.FormulaClient", "listNextResults", resp, "Failure responding to next results request")
   379  	}
   380  	return
   381  }
   382  
   383  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   384  func (client FormulaClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationFormulaIterator, err error) {
   385  	if tracing.IsEnabled() {
   386  		ctx = tracing.StartSpan(ctx, fqdn+"/FormulaClient.List")
   387  		defer func() {
   388  			sc := -1
   389  			if result.Response().Response.Response != nil {
   390  				sc = result.page.Response().Response.Response.StatusCode
   391  			}
   392  			tracing.EndSpan(ctx, sc, err)
   393  		}()
   394  	}
   395  	result.page, err = client.List(ctx, resourceGroupName, labName, filter, top, orderBy)
   396  	return
   397  }
   398  

View as plain text