...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/devtestlabs/mgmt/2015-05-21-preview/dtl/cost.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  // CostClient is the azure DevTest Labs REST API version 2015-05-21-preview.
    18  type CostClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewCostClient creates an instance of the CostClient client.
    23  func NewCostClient(subscriptionID string) CostClient {
    24  	return NewCostClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewCostClientWithBaseURI creates an instance of the CostClient 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 NewCostClientWithBaseURI(baseURI string, subscriptionID string) CostClient {
    30  	return CostClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // GetResource get cost.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group.
    36  // labName - the name of the lab.
    37  // name - the name of the cost.
    38  func (client CostClient) GetResource(ctx context.Context, resourceGroupName string, labName string, name string) (result Cost, err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/CostClient.GetResource")
    41  		defer func() {
    42  			sc := -1
    43  			if result.Response.Response != nil {
    44  				sc = result.Response.Response.StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	req, err := client.GetResourcePreparer(ctx, resourceGroupName, labName, name)
    50  	if err != nil {
    51  		err = autorest.NewErrorWithError(err, "dtl.CostClient", "GetResource", nil, "Failure preparing request")
    52  		return
    53  	}
    54  
    55  	resp, err := client.GetResourceSender(req)
    56  	if err != nil {
    57  		result.Response = autorest.Response{Response: resp}
    58  		err = autorest.NewErrorWithError(err, "dtl.CostClient", "GetResource", resp, "Failure sending request")
    59  		return
    60  	}
    61  
    62  	result, err = client.GetResourceResponder(resp)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "dtl.CostClient", "GetResource", resp, "Failure responding to request")
    65  		return
    66  	}
    67  
    68  	return
    69  }
    70  
    71  // GetResourcePreparer prepares the GetResource request.
    72  func (client CostClient) GetResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
    73  	pathParameters := map[string]interface{}{
    74  		"labName":           autorest.Encode("path", labName),
    75  		"name":              autorest.Encode("path", name),
    76  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    77  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    78  	}
    79  
    80  	const APIVersion = "2015-05-21-preview"
    81  	queryParameters := map[string]interface{}{
    82  		"api-version": APIVersion,
    83  	}
    84  
    85  	preparer := autorest.CreatePreparer(
    86  		autorest.AsGet(),
    87  		autorest.WithBaseURL(client.BaseURI),
    88  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}", pathParameters),
    89  		autorest.WithQueryParameters(queryParameters))
    90  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    91  }
    92  
    93  // GetResourceSender sends the GetResource request. The method will close the
    94  // http.Response Body if it receives an error.
    95  func (client CostClient) GetResourceSender(req *http.Request) (*http.Response, error) {
    96  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    97  }
    98  
    99  // GetResourceResponder handles the response to the GetResource request. The method always
   100  // closes the http.Response Body.
   101  func (client CostClient) GetResourceResponder(resp *http.Response) (result Cost, err error) {
   102  	err = autorest.Respond(
   103  		resp,
   104  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   105  		autorest.ByUnmarshallingJSON(&result),
   106  		autorest.ByClosing())
   107  	result.Response = autorest.Response{Response: resp}
   108  	return
   109  }
   110  
   111  // List list costs.
   112  // Parameters:
   113  // resourceGroupName - the name of the resource group.
   114  // labName - the name of the lab.
   115  // filter - the filter to apply on the operation.
   116  func (client CostClient) List(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationCostPage, err error) {
   117  	if tracing.IsEnabled() {
   118  		ctx = tracing.StartSpan(ctx, fqdn+"/CostClient.List")
   119  		defer func() {
   120  			sc := -1
   121  			if result.rwcc.Response.Response != nil {
   122  				sc = result.rwcc.Response.Response.StatusCode
   123  			}
   124  			tracing.EndSpan(ctx, sc, err)
   125  		}()
   126  	}
   127  	result.fn = client.listNextResults
   128  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, filter, top, orderBy)
   129  	if err != nil {
   130  		err = autorest.NewErrorWithError(err, "dtl.CostClient", "List", nil, "Failure preparing request")
   131  		return
   132  	}
   133  
   134  	resp, err := client.ListSender(req)
   135  	if err != nil {
   136  		result.rwcc.Response = autorest.Response{Response: resp}
   137  		err = autorest.NewErrorWithError(err, "dtl.CostClient", "List", resp, "Failure sending request")
   138  		return
   139  	}
   140  
   141  	result.rwcc, err = client.ListResponder(resp)
   142  	if err != nil {
   143  		err = autorest.NewErrorWithError(err, "dtl.CostClient", "List", resp, "Failure responding to request")
   144  		return
   145  	}
   146  	if result.rwcc.hasNextLink() && result.rwcc.IsEmpty() {
   147  		err = result.NextWithContext(ctx)
   148  		return
   149  	}
   150  
   151  	return
   152  }
   153  
   154  // ListPreparer prepares the List request.
   155  func (client CostClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (*http.Request, error) {
   156  	pathParameters := map[string]interface{}{
   157  		"labName":           autorest.Encode("path", labName),
   158  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   159  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   160  	}
   161  
   162  	const APIVersion = "2015-05-21-preview"
   163  	queryParameters := map[string]interface{}{
   164  		"api-version": APIVersion,
   165  	}
   166  	if len(filter) > 0 {
   167  		queryParameters["$filter"] = autorest.Encode("query", filter)
   168  	}
   169  	if top != nil {
   170  		queryParameters["$top"] = autorest.Encode("query", *top)
   171  	}
   172  	if len(orderBy) > 0 {
   173  		queryParameters["$orderBy"] = autorest.Encode("query", orderBy)
   174  	}
   175  
   176  	preparer := autorest.CreatePreparer(
   177  		autorest.AsGet(),
   178  		autorest.WithBaseURL(client.BaseURI),
   179  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs", pathParameters),
   180  		autorest.WithQueryParameters(queryParameters))
   181  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   182  }
   183  
   184  // ListSender sends the List request. The method will close the
   185  // http.Response Body if it receives an error.
   186  func (client CostClient) ListSender(req *http.Request) (*http.Response, error) {
   187  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   188  }
   189  
   190  // ListResponder handles the response to the List request. The method always
   191  // closes the http.Response Body.
   192  func (client CostClient) ListResponder(resp *http.Response) (result ResponseWithContinuationCost, err error) {
   193  	err = autorest.Respond(
   194  		resp,
   195  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   196  		autorest.ByUnmarshallingJSON(&result),
   197  		autorest.ByClosing())
   198  	result.Response = autorest.Response{Response: resp}
   199  	return
   200  }
   201  
   202  // listNextResults retrieves the next set of results, if any.
   203  func (client CostClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationCost) (result ResponseWithContinuationCost, err error) {
   204  	req, err := lastResults.responseWithContinuationCostPreparer(ctx)
   205  	if err != nil {
   206  		return result, autorest.NewErrorWithError(err, "dtl.CostClient", "listNextResults", nil, "Failure preparing next results request")
   207  	}
   208  	if req == nil {
   209  		return
   210  	}
   211  	resp, err := client.ListSender(req)
   212  	if err != nil {
   213  		result.Response = autorest.Response{Response: resp}
   214  		return result, autorest.NewErrorWithError(err, "dtl.CostClient", "listNextResults", resp, "Failure sending next results request")
   215  	}
   216  	result, err = client.ListResponder(resp)
   217  	if err != nil {
   218  		err = autorest.NewErrorWithError(err, "dtl.CostClient", "listNextResults", resp, "Failure responding to next results request")
   219  	}
   220  	return
   221  }
   222  
   223  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   224  func (client CostClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationCostIterator, err error) {
   225  	if tracing.IsEnabled() {
   226  		ctx = tracing.StartSpan(ctx, fqdn+"/CostClient.List")
   227  		defer func() {
   228  			sc := -1
   229  			if result.Response().Response.Response != nil {
   230  				sc = result.page.Response().Response.Response.StatusCode
   231  			}
   232  			tracing.EndSpan(ctx, sc, err)
   233  		}()
   234  	}
   235  	result.page, err = client.List(ctx, resourceGroupName, labName, filter, top, orderBy)
   236  	return
   237  }
   238  
   239  // RefreshData refresh Lab's Cost Data. This operation can take a while to complete.
   240  // Parameters:
   241  // resourceGroupName - the name of the resource group.
   242  // labName - the name of the lab.
   243  // name - the name of the cost.
   244  func (client CostClient) RefreshData(ctx context.Context, resourceGroupName string, labName string, name string) (result CostRefreshDataFuture, err error) {
   245  	if tracing.IsEnabled() {
   246  		ctx = tracing.StartSpan(ctx, fqdn+"/CostClient.RefreshData")
   247  		defer func() {
   248  			sc := -1
   249  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   250  				sc = result.FutureAPI.Response().StatusCode
   251  			}
   252  			tracing.EndSpan(ctx, sc, err)
   253  		}()
   254  	}
   255  	req, err := client.RefreshDataPreparer(ctx, resourceGroupName, labName, name)
   256  	if err != nil {
   257  		err = autorest.NewErrorWithError(err, "dtl.CostClient", "RefreshData", nil, "Failure preparing request")
   258  		return
   259  	}
   260  
   261  	result, err = client.RefreshDataSender(req)
   262  	if err != nil {
   263  		err = autorest.NewErrorWithError(err, "dtl.CostClient", "RefreshData", result.Response(), "Failure sending request")
   264  		return
   265  	}
   266  
   267  	return
   268  }
   269  
   270  // RefreshDataPreparer prepares the RefreshData request.
   271  func (client CostClient) RefreshDataPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   272  	pathParameters := map[string]interface{}{
   273  		"labName":           autorest.Encode("path", labName),
   274  		"name":              autorest.Encode("path", name),
   275  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   276  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   277  	}
   278  
   279  	const APIVersion = "2015-05-21-preview"
   280  	queryParameters := map[string]interface{}{
   281  		"api-version": APIVersion,
   282  	}
   283  
   284  	preparer := autorest.CreatePreparer(
   285  		autorest.AsPost(),
   286  		autorest.WithBaseURL(client.BaseURI),
   287  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}/refreshData", pathParameters),
   288  		autorest.WithQueryParameters(queryParameters))
   289  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   290  }
   291  
   292  // RefreshDataSender sends the RefreshData request. The method will close the
   293  // http.Response Body if it receives an error.
   294  func (client CostClient) RefreshDataSender(req *http.Request) (future CostRefreshDataFuture, err error) {
   295  	var resp *http.Response
   296  	future.FutureAPI = &azure.Future{}
   297  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   298  	if err != nil {
   299  		return
   300  	}
   301  	var azf azure.Future
   302  	azf, err = azure.NewFutureFromResponse(resp)
   303  	future.FutureAPI = &azf
   304  	future.Result = future.result
   305  	return
   306  }
   307  
   308  // RefreshDataResponder handles the response to the RefreshData request. The method always
   309  // closes the http.Response Body.
   310  func (client CostClient) RefreshDataResponder(resp *http.Response) (result autorest.Response, err error) {
   311  	err = autorest.Respond(
   312  		resp,
   313  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   314  		autorest.ByClosing())
   315  	result.Response = resp
   316  	return
   317  }
   318  

View as plain text