...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl/servicerunners.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  // ServiceRunnersClient is the the DevTest Labs Client.
    18  type ServiceRunnersClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewServiceRunnersClient creates an instance of the ServiceRunnersClient client.
    23  func NewServiceRunnersClient(subscriptionID string) ServiceRunnersClient {
    24  	return NewServiceRunnersClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewServiceRunnersClientWithBaseURI creates an instance of the ServiceRunnersClient client using a custom endpoint.
    28  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewServiceRunnersClientWithBaseURI(baseURI string, subscriptionID string) ServiceRunnersClient {
    30  	return ServiceRunnersClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate create or replace an existing Service runner.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group.
    36  // labName - the name of the lab.
    37  // name - the name of the service runner.
    38  // serviceRunner - a container for a managed identity to execute DevTest lab services.
    39  func (client ServiceRunnersClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, name string, serviceRunner ServiceRunner) (result ServiceRunner, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceRunnersClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, serviceRunner)
    51  	if err != nil {
    52  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "CreateOrUpdate", nil, "Failure preparing request")
    53  		return
    54  	}
    55  
    56  	resp, err := client.CreateOrUpdateSender(req)
    57  	if err != nil {
    58  		result.Response = autorest.Response{Response: resp}
    59  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "CreateOrUpdate", resp, "Failure sending request")
    60  		return
    61  	}
    62  
    63  	result, err = client.CreateOrUpdateResponder(resp)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "CreateOrUpdate", resp, "Failure responding to request")
    66  		return
    67  	}
    68  
    69  	return
    70  }
    71  
    72  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    73  func (client ServiceRunnersClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, serviceRunner ServiceRunner) (*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 = "2016-05-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}/servicerunners/{name}", pathParameters),
    91  		autorest.WithJSON(serviceRunner),
    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 ServiceRunnersClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
    99  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   100  }
   101  
   102  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   103  // closes the http.Response Body.
   104  func (client ServiceRunnersClient) CreateOrUpdateResponder(resp *http.Response) (result ServiceRunner, err error) {
   105  	err = autorest.Respond(
   106  		resp,
   107  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   108  		autorest.ByUnmarshallingJSON(&result),
   109  		autorest.ByClosing())
   110  	result.Response = autorest.Response{Response: resp}
   111  	return
   112  }
   113  
   114  // Delete delete service runner.
   115  // Parameters:
   116  // resourceGroupName - the name of the resource group.
   117  // labName - the name of the lab.
   118  // name - the name of the service runner.
   119  func (client ServiceRunnersClient) Delete(ctx context.Context, resourceGroupName string, labName string, name string) (result autorest.Response, err error) {
   120  	if tracing.IsEnabled() {
   121  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceRunnersClient.Delete")
   122  		defer func() {
   123  			sc := -1
   124  			if result.Response != nil {
   125  				sc = result.Response.StatusCode
   126  			}
   127  			tracing.EndSpan(ctx, sc, err)
   128  		}()
   129  	}
   130  	req, err := client.DeletePreparer(ctx, resourceGroupName, labName, name)
   131  	if err != nil {
   132  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "Delete", nil, "Failure preparing request")
   133  		return
   134  	}
   135  
   136  	resp, err := client.DeleteSender(req)
   137  	if err != nil {
   138  		result.Response = resp
   139  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "Delete", resp, "Failure sending request")
   140  		return
   141  	}
   142  
   143  	result, err = client.DeleteResponder(resp)
   144  	if err != nil {
   145  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "Delete", resp, "Failure responding to request")
   146  		return
   147  	}
   148  
   149  	return
   150  }
   151  
   152  // DeletePreparer prepares the Delete request.
   153  func (client ServiceRunnersClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   154  	pathParameters := map[string]interface{}{
   155  		"labName":           autorest.Encode("path", labName),
   156  		"name":              autorest.Encode("path", name),
   157  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   158  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   159  	}
   160  
   161  	const APIVersion = "2016-05-15"
   162  	queryParameters := map[string]interface{}{
   163  		"api-version": APIVersion,
   164  	}
   165  
   166  	preparer := autorest.CreatePreparer(
   167  		autorest.AsDelete(),
   168  		autorest.WithBaseURL(client.BaseURI),
   169  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/servicerunners/{name}", pathParameters),
   170  		autorest.WithQueryParameters(queryParameters))
   171  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   172  }
   173  
   174  // DeleteSender sends the Delete request. The method will close the
   175  // http.Response Body if it receives an error.
   176  func (client ServiceRunnersClient) DeleteSender(req *http.Request) (*http.Response, error) {
   177  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   178  }
   179  
   180  // DeleteResponder handles the response to the Delete request. The method always
   181  // closes the http.Response Body.
   182  func (client ServiceRunnersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   183  	err = autorest.Respond(
   184  		resp,
   185  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   186  		autorest.ByClosing())
   187  	result.Response = resp
   188  	return
   189  }
   190  
   191  // Get get service runner.
   192  // Parameters:
   193  // resourceGroupName - the name of the resource group.
   194  // labName - the name of the lab.
   195  // name - the name of the service runner.
   196  func (client ServiceRunnersClient) Get(ctx context.Context, resourceGroupName string, labName string, name string) (result ServiceRunner, err error) {
   197  	if tracing.IsEnabled() {
   198  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceRunnersClient.Get")
   199  		defer func() {
   200  			sc := -1
   201  			if result.Response.Response != nil {
   202  				sc = result.Response.Response.StatusCode
   203  			}
   204  			tracing.EndSpan(ctx, sc, err)
   205  		}()
   206  	}
   207  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, name)
   208  	if err != nil {
   209  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "Get", nil, "Failure preparing request")
   210  		return
   211  	}
   212  
   213  	resp, err := client.GetSender(req)
   214  	if err != nil {
   215  		result.Response = autorest.Response{Response: resp}
   216  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "Get", resp, "Failure sending request")
   217  		return
   218  	}
   219  
   220  	result, err = client.GetResponder(resp)
   221  	if err != nil {
   222  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "Get", resp, "Failure responding to request")
   223  		return
   224  	}
   225  
   226  	return
   227  }
   228  
   229  // GetPreparer prepares the Get request.
   230  func (client ServiceRunnersClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   231  	pathParameters := map[string]interface{}{
   232  		"labName":           autorest.Encode("path", labName),
   233  		"name":              autorest.Encode("path", name),
   234  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   235  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   236  	}
   237  
   238  	const APIVersion = "2016-05-15"
   239  	queryParameters := map[string]interface{}{
   240  		"api-version": APIVersion,
   241  	}
   242  
   243  	preparer := autorest.CreatePreparer(
   244  		autorest.AsGet(),
   245  		autorest.WithBaseURL(client.BaseURI),
   246  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/servicerunners/{name}", pathParameters),
   247  		autorest.WithQueryParameters(queryParameters))
   248  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   249  }
   250  
   251  // GetSender sends the Get request. The method will close the
   252  // http.Response Body if it receives an error.
   253  func (client ServiceRunnersClient) GetSender(req *http.Request) (*http.Response, error) {
   254  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   255  }
   256  
   257  // GetResponder handles the response to the Get request. The method always
   258  // closes the http.Response Body.
   259  func (client ServiceRunnersClient) GetResponder(resp *http.Response) (result ServiceRunner, err error) {
   260  	err = autorest.Respond(
   261  		resp,
   262  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   263  		autorest.ByUnmarshallingJSON(&result),
   264  		autorest.ByClosing())
   265  	result.Response = autorest.Response{Response: resp}
   266  	return
   267  }
   268  
   269  // List list service runners in a given lab.
   270  // Parameters:
   271  // resourceGroupName - the name of the resource group.
   272  // labName - the name of the lab.
   273  // filter - the filter to apply to the operation.
   274  // top - the maximum number of resources to return from the operation.
   275  // orderby - the ordering expression for the results, using OData notation.
   276  func (client ServiceRunnersClient) List(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderby string) (result ResponseWithContinuationServiceRunnerPage, err error) {
   277  	if tracing.IsEnabled() {
   278  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceRunnersClient.List")
   279  		defer func() {
   280  			sc := -1
   281  			if result.rwcsr.Response.Response != nil {
   282  				sc = result.rwcsr.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.ServiceRunnersClient", "List", nil, "Failure preparing request")
   291  		return
   292  	}
   293  
   294  	resp, err := client.ListSender(req)
   295  	if err != nil {
   296  		result.rwcsr.Response = autorest.Response{Response: resp}
   297  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "List", resp, "Failure sending request")
   298  		return
   299  	}
   300  
   301  	result.rwcsr, err = client.ListResponder(resp)
   302  	if err != nil {
   303  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "List", resp, "Failure responding to request")
   304  		return
   305  	}
   306  	if result.rwcsr.hasNextLink() && result.rwcsr.IsEmpty() {
   307  		err = result.NextWithContext(ctx)
   308  		return
   309  	}
   310  
   311  	return
   312  }
   313  
   314  // ListPreparer prepares the List request.
   315  func (client ServiceRunnersClient) 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 = "2016-05-15"
   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}/servicerunners", 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 ServiceRunnersClient) 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 ServiceRunnersClient) ListResponder(resp *http.Response) (result ResponseWithContinuationServiceRunner, 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 ServiceRunnersClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationServiceRunner) (result ResponseWithContinuationServiceRunner, err error) {
   364  	req, err := lastResults.responseWithContinuationServiceRunnerPreparer(ctx)
   365  	if err != nil {
   366  		return result, autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "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.ServiceRunnersClient", "listNextResults", resp, "Failure sending next results request")
   375  	}
   376  	result, err = client.ListResponder(resp)
   377  	if err != nil {
   378  		err = autorest.NewErrorWithError(err, "dtl.ServiceRunnersClient", "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 ServiceRunnersClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderby string) (result ResponseWithContinuationServiceRunnerIterator, err error) {
   385  	if tracing.IsEnabled() {
   386  		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceRunnersClient.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