...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/devtestlabs/mgmt/2015-05-21-preview/dtl/virtualmachine.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  // VirtualMachineClient is the azure DevTest Labs REST API version 2015-05-21-preview.
    18  type VirtualMachineClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewVirtualMachineClient creates an instance of the VirtualMachineClient client.
    23  func NewVirtualMachineClient(subscriptionID string) VirtualMachineClient {
    24  	return NewVirtualMachineClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewVirtualMachineClientWithBaseURI creates an instance of the VirtualMachineClient 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 NewVirtualMachineClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineClient {
    30  	return VirtualMachineClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // ApplyArtifacts apply artifacts to Lab VM. 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 virtual Machine.
    38  func (client VirtualMachineClient) ApplyArtifacts(ctx context.Context, resourceGroupName string, labName string, name string, applyArtifactsRequest ApplyArtifactsRequest) (result VirtualMachineApplyArtifactsFuture, err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.ApplyArtifacts")
    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.ApplyArtifactsPreparer(ctx, resourceGroupName, labName, name, applyArtifactsRequest)
    50  	if err != nil {
    51  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "ApplyArtifacts", nil, "Failure preparing request")
    52  		return
    53  	}
    54  
    55  	result, err = client.ApplyArtifactsSender(req)
    56  	if err != nil {
    57  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "ApplyArtifacts", result.Response(), "Failure sending request")
    58  		return
    59  	}
    60  
    61  	return
    62  }
    63  
    64  // ApplyArtifactsPreparer prepares the ApplyArtifacts request.
    65  func (client VirtualMachineClient) ApplyArtifactsPreparer(ctx context.Context, resourceGroupName string, labName string, name string, applyArtifactsRequest ApplyArtifactsRequest) (*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.AsPost(),
    81  		autorest.WithBaseURL(client.BaseURI),
    82  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/applyArtifacts", pathParameters),
    83  		autorest.WithJSON(applyArtifactsRequest),
    84  		autorest.WithQueryParameters(queryParameters))
    85  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    86  }
    87  
    88  // ApplyArtifactsSender sends the ApplyArtifacts request. The method will close the
    89  // http.Response Body if it receives an error.
    90  func (client VirtualMachineClient) ApplyArtifactsSender(req *http.Request) (future VirtualMachineApplyArtifactsFuture, 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  // ApplyArtifactsResponder handles the response to the ApplyArtifacts request. The method always
   105  // closes the http.Response Body.
   106  func (client VirtualMachineClient) ApplyArtifactsResponder(resp *http.Response) (result autorest.Response, err error) {
   107  	err = autorest.Respond(
   108  		resp,
   109  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   110  		autorest.ByClosing())
   111  	result.Response = resp
   112  	return
   113  }
   114  
   115  // CreateOrUpdateResource create or replace an existing Virtual Machine. This operation can take a while to complete.
   116  // Parameters:
   117  // resourceGroupName - the name of the resource group.
   118  // labName - the name of the lab.
   119  // name - the name of the virtual Machine.
   120  func (client VirtualMachineClient) CreateOrUpdateResource(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (result VirtualMachineCreateOrUpdateResourceFuture, err error) {
   121  	if tracing.IsEnabled() {
   122  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.CreateOrUpdateResource")
   123  		defer func() {
   124  			sc := -1
   125  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   126  				sc = result.FutureAPI.Response().StatusCode
   127  			}
   128  			tracing.EndSpan(ctx, sc, err)
   129  		}()
   130  	}
   131  	req, err := client.CreateOrUpdateResourcePreparer(ctx, resourceGroupName, labName, name, labVirtualMachine)
   132  	if err != nil {
   133  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "CreateOrUpdateResource", nil, "Failure preparing request")
   134  		return
   135  	}
   136  
   137  	result, err = client.CreateOrUpdateResourceSender(req)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "CreateOrUpdateResource", result.Response(), "Failure sending request")
   140  		return
   141  	}
   142  
   143  	return
   144  }
   145  
   146  // CreateOrUpdateResourcePreparer prepares the CreateOrUpdateResource request.
   147  func (client VirtualMachineClient) CreateOrUpdateResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (*http.Request, error) {
   148  	pathParameters := map[string]interface{}{
   149  		"labName":           autorest.Encode("path", labName),
   150  		"name":              autorest.Encode("path", name),
   151  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   152  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   153  	}
   154  
   155  	const APIVersion = "2015-05-21-preview"
   156  	queryParameters := map[string]interface{}{
   157  		"api-version": APIVersion,
   158  	}
   159  
   160  	preparer := autorest.CreatePreparer(
   161  		autorest.AsContentType("application/json; charset=utf-8"),
   162  		autorest.AsPut(),
   163  		autorest.WithBaseURL(client.BaseURI),
   164  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
   165  		autorest.WithJSON(labVirtualMachine),
   166  		autorest.WithQueryParameters(queryParameters))
   167  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   168  }
   169  
   170  // CreateOrUpdateResourceSender sends the CreateOrUpdateResource request. The method will close the
   171  // http.Response Body if it receives an error.
   172  func (client VirtualMachineClient) CreateOrUpdateResourceSender(req *http.Request) (future VirtualMachineCreateOrUpdateResourceFuture, err error) {
   173  	var resp *http.Response
   174  	future.FutureAPI = &azure.Future{}
   175  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   176  	if err != nil {
   177  		return
   178  	}
   179  	var azf azure.Future
   180  	azf, err = azure.NewFutureFromResponse(resp)
   181  	future.FutureAPI = &azf
   182  	future.Result = future.result
   183  	return
   184  }
   185  
   186  // CreateOrUpdateResourceResponder handles the response to the CreateOrUpdateResource request. The method always
   187  // closes the http.Response Body.
   188  func (client VirtualMachineClient) CreateOrUpdateResourceResponder(resp *http.Response) (result LabVirtualMachine, err error) {
   189  	err = autorest.Respond(
   190  		resp,
   191  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   192  		autorest.ByUnmarshallingJSON(&result),
   193  		autorest.ByClosing())
   194  	result.Response = autorest.Response{Response: resp}
   195  	return
   196  }
   197  
   198  // DeleteResource delete virtual machine. This operation can take a while to complete.
   199  // Parameters:
   200  // resourceGroupName - the name of the resource group.
   201  // labName - the name of the lab.
   202  // name - the name of the virtual Machine.
   203  func (client VirtualMachineClient) DeleteResource(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachineDeleteResourceFuture, err error) {
   204  	if tracing.IsEnabled() {
   205  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.DeleteResource")
   206  		defer func() {
   207  			sc := -1
   208  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   209  				sc = result.FutureAPI.Response().StatusCode
   210  			}
   211  			tracing.EndSpan(ctx, sc, err)
   212  		}()
   213  	}
   214  	req, err := client.DeleteResourcePreparer(ctx, resourceGroupName, labName, name)
   215  	if err != nil {
   216  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "DeleteResource", nil, "Failure preparing request")
   217  		return
   218  	}
   219  
   220  	result, err = client.DeleteResourceSender(req)
   221  	if err != nil {
   222  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "DeleteResource", result.Response(), "Failure sending request")
   223  		return
   224  	}
   225  
   226  	return
   227  }
   228  
   229  // DeleteResourcePreparer prepares the DeleteResource request.
   230  func (client VirtualMachineClient) DeleteResourcePreparer(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 = "2015-05-21-preview"
   239  	queryParameters := map[string]interface{}{
   240  		"api-version": APIVersion,
   241  	}
   242  
   243  	preparer := autorest.CreatePreparer(
   244  		autorest.AsDelete(),
   245  		autorest.WithBaseURL(client.BaseURI),
   246  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
   247  		autorest.WithQueryParameters(queryParameters))
   248  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   249  }
   250  
   251  // DeleteResourceSender sends the DeleteResource request. The method will close the
   252  // http.Response Body if it receives an error.
   253  func (client VirtualMachineClient) DeleteResourceSender(req *http.Request) (future VirtualMachineDeleteResourceFuture, err error) {
   254  	var resp *http.Response
   255  	future.FutureAPI = &azure.Future{}
   256  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   257  	if err != nil {
   258  		return
   259  	}
   260  	var azf azure.Future
   261  	azf, err = azure.NewFutureFromResponse(resp)
   262  	future.FutureAPI = &azf
   263  	future.Result = future.result
   264  	return
   265  }
   266  
   267  // DeleteResourceResponder handles the response to the DeleteResource request. The method always
   268  // closes the http.Response Body.
   269  func (client VirtualMachineClient) DeleteResourceResponder(resp *http.Response) (result autorest.Response, err error) {
   270  	err = autorest.Respond(
   271  		resp,
   272  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   273  		autorest.ByClosing())
   274  	result.Response = resp
   275  	return
   276  }
   277  
   278  // GetResource get virtual machine.
   279  // Parameters:
   280  // resourceGroupName - the name of the resource group.
   281  // labName - the name of the lab.
   282  // name - the name of the virtual Machine.
   283  func (client VirtualMachineClient) GetResource(ctx context.Context, resourceGroupName string, labName string, name string) (result LabVirtualMachine, err error) {
   284  	if tracing.IsEnabled() {
   285  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.GetResource")
   286  		defer func() {
   287  			sc := -1
   288  			if result.Response.Response != nil {
   289  				sc = result.Response.Response.StatusCode
   290  			}
   291  			tracing.EndSpan(ctx, sc, err)
   292  		}()
   293  	}
   294  	req, err := client.GetResourcePreparer(ctx, resourceGroupName, labName, name)
   295  	if err != nil {
   296  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "GetResource", nil, "Failure preparing request")
   297  		return
   298  	}
   299  
   300  	resp, err := client.GetResourceSender(req)
   301  	if err != nil {
   302  		result.Response = autorest.Response{Response: resp}
   303  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "GetResource", resp, "Failure sending request")
   304  		return
   305  	}
   306  
   307  	result, err = client.GetResourceResponder(resp)
   308  	if err != nil {
   309  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "GetResource", resp, "Failure responding to request")
   310  		return
   311  	}
   312  
   313  	return
   314  }
   315  
   316  // GetResourcePreparer prepares the GetResource request.
   317  func (client VirtualMachineClient) GetResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   318  	pathParameters := map[string]interface{}{
   319  		"labName":           autorest.Encode("path", labName),
   320  		"name":              autorest.Encode("path", name),
   321  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   322  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   323  	}
   324  
   325  	const APIVersion = "2015-05-21-preview"
   326  	queryParameters := map[string]interface{}{
   327  		"api-version": APIVersion,
   328  	}
   329  
   330  	preparer := autorest.CreatePreparer(
   331  		autorest.AsGet(),
   332  		autorest.WithBaseURL(client.BaseURI),
   333  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
   334  		autorest.WithQueryParameters(queryParameters))
   335  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   336  }
   337  
   338  // GetResourceSender sends the GetResource request. The method will close the
   339  // http.Response Body if it receives an error.
   340  func (client VirtualMachineClient) GetResourceSender(req *http.Request) (*http.Response, error) {
   341  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   342  }
   343  
   344  // GetResourceResponder handles the response to the GetResource request. The method always
   345  // closes the http.Response Body.
   346  func (client VirtualMachineClient) GetResourceResponder(resp *http.Response) (result LabVirtualMachine, err error) {
   347  	err = autorest.Respond(
   348  		resp,
   349  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   350  		autorest.ByUnmarshallingJSON(&result),
   351  		autorest.ByClosing())
   352  	result.Response = autorest.Response{Response: resp}
   353  	return
   354  }
   355  
   356  // List list virtual machines.
   357  // Parameters:
   358  // resourceGroupName - the name of the resource group.
   359  // labName - the name of the lab.
   360  // filter - the filter to apply on the operation.
   361  func (client VirtualMachineClient) List(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationLabVirtualMachinePage, err error) {
   362  	if tracing.IsEnabled() {
   363  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.List")
   364  		defer func() {
   365  			sc := -1
   366  			if result.rwclvm.Response.Response != nil {
   367  				sc = result.rwclvm.Response.Response.StatusCode
   368  			}
   369  			tracing.EndSpan(ctx, sc, err)
   370  		}()
   371  	}
   372  	result.fn = client.listNextResults
   373  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, filter, top, orderBy)
   374  	if err != nil {
   375  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "List", nil, "Failure preparing request")
   376  		return
   377  	}
   378  
   379  	resp, err := client.ListSender(req)
   380  	if err != nil {
   381  		result.rwclvm.Response = autorest.Response{Response: resp}
   382  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "List", resp, "Failure sending request")
   383  		return
   384  	}
   385  
   386  	result.rwclvm, err = client.ListResponder(resp)
   387  	if err != nil {
   388  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "List", resp, "Failure responding to request")
   389  		return
   390  	}
   391  	if result.rwclvm.hasNextLink() && result.rwclvm.IsEmpty() {
   392  		err = result.NextWithContext(ctx)
   393  		return
   394  	}
   395  
   396  	return
   397  }
   398  
   399  // ListPreparer prepares the List request.
   400  func (client VirtualMachineClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (*http.Request, error) {
   401  	pathParameters := map[string]interface{}{
   402  		"labName":           autorest.Encode("path", labName),
   403  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   404  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   405  	}
   406  
   407  	const APIVersion = "2015-05-21-preview"
   408  	queryParameters := map[string]interface{}{
   409  		"api-version": APIVersion,
   410  	}
   411  	if len(filter) > 0 {
   412  		queryParameters["$filter"] = autorest.Encode("query", filter)
   413  	}
   414  	if top != nil {
   415  		queryParameters["$top"] = autorest.Encode("query", *top)
   416  	}
   417  	if len(orderBy) > 0 {
   418  		queryParameters["$orderBy"] = autorest.Encode("query", orderBy)
   419  	}
   420  
   421  	preparer := autorest.CreatePreparer(
   422  		autorest.AsGet(),
   423  		autorest.WithBaseURL(client.BaseURI),
   424  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines", pathParameters),
   425  		autorest.WithQueryParameters(queryParameters))
   426  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   427  }
   428  
   429  // ListSender sends the List request. The method will close the
   430  // http.Response Body if it receives an error.
   431  func (client VirtualMachineClient) ListSender(req *http.Request) (*http.Response, error) {
   432  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   433  }
   434  
   435  // ListResponder handles the response to the List request. The method always
   436  // closes the http.Response Body.
   437  func (client VirtualMachineClient) ListResponder(resp *http.Response) (result ResponseWithContinuationLabVirtualMachine, err error) {
   438  	err = autorest.Respond(
   439  		resp,
   440  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   441  		autorest.ByUnmarshallingJSON(&result),
   442  		autorest.ByClosing())
   443  	result.Response = autorest.Response{Response: resp}
   444  	return
   445  }
   446  
   447  // listNextResults retrieves the next set of results, if any.
   448  func (client VirtualMachineClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationLabVirtualMachine) (result ResponseWithContinuationLabVirtualMachine, err error) {
   449  	req, err := lastResults.responseWithContinuationLabVirtualMachinePreparer(ctx)
   450  	if err != nil {
   451  		return result, autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "listNextResults", nil, "Failure preparing next results request")
   452  	}
   453  	if req == nil {
   454  		return
   455  	}
   456  	resp, err := client.ListSender(req)
   457  	if err != nil {
   458  		result.Response = autorest.Response{Response: resp}
   459  		return result, autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "listNextResults", resp, "Failure sending next results request")
   460  	}
   461  	result, err = client.ListResponder(resp)
   462  	if err != nil {
   463  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "listNextResults", resp, "Failure responding to next results request")
   464  	}
   465  	return
   466  }
   467  
   468  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   469  func (client VirtualMachineClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationLabVirtualMachineIterator, err error) {
   470  	if tracing.IsEnabled() {
   471  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.List")
   472  		defer func() {
   473  			sc := -1
   474  			if result.Response().Response.Response != nil {
   475  				sc = result.page.Response().Response.Response.StatusCode
   476  			}
   477  			tracing.EndSpan(ctx, sc, err)
   478  		}()
   479  	}
   480  	result.page, err = client.List(ctx, resourceGroupName, labName, filter, top, orderBy)
   481  	return
   482  }
   483  
   484  // PatchResource modify properties of virtual machines.
   485  // Parameters:
   486  // resourceGroupName - the name of the resource group.
   487  // labName - the name of the lab.
   488  // name - the name of the virtual Machine.
   489  func (client VirtualMachineClient) PatchResource(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (result LabVirtualMachine, err error) {
   490  	if tracing.IsEnabled() {
   491  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.PatchResource")
   492  		defer func() {
   493  			sc := -1
   494  			if result.Response.Response != nil {
   495  				sc = result.Response.Response.StatusCode
   496  			}
   497  			tracing.EndSpan(ctx, sc, err)
   498  		}()
   499  	}
   500  	req, err := client.PatchResourcePreparer(ctx, resourceGroupName, labName, name, labVirtualMachine)
   501  	if err != nil {
   502  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "PatchResource", nil, "Failure preparing request")
   503  		return
   504  	}
   505  
   506  	resp, err := client.PatchResourceSender(req)
   507  	if err != nil {
   508  		result.Response = autorest.Response{Response: resp}
   509  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "PatchResource", resp, "Failure sending request")
   510  		return
   511  	}
   512  
   513  	result, err = client.PatchResourceResponder(resp)
   514  	if err != nil {
   515  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "PatchResource", resp, "Failure responding to request")
   516  		return
   517  	}
   518  
   519  	return
   520  }
   521  
   522  // PatchResourcePreparer prepares the PatchResource request.
   523  func (client VirtualMachineClient) PatchResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (*http.Request, error) {
   524  	pathParameters := map[string]interface{}{
   525  		"labName":           autorest.Encode("path", labName),
   526  		"name":              autorest.Encode("path", name),
   527  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   528  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   529  	}
   530  
   531  	const APIVersion = "2015-05-21-preview"
   532  	queryParameters := map[string]interface{}{
   533  		"api-version": APIVersion,
   534  	}
   535  
   536  	preparer := autorest.CreatePreparer(
   537  		autorest.AsContentType("application/json; charset=utf-8"),
   538  		autorest.AsPatch(),
   539  		autorest.WithBaseURL(client.BaseURI),
   540  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
   541  		autorest.WithJSON(labVirtualMachine),
   542  		autorest.WithQueryParameters(queryParameters))
   543  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   544  }
   545  
   546  // PatchResourceSender sends the PatchResource request. The method will close the
   547  // http.Response Body if it receives an error.
   548  func (client VirtualMachineClient) PatchResourceSender(req *http.Request) (*http.Response, error) {
   549  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   550  }
   551  
   552  // PatchResourceResponder handles the response to the PatchResource request. The method always
   553  // closes the http.Response Body.
   554  func (client VirtualMachineClient) PatchResourceResponder(resp *http.Response) (result LabVirtualMachine, err error) {
   555  	err = autorest.Respond(
   556  		resp,
   557  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   558  		autorest.ByUnmarshallingJSON(&result),
   559  		autorest.ByClosing())
   560  	result.Response = autorest.Response{Response: resp}
   561  	return
   562  }
   563  
   564  // Start start a Lab VM. This operation can take a while to complete.
   565  // Parameters:
   566  // resourceGroupName - the name of the resource group.
   567  // labName - the name of the lab.
   568  // name - the name of the virtual Machine.
   569  func (client VirtualMachineClient) Start(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachineStartFuture, err error) {
   570  	if tracing.IsEnabled() {
   571  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.Start")
   572  		defer func() {
   573  			sc := -1
   574  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   575  				sc = result.FutureAPI.Response().StatusCode
   576  			}
   577  			tracing.EndSpan(ctx, sc, err)
   578  		}()
   579  	}
   580  	req, err := client.StartPreparer(ctx, resourceGroupName, labName, name)
   581  	if err != nil {
   582  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "Start", nil, "Failure preparing request")
   583  		return
   584  	}
   585  
   586  	result, err = client.StartSender(req)
   587  	if err != nil {
   588  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "Start", result.Response(), "Failure sending request")
   589  		return
   590  	}
   591  
   592  	return
   593  }
   594  
   595  // StartPreparer prepares the Start request.
   596  func (client VirtualMachineClient) StartPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   597  	pathParameters := map[string]interface{}{
   598  		"labName":           autorest.Encode("path", labName),
   599  		"name":              autorest.Encode("path", name),
   600  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   601  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   602  	}
   603  
   604  	const APIVersion = "2015-05-21-preview"
   605  	queryParameters := map[string]interface{}{
   606  		"api-version": APIVersion,
   607  	}
   608  
   609  	preparer := autorest.CreatePreparer(
   610  		autorest.AsPost(),
   611  		autorest.WithBaseURL(client.BaseURI),
   612  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/start", pathParameters),
   613  		autorest.WithQueryParameters(queryParameters))
   614  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   615  }
   616  
   617  // StartSender sends the Start request. The method will close the
   618  // http.Response Body if it receives an error.
   619  func (client VirtualMachineClient) StartSender(req *http.Request) (future VirtualMachineStartFuture, err error) {
   620  	var resp *http.Response
   621  	future.FutureAPI = &azure.Future{}
   622  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   623  	if err != nil {
   624  		return
   625  	}
   626  	var azf azure.Future
   627  	azf, err = azure.NewFutureFromResponse(resp)
   628  	future.FutureAPI = &azf
   629  	future.Result = future.result
   630  	return
   631  }
   632  
   633  // StartResponder handles the response to the Start request. The method always
   634  // closes the http.Response Body.
   635  func (client VirtualMachineClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
   636  	err = autorest.Respond(
   637  		resp,
   638  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   639  		autorest.ByClosing())
   640  	result.Response = resp
   641  	return
   642  }
   643  
   644  // Stop stop a Lab VM. This operation can take a while to complete.
   645  // Parameters:
   646  // resourceGroupName - the name of the resource group.
   647  // labName - the name of the lab.
   648  // name - the name of the virtual Machine.
   649  func (client VirtualMachineClient) Stop(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachineStopFuture, err error) {
   650  	if tracing.IsEnabled() {
   651  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.Stop")
   652  		defer func() {
   653  			sc := -1
   654  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   655  				sc = result.FutureAPI.Response().StatusCode
   656  			}
   657  			tracing.EndSpan(ctx, sc, err)
   658  		}()
   659  	}
   660  	req, err := client.StopPreparer(ctx, resourceGroupName, labName, name)
   661  	if err != nil {
   662  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "Stop", nil, "Failure preparing request")
   663  		return
   664  	}
   665  
   666  	result, err = client.StopSender(req)
   667  	if err != nil {
   668  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "Stop", result.Response(), "Failure sending request")
   669  		return
   670  	}
   671  
   672  	return
   673  }
   674  
   675  // StopPreparer prepares the Stop request.
   676  func (client VirtualMachineClient) StopPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   677  	pathParameters := map[string]interface{}{
   678  		"labName":           autorest.Encode("path", labName),
   679  		"name":              autorest.Encode("path", name),
   680  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   681  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   682  	}
   683  
   684  	const APIVersion = "2015-05-21-preview"
   685  	queryParameters := map[string]interface{}{
   686  		"api-version": APIVersion,
   687  	}
   688  
   689  	preparer := autorest.CreatePreparer(
   690  		autorest.AsPost(),
   691  		autorest.WithBaseURL(client.BaseURI),
   692  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/stop", pathParameters),
   693  		autorest.WithQueryParameters(queryParameters))
   694  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   695  }
   696  
   697  // StopSender sends the Stop request. The method will close the
   698  // http.Response Body if it receives an error.
   699  func (client VirtualMachineClient) StopSender(req *http.Request) (future VirtualMachineStopFuture, err error) {
   700  	var resp *http.Response
   701  	future.FutureAPI = &azure.Future{}
   702  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   703  	if err != nil {
   704  		return
   705  	}
   706  	var azf azure.Future
   707  	azf, err = azure.NewFutureFromResponse(resp)
   708  	future.FutureAPI = &azf
   709  	future.Result = future.result
   710  	return
   711  }
   712  
   713  // StopResponder handles the response to the Stop request. The method always
   714  // closes the http.Response Body.
   715  func (client VirtualMachineClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
   716  	err = autorest.Respond(
   717  		resp,
   718  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   719  		autorest.ByClosing())
   720  	result.Response = resp
   721  	return
   722  }
   723  

View as plain text