...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl/virtualmachineschedules.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  // VirtualMachineSchedulesClient is the the DevTest Labs Client.
    19  type VirtualMachineSchedulesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewVirtualMachineSchedulesClient creates an instance of the VirtualMachineSchedulesClient client.
    24  func NewVirtualMachineSchedulesClient(subscriptionID string) VirtualMachineSchedulesClient {
    25  	return NewVirtualMachineSchedulesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewVirtualMachineSchedulesClientWithBaseURI creates an instance of the VirtualMachineSchedulesClient client using a
    29  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    30  // Azure stack).
    31  func NewVirtualMachineSchedulesClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineSchedulesClient {
    32  	return VirtualMachineSchedulesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate create or replace an existing schedule.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group.
    38  // labName - the name of the lab.
    39  // virtualMachineName - the name of the virtual machine.
    40  // name - the name of the schedule.
    41  // schedule - a schedule.
    42  func (client VirtualMachineSchedulesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string, schedule Schedule) (result Schedule, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineSchedulesClient.CreateOrUpdate")
    45  		defer func() {
    46  			sc := -1
    47  			if result.Response.Response != nil {
    48  				sc = result.Response.Response.StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	if err := validation.Validate([]validation.Validation{
    54  		{TargetValue: schedule,
    55  			Constraints: []validation.Constraint{{Target: "schedule.ScheduleProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    56  		return result, validation.NewError("dtl.VirtualMachineSchedulesClient", "CreateOrUpdate", err.Error())
    57  	}
    58  
    59  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, virtualMachineName, name, schedule)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "CreateOrUpdate", nil, "Failure preparing request")
    62  		return
    63  	}
    64  
    65  	resp, err := client.CreateOrUpdateSender(req)
    66  	if err != nil {
    67  		result.Response = autorest.Response{Response: resp}
    68  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "CreateOrUpdate", resp, "Failure sending request")
    69  		return
    70  	}
    71  
    72  	result, err = client.CreateOrUpdateResponder(resp)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "CreateOrUpdate", resp, "Failure responding to request")
    75  		return
    76  	}
    77  
    78  	return
    79  }
    80  
    81  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    82  func (client VirtualMachineSchedulesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string, schedule Schedule) (*http.Request, error) {
    83  	pathParameters := map[string]interface{}{
    84  		"labName":            autorest.Encode("path", labName),
    85  		"name":               autorest.Encode("path", name),
    86  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
    87  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
    88  		"virtualMachineName": autorest.Encode("path", virtualMachineName),
    89  	}
    90  
    91  	const APIVersion = "2016-05-15"
    92  	queryParameters := map[string]interface{}{
    93  		"api-version": APIVersion,
    94  	}
    95  
    96  	preparer := autorest.CreatePreparer(
    97  		autorest.AsContentType("application/json; charset=utf-8"),
    98  		autorest.AsPut(),
    99  		autorest.WithBaseURL(client.BaseURI),
   100  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}", pathParameters),
   101  		autorest.WithJSON(schedule),
   102  		autorest.WithQueryParameters(queryParameters))
   103  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   104  }
   105  
   106  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   107  // http.Response Body if it receives an error.
   108  func (client VirtualMachineSchedulesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   109  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   110  }
   111  
   112  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   113  // closes the http.Response Body.
   114  func (client VirtualMachineSchedulesClient) CreateOrUpdateResponder(resp *http.Response) (result Schedule, 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 schedule.
   125  // Parameters:
   126  // resourceGroupName - the name of the resource group.
   127  // labName - the name of the lab.
   128  // virtualMachineName - the name of the virtual machine.
   129  // name - the name of the schedule.
   130  func (client VirtualMachineSchedulesClient) Delete(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string) (result autorest.Response, err error) {
   131  	if tracing.IsEnabled() {
   132  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineSchedulesClient.Delete")
   133  		defer func() {
   134  			sc := -1
   135  			if result.Response != nil {
   136  				sc = result.Response.StatusCode
   137  			}
   138  			tracing.EndSpan(ctx, sc, err)
   139  		}()
   140  	}
   141  	req, err := client.DeletePreparer(ctx, resourceGroupName, labName, virtualMachineName, name)
   142  	if err != nil {
   143  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Delete", nil, "Failure preparing request")
   144  		return
   145  	}
   146  
   147  	resp, err := client.DeleteSender(req)
   148  	if err != nil {
   149  		result.Response = resp
   150  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Delete", resp, "Failure sending request")
   151  		return
   152  	}
   153  
   154  	result, err = client.DeleteResponder(resp)
   155  	if err != nil {
   156  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Delete", resp, "Failure responding to request")
   157  		return
   158  	}
   159  
   160  	return
   161  }
   162  
   163  // DeletePreparer prepares the Delete request.
   164  func (client VirtualMachineSchedulesClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string) (*http.Request, error) {
   165  	pathParameters := map[string]interface{}{
   166  		"labName":            autorest.Encode("path", labName),
   167  		"name":               autorest.Encode("path", name),
   168  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   169  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   170  		"virtualMachineName": autorest.Encode("path", virtualMachineName),
   171  	}
   172  
   173  	const APIVersion = "2016-05-15"
   174  	queryParameters := map[string]interface{}{
   175  		"api-version": APIVersion,
   176  	}
   177  
   178  	preparer := autorest.CreatePreparer(
   179  		autorest.AsDelete(),
   180  		autorest.WithBaseURL(client.BaseURI),
   181  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}", pathParameters),
   182  		autorest.WithQueryParameters(queryParameters))
   183  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   184  }
   185  
   186  // DeleteSender sends the Delete request. The method will close the
   187  // http.Response Body if it receives an error.
   188  func (client VirtualMachineSchedulesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   189  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   190  }
   191  
   192  // DeleteResponder handles the response to the Delete request. The method always
   193  // closes the http.Response Body.
   194  func (client VirtualMachineSchedulesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   195  	err = autorest.Respond(
   196  		resp,
   197  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   198  		autorest.ByClosing())
   199  	result.Response = resp
   200  	return
   201  }
   202  
   203  // Execute execute a schedule. This operation can take a while to complete.
   204  // Parameters:
   205  // resourceGroupName - the name of the resource group.
   206  // labName - the name of the lab.
   207  // virtualMachineName - the name of the virtual machine.
   208  // name - the name of the schedule.
   209  func (client VirtualMachineSchedulesClient) Execute(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string) (result VirtualMachineSchedulesExecuteFuture, err error) {
   210  	if tracing.IsEnabled() {
   211  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineSchedulesClient.Execute")
   212  		defer func() {
   213  			sc := -1
   214  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   215  				sc = result.FutureAPI.Response().StatusCode
   216  			}
   217  			tracing.EndSpan(ctx, sc, err)
   218  		}()
   219  	}
   220  	req, err := client.ExecutePreparer(ctx, resourceGroupName, labName, virtualMachineName, name)
   221  	if err != nil {
   222  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Execute", nil, "Failure preparing request")
   223  		return
   224  	}
   225  
   226  	result, err = client.ExecuteSender(req)
   227  	if err != nil {
   228  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Execute", result.Response(), "Failure sending request")
   229  		return
   230  	}
   231  
   232  	return
   233  }
   234  
   235  // ExecutePreparer prepares the Execute request.
   236  func (client VirtualMachineSchedulesClient) ExecutePreparer(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string) (*http.Request, error) {
   237  	pathParameters := map[string]interface{}{
   238  		"labName":            autorest.Encode("path", labName),
   239  		"name":               autorest.Encode("path", name),
   240  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   241  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   242  		"virtualMachineName": autorest.Encode("path", virtualMachineName),
   243  	}
   244  
   245  	const APIVersion = "2016-05-15"
   246  	queryParameters := map[string]interface{}{
   247  		"api-version": APIVersion,
   248  	}
   249  
   250  	preparer := autorest.CreatePreparer(
   251  		autorest.AsPost(),
   252  		autorest.WithBaseURL(client.BaseURI),
   253  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}/execute", pathParameters),
   254  		autorest.WithQueryParameters(queryParameters))
   255  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   256  }
   257  
   258  // ExecuteSender sends the Execute request. The method will close the
   259  // http.Response Body if it receives an error.
   260  func (client VirtualMachineSchedulesClient) ExecuteSender(req *http.Request) (future VirtualMachineSchedulesExecuteFuture, err error) {
   261  	var resp *http.Response
   262  	future.FutureAPI = &azure.Future{}
   263  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   264  	if err != nil {
   265  		return
   266  	}
   267  	var azf azure.Future
   268  	azf, err = azure.NewFutureFromResponse(resp)
   269  	future.FutureAPI = &azf
   270  	future.Result = future.result
   271  	return
   272  }
   273  
   274  // ExecuteResponder handles the response to the Execute request. The method always
   275  // closes the http.Response Body.
   276  func (client VirtualMachineSchedulesClient) ExecuteResponder(resp *http.Response) (result autorest.Response, err error) {
   277  	err = autorest.Respond(
   278  		resp,
   279  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   280  		autorest.ByClosing())
   281  	result.Response = resp
   282  	return
   283  }
   284  
   285  // Get get schedule.
   286  // Parameters:
   287  // resourceGroupName - the name of the resource group.
   288  // labName - the name of the lab.
   289  // virtualMachineName - the name of the virtual machine.
   290  // name - the name of the schedule.
   291  // expand - specify the $expand query. Example: 'properties($select=status)'
   292  func (client VirtualMachineSchedulesClient) Get(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string, expand string) (result Schedule, err error) {
   293  	if tracing.IsEnabled() {
   294  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineSchedulesClient.Get")
   295  		defer func() {
   296  			sc := -1
   297  			if result.Response.Response != nil {
   298  				sc = result.Response.Response.StatusCode
   299  			}
   300  			tracing.EndSpan(ctx, sc, err)
   301  		}()
   302  	}
   303  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, virtualMachineName, name, expand)
   304  	if err != nil {
   305  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Get", nil, "Failure preparing request")
   306  		return
   307  	}
   308  
   309  	resp, err := client.GetSender(req)
   310  	if err != nil {
   311  		result.Response = autorest.Response{Response: resp}
   312  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Get", resp, "Failure sending request")
   313  		return
   314  	}
   315  
   316  	result, err = client.GetResponder(resp)
   317  	if err != nil {
   318  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Get", resp, "Failure responding to request")
   319  		return
   320  	}
   321  
   322  	return
   323  }
   324  
   325  // GetPreparer prepares the Get request.
   326  func (client VirtualMachineSchedulesClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string, expand string) (*http.Request, error) {
   327  	pathParameters := map[string]interface{}{
   328  		"labName":            autorest.Encode("path", labName),
   329  		"name":               autorest.Encode("path", name),
   330  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   331  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   332  		"virtualMachineName": autorest.Encode("path", virtualMachineName),
   333  	}
   334  
   335  	const APIVersion = "2016-05-15"
   336  	queryParameters := map[string]interface{}{
   337  		"api-version": APIVersion,
   338  	}
   339  	if len(expand) > 0 {
   340  		queryParameters["$expand"] = autorest.Encode("query", expand)
   341  	}
   342  
   343  	preparer := autorest.CreatePreparer(
   344  		autorest.AsGet(),
   345  		autorest.WithBaseURL(client.BaseURI),
   346  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}", pathParameters),
   347  		autorest.WithQueryParameters(queryParameters))
   348  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   349  }
   350  
   351  // GetSender sends the Get request. The method will close the
   352  // http.Response Body if it receives an error.
   353  func (client VirtualMachineSchedulesClient) GetSender(req *http.Request) (*http.Response, error) {
   354  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   355  }
   356  
   357  // GetResponder handles the response to the Get request. The method always
   358  // closes the http.Response Body.
   359  func (client VirtualMachineSchedulesClient) GetResponder(resp *http.Response) (result Schedule, err error) {
   360  	err = autorest.Respond(
   361  		resp,
   362  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   363  		autorest.ByUnmarshallingJSON(&result),
   364  		autorest.ByClosing())
   365  	result.Response = autorest.Response{Response: resp}
   366  	return
   367  }
   368  
   369  // List list schedules in a given virtual machine.
   370  // Parameters:
   371  // resourceGroupName - the name of the resource group.
   372  // labName - the name of the lab.
   373  // virtualMachineName - the name of the virtual machine.
   374  // expand - specify the $expand query. Example: 'properties($select=status)'
   375  // filter - the filter to apply to the operation.
   376  // top - the maximum number of resources to return from the operation.
   377  // orderby - the ordering expression for the results, using OData notation.
   378  func (client VirtualMachineSchedulesClient) List(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationSchedulePage, err error) {
   379  	if tracing.IsEnabled() {
   380  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineSchedulesClient.List")
   381  		defer func() {
   382  			sc := -1
   383  			if result.rwcs.Response.Response != nil {
   384  				sc = result.rwcs.Response.Response.StatusCode
   385  			}
   386  			tracing.EndSpan(ctx, sc, err)
   387  		}()
   388  	}
   389  	result.fn = client.listNextResults
   390  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, virtualMachineName, expand, filter, top, orderby)
   391  	if err != nil {
   392  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "List", nil, "Failure preparing request")
   393  		return
   394  	}
   395  
   396  	resp, err := client.ListSender(req)
   397  	if err != nil {
   398  		result.rwcs.Response = autorest.Response{Response: resp}
   399  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "List", resp, "Failure sending request")
   400  		return
   401  	}
   402  
   403  	result.rwcs, err = client.ListResponder(resp)
   404  	if err != nil {
   405  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "List", resp, "Failure responding to request")
   406  		return
   407  	}
   408  	if result.rwcs.hasNextLink() && result.rwcs.IsEmpty() {
   409  		err = result.NextWithContext(ctx)
   410  		return
   411  	}
   412  
   413  	return
   414  }
   415  
   416  // ListPreparer prepares the List request.
   417  func (client VirtualMachineSchedulesClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   418  	pathParameters := map[string]interface{}{
   419  		"labName":            autorest.Encode("path", labName),
   420  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   421  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   422  		"virtualMachineName": autorest.Encode("path", virtualMachineName),
   423  	}
   424  
   425  	const APIVersion = "2016-05-15"
   426  	queryParameters := map[string]interface{}{
   427  		"api-version": APIVersion,
   428  	}
   429  	if len(expand) > 0 {
   430  		queryParameters["$expand"] = autorest.Encode("query", expand)
   431  	}
   432  	if len(filter) > 0 {
   433  		queryParameters["$filter"] = autorest.Encode("query", filter)
   434  	}
   435  	if top != nil {
   436  		queryParameters["$top"] = autorest.Encode("query", *top)
   437  	}
   438  	if len(orderby) > 0 {
   439  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   440  	}
   441  
   442  	preparer := autorest.CreatePreparer(
   443  		autorest.AsGet(),
   444  		autorest.WithBaseURL(client.BaseURI),
   445  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules", pathParameters),
   446  		autorest.WithQueryParameters(queryParameters))
   447  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   448  }
   449  
   450  // ListSender sends the List request. The method will close the
   451  // http.Response Body if it receives an error.
   452  func (client VirtualMachineSchedulesClient) ListSender(req *http.Request) (*http.Response, error) {
   453  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   454  }
   455  
   456  // ListResponder handles the response to the List request. The method always
   457  // closes the http.Response Body.
   458  func (client VirtualMachineSchedulesClient) ListResponder(resp *http.Response) (result ResponseWithContinuationSchedule, err error) {
   459  	err = autorest.Respond(
   460  		resp,
   461  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   462  		autorest.ByUnmarshallingJSON(&result),
   463  		autorest.ByClosing())
   464  	result.Response = autorest.Response{Response: resp}
   465  	return
   466  }
   467  
   468  // listNextResults retrieves the next set of results, if any.
   469  func (client VirtualMachineSchedulesClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationSchedule) (result ResponseWithContinuationSchedule, err error) {
   470  	req, err := lastResults.responseWithContinuationSchedulePreparer(ctx)
   471  	if err != nil {
   472  		return result, autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "listNextResults", nil, "Failure preparing next results request")
   473  	}
   474  	if req == nil {
   475  		return
   476  	}
   477  	resp, err := client.ListSender(req)
   478  	if err != nil {
   479  		result.Response = autorest.Response{Response: resp}
   480  		return result, autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "listNextResults", resp, "Failure sending next results request")
   481  	}
   482  	result, err = client.ListResponder(resp)
   483  	if err != nil {
   484  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "listNextResults", resp, "Failure responding to next results request")
   485  	}
   486  	return
   487  }
   488  
   489  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   490  func (client VirtualMachineSchedulesClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationScheduleIterator, err error) {
   491  	if tracing.IsEnabled() {
   492  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineSchedulesClient.List")
   493  		defer func() {
   494  			sc := -1
   495  			if result.Response().Response.Response != nil {
   496  				sc = result.page.Response().Response.Response.StatusCode
   497  			}
   498  			tracing.EndSpan(ctx, sc, err)
   499  		}()
   500  	}
   501  	result.page, err = client.List(ctx, resourceGroupName, labName, virtualMachineName, expand, filter, top, orderby)
   502  	return
   503  }
   504  
   505  // Update modify properties of schedules.
   506  // Parameters:
   507  // resourceGroupName - the name of the resource group.
   508  // labName - the name of the lab.
   509  // virtualMachineName - the name of the virtual machine.
   510  // name - the name of the schedule.
   511  // schedule - a schedule.
   512  func (client VirtualMachineSchedulesClient) Update(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string, schedule ScheduleFragment) (result Schedule, err error) {
   513  	if tracing.IsEnabled() {
   514  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineSchedulesClient.Update")
   515  		defer func() {
   516  			sc := -1
   517  			if result.Response.Response != nil {
   518  				sc = result.Response.Response.StatusCode
   519  			}
   520  			tracing.EndSpan(ctx, sc, err)
   521  		}()
   522  	}
   523  	req, err := client.UpdatePreparer(ctx, resourceGroupName, labName, virtualMachineName, name, schedule)
   524  	if err != nil {
   525  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Update", nil, "Failure preparing request")
   526  		return
   527  	}
   528  
   529  	resp, err := client.UpdateSender(req)
   530  	if err != nil {
   531  		result.Response = autorest.Response{Response: resp}
   532  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Update", resp, "Failure sending request")
   533  		return
   534  	}
   535  
   536  	result, err = client.UpdateResponder(resp)
   537  	if err != nil {
   538  		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineSchedulesClient", "Update", resp, "Failure responding to request")
   539  		return
   540  	}
   541  
   542  	return
   543  }
   544  
   545  // UpdatePreparer prepares the Update request.
   546  func (client VirtualMachineSchedulesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, labName string, virtualMachineName string, name string, schedule ScheduleFragment) (*http.Request, error) {
   547  	pathParameters := map[string]interface{}{
   548  		"labName":            autorest.Encode("path", labName),
   549  		"name":               autorest.Encode("path", name),
   550  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   551  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   552  		"virtualMachineName": autorest.Encode("path", virtualMachineName),
   553  	}
   554  
   555  	const APIVersion = "2016-05-15"
   556  	queryParameters := map[string]interface{}{
   557  		"api-version": APIVersion,
   558  	}
   559  
   560  	preparer := autorest.CreatePreparer(
   561  		autorest.AsContentType("application/json; charset=utf-8"),
   562  		autorest.AsPatch(),
   563  		autorest.WithBaseURL(client.BaseURI),
   564  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}", pathParameters),
   565  		autorest.WithJSON(schedule),
   566  		autorest.WithQueryParameters(queryParameters))
   567  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   568  }
   569  
   570  // UpdateSender sends the Update request. The method will close the
   571  // http.Response Body if it receives an error.
   572  func (client VirtualMachineSchedulesClient) UpdateSender(req *http.Request) (*http.Response, error) {
   573  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   574  }
   575  
   576  // UpdateResponder handles the response to the Update request. The method always
   577  // closes the http.Response Body.
   578  func (client VirtualMachineSchedulesClient) UpdateResponder(resp *http.Response) (result Schedule, err error) {
   579  	err = autorest.Respond(
   580  		resp,
   581  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   582  		autorest.ByUnmarshallingJSON(&result),
   583  		autorest.ByClosing())
   584  	result.Response = autorest.Response{Response: resp}
   585  	return
   586  }
   587  

View as plain text