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/tracing" 25 "net/http" 26) 27 28// VirtualMachineExtensionsClient is the compute Client 29type VirtualMachineExtensionsClient struct { 30 BaseClient 31} 32 33// NewVirtualMachineExtensionsClient creates an instance of the VirtualMachineExtensionsClient client. 34func NewVirtualMachineExtensionsClient(subscriptionID string) VirtualMachineExtensionsClient { 35 return NewVirtualMachineExtensionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewVirtualMachineExtensionsClientWithBaseURI creates an instance of the VirtualMachineExtensionsClient client using 39// a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 40// clouds, Azure stack). 41func NewVirtualMachineExtensionsClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineExtensionsClient { 42 return VirtualMachineExtensionsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate the operation to create or update the extension. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// VMName - the name of the virtual machine where the extension should be created or updated. 49// VMExtensionName - the name of the virtual machine extension. 50// extensionParameters - parameters supplied to the Create Virtual Machine Extension operation. 51func (client VirtualMachineExtensionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, VMName string, VMExtensionName string, extensionParameters VirtualMachineExtension) (result VirtualMachineExtensionsCreateOrUpdateFuture, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineExtensionsClient.CreateOrUpdate") 54 defer func() { 55 sc := -1 56 if result.Response() != nil { 57 sc = result.Response().StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, VMName, VMExtensionName, extensionParameters) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "CreateOrUpdate", nil, "Failure preparing request") 65 return 66 } 67 68 result, err = client.CreateOrUpdateSender(req) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 71 return 72 } 73 74 return 75} 76 77// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 78func (client VirtualMachineExtensionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, VMName string, VMExtensionName string, extensionParameters VirtualMachineExtension) (*http.Request, error) { 79 pathParameters := map[string]interface{}{ 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 "vmExtensionName": autorest.Encode("path", VMExtensionName), 83 "vmName": autorest.Encode("path", VMName), 84 } 85 86 const APIVersion = "2018-10-01" 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.Compute/virtualMachines/{vmName}/extensions/{vmExtensionName}", pathParameters), 96 autorest.WithJSON(extensionParameters), 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. 103func (client VirtualMachineExtensionsClient) CreateOrUpdateSender(req *http.Request) (future VirtualMachineExtensionsCreateOrUpdateFuture, err error) { 104 var resp *http.Response 105 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 106 if err != nil { 107 return 108 } 109 future.Future, err = azure.NewFutureFromResponse(resp) 110 return 111} 112 113// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 114// closes the http.Response Body. 115func (client VirtualMachineExtensionsClient) CreateOrUpdateResponder(resp *http.Response) (result VirtualMachineExtension, err error) { 116 err = autorest.Respond( 117 resp, 118 client.ByInspecting(), 119 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// Delete the operation to delete the extension. 127// Parameters: 128// resourceGroupName - the name of the resource group. 129// VMName - the name of the virtual machine where the extension should be deleted. 130// VMExtensionName - the name of the virtual machine extension. 131func (client VirtualMachineExtensionsClient) Delete(ctx context.Context, resourceGroupName string, VMName string, VMExtensionName string) (result VirtualMachineExtensionsDeleteFuture, err error) { 132 if tracing.IsEnabled() { 133 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineExtensionsClient.Delete") 134 defer func() { 135 sc := -1 136 if result.Response() != nil { 137 sc = result.Response().StatusCode 138 } 139 tracing.EndSpan(ctx, sc, err) 140 }() 141 } 142 req, err := client.DeletePreparer(ctx, resourceGroupName, VMName, VMExtensionName) 143 if err != nil { 144 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "Delete", nil, "Failure preparing request") 145 return 146 } 147 148 result, err = client.DeleteSender(req) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "Delete", result.Response(), "Failure sending request") 151 return 152 } 153 154 return 155} 156 157// DeletePreparer prepares the Delete request. 158func (client VirtualMachineExtensionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, VMName string, VMExtensionName string) (*http.Request, error) { 159 pathParameters := map[string]interface{}{ 160 "resourceGroupName": autorest.Encode("path", resourceGroupName), 161 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 162 "vmExtensionName": autorest.Encode("path", VMExtensionName), 163 "vmName": autorest.Encode("path", VMName), 164 } 165 166 const APIVersion = "2018-10-01" 167 queryParameters := map[string]interface{}{ 168 "api-version": APIVersion, 169 } 170 171 preparer := autorest.CreatePreparer( 172 autorest.AsDelete(), 173 autorest.WithBaseURL(client.BaseURI), 174 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/extensions/{vmExtensionName}", pathParameters), 175 autorest.WithQueryParameters(queryParameters)) 176 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 177} 178 179// DeleteSender sends the Delete request. The method will close the 180// http.Response Body if it receives an error. 181func (client VirtualMachineExtensionsClient) DeleteSender(req *http.Request) (future VirtualMachineExtensionsDeleteFuture, err error) { 182 var resp *http.Response 183 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 184 if err != nil { 185 return 186 } 187 future.Future, err = azure.NewFutureFromResponse(resp) 188 return 189} 190 191// DeleteResponder handles the response to the Delete request. The method always 192// closes the http.Response Body. 193func (client VirtualMachineExtensionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 194 err = autorest.Respond( 195 resp, 196 client.ByInspecting(), 197 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 198 autorest.ByClosing()) 199 result.Response = resp 200 return 201} 202 203// Get the operation to get the extension. 204// Parameters: 205// resourceGroupName - the name of the resource group. 206// VMName - the name of the virtual machine containing the extension. 207// VMExtensionName - the name of the virtual machine extension. 208// expand - the expand expression to apply on the operation. 209func (client VirtualMachineExtensionsClient) Get(ctx context.Context, resourceGroupName string, VMName string, VMExtensionName string, expand string) (result VirtualMachineExtension, err error) { 210 if tracing.IsEnabled() { 211 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineExtensionsClient.Get") 212 defer func() { 213 sc := -1 214 if result.Response.Response != nil { 215 sc = result.Response.Response.StatusCode 216 } 217 tracing.EndSpan(ctx, sc, err) 218 }() 219 } 220 req, err := client.GetPreparer(ctx, resourceGroupName, VMName, VMExtensionName, expand) 221 if err != nil { 222 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "Get", nil, "Failure preparing request") 223 return 224 } 225 226 resp, err := client.GetSender(req) 227 if err != nil { 228 result.Response = autorest.Response{Response: resp} 229 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "Get", resp, "Failure sending request") 230 return 231 } 232 233 result, err = client.GetResponder(resp) 234 if err != nil { 235 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "Get", resp, "Failure responding to request") 236 } 237 238 return 239} 240 241// GetPreparer prepares the Get request. 242func (client VirtualMachineExtensionsClient) GetPreparer(ctx context.Context, resourceGroupName string, VMName string, VMExtensionName string, expand string) (*http.Request, error) { 243 pathParameters := map[string]interface{}{ 244 "resourceGroupName": autorest.Encode("path", resourceGroupName), 245 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 246 "vmExtensionName": autorest.Encode("path", VMExtensionName), 247 "vmName": autorest.Encode("path", VMName), 248 } 249 250 const APIVersion = "2018-10-01" 251 queryParameters := map[string]interface{}{ 252 "api-version": APIVersion, 253 } 254 if len(expand) > 0 { 255 queryParameters["$expand"] = autorest.Encode("query", expand) 256 } 257 258 preparer := autorest.CreatePreparer( 259 autorest.AsGet(), 260 autorest.WithBaseURL(client.BaseURI), 261 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/extensions/{vmExtensionName}", pathParameters), 262 autorest.WithQueryParameters(queryParameters)) 263 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 264} 265 266// GetSender sends the Get request. The method will close the 267// http.Response Body if it receives an error. 268func (client VirtualMachineExtensionsClient) GetSender(req *http.Request) (*http.Response, error) { 269 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 270} 271 272// GetResponder handles the response to the Get request. The method always 273// closes the http.Response Body. 274func (client VirtualMachineExtensionsClient) GetResponder(resp *http.Response) (result VirtualMachineExtension, err error) { 275 err = autorest.Respond( 276 resp, 277 client.ByInspecting(), 278 azure.WithErrorUnlessStatusCode(http.StatusOK), 279 autorest.ByUnmarshallingJSON(&result), 280 autorest.ByClosing()) 281 result.Response = autorest.Response{Response: resp} 282 return 283} 284 285// List the operation to get all extensions of a Virtual Machine. 286// Parameters: 287// resourceGroupName - the name of the resource group. 288// VMName - the name of the virtual machine containing the extension. 289// expand - the expand expression to apply on the operation. 290func (client VirtualMachineExtensionsClient) List(ctx context.Context, resourceGroupName string, VMName string, expand string) (result VirtualMachineExtensionsListResult, err error) { 291 if tracing.IsEnabled() { 292 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineExtensionsClient.List") 293 defer func() { 294 sc := -1 295 if result.Response.Response != nil { 296 sc = result.Response.Response.StatusCode 297 } 298 tracing.EndSpan(ctx, sc, err) 299 }() 300 } 301 req, err := client.ListPreparer(ctx, resourceGroupName, VMName, expand) 302 if err != nil { 303 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "List", nil, "Failure preparing request") 304 return 305 } 306 307 resp, err := client.ListSender(req) 308 if err != nil { 309 result.Response = autorest.Response{Response: resp} 310 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "List", resp, "Failure sending request") 311 return 312 } 313 314 result, err = client.ListResponder(resp) 315 if err != nil { 316 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "List", resp, "Failure responding to request") 317 } 318 319 return 320} 321 322// ListPreparer prepares the List request. 323func (client VirtualMachineExtensionsClient) ListPreparer(ctx context.Context, resourceGroupName string, VMName string, expand string) (*http.Request, error) { 324 pathParameters := map[string]interface{}{ 325 "resourceGroupName": autorest.Encode("path", resourceGroupName), 326 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 327 "vmName": autorest.Encode("path", VMName), 328 } 329 330 const APIVersion = "2018-10-01" 331 queryParameters := map[string]interface{}{ 332 "api-version": APIVersion, 333 } 334 if len(expand) > 0 { 335 queryParameters["$expand"] = autorest.Encode("query", expand) 336 } 337 338 preparer := autorest.CreatePreparer( 339 autorest.AsGet(), 340 autorest.WithBaseURL(client.BaseURI), 341 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/extensions", pathParameters), 342 autorest.WithQueryParameters(queryParameters)) 343 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 344} 345 346// ListSender sends the List request. The method will close the 347// http.Response Body if it receives an error. 348func (client VirtualMachineExtensionsClient) ListSender(req *http.Request) (*http.Response, error) { 349 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 350} 351 352// ListResponder handles the response to the List request. The method always 353// closes the http.Response Body. 354func (client VirtualMachineExtensionsClient) ListResponder(resp *http.Response) (result VirtualMachineExtensionsListResult, err error) { 355 err = autorest.Respond( 356 resp, 357 client.ByInspecting(), 358 azure.WithErrorUnlessStatusCode(http.StatusOK), 359 autorest.ByUnmarshallingJSON(&result), 360 autorest.ByClosing()) 361 result.Response = autorest.Response{Response: resp} 362 return 363} 364 365// Update the operation to update the extension. 366// Parameters: 367// resourceGroupName - the name of the resource group. 368// VMName - the name of the virtual machine where the extension should be updated. 369// VMExtensionName - the name of the virtual machine extension. 370// extensionParameters - parameters supplied to the Update Virtual Machine Extension operation. 371func (client VirtualMachineExtensionsClient) Update(ctx context.Context, resourceGroupName string, VMName string, VMExtensionName string, extensionParameters VirtualMachineExtensionUpdate) (result VirtualMachineExtensionsUpdateFuture, err error) { 372 if tracing.IsEnabled() { 373 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineExtensionsClient.Update") 374 defer func() { 375 sc := -1 376 if result.Response() != nil { 377 sc = result.Response().StatusCode 378 } 379 tracing.EndSpan(ctx, sc, err) 380 }() 381 } 382 req, err := client.UpdatePreparer(ctx, resourceGroupName, VMName, VMExtensionName, extensionParameters) 383 if err != nil { 384 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "Update", nil, "Failure preparing request") 385 return 386 } 387 388 result, err = client.UpdateSender(req) 389 if err != nil { 390 err = autorest.NewErrorWithError(err, "compute.VirtualMachineExtensionsClient", "Update", result.Response(), "Failure sending request") 391 return 392 } 393 394 return 395} 396 397// UpdatePreparer prepares the Update request. 398func (client VirtualMachineExtensionsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, VMName string, VMExtensionName string, extensionParameters VirtualMachineExtensionUpdate) (*http.Request, error) { 399 pathParameters := map[string]interface{}{ 400 "resourceGroupName": autorest.Encode("path", resourceGroupName), 401 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 402 "vmExtensionName": autorest.Encode("path", VMExtensionName), 403 "vmName": autorest.Encode("path", VMName), 404 } 405 406 const APIVersion = "2018-10-01" 407 queryParameters := map[string]interface{}{ 408 "api-version": APIVersion, 409 } 410 411 preparer := autorest.CreatePreparer( 412 autorest.AsContentType("application/json; charset=utf-8"), 413 autorest.AsPatch(), 414 autorest.WithBaseURL(client.BaseURI), 415 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/extensions/{vmExtensionName}", pathParameters), 416 autorest.WithJSON(extensionParameters), 417 autorest.WithQueryParameters(queryParameters)) 418 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 419} 420 421// UpdateSender sends the Update request. The method will close the 422// http.Response Body if it receives an error. 423func (client VirtualMachineExtensionsClient) UpdateSender(req *http.Request) (future VirtualMachineExtensionsUpdateFuture, err error) { 424 var resp *http.Response 425 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 426 if err != nil { 427 return 428 } 429 future.Future, err = azure.NewFutureFromResponse(resp) 430 return 431} 432 433// UpdateResponder handles the response to the Update request. The method always 434// closes the http.Response Body. 435func (client VirtualMachineExtensionsClient) UpdateResponder(resp *http.Response) (result VirtualMachineExtension, err error) { 436 err = autorest.Respond( 437 resp, 438 client.ByInspecting(), 439 azure.WithErrorUnlessStatusCode(http.StatusOK), 440 autorest.ByUnmarshallingJSON(&result), 441 autorest.ByClosing()) 442 result.Response = autorest.Response{Response: resp} 443 return 444} 445