1package compute 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// VirtualMachineRunCommandsClient is the compute Client 30type VirtualMachineRunCommandsClient struct { 31 BaseClient 32} 33 34// NewVirtualMachineRunCommandsClient creates an instance of the VirtualMachineRunCommandsClient client. 35func NewVirtualMachineRunCommandsClient(subscriptionID string) VirtualMachineRunCommandsClient { 36 return NewVirtualMachineRunCommandsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewVirtualMachineRunCommandsClientWithBaseURI creates an instance of the VirtualMachineRunCommandsClient client. 40func NewVirtualMachineRunCommandsClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineRunCommandsClient { 41 return VirtualMachineRunCommandsClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// Get gets specific run command for a subscription in a location. 45// Parameters: 46// location - the location upon which run commands is queried. 47// commandID - the command id. 48func (client VirtualMachineRunCommandsClient) Get(ctx context.Context, location string, commandID string) (result RunCommandDocument, err error) { 49 if tracing.IsEnabled() { 50 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineRunCommandsClient.Get") 51 defer func() { 52 sc := -1 53 if result.Response.Response != nil { 54 sc = result.Response.Response.StatusCode 55 } 56 tracing.EndSpan(ctx, sc, err) 57 }() 58 } 59 if err := validation.Validate([]validation.Validation{ 60 {TargetValue: location, 61 Constraints: []validation.Constraint{{Target: "location", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 62 return result, validation.NewError("compute.VirtualMachineRunCommandsClient", "Get", err.Error()) 63 } 64 65 req, err := client.GetPreparer(ctx, location, commandID) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "Get", nil, "Failure preparing request") 68 return 69 } 70 71 resp, err := client.GetSender(req) 72 if err != nil { 73 result.Response = autorest.Response{Response: resp} 74 err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "Get", resp, "Failure sending request") 75 return 76 } 77 78 result, err = client.GetResponder(resp) 79 if err != nil { 80 err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "Get", resp, "Failure responding to request") 81 } 82 83 return 84} 85 86// GetPreparer prepares the Get request. 87func (client VirtualMachineRunCommandsClient) GetPreparer(ctx context.Context, location string, commandID string) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "commandId": autorest.Encode("path", commandID), 90 "location": autorest.Encode("path", location), 91 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 92 } 93 94 const APIVersion = "2017-12-01" 95 queryParameters := map[string]interface{}{ 96 "api-version": APIVersion, 97 } 98 99 preparer := autorest.CreatePreparer( 100 autorest.AsGet(), 101 autorest.WithBaseURL(client.BaseURI), 102 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/runCommands/{commandId}", pathParameters), 103 autorest.WithQueryParameters(queryParameters)) 104 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 105} 106 107// GetSender sends the Get request. The method will close the 108// http.Response Body if it receives an error. 109func (client VirtualMachineRunCommandsClient) GetSender(req *http.Request) (*http.Response, error) { 110 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 111 return autorest.SendWithSender(client, req, sd...) 112} 113 114// GetResponder handles the response to the Get request. The method always 115// closes the http.Response Body. 116func (client VirtualMachineRunCommandsClient) GetResponder(resp *http.Response) (result RunCommandDocument, err error) { 117 err = autorest.Respond( 118 resp, 119 client.ByInspecting(), 120 azure.WithErrorUnlessStatusCode(http.StatusOK), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// List lists all available run commands for a subscription in a location. 128// Parameters: 129// location - the location upon which run commands is queried. 130func (client VirtualMachineRunCommandsClient) List(ctx context.Context, location string) (result RunCommandListResultPage, err error) { 131 if tracing.IsEnabled() { 132 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineRunCommandsClient.List") 133 defer func() { 134 sc := -1 135 if result.rclr.Response.Response != nil { 136 sc = result.rclr.Response.Response.StatusCode 137 } 138 tracing.EndSpan(ctx, sc, err) 139 }() 140 } 141 if err := validation.Validate([]validation.Validation{ 142 {TargetValue: location, 143 Constraints: []validation.Constraint{{Target: "location", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 144 return result, validation.NewError("compute.VirtualMachineRunCommandsClient", "List", err.Error()) 145 } 146 147 result.fn = client.listNextResults 148 req, err := client.ListPreparer(ctx, location) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "List", nil, "Failure preparing request") 151 return 152 } 153 154 resp, err := client.ListSender(req) 155 if err != nil { 156 result.rclr.Response = autorest.Response{Response: resp} 157 err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "List", resp, "Failure sending request") 158 return 159 } 160 161 result.rclr, err = client.ListResponder(resp) 162 if err != nil { 163 err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "List", resp, "Failure responding to request") 164 } 165 166 return 167} 168 169// ListPreparer prepares the List request. 170func (client VirtualMachineRunCommandsClient) ListPreparer(ctx context.Context, location string) (*http.Request, error) { 171 pathParameters := map[string]interface{}{ 172 "location": autorest.Encode("path", location), 173 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 174 } 175 176 const APIVersion = "2017-12-01" 177 queryParameters := map[string]interface{}{ 178 "api-version": APIVersion, 179 } 180 181 preparer := autorest.CreatePreparer( 182 autorest.AsGet(), 183 autorest.WithBaseURL(client.BaseURI), 184 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/runCommands", pathParameters), 185 autorest.WithQueryParameters(queryParameters)) 186 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 187} 188 189// ListSender sends the List request. The method will close the 190// http.Response Body if it receives an error. 191func (client VirtualMachineRunCommandsClient) ListSender(req *http.Request) (*http.Response, error) { 192 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 193 return autorest.SendWithSender(client, req, sd...) 194} 195 196// ListResponder handles the response to the List request. The method always 197// closes the http.Response Body. 198func (client VirtualMachineRunCommandsClient) ListResponder(resp *http.Response) (result RunCommandListResult, err error) { 199 err = autorest.Respond( 200 resp, 201 client.ByInspecting(), 202 azure.WithErrorUnlessStatusCode(http.StatusOK), 203 autorest.ByUnmarshallingJSON(&result), 204 autorest.ByClosing()) 205 result.Response = autorest.Response{Response: resp} 206 return 207} 208 209// listNextResults retrieves the next set of results, if any. 210func (client VirtualMachineRunCommandsClient) listNextResults(ctx context.Context, lastResults RunCommandListResult) (result RunCommandListResult, err error) { 211 req, err := lastResults.runCommandListResultPreparer(ctx) 212 if err != nil { 213 return result, autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "listNextResults", nil, "Failure preparing next results request") 214 } 215 if req == nil { 216 return 217 } 218 resp, err := client.ListSender(req) 219 if err != nil { 220 result.Response = autorest.Response{Response: resp} 221 return result, autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "listNextResults", resp, "Failure sending next results request") 222 } 223 result, err = client.ListResponder(resp) 224 if err != nil { 225 err = autorest.NewErrorWithError(err, "compute.VirtualMachineRunCommandsClient", "listNextResults", resp, "Failure responding to next results request") 226 } 227 return 228} 229 230// ListComplete enumerates all values, automatically crossing page boundaries as required. 231func (client VirtualMachineRunCommandsClient) ListComplete(ctx context.Context, location string) (result RunCommandListResultIterator, err error) { 232 if tracing.IsEnabled() { 233 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineRunCommandsClient.List") 234 defer func() { 235 sc := -1 236 if result.Response().Response.Response != nil { 237 sc = result.page.Response().Response.Response.StatusCode 238 } 239 tracing.EndSpan(ctx, sc, err) 240 }() 241 } 242 result.page, err = client.List(ctx, location) 243 return 244} 245