...

Source file src/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-03-30/compute/virtualmachineruncommands.go

Documentation: github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-03-30/compute

     1  package compute
     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  // VirtualMachineRunCommandsClient is the compute Client
    19  type VirtualMachineRunCommandsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewVirtualMachineRunCommandsClient creates an instance of the VirtualMachineRunCommandsClient client.
    24  func NewVirtualMachineRunCommandsClient(subscriptionID string) VirtualMachineRunCommandsClient {
    25  	return NewVirtualMachineRunCommandsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewVirtualMachineRunCommandsClientWithBaseURI creates an instance of the VirtualMachineRunCommandsClient client
    29  // using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    30  // clouds, Azure stack).
    31  func NewVirtualMachineRunCommandsClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineRunCommandsClient {
    32  	return VirtualMachineRunCommandsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // Get gets specific run command for a subscription in a location.
    36  // Parameters:
    37  // location - the location upon which run commands is queried.
    38  // commandID - the command id.
    39  func (client VirtualMachineRunCommandsClient) Get(ctx context.Context, location string, commandID string) (result RunCommandDocument, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineRunCommandsClient.Get")
    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: location,
    52  			Constraints: []validation.Constraint{{Target: "location", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
    53  		return result, validation.NewError("compute.VirtualMachineRunCommandsClient", "Get", err.Error())
    54  	}
    55  
    56  	req, err := client.GetPreparer(ctx, location, commandID)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "Get", nil, "Failure preparing request")
    59  		return
    60  	}
    61  
    62  	resp, err := client.GetSender(req)
    63  	if err != nil {
    64  		result.Response = autorest.Response{Response: resp}
    65  		err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "Get", resp, "Failure sending request")
    66  		return
    67  	}
    68  
    69  	result, err = client.GetResponder(resp)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "Get", resp, "Failure responding to request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // GetPreparer prepares the Get request.
    79  func (client VirtualMachineRunCommandsClient) GetPreparer(ctx context.Context, location string, commandID string) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"commandId":      autorest.Encode("path", commandID),
    82  		"location":       autorest.Encode("path", location),
    83  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    84  	}
    85  
    86  	const APIVersion = "2017-03-30"
    87  	queryParameters := map[string]interface{}{
    88  		"api-version": APIVersion,
    89  	}
    90  
    91  	preparer := autorest.CreatePreparer(
    92  		autorest.AsGet(),
    93  		autorest.WithBaseURL(client.BaseURI),
    94  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/runCommands/{commandId}", pathParameters),
    95  		autorest.WithQueryParameters(queryParameters))
    96  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    97  }
    98  
    99  // GetSender sends the Get request. The method will close the
   100  // http.Response Body if it receives an error.
   101  func (client VirtualMachineRunCommandsClient) GetSender(req *http.Request) (*http.Response, error) {
   102  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   103  }
   104  
   105  // GetResponder handles the response to the Get request. The method always
   106  // closes the http.Response Body.
   107  func (client VirtualMachineRunCommandsClient) GetResponder(resp *http.Response) (result RunCommandDocument, err error) {
   108  	err = autorest.Respond(
   109  		resp,
   110  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   111  		autorest.ByUnmarshallingJSON(&result),
   112  		autorest.ByClosing())
   113  	result.Response = autorest.Response{Response: resp}
   114  	return
   115  }
   116  
   117  // List lists all available run commands for a subscription in a location.
   118  // Parameters:
   119  // location - the location upon which run commands is queried.
   120  func (client VirtualMachineRunCommandsClient) List(ctx context.Context, location string) (result RunCommandListResultPage, err error) {
   121  	if tracing.IsEnabled() {
   122  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineRunCommandsClient.List")
   123  		defer func() {
   124  			sc := -1
   125  			if result.rclr.Response.Response != nil {
   126  				sc = result.rclr.Response.Response.StatusCode
   127  			}
   128  			tracing.EndSpan(ctx, sc, err)
   129  		}()
   130  	}
   131  	if err := validation.Validate([]validation.Validation{
   132  		{TargetValue: location,
   133  			Constraints: []validation.Constraint{{Target: "location", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
   134  		return result, validation.NewError("compute.VirtualMachineRunCommandsClient", "List", err.Error())
   135  	}
   136  
   137  	result.fn = client.listNextResults
   138  	req, err := client.ListPreparer(ctx, location)
   139  	if err != nil {
   140  		err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "List", nil, "Failure preparing request")
   141  		return
   142  	}
   143  
   144  	resp, err := client.ListSender(req)
   145  	if err != nil {
   146  		result.rclr.Response = autorest.Response{Response: resp}
   147  		err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "List", resp, "Failure sending request")
   148  		return
   149  	}
   150  
   151  	result.rclr, err = client.ListResponder(resp)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "List", resp, "Failure responding to request")
   154  		return
   155  	}
   156  	if result.rclr.hasNextLink() && result.rclr.IsEmpty() {
   157  		err = result.NextWithContext(ctx)
   158  		return
   159  	}
   160  
   161  	return
   162  }
   163  
   164  // ListPreparer prepares the List request.
   165  func (client VirtualMachineRunCommandsClient) ListPreparer(ctx context.Context, location string) (*http.Request, error) {
   166  	pathParameters := map[string]interface{}{
   167  		"location":       autorest.Encode("path", location),
   168  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   169  	}
   170  
   171  	const APIVersion = "2017-03-30"
   172  	queryParameters := map[string]interface{}{
   173  		"api-version": APIVersion,
   174  	}
   175  
   176  	preparer := autorest.CreatePreparer(
   177  		autorest.AsGet(),
   178  		autorest.WithBaseURL(client.BaseURI),
   179  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/runCommands", pathParameters),
   180  		autorest.WithQueryParameters(queryParameters))
   181  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   182  }
   183  
   184  // ListSender sends the List request. The method will close the
   185  // http.Response Body if it receives an error.
   186  func (client VirtualMachineRunCommandsClient) ListSender(req *http.Request) (*http.Response, error) {
   187  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   188  }
   189  
   190  // ListResponder handles the response to the List request. The method always
   191  // closes the http.Response Body.
   192  func (client VirtualMachineRunCommandsClient) ListResponder(resp *http.Response) (result RunCommandListResult, err error) {
   193  	err = autorest.Respond(
   194  		resp,
   195  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   196  		autorest.ByUnmarshallingJSON(&result),
   197  		autorest.ByClosing())
   198  	result.Response = autorest.Response{Response: resp}
   199  	return
   200  }
   201  
   202  // listNextResults retrieves the next set of results, if any.
   203  func (client VirtualMachineRunCommandsClient) listNextResults(ctx context.Context, lastResults RunCommandListResult) (result RunCommandListResult, err error) {
   204  	req, err := lastResults.runCommandListResultPreparer(ctx)
   205  	if err != nil {
   206  		return result, autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "listNextResults", nil, "Failure preparing next results request")
   207  	}
   208  	if req == nil {
   209  		return
   210  	}
   211  	resp, err := client.ListSender(req)
   212  	if err != nil {
   213  		result.Response = autorest.Response{Response: resp}
   214  		return result, autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "listNextResults", resp, "Failure sending next results request")
   215  	}
   216  	result, err = client.ListResponder(resp)
   217  	if err != nil {
   218  		err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "listNextResults", resp, "Failure responding to next results request")
   219  	}
   220  	return
   221  }
   222  
   223  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   224  func (client VirtualMachineRunCommandsClient) ListComplete(ctx context.Context, location string) (result RunCommandListResultIterator, err error) {
   225  	if tracing.IsEnabled() {
   226  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineRunCommandsClient.List")
   227  		defer func() {
   228  			sc := -1
   229  			if result.Response().Response.Response != nil {
   230  				sc = result.page.Response().Response.Response.StatusCode
   231  			}
   232  			tracing.EndSpan(ctx, sc, err)
   233  		}()
   234  	}
   235  	result.page, err = client.List(ctx, location)
   236  	return
   237  }
   238  

View as plain text