1// Package operationalinsights implements the Azure ARM Operationalinsights service API version 2015-11-01-preview. 2// 3// Operational Insights Client 4package operationalinsights 5 6// Copyright (c) Microsoft Corporation. All rights reserved. 7// Licensed under the MIT License. See License.txt in the project root for license information. 8// 9// Code generated by Microsoft (R) AutoRest Code Generator. 10// Changes may cause incorrect behavior and will be lost if the code is regenerated. 11 12import ( 13 "context" 14 "github.com/Azure/go-autorest/autorest" 15 "github.com/Azure/go-autorest/autorest/azure" 16 "github.com/Azure/go-autorest/tracing" 17 "net/http" 18) 19 20const ( 21 // DefaultBaseURI is the default URI used for the service Operationalinsights 22 DefaultBaseURI = "https://management.azure.com" 23) 24 25// BaseClient is the base client for Operationalinsights. 26type BaseClient struct { 27 autorest.Client 28 BaseURI string 29 SubscriptionID string 30} 31 32// New creates an instance of the BaseClient client. 33func New(subscriptionID string) BaseClient { 34 return NewWithBaseURI(DefaultBaseURI, subscriptionID) 35} 36 37// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with 38// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 39func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { 40 return BaseClient{ 41 Client: autorest.NewClientWithUserAgent(UserAgent()), 42 BaseURI: baseURI, 43 SubscriptionID: subscriptionID, 44 } 45} 46 47// GetAsyncOperationsStatus get the status of an azure asynchronous operation. 48// Parameters: 49// location - the region name of operation. 50// asyncOperationID - the operation Id. 51func (client BaseClient) GetAsyncOperationsStatus(ctx context.Context, location string, asyncOperationID string) (result OperationStatus, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetAsyncOperationsStatus") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 req, err := client.GetAsyncOperationsStatusPreparer(ctx, location, asyncOperationID) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "operationalinsights.BaseClient", "GetAsyncOperationsStatus", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.GetAsyncOperationsStatusSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "operationalinsights.BaseClient", "GetAsyncOperationsStatus", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.GetAsyncOperationsStatusResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "operationalinsights.BaseClient", "GetAsyncOperationsStatus", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// GetAsyncOperationsStatusPreparer prepares the GetAsyncOperationsStatus request. 85func (client BaseClient) GetAsyncOperationsStatusPreparer(ctx context.Context, location string, asyncOperationID string) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "asyncOperationId": autorest.Encode("path", asyncOperationID), 88 "location": autorest.Encode("path", location), 89 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 90 } 91 92 const APIVersion = "2015-11-01-preview" 93 queryParameters := map[string]interface{}{ 94 "api-version": APIVersion, 95 } 96 97 preparer := autorest.CreatePreparer( 98 autorest.AsGet(), 99 autorest.WithBaseURL(client.BaseURI), 100 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.OperationalInsights/locations/{location}/operationStatuses/{asyncOperationId}", pathParameters), 101 autorest.WithQueryParameters(queryParameters)) 102 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 103} 104 105// GetAsyncOperationsStatusSender sends the GetAsyncOperationsStatus request. The method will close the 106// http.Response Body if it receives an error. 107func (client BaseClient) GetAsyncOperationsStatusSender(req *http.Request) (*http.Response, error) { 108 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 109} 110 111// GetAsyncOperationsStatusResponder handles the response to the GetAsyncOperationsStatus request. The method always 112// closes the http.Response Body. 113func (client BaseClient) GetAsyncOperationsStatusResponder(resp *http.Response) (result OperationStatus, err error) { 114 err = autorest.Respond( 115 resp, 116 azure.WithErrorUnlessStatusCode(http.StatusOK), 117 autorest.ByUnmarshallingJSON(&result), 118 autorest.ByClosing()) 119 result.Response = autorest.Response{Response: resp} 120 return 121} 122