...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl/globalschedules.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  // GlobalSchedulesClient is the the DevTest Labs Client.
    19  type GlobalSchedulesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewGlobalSchedulesClient creates an instance of the GlobalSchedulesClient client.
    24  func NewGlobalSchedulesClient(subscriptionID string) GlobalSchedulesClient {
    25  	return NewGlobalSchedulesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewGlobalSchedulesClientWithBaseURI creates an instance of the GlobalSchedulesClient client using a custom endpoint.
    29  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewGlobalSchedulesClientWithBaseURI(baseURI string, subscriptionID string) GlobalSchedulesClient {
    31  	return GlobalSchedulesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate create or replace an existing schedule.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // name - the name of the schedule.
    38  // schedule - a schedule.
    39  func (client GlobalSchedulesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, name string, schedule Schedule) (result Schedule, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.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  	if err := validation.Validate([]validation.Validation{
    51  		{TargetValue: schedule,
    52  			Constraints: []validation.Constraint{{Target: "schedule.ScheduleProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    53  		return result, validation.NewError("dtl.GlobalSchedulesClient", "CreateOrUpdate", err.Error())
    54  	}
    55  
    56  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, name, schedule)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "CreateOrUpdate", nil, "Failure preparing request")
    59  		return
    60  	}
    61  
    62  	resp, err := client.CreateOrUpdateSender(req)
    63  	if err != nil {
    64  		result.Response = autorest.Response{Response: resp}
    65  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "CreateOrUpdate", resp, "Failure sending request")
    66  		return
    67  	}
    68  
    69  	result, err = client.CreateOrUpdateResponder(resp)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "CreateOrUpdate", resp, "Failure responding to request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    79  func (client GlobalSchedulesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, name string, schedule Schedule) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"name":              autorest.Encode("path", name),
    82  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    83  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    84  	}
    85  
    86  	const APIVersion = "2016-05-15"
    87  	queryParameters := map[string]interface{}{
    88  		"api-version": APIVersion,
    89  	}
    90  
    91  	preparer := autorest.CreatePreparer(
    92  		autorest.AsContentType("application/json; charset=utf-8"),
    93  		autorest.AsPut(),
    94  		autorest.WithBaseURL(client.BaseURI),
    95  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}", pathParameters),
    96  		autorest.WithJSON(schedule),
    97  		autorest.WithQueryParameters(queryParameters))
    98  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    99  }
   100  
   101  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   102  // http.Response Body if it receives an error.
   103  func (client GlobalSchedulesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   104  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   105  }
   106  
   107  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   108  // closes the http.Response Body.
   109  func (client GlobalSchedulesClient) CreateOrUpdateResponder(resp *http.Response) (result Schedule, err error) {
   110  	err = autorest.Respond(
   111  		resp,
   112  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   113  		autorest.ByUnmarshallingJSON(&result),
   114  		autorest.ByClosing())
   115  	result.Response = autorest.Response{Response: resp}
   116  	return
   117  }
   118  
   119  // Delete delete schedule.
   120  // Parameters:
   121  // resourceGroupName - the name of the resource group.
   122  // name - the name of the schedule.
   123  func (client GlobalSchedulesClient) Delete(ctx context.Context, resourceGroupName string, name string) (result autorest.Response, err error) {
   124  	if tracing.IsEnabled() {
   125  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Delete")
   126  		defer func() {
   127  			sc := -1
   128  			if result.Response != nil {
   129  				sc = result.Response.StatusCode
   130  			}
   131  			tracing.EndSpan(ctx, sc, err)
   132  		}()
   133  	}
   134  	req, err := client.DeletePreparer(ctx, resourceGroupName, name)
   135  	if err != nil {
   136  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Delete", nil, "Failure preparing request")
   137  		return
   138  	}
   139  
   140  	resp, err := client.DeleteSender(req)
   141  	if err != nil {
   142  		result.Response = resp
   143  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Delete", resp, "Failure sending request")
   144  		return
   145  	}
   146  
   147  	result, err = client.DeleteResponder(resp)
   148  	if err != nil {
   149  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Delete", resp, "Failure responding to request")
   150  		return
   151  	}
   152  
   153  	return
   154  }
   155  
   156  // DeletePreparer prepares the Delete request.
   157  func (client GlobalSchedulesClient) DeletePreparer(ctx context.Context, resourceGroupName string, name string) (*http.Request, error) {
   158  	pathParameters := map[string]interface{}{
   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/schedules/{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 GlobalSchedulesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   180  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   181  }
   182  
   183  // DeleteResponder handles the response to the Delete request. The method always
   184  // closes the http.Response Body.
   185  func (client GlobalSchedulesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   186  	err = autorest.Respond(
   187  		resp,
   188  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   189  		autorest.ByClosing())
   190  	result.Response = resp
   191  	return
   192  }
   193  
   194  // Execute execute a schedule. This operation can take a while to complete.
   195  // Parameters:
   196  // resourceGroupName - the name of the resource group.
   197  // name - the name of the schedule.
   198  func (client GlobalSchedulesClient) Execute(ctx context.Context, resourceGroupName string, name string) (result GlobalSchedulesExecuteFuture, err error) {
   199  	if tracing.IsEnabled() {
   200  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Execute")
   201  		defer func() {
   202  			sc := -1
   203  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   204  				sc = result.FutureAPI.Response().StatusCode
   205  			}
   206  			tracing.EndSpan(ctx, sc, err)
   207  		}()
   208  	}
   209  	req, err := client.ExecutePreparer(ctx, resourceGroupName, name)
   210  	if err != nil {
   211  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Execute", nil, "Failure preparing request")
   212  		return
   213  	}
   214  
   215  	result, err = client.ExecuteSender(req)
   216  	if err != nil {
   217  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Execute", result.Response(), "Failure sending request")
   218  		return
   219  	}
   220  
   221  	return
   222  }
   223  
   224  // ExecutePreparer prepares the Execute request.
   225  func (client GlobalSchedulesClient) ExecutePreparer(ctx context.Context, resourceGroupName string, name string) (*http.Request, error) {
   226  	pathParameters := map[string]interface{}{
   227  		"name":              autorest.Encode("path", name),
   228  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   229  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   230  	}
   231  
   232  	const APIVersion = "2016-05-15"
   233  	queryParameters := map[string]interface{}{
   234  		"api-version": APIVersion,
   235  	}
   236  
   237  	preparer := autorest.CreatePreparer(
   238  		autorest.AsPost(),
   239  		autorest.WithBaseURL(client.BaseURI),
   240  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/execute", pathParameters),
   241  		autorest.WithQueryParameters(queryParameters))
   242  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   243  }
   244  
   245  // ExecuteSender sends the Execute request. The method will close the
   246  // http.Response Body if it receives an error.
   247  func (client GlobalSchedulesClient) ExecuteSender(req *http.Request) (future GlobalSchedulesExecuteFuture, err error) {
   248  	var resp *http.Response
   249  	future.FutureAPI = &azure.Future{}
   250  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   251  	if err != nil {
   252  		return
   253  	}
   254  	var azf azure.Future
   255  	azf, err = azure.NewFutureFromResponse(resp)
   256  	future.FutureAPI = &azf
   257  	future.Result = future.result
   258  	return
   259  }
   260  
   261  // ExecuteResponder handles the response to the Execute request. The method always
   262  // closes the http.Response Body.
   263  func (client GlobalSchedulesClient) ExecuteResponder(resp *http.Response) (result autorest.Response, err error) {
   264  	err = autorest.Respond(
   265  		resp,
   266  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   267  		autorest.ByClosing())
   268  	result.Response = resp
   269  	return
   270  }
   271  
   272  // Get get schedule.
   273  // Parameters:
   274  // resourceGroupName - the name of the resource group.
   275  // name - the name of the schedule.
   276  // expand - specify the $expand query. Example: 'properties($select=status)'
   277  func (client GlobalSchedulesClient) Get(ctx context.Context, resourceGroupName string, name string, expand string) (result Schedule, err error) {
   278  	if tracing.IsEnabled() {
   279  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Get")
   280  		defer func() {
   281  			sc := -1
   282  			if result.Response.Response != nil {
   283  				sc = result.Response.Response.StatusCode
   284  			}
   285  			tracing.EndSpan(ctx, sc, err)
   286  		}()
   287  	}
   288  	req, err := client.GetPreparer(ctx, resourceGroupName, name, expand)
   289  	if err != nil {
   290  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Get", nil, "Failure preparing request")
   291  		return
   292  	}
   293  
   294  	resp, err := client.GetSender(req)
   295  	if err != nil {
   296  		result.Response = autorest.Response{Response: resp}
   297  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Get", resp, "Failure sending request")
   298  		return
   299  	}
   300  
   301  	result, err = client.GetResponder(resp)
   302  	if err != nil {
   303  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Get", resp, "Failure responding to request")
   304  		return
   305  	}
   306  
   307  	return
   308  }
   309  
   310  // GetPreparer prepares the Get request.
   311  func (client GlobalSchedulesClient) GetPreparer(ctx context.Context, resourceGroupName string, name string, expand string) (*http.Request, error) {
   312  	pathParameters := map[string]interface{}{
   313  		"name":              autorest.Encode("path", name),
   314  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   315  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   316  	}
   317  
   318  	const APIVersion = "2016-05-15"
   319  	queryParameters := map[string]interface{}{
   320  		"api-version": APIVersion,
   321  	}
   322  	if len(expand) > 0 {
   323  		queryParameters["$expand"] = autorest.Encode("query", expand)
   324  	}
   325  
   326  	preparer := autorest.CreatePreparer(
   327  		autorest.AsGet(),
   328  		autorest.WithBaseURL(client.BaseURI),
   329  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}", pathParameters),
   330  		autorest.WithQueryParameters(queryParameters))
   331  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   332  }
   333  
   334  // GetSender sends the Get request. The method will close the
   335  // http.Response Body if it receives an error.
   336  func (client GlobalSchedulesClient) GetSender(req *http.Request) (*http.Response, error) {
   337  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   338  }
   339  
   340  // GetResponder handles the response to the Get request. The method always
   341  // closes the http.Response Body.
   342  func (client GlobalSchedulesClient) GetResponder(resp *http.Response) (result Schedule, err error) {
   343  	err = autorest.Respond(
   344  		resp,
   345  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   346  		autorest.ByUnmarshallingJSON(&result),
   347  		autorest.ByClosing())
   348  	result.Response = autorest.Response{Response: resp}
   349  	return
   350  }
   351  
   352  // ListByResourceGroup list schedules in a resource group.
   353  // Parameters:
   354  // resourceGroupName - the name of the resource group.
   355  // expand - specify the $expand query. Example: 'properties($select=status)'
   356  // filter - the filter to apply to the operation.
   357  // top - the maximum number of resources to return from the operation.
   358  // orderby - the ordering expression for the results, using OData notation.
   359  func (client GlobalSchedulesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationSchedulePage, err error) {
   360  	if tracing.IsEnabled() {
   361  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.ListByResourceGroup")
   362  		defer func() {
   363  			sc := -1
   364  			if result.rwcs.Response.Response != nil {
   365  				sc = result.rwcs.Response.Response.StatusCode
   366  			}
   367  			tracing.EndSpan(ctx, sc, err)
   368  		}()
   369  	}
   370  	result.fn = client.listByResourceGroupNextResults
   371  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, expand, filter, top, orderby)
   372  	if err != nil {
   373  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListByResourceGroup", nil, "Failure preparing request")
   374  		return
   375  	}
   376  
   377  	resp, err := client.ListByResourceGroupSender(req)
   378  	if err != nil {
   379  		result.rwcs.Response = autorest.Response{Response: resp}
   380  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListByResourceGroup", resp, "Failure sending request")
   381  		return
   382  	}
   383  
   384  	result.rwcs, err = client.ListByResourceGroupResponder(resp)
   385  	if err != nil {
   386  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListByResourceGroup", resp, "Failure responding to request")
   387  		return
   388  	}
   389  	if result.rwcs.hasNextLink() && result.rwcs.IsEmpty() {
   390  		err = result.NextWithContext(ctx)
   391  		return
   392  	}
   393  
   394  	return
   395  }
   396  
   397  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   398  func (client GlobalSchedulesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   399  	pathParameters := map[string]interface{}{
   400  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   401  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   402  	}
   403  
   404  	const APIVersion = "2016-05-15"
   405  	queryParameters := map[string]interface{}{
   406  		"api-version": APIVersion,
   407  	}
   408  	if len(expand) > 0 {
   409  		queryParameters["$expand"] = autorest.Encode("query", expand)
   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/schedules", pathParameters),
   425  		autorest.WithQueryParameters(queryParameters))
   426  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   427  }
   428  
   429  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   430  // http.Response Body if it receives an error.
   431  func (client GlobalSchedulesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   432  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   433  }
   434  
   435  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   436  // closes the http.Response Body.
   437  func (client GlobalSchedulesClient) ListByResourceGroupResponder(resp *http.Response) (result ResponseWithContinuationSchedule, 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  // listByResourceGroupNextResults retrieves the next set of results, if any.
   448  func (client GlobalSchedulesClient) listByResourceGroupNextResults(ctx context.Context, lastResults ResponseWithContinuationSchedule) (result ResponseWithContinuationSchedule, err error) {
   449  	req, err := lastResults.responseWithContinuationSchedulePreparer(ctx)
   450  	if err != nil {
   451  		return result, autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
   452  	}
   453  	if req == nil {
   454  		return
   455  	}
   456  	resp, err := client.ListByResourceGroupSender(req)
   457  	if err != nil {
   458  		result.Response = autorest.Response{Response: resp}
   459  		return result, autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
   460  	}
   461  	result, err = client.ListByResourceGroupResponder(resp)
   462  	if err != nil {
   463  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
   464  	}
   465  	return
   466  }
   467  
   468  // ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
   469  func (client GlobalSchedulesClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationScheduleIterator, err error) {
   470  	if tracing.IsEnabled() {
   471  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.ListByResourceGroup")
   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.ListByResourceGroup(ctx, resourceGroupName, expand, filter, top, orderby)
   481  	return
   482  }
   483  
   484  // ListBySubscription list schedules in a subscription.
   485  // Parameters:
   486  // expand - specify the $expand query. Example: 'properties($select=status)'
   487  // filter - the filter to apply to the operation.
   488  // top - the maximum number of resources to return from the operation.
   489  // orderby - the ordering expression for the results, using OData notation.
   490  func (client GlobalSchedulesClient) ListBySubscription(ctx context.Context, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationSchedulePage, err error) {
   491  	if tracing.IsEnabled() {
   492  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.ListBySubscription")
   493  		defer func() {
   494  			sc := -1
   495  			if result.rwcs.Response.Response != nil {
   496  				sc = result.rwcs.Response.Response.StatusCode
   497  			}
   498  			tracing.EndSpan(ctx, sc, err)
   499  		}()
   500  	}
   501  	result.fn = client.listBySubscriptionNextResults
   502  	req, err := client.ListBySubscriptionPreparer(ctx, expand, filter, top, orderby)
   503  	if err != nil {
   504  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListBySubscription", nil, "Failure preparing request")
   505  		return
   506  	}
   507  
   508  	resp, err := client.ListBySubscriptionSender(req)
   509  	if err != nil {
   510  		result.rwcs.Response = autorest.Response{Response: resp}
   511  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListBySubscription", resp, "Failure sending request")
   512  		return
   513  	}
   514  
   515  	result.rwcs, err = client.ListBySubscriptionResponder(resp)
   516  	if err != nil {
   517  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListBySubscription", resp, "Failure responding to request")
   518  		return
   519  	}
   520  	if result.rwcs.hasNextLink() && result.rwcs.IsEmpty() {
   521  		err = result.NextWithContext(ctx)
   522  		return
   523  	}
   524  
   525  	return
   526  }
   527  
   528  // ListBySubscriptionPreparer prepares the ListBySubscription request.
   529  func (client GlobalSchedulesClient) ListBySubscriptionPreparer(ctx context.Context, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   530  	pathParameters := map[string]interface{}{
   531  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   532  	}
   533  
   534  	const APIVersion = "2016-05-15"
   535  	queryParameters := map[string]interface{}{
   536  		"api-version": APIVersion,
   537  	}
   538  	if len(expand) > 0 {
   539  		queryParameters["$expand"] = autorest.Encode("query", expand)
   540  	}
   541  	if len(filter) > 0 {
   542  		queryParameters["$filter"] = autorest.Encode("query", filter)
   543  	}
   544  	if top != nil {
   545  		queryParameters["$top"] = autorest.Encode("query", *top)
   546  	}
   547  	if len(orderby) > 0 {
   548  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   549  	}
   550  
   551  	preparer := autorest.CreatePreparer(
   552  		autorest.AsGet(),
   553  		autorest.WithBaseURL(client.BaseURI),
   554  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DevTestLab/schedules", pathParameters),
   555  		autorest.WithQueryParameters(queryParameters))
   556  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   557  }
   558  
   559  // ListBySubscriptionSender sends the ListBySubscription request. The method will close the
   560  // http.Response Body if it receives an error.
   561  func (client GlobalSchedulesClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
   562  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   563  }
   564  
   565  // ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
   566  // closes the http.Response Body.
   567  func (client GlobalSchedulesClient) ListBySubscriptionResponder(resp *http.Response) (result ResponseWithContinuationSchedule, err error) {
   568  	err = autorest.Respond(
   569  		resp,
   570  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   571  		autorest.ByUnmarshallingJSON(&result),
   572  		autorest.ByClosing())
   573  	result.Response = autorest.Response{Response: resp}
   574  	return
   575  }
   576  
   577  // listBySubscriptionNextResults retrieves the next set of results, if any.
   578  func (client GlobalSchedulesClient) listBySubscriptionNextResults(ctx context.Context, lastResults ResponseWithContinuationSchedule) (result ResponseWithContinuationSchedule, err error) {
   579  	req, err := lastResults.responseWithContinuationSchedulePreparer(ctx)
   580  	if err != nil {
   581  		return result, autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request")
   582  	}
   583  	if req == nil {
   584  		return
   585  	}
   586  	resp, err := client.ListBySubscriptionSender(req)
   587  	if err != nil {
   588  		result.Response = autorest.Response{Response: resp}
   589  		return result, autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listBySubscriptionNextResults", resp, "Failure sending next results request")
   590  	}
   591  	result, err = client.ListBySubscriptionResponder(resp)
   592  	if err != nil {
   593  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request")
   594  	}
   595  	return
   596  }
   597  
   598  // ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required.
   599  func (client GlobalSchedulesClient) ListBySubscriptionComplete(ctx context.Context, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationScheduleIterator, err error) {
   600  	if tracing.IsEnabled() {
   601  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.ListBySubscription")
   602  		defer func() {
   603  			sc := -1
   604  			if result.Response().Response.Response != nil {
   605  				sc = result.page.Response().Response.Response.StatusCode
   606  			}
   607  			tracing.EndSpan(ctx, sc, err)
   608  		}()
   609  	}
   610  	result.page, err = client.ListBySubscription(ctx, expand, filter, top, orderby)
   611  	return
   612  }
   613  
   614  // Retarget updates a schedule's target resource Id. This operation can take a while to complete.
   615  // Parameters:
   616  // resourceGroupName - the name of the resource group.
   617  // name - the name of the schedule.
   618  // retargetScheduleProperties - properties for retargeting a virtual machine schedule.
   619  func (client GlobalSchedulesClient) Retarget(ctx context.Context, resourceGroupName string, name string, retargetScheduleProperties RetargetScheduleProperties) (result GlobalSchedulesRetargetFuture, err error) {
   620  	if tracing.IsEnabled() {
   621  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Retarget")
   622  		defer func() {
   623  			sc := -1
   624  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   625  				sc = result.FutureAPI.Response().StatusCode
   626  			}
   627  			tracing.EndSpan(ctx, sc, err)
   628  		}()
   629  	}
   630  	req, err := client.RetargetPreparer(ctx, resourceGroupName, name, retargetScheduleProperties)
   631  	if err != nil {
   632  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Retarget", nil, "Failure preparing request")
   633  		return
   634  	}
   635  
   636  	result, err = client.RetargetSender(req)
   637  	if err != nil {
   638  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Retarget", result.Response(), "Failure sending request")
   639  		return
   640  	}
   641  
   642  	return
   643  }
   644  
   645  // RetargetPreparer prepares the Retarget request.
   646  func (client GlobalSchedulesClient) RetargetPreparer(ctx context.Context, resourceGroupName string, name string, retargetScheduleProperties RetargetScheduleProperties) (*http.Request, error) {
   647  	pathParameters := map[string]interface{}{
   648  		"name":              autorest.Encode("path", name),
   649  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   650  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   651  	}
   652  
   653  	const APIVersion = "2016-05-15"
   654  	queryParameters := map[string]interface{}{
   655  		"api-version": APIVersion,
   656  	}
   657  
   658  	preparer := autorest.CreatePreparer(
   659  		autorest.AsContentType("application/json; charset=utf-8"),
   660  		autorest.AsPost(),
   661  		autorest.WithBaseURL(client.BaseURI),
   662  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/retarget", pathParameters),
   663  		autorest.WithJSON(retargetScheduleProperties),
   664  		autorest.WithQueryParameters(queryParameters))
   665  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   666  }
   667  
   668  // RetargetSender sends the Retarget request. The method will close the
   669  // http.Response Body if it receives an error.
   670  func (client GlobalSchedulesClient) RetargetSender(req *http.Request) (future GlobalSchedulesRetargetFuture, err error) {
   671  	var resp *http.Response
   672  	future.FutureAPI = &azure.Future{}
   673  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   674  	if err != nil {
   675  		return
   676  	}
   677  	var azf azure.Future
   678  	azf, err = azure.NewFutureFromResponse(resp)
   679  	future.FutureAPI = &azf
   680  	future.Result = future.result
   681  	return
   682  }
   683  
   684  // RetargetResponder handles the response to the Retarget request. The method always
   685  // closes the http.Response Body.
   686  func (client GlobalSchedulesClient) RetargetResponder(resp *http.Response) (result autorest.Response, err error) {
   687  	err = autorest.Respond(
   688  		resp,
   689  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   690  		autorest.ByClosing())
   691  	result.Response = resp
   692  	return
   693  }
   694  
   695  // Update modify properties of schedules.
   696  // Parameters:
   697  // resourceGroupName - the name of the resource group.
   698  // name - the name of the schedule.
   699  // schedule - a schedule.
   700  func (client GlobalSchedulesClient) Update(ctx context.Context, resourceGroupName string, name string, schedule ScheduleFragment) (result Schedule, err error) {
   701  	if tracing.IsEnabled() {
   702  		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Update")
   703  		defer func() {
   704  			sc := -1
   705  			if result.Response.Response != nil {
   706  				sc = result.Response.Response.StatusCode
   707  			}
   708  			tracing.EndSpan(ctx, sc, err)
   709  		}()
   710  	}
   711  	req, err := client.UpdatePreparer(ctx, resourceGroupName, name, schedule)
   712  	if err != nil {
   713  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Update", nil, "Failure preparing request")
   714  		return
   715  	}
   716  
   717  	resp, err := client.UpdateSender(req)
   718  	if err != nil {
   719  		result.Response = autorest.Response{Response: resp}
   720  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Update", resp, "Failure sending request")
   721  		return
   722  	}
   723  
   724  	result, err = client.UpdateResponder(resp)
   725  	if err != nil {
   726  		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Update", resp, "Failure responding to request")
   727  		return
   728  	}
   729  
   730  	return
   731  }
   732  
   733  // UpdatePreparer prepares the Update request.
   734  func (client GlobalSchedulesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, name string, schedule ScheduleFragment) (*http.Request, error) {
   735  	pathParameters := map[string]interface{}{
   736  		"name":              autorest.Encode("path", name),
   737  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   738  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   739  	}
   740  
   741  	const APIVersion = "2016-05-15"
   742  	queryParameters := map[string]interface{}{
   743  		"api-version": APIVersion,
   744  	}
   745  
   746  	preparer := autorest.CreatePreparer(
   747  		autorest.AsContentType("application/json; charset=utf-8"),
   748  		autorest.AsPatch(),
   749  		autorest.WithBaseURL(client.BaseURI),
   750  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}", pathParameters),
   751  		autorest.WithJSON(schedule),
   752  		autorest.WithQueryParameters(queryParameters))
   753  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   754  }
   755  
   756  // UpdateSender sends the Update request. The method will close the
   757  // http.Response Body if it receives an error.
   758  func (client GlobalSchedulesClient) UpdateSender(req *http.Request) (*http.Response, error) {
   759  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   760  }
   761  
   762  // UpdateResponder handles the response to the Update request. The method always
   763  // closes the http.Response Body.
   764  func (client GlobalSchedulesClient) UpdateResponder(resp *http.Response) (result Schedule, err error) {
   765  	err = autorest.Respond(
   766  		resp,
   767  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   768  		autorest.ByUnmarshallingJSON(&result),
   769  		autorest.ByClosing())
   770  	result.Response = autorest.Response{Response: resp}
   771  	return
   772  }
   773  

View as plain text