...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl/armtemplates.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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // ArmTemplatesClient is the the DevTest Labs Client.
    18  type ArmTemplatesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewArmTemplatesClient creates an instance of the ArmTemplatesClient client.
    23  func NewArmTemplatesClient(subscriptionID string) ArmTemplatesClient {
    24  	return NewArmTemplatesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewArmTemplatesClientWithBaseURI creates an instance of the ArmTemplatesClient client using a custom endpoint.  Use
    28  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewArmTemplatesClientWithBaseURI(baseURI string, subscriptionID string) ArmTemplatesClient {
    30  	return ArmTemplatesClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Get get azure resource manager template.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group.
    36  // labName - the name of the lab.
    37  // artifactSourceName - the name of the artifact source.
    38  // name - the name of the azure Resource Manager template.
    39  // expand - specify the $expand query. Example: 'properties($select=displayName)'
    40  func (client ArmTemplatesClient) Get(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, expand string) (result ArmTemplate, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/ArmTemplatesClient.Get")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, artifactSourceName, name, expand)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "dtl.ArmTemplatesClient", "Get", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.GetSender(req)
    58  	if err != nil {
    59  		result.Response = autorest.Response{Response: resp}
    60  		err = autorest.NewErrorWithError(err, "dtl.ArmTemplatesClient", "Get", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result, err = client.GetResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "dtl.ArmTemplatesClient", "Get", resp, "Failure responding to request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // GetPreparer prepares the Get request.
    74  func (client ArmTemplatesClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, expand string) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"artifactSourceName": autorest.Encode("path", artifactSourceName),
    77  		"labName":            autorest.Encode("path", labName),
    78  		"name":               autorest.Encode("path", name),
    79  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
    80  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
    81  	}
    82  
    83  	const APIVersion = "2016-05-15"
    84  	queryParameters := map[string]interface{}{
    85  		"api-version": APIVersion,
    86  	}
    87  	if len(expand) > 0 {
    88  		queryParameters["$expand"] = autorest.Encode("query", expand)
    89  	}
    90  
    91  	preparer := autorest.CreatePreparer(
    92  		autorest.AsGet(),
    93  		autorest.WithBaseURL(client.BaseURI),
    94  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates/{name}", pathParameters),
    95  		autorest.WithQueryParameters(queryParameters))
    96  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    97  }
    98  
    99  // GetSender sends the Get request. The method will close the
   100  // http.Response Body if it receives an error.
   101  func (client ArmTemplatesClient) GetSender(req *http.Request) (*http.Response, error) {
   102  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   103  }
   104  
   105  // GetResponder handles the response to the Get request. The method always
   106  // closes the http.Response Body.
   107  func (client ArmTemplatesClient) GetResponder(resp *http.Response) (result ArmTemplate, err error) {
   108  	err = autorest.Respond(
   109  		resp,
   110  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   111  		autorest.ByUnmarshallingJSON(&result),
   112  		autorest.ByClosing())
   113  	result.Response = autorest.Response{Response: resp}
   114  	return
   115  }
   116  
   117  // List list azure resource manager templates in a given artifact source.
   118  // Parameters:
   119  // resourceGroupName - the name of the resource group.
   120  // labName - the name of the lab.
   121  // artifactSourceName - the name of the artifact source.
   122  // expand - specify the $expand query. Example: 'properties($select=displayName)'
   123  // filter - the filter to apply to the operation.
   124  // top - the maximum number of resources to return from the operation.
   125  // orderby - the ordering expression for the results, using OData notation.
   126  func (client ArmTemplatesClient) List(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationArmTemplatePage, err error) {
   127  	if tracing.IsEnabled() {
   128  		ctx = tracing.StartSpan(ctx, fqdn+"/ArmTemplatesClient.List")
   129  		defer func() {
   130  			sc := -1
   131  			if result.rwcat.Response.Response != nil {
   132  				sc = result.rwcat.Response.Response.StatusCode
   133  			}
   134  			tracing.EndSpan(ctx, sc, err)
   135  		}()
   136  	}
   137  	result.fn = client.listNextResults
   138  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, artifactSourceName, expand, filter, top, orderby)
   139  	if err != nil {
   140  		err = autorest.NewErrorWithError(err, "dtl.ArmTemplatesClient", "List", nil, "Failure preparing request")
   141  		return
   142  	}
   143  
   144  	resp, err := client.ListSender(req)
   145  	if err != nil {
   146  		result.rwcat.Response = autorest.Response{Response: resp}
   147  		err = autorest.NewErrorWithError(err, "dtl.ArmTemplatesClient", "List", resp, "Failure sending request")
   148  		return
   149  	}
   150  
   151  	result.rwcat, err = client.ListResponder(resp)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "dtl.ArmTemplatesClient", "List", resp, "Failure responding to request")
   154  		return
   155  	}
   156  	if result.rwcat.hasNextLink() && result.rwcat.IsEmpty() {
   157  		err = result.NextWithContext(ctx)
   158  		return
   159  	}
   160  
   161  	return
   162  }
   163  
   164  // ListPreparer prepares the List request.
   165  func (client ArmTemplatesClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   166  	pathParameters := map[string]interface{}{
   167  		"artifactSourceName": autorest.Encode("path", artifactSourceName),
   168  		"labName":            autorest.Encode("path", labName),
   169  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   170  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   171  	}
   172  
   173  	const APIVersion = "2016-05-15"
   174  	queryParameters := map[string]interface{}{
   175  		"api-version": APIVersion,
   176  	}
   177  	if len(expand) > 0 {
   178  		queryParameters["$expand"] = autorest.Encode("query", expand)
   179  	}
   180  	if len(filter) > 0 {
   181  		queryParameters["$filter"] = autorest.Encode("query", filter)
   182  	}
   183  	if top != nil {
   184  		queryParameters["$top"] = autorest.Encode("query", *top)
   185  	}
   186  	if len(orderby) > 0 {
   187  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   188  	}
   189  
   190  	preparer := autorest.CreatePreparer(
   191  		autorest.AsGet(),
   192  		autorest.WithBaseURL(client.BaseURI),
   193  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates", pathParameters),
   194  		autorest.WithQueryParameters(queryParameters))
   195  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   196  }
   197  
   198  // ListSender sends the List request. The method will close the
   199  // http.Response Body if it receives an error.
   200  func (client ArmTemplatesClient) ListSender(req *http.Request) (*http.Response, error) {
   201  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   202  }
   203  
   204  // ListResponder handles the response to the List request. The method always
   205  // closes the http.Response Body.
   206  func (client ArmTemplatesClient) ListResponder(resp *http.Response) (result ResponseWithContinuationArmTemplate, err error) {
   207  	err = autorest.Respond(
   208  		resp,
   209  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   210  		autorest.ByUnmarshallingJSON(&result),
   211  		autorest.ByClosing())
   212  	result.Response = autorest.Response{Response: resp}
   213  	return
   214  }
   215  
   216  // listNextResults retrieves the next set of results, if any.
   217  func (client ArmTemplatesClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationArmTemplate) (result ResponseWithContinuationArmTemplate, err error) {
   218  	req, err := lastResults.responseWithContinuationArmTemplatePreparer(ctx)
   219  	if err != nil {
   220  		return result, autorest.NewErrorWithError(err, "dtl.ArmTemplatesClient", "listNextResults", nil, "Failure preparing next results request")
   221  	}
   222  	if req == nil {
   223  		return
   224  	}
   225  	resp, err := client.ListSender(req)
   226  	if err != nil {
   227  		result.Response = autorest.Response{Response: resp}
   228  		return result, autorest.NewErrorWithError(err, "dtl.ArmTemplatesClient", "listNextResults", resp, "Failure sending next results request")
   229  	}
   230  	result, err = client.ListResponder(resp)
   231  	if err != nil {
   232  		err = autorest.NewErrorWithError(err, "dtl.ArmTemplatesClient", "listNextResults", resp, "Failure responding to next results request")
   233  	}
   234  	return
   235  }
   236  
   237  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   238  func (client ArmTemplatesClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationArmTemplateIterator, err error) {
   239  	if tracing.IsEnabled() {
   240  		ctx = tracing.StartSpan(ctx, fqdn+"/ArmTemplatesClient.List")
   241  		defer func() {
   242  			sc := -1
   243  			if result.Response().Response.Response != nil {
   244  				sc = result.page.Response().Response.Response.StatusCode
   245  			}
   246  			tracing.EndSpan(ctx, sc, err)
   247  		}()
   248  	}
   249  	result.page, err = client.List(ctx, resourceGroupName, labName, artifactSourceName, expand, filter, top, orderby)
   250  	return
   251  }
   252  

View as plain text