...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl/customimages.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  // CustomImagesClient is the the DevTest Labs Client.
    19  type CustomImagesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewCustomImagesClient creates an instance of the CustomImagesClient client.
    24  func NewCustomImagesClient(subscriptionID string) CustomImagesClient {
    25  	return NewCustomImagesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewCustomImagesClientWithBaseURI creates an instance of the CustomImagesClient client using a custom endpoint.  Use
    29  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewCustomImagesClientWithBaseURI(baseURI string, subscriptionID string) CustomImagesClient {
    31  	return CustomImagesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate create or replace an existing custom image. 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 custom image.
    39  // customImage - a custom image.
    40  func (client CustomImagesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, name string, customImage CustomImage) (result CustomImagesCreateOrUpdateFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/CustomImagesClient.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: customImage,
    53  			Constraints: []validation.Constraint{{Target: "customImage.CustomImageProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    54  		return result, validation.NewError("dtl.CustomImagesClient", "CreateOrUpdate", err.Error())
    55  	}
    56  
    57  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, customImage)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "CreateOrUpdate", nil, "Failure preparing request")
    60  		return
    61  	}
    62  
    63  	result, err = client.CreateOrUpdateSender(req)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    66  		return
    67  	}
    68  
    69  	return
    70  }
    71  
    72  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    73  func (client CustomImagesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, customImage CustomImage) (*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}/customimages/{name}", pathParameters),
    91  		autorest.WithJSON(customImage),
    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 CustomImagesClient) CreateOrUpdateSender(req *http.Request) (future CustomImagesCreateOrUpdateFuture, err error) {
    99  	var resp *http.Response
   100  	future.FutureAPI = &azure.Future{}
   101  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   102  	if err != nil {
   103  		return
   104  	}
   105  	var azf azure.Future
   106  	azf, err = azure.NewFutureFromResponse(resp)
   107  	future.FutureAPI = &azf
   108  	future.Result = future.result
   109  	return
   110  }
   111  
   112  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   113  // closes the http.Response Body.
   114  func (client CustomImagesClient) CreateOrUpdateResponder(resp *http.Response) (result CustomImage, err error) {
   115  	err = autorest.Respond(
   116  		resp,
   117  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   118  		autorest.ByUnmarshallingJSON(&result),
   119  		autorest.ByClosing())
   120  	result.Response = autorest.Response{Response: resp}
   121  	return
   122  }
   123  
   124  // Delete delete custom image. This operation can take a while to complete.
   125  // Parameters:
   126  // resourceGroupName - the name of the resource group.
   127  // labName - the name of the lab.
   128  // name - the name of the custom image.
   129  func (client CustomImagesClient) Delete(ctx context.Context, resourceGroupName string, labName string, name string) (result CustomImagesDeleteFuture, err error) {
   130  	if tracing.IsEnabled() {
   131  		ctx = tracing.StartSpan(ctx, fqdn+"/CustomImagesClient.Delete")
   132  		defer func() {
   133  			sc := -1
   134  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   135  				sc = result.FutureAPI.Response().StatusCode
   136  			}
   137  			tracing.EndSpan(ctx, sc, err)
   138  		}()
   139  	}
   140  	req, err := client.DeletePreparer(ctx, resourceGroupName, labName, name)
   141  	if err != nil {
   142  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "Delete", nil, "Failure preparing request")
   143  		return
   144  	}
   145  
   146  	result, err = client.DeleteSender(req)
   147  	if err != nil {
   148  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "Delete", result.Response(), "Failure sending request")
   149  		return
   150  	}
   151  
   152  	return
   153  }
   154  
   155  // DeletePreparer prepares the Delete request.
   156  func (client CustomImagesClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   157  	pathParameters := map[string]interface{}{
   158  		"labName":           autorest.Encode("path", labName),
   159  		"name":              autorest.Encode("path", name),
   160  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   161  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   162  	}
   163  
   164  	const APIVersion = "2016-05-15"
   165  	queryParameters := map[string]interface{}{
   166  		"api-version": APIVersion,
   167  	}
   168  
   169  	preparer := autorest.CreatePreparer(
   170  		autorest.AsDelete(),
   171  		autorest.WithBaseURL(client.BaseURI),
   172  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}", pathParameters),
   173  		autorest.WithQueryParameters(queryParameters))
   174  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   175  }
   176  
   177  // DeleteSender sends the Delete request. The method will close the
   178  // http.Response Body if it receives an error.
   179  func (client CustomImagesClient) DeleteSender(req *http.Request) (future CustomImagesDeleteFuture, err error) {
   180  	var resp *http.Response
   181  	future.FutureAPI = &azure.Future{}
   182  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   183  	if err != nil {
   184  		return
   185  	}
   186  	var azf azure.Future
   187  	azf, err = azure.NewFutureFromResponse(resp)
   188  	future.FutureAPI = &azf
   189  	future.Result = future.result
   190  	return
   191  }
   192  
   193  // DeleteResponder handles the response to the Delete request. The method always
   194  // closes the http.Response Body.
   195  func (client CustomImagesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   196  	err = autorest.Respond(
   197  		resp,
   198  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   199  		autorest.ByClosing())
   200  	result.Response = resp
   201  	return
   202  }
   203  
   204  // Get get custom image.
   205  // Parameters:
   206  // resourceGroupName - the name of the resource group.
   207  // labName - the name of the lab.
   208  // name - the name of the custom image.
   209  // expand - specify the $expand query. Example: 'properties($select=vm)'
   210  func (client CustomImagesClient) Get(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (result CustomImage, err error) {
   211  	if tracing.IsEnabled() {
   212  		ctx = tracing.StartSpan(ctx, fqdn+"/CustomImagesClient.Get")
   213  		defer func() {
   214  			sc := -1
   215  			if result.Response.Response != nil {
   216  				sc = result.Response.Response.StatusCode
   217  			}
   218  			tracing.EndSpan(ctx, sc, err)
   219  		}()
   220  	}
   221  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, name, expand)
   222  	if err != nil {
   223  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "Get", nil, "Failure preparing request")
   224  		return
   225  	}
   226  
   227  	resp, err := client.GetSender(req)
   228  	if err != nil {
   229  		result.Response = autorest.Response{Response: resp}
   230  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "Get", resp, "Failure sending request")
   231  		return
   232  	}
   233  
   234  	result, err = client.GetResponder(resp)
   235  	if err != nil {
   236  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "Get", resp, "Failure responding to request")
   237  		return
   238  	}
   239  
   240  	return
   241  }
   242  
   243  // GetPreparer prepares the Get request.
   244  func (client CustomImagesClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (*http.Request, error) {
   245  	pathParameters := map[string]interface{}{
   246  		"labName":           autorest.Encode("path", labName),
   247  		"name":              autorest.Encode("path", name),
   248  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   249  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   250  	}
   251  
   252  	const APIVersion = "2016-05-15"
   253  	queryParameters := map[string]interface{}{
   254  		"api-version": APIVersion,
   255  	}
   256  	if len(expand) > 0 {
   257  		queryParameters["$expand"] = autorest.Encode("query", expand)
   258  	}
   259  
   260  	preparer := autorest.CreatePreparer(
   261  		autorest.AsGet(),
   262  		autorest.WithBaseURL(client.BaseURI),
   263  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}", pathParameters),
   264  		autorest.WithQueryParameters(queryParameters))
   265  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   266  }
   267  
   268  // GetSender sends the Get request. The method will close the
   269  // http.Response Body if it receives an error.
   270  func (client CustomImagesClient) GetSender(req *http.Request) (*http.Response, error) {
   271  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   272  }
   273  
   274  // GetResponder handles the response to the Get request. The method always
   275  // closes the http.Response Body.
   276  func (client CustomImagesClient) GetResponder(resp *http.Response) (result CustomImage, err error) {
   277  	err = autorest.Respond(
   278  		resp,
   279  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   280  		autorest.ByUnmarshallingJSON(&result),
   281  		autorest.ByClosing())
   282  	result.Response = autorest.Response{Response: resp}
   283  	return
   284  }
   285  
   286  // List list custom images in a given lab.
   287  // Parameters:
   288  // resourceGroupName - the name of the resource group.
   289  // labName - the name of the lab.
   290  // expand - specify the $expand query. Example: 'properties($select=vm)'
   291  // filter - the filter to apply to the operation.
   292  // top - the maximum number of resources to return from the operation.
   293  // orderby - the ordering expression for the results, using OData notation.
   294  func (client CustomImagesClient) List(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationCustomImagePage, err error) {
   295  	if tracing.IsEnabled() {
   296  		ctx = tracing.StartSpan(ctx, fqdn+"/CustomImagesClient.List")
   297  		defer func() {
   298  			sc := -1
   299  			if result.rwcci.Response.Response != nil {
   300  				sc = result.rwcci.Response.Response.StatusCode
   301  			}
   302  			tracing.EndSpan(ctx, sc, err)
   303  		}()
   304  	}
   305  	result.fn = client.listNextResults
   306  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   307  	if err != nil {
   308  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "List", nil, "Failure preparing request")
   309  		return
   310  	}
   311  
   312  	resp, err := client.ListSender(req)
   313  	if err != nil {
   314  		result.rwcci.Response = autorest.Response{Response: resp}
   315  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "List", resp, "Failure sending request")
   316  		return
   317  	}
   318  
   319  	result.rwcci, err = client.ListResponder(resp)
   320  	if err != nil {
   321  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "List", resp, "Failure responding to request")
   322  		return
   323  	}
   324  	if result.rwcci.hasNextLink() && result.rwcci.IsEmpty() {
   325  		err = result.NextWithContext(ctx)
   326  		return
   327  	}
   328  
   329  	return
   330  }
   331  
   332  // ListPreparer prepares the List request.
   333  func (client CustomImagesClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   334  	pathParameters := map[string]interface{}{
   335  		"labName":           autorest.Encode("path", labName),
   336  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   337  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   338  	}
   339  
   340  	const APIVersion = "2016-05-15"
   341  	queryParameters := map[string]interface{}{
   342  		"api-version": APIVersion,
   343  	}
   344  	if len(expand) > 0 {
   345  		queryParameters["$expand"] = autorest.Encode("query", expand)
   346  	}
   347  	if len(filter) > 0 {
   348  		queryParameters["$filter"] = autorest.Encode("query", filter)
   349  	}
   350  	if top != nil {
   351  		queryParameters["$top"] = autorest.Encode("query", *top)
   352  	}
   353  	if len(orderby) > 0 {
   354  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   355  	}
   356  
   357  	preparer := autorest.CreatePreparer(
   358  		autorest.AsGet(),
   359  		autorest.WithBaseURL(client.BaseURI),
   360  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages", pathParameters),
   361  		autorest.WithQueryParameters(queryParameters))
   362  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   363  }
   364  
   365  // ListSender sends the List request. The method will close the
   366  // http.Response Body if it receives an error.
   367  func (client CustomImagesClient) ListSender(req *http.Request) (*http.Response, error) {
   368  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   369  }
   370  
   371  // ListResponder handles the response to the List request. The method always
   372  // closes the http.Response Body.
   373  func (client CustomImagesClient) ListResponder(resp *http.Response) (result ResponseWithContinuationCustomImage, err error) {
   374  	err = autorest.Respond(
   375  		resp,
   376  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   377  		autorest.ByUnmarshallingJSON(&result),
   378  		autorest.ByClosing())
   379  	result.Response = autorest.Response{Response: resp}
   380  	return
   381  }
   382  
   383  // listNextResults retrieves the next set of results, if any.
   384  func (client CustomImagesClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationCustomImage) (result ResponseWithContinuationCustomImage, err error) {
   385  	req, err := lastResults.responseWithContinuationCustomImagePreparer(ctx)
   386  	if err != nil {
   387  		return result, autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "listNextResults", nil, "Failure preparing next results request")
   388  	}
   389  	if req == nil {
   390  		return
   391  	}
   392  	resp, err := client.ListSender(req)
   393  	if err != nil {
   394  		result.Response = autorest.Response{Response: resp}
   395  		return result, autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "listNextResults", resp, "Failure sending next results request")
   396  	}
   397  	result, err = client.ListResponder(resp)
   398  	if err != nil {
   399  		err = autorest.NewErrorWithError(err, "dtl.CustomImagesClient", "listNextResults", resp, "Failure responding to next results request")
   400  	}
   401  	return
   402  }
   403  
   404  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   405  func (client CustomImagesClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationCustomImageIterator, err error) {
   406  	if tracing.IsEnabled() {
   407  		ctx = tracing.StartSpan(ctx, fqdn+"/CustomImagesClient.List")
   408  		defer func() {
   409  			sc := -1
   410  			if result.Response().Response.Response != nil {
   411  				sc = result.page.Response().Response.Response.StatusCode
   412  			}
   413  			tracing.EndSpan(ctx, sc, err)
   414  		}()
   415  	}
   416  	result.page, err = client.List(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   417  	return
   418  }
   419  

View as plain text