1package 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 9import ( 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// DedicatedHostsClient is the compute Client 19type DedicatedHostsClient struct { 20 BaseClient 21} 22 23// NewDedicatedHostsClient creates an instance of the DedicatedHostsClient client. 24func NewDedicatedHostsClient(subscriptionID string) DedicatedHostsClient { 25 return NewDedicatedHostsClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewDedicatedHostsClientWithBaseURI creates an instance of the DedicatedHostsClient 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). 30func NewDedicatedHostsClientWithBaseURI(baseURI string, subscriptionID string) DedicatedHostsClient { 31 return DedicatedHostsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate create or update a dedicated host . 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// hostGroupName - the name of the dedicated host group. 38// hostName - the name of the dedicated host . 39// parameters - parameters supplied to the Create Dedicated Host. 40func (client DedicatedHostsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, parameters DedicatedHost) (result DedicatedHostsCreateOrUpdateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/DedicatedHostsClient.CreateOrUpdate") 43 defer func() { 44 sc := -1 45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 46 sc = result.FutureAPI.Response().StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: parameters, 53 Constraints: []validation.Constraint{{Target: "parameters.DedicatedHostProperties", Name: validation.Null, Rule: false, 54 Chain: []validation.Constraint{{Target: "parameters.DedicatedHostProperties.PlatformFaultDomain", Name: validation.Null, Rule: false, 55 Chain: []validation.Constraint{{Target: "parameters.DedicatedHostProperties.PlatformFaultDomain", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}, 56 }}, 57 {Target: "parameters.Sku", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 58 return result, validation.NewError("compute.DedicatedHostsClient", "CreateOrUpdate", err.Error()) 59 } 60 61 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, hostGroupName, hostName, parameters) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "CreateOrUpdate", nil, "Failure preparing request") 64 return 65 } 66 67 result, err = client.CreateOrUpdateSender(req) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "CreateOrUpdate", nil, "Failure sending request") 70 return 71 } 72 73 return 74} 75 76// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 77func (client DedicatedHostsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, parameters DedicatedHost) (*http.Request, error) { 78 pathParameters := map[string]interface{}{ 79 "hostGroupName": autorest.Encode("path", hostGroupName), 80 "hostName": autorest.Encode("path", hostName), 81 "resourceGroupName": autorest.Encode("path", resourceGroupName), 82 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 83 } 84 85 const APIVersion = "2020-06-01" 86 queryParameters := map[string]interface{}{ 87 "api-version": APIVersion, 88 } 89 90 preparer := autorest.CreatePreparer( 91 autorest.AsContentType("application/json; charset=utf-8"), 92 autorest.AsPut(), 93 autorest.WithBaseURL(client.BaseURI), 94 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/hostGroups/{hostGroupName}/hosts/{hostName}", pathParameters), 95 autorest.WithJSON(parameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 101// http.Response Body if it receives an error. 102func (client DedicatedHostsClient) CreateOrUpdateSender(req *http.Request) (future DedicatedHostsCreateOrUpdateFuture, err error) { 103 var resp *http.Response 104 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 105 if err != nil { 106 return 107 } 108 var azf azure.Future 109 azf, err = azure.NewFutureFromResponse(resp) 110 future.FutureAPI = &azf 111 future.Result = future.result 112 return 113} 114 115// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 116// closes the http.Response Body. 117func (client DedicatedHostsClient) CreateOrUpdateResponder(resp *http.Response) (result DedicatedHost, err error) { 118 err = autorest.Respond( 119 resp, 120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// Delete delete a dedicated host. 128// Parameters: 129// resourceGroupName - the name of the resource group. 130// hostGroupName - the name of the dedicated host group. 131// hostName - the name of the dedicated host. 132func (client DedicatedHostsClient) Delete(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string) (result DedicatedHostsDeleteFuture, err error) { 133 if tracing.IsEnabled() { 134 ctx = tracing.StartSpan(ctx, fqdn+"/DedicatedHostsClient.Delete") 135 defer func() { 136 sc := -1 137 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 138 sc = result.FutureAPI.Response().StatusCode 139 } 140 tracing.EndSpan(ctx, sc, err) 141 }() 142 } 143 req, err := client.DeletePreparer(ctx, resourceGroupName, hostGroupName, hostName) 144 if err != nil { 145 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "Delete", nil, "Failure preparing request") 146 return 147 } 148 149 result, err = client.DeleteSender(req) 150 if err != nil { 151 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "Delete", nil, "Failure sending request") 152 return 153 } 154 155 return 156} 157 158// DeletePreparer prepares the Delete request. 159func (client DedicatedHostsClient) DeletePreparer(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string) (*http.Request, error) { 160 pathParameters := map[string]interface{}{ 161 "hostGroupName": autorest.Encode("path", hostGroupName), 162 "hostName": autorest.Encode("path", hostName), 163 "resourceGroupName": autorest.Encode("path", resourceGroupName), 164 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 165 } 166 167 const APIVersion = "2020-06-01" 168 queryParameters := map[string]interface{}{ 169 "api-version": APIVersion, 170 } 171 172 preparer := autorest.CreatePreparer( 173 autorest.AsDelete(), 174 autorest.WithBaseURL(client.BaseURI), 175 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/hostGroups/{hostGroupName}/hosts/{hostName}", pathParameters), 176 autorest.WithQueryParameters(queryParameters)) 177 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 178} 179 180// DeleteSender sends the Delete request. The method will close the 181// http.Response Body if it receives an error. 182func (client DedicatedHostsClient) DeleteSender(req *http.Request) (future DedicatedHostsDeleteFuture, err error) { 183 var resp *http.Response 184 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 185 if err != nil { 186 return 187 } 188 var azf azure.Future 189 azf, err = azure.NewFutureFromResponse(resp) 190 future.FutureAPI = &azf 191 future.Result = future.result 192 return 193} 194 195// DeleteResponder handles the response to the Delete request. The method always 196// closes the http.Response Body. 197func (client DedicatedHostsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 198 err = autorest.Respond( 199 resp, 200 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 201 autorest.ByClosing()) 202 result.Response = resp 203 return 204} 205 206// Get retrieves information about a dedicated host. 207// Parameters: 208// resourceGroupName - the name of the resource group. 209// hostGroupName - the name of the dedicated host group. 210// hostName - the name of the dedicated host. 211// expand - the expand expression to apply on the operation. 212func (client DedicatedHostsClient) Get(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, expand InstanceViewTypes) (result DedicatedHost, err error) { 213 if tracing.IsEnabled() { 214 ctx = tracing.StartSpan(ctx, fqdn+"/DedicatedHostsClient.Get") 215 defer func() { 216 sc := -1 217 if result.Response.Response != nil { 218 sc = result.Response.Response.StatusCode 219 } 220 tracing.EndSpan(ctx, sc, err) 221 }() 222 } 223 req, err := client.GetPreparer(ctx, resourceGroupName, hostGroupName, hostName, expand) 224 if err != nil { 225 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "Get", nil, "Failure preparing request") 226 return 227 } 228 229 resp, err := client.GetSender(req) 230 if err != nil { 231 result.Response = autorest.Response{Response: resp} 232 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "Get", resp, "Failure sending request") 233 return 234 } 235 236 result, err = client.GetResponder(resp) 237 if err != nil { 238 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "Get", resp, "Failure responding to request") 239 return 240 } 241 242 return 243} 244 245// GetPreparer prepares the Get request. 246func (client DedicatedHostsClient) GetPreparer(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, expand InstanceViewTypes) (*http.Request, error) { 247 pathParameters := map[string]interface{}{ 248 "hostGroupName": autorest.Encode("path", hostGroupName), 249 "hostName": autorest.Encode("path", hostName), 250 "resourceGroupName": autorest.Encode("path", resourceGroupName), 251 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 252 } 253 254 const APIVersion = "2020-06-01" 255 queryParameters := map[string]interface{}{ 256 "api-version": APIVersion, 257 } 258 if len(string(expand)) > 0 { 259 queryParameters["$expand"] = autorest.Encode("query", expand) 260 } 261 262 preparer := autorest.CreatePreparer( 263 autorest.AsGet(), 264 autorest.WithBaseURL(client.BaseURI), 265 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/hostGroups/{hostGroupName}/hosts/{hostName}", pathParameters), 266 autorest.WithQueryParameters(queryParameters)) 267 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 268} 269 270// GetSender sends the Get request. The method will close the 271// http.Response Body if it receives an error. 272func (client DedicatedHostsClient) GetSender(req *http.Request) (*http.Response, error) { 273 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 274} 275 276// GetResponder handles the response to the Get request. The method always 277// closes the http.Response Body. 278func (client DedicatedHostsClient) GetResponder(resp *http.Response) (result DedicatedHost, err error) { 279 err = autorest.Respond( 280 resp, 281 azure.WithErrorUnlessStatusCode(http.StatusOK), 282 autorest.ByUnmarshallingJSON(&result), 283 autorest.ByClosing()) 284 result.Response = autorest.Response{Response: resp} 285 return 286} 287 288// ListByHostGroup lists all of the dedicated hosts in the specified dedicated host group. Use the nextLink property in 289// the response to get the next page of dedicated hosts. 290// Parameters: 291// resourceGroupName - the name of the resource group. 292// hostGroupName - the name of the dedicated host group. 293func (client DedicatedHostsClient) ListByHostGroup(ctx context.Context, resourceGroupName string, hostGroupName string) (result DedicatedHostListResultPage, err error) { 294 if tracing.IsEnabled() { 295 ctx = tracing.StartSpan(ctx, fqdn+"/DedicatedHostsClient.ListByHostGroup") 296 defer func() { 297 sc := -1 298 if result.dhlr.Response.Response != nil { 299 sc = result.dhlr.Response.Response.StatusCode 300 } 301 tracing.EndSpan(ctx, sc, err) 302 }() 303 } 304 result.fn = client.listByHostGroupNextResults 305 req, err := client.ListByHostGroupPreparer(ctx, resourceGroupName, hostGroupName) 306 if err != nil { 307 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "ListByHostGroup", nil, "Failure preparing request") 308 return 309 } 310 311 resp, err := client.ListByHostGroupSender(req) 312 if err != nil { 313 result.dhlr.Response = autorest.Response{Response: resp} 314 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "ListByHostGroup", resp, "Failure sending request") 315 return 316 } 317 318 result.dhlr, err = client.ListByHostGroupResponder(resp) 319 if err != nil { 320 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "ListByHostGroup", resp, "Failure responding to request") 321 return 322 } 323 if result.dhlr.hasNextLink() && result.dhlr.IsEmpty() { 324 err = result.NextWithContext(ctx) 325 return 326 } 327 328 return 329} 330 331// ListByHostGroupPreparer prepares the ListByHostGroup request. 332func (client DedicatedHostsClient) ListByHostGroupPreparer(ctx context.Context, resourceGroupName string, hostGroupName string) (*http.Request, error) { 333 pathParameters := map[string]interface{}{ 334 "hostGroupName": autorest.Encode("path", hostGroupName), 335 "resourceGroupName": autorest.Encode("path", resourceGroupName), 336 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 337 } 338 339 const APIVersion = "2020-06-01" 340 queryParameters := map[string]interface{}{ 341 "api-version": APIVersion, 342 } 343 344 preparer := autorest.CreatePreparer( 345 autorest.AsGet(), 346 autorest.WithBaseURL(client.BaseURI), 347 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/hostGroups/{hostGroupName}/hosts", pathParameters), 348 autorest.WithQueryParameters(queryParameters)) 349 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 350} 351 352// ListByHostGroupSender sends the ListByHostGroup request. The method will close the 353// http.Response Body if it receives an error. 354func (client DedicatedHostsClient) ListByHostGroupSender(req *http.Request) (*http.Response, error) { 355 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 356} 357 358// ListByHostGroupResponder handles the response to the ListByHostGroup request. The method always 359// closes the http.Response Body. 360func (client DedicatedHostsClient) ListByHostGroupResponder(resp *http.Response) (result DedicatedHostListResult, err error) { 361 err = autorest.Respond( 362 resp, 363 azure.WithErrorUnlessStatusCode(http.StatusOK), 364 autorest.ByUnmarshallingJSON(&result), 365 autorest.ByClosing()) 366 result.Response = autorest.Response{Response: resp} 367 return 368} 369 370// listByHostGroupNextResults retrieves the next set of results, if any. 371func (client DedicatedHostsClient) listByHostGroupNextResults(ctx context.Context, lastResults DedicatedHostListResult) (result DedicatedHostListResult, err error) { 372 req, err := lastResults.dedicatedHostListResultPreparer(ctx) 373 if err != nil { 374 return result, autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "listByHostGroupNextResults", nil, "Failure preparing next results request") 375 } 376 if req == nil { 377 return 378 } 379 resp, err := client.ListByHostGroupSender(req) 380 if err != nil { 381 result.Response = autorest.Response{Response: resp} 382 return result, autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "listByHostGroupNextResults", resp, "Failure sending next results request") 383 } 384 result, err = client.ListByHostGroupResponder(resp) 385 if err != nil { 386 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "listByHostGroupNextResults", resp, "Failure responding to next results request") 387 } 388 return 389} 390 391// ListByHostGroupComplete enumerates all values, automatically crossing page boundaries as required. 392func (client DedicatedHostsClient) ListByHostGroupComplete(ctx context.Context, resourceGroupName string, hostGroupName string) (result DedicatedHostListResultIterator, err error) { 393 if tracing.IsEnabled() { 394 ctx = tracing.StartSpan(ctx, fqdn+"/DedicatedHostsClient.ListByHostGroup") 395 defer func() { 396 sc := -1 397 if result.Response().Response.Response != nil { 398 sc = result.page.Response().Response.Response.StatusCode 399 } 400 tracing.EndSpan(ctx, sc, err) 401 }() 402 } 403 result.page, err = client.ListByHostGroup(ctx, resourceGroupName, hostGroupName) 404 return 405} 406 407// Update update an dedicated host . 408// Parameters: 409// resourceGroupName - the name of the resource group. 410// hostGroupName - the name of the dedicated host group. 411// hostName - the name of the dedicated host . 412// parameters - parameters supplied to the Update Dedicated Host operation. 413func (client DedicatedHostsClient) Update(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, parameters DedicatedHostUpdate) (result DedicatedHostsUpdateFuture, err error) { 414 if tracing.IsEnabled() { 415 ctx = tracing.StartSpan(ctx, fqdn+"/DedicatedHostsClient.Update") 416 defer func() { 417 sc := -1 418 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 419 sc = result.FutureAPI.Response().StatusCode 420 } 421 tracing.EndSpan(ctx, sc, err) 422 }() 423 } 424 req, err := client.UpdatePreparer(ctx, resourceGroupName, hostGroupName, hostName, parameters) 425 if err != nil { 426 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "Update", nil, "Failure preparing request") 427 return 428 } 429 430 result, err = client.UpdateSender(req) 431 if err != nil { 432 err = autorest.NewErrorWithError(err, "compute.DedicatedHostsClient", "Update", nil, "Failure sending request") 433 return 434 } 435 436 return 437} 438 439// UpdatePreparer prepares the Update request. 440func (client DedicatedHostsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, hostGroupName string, hostName string, parameters DedicatedHostUpdate) (*http.Request, error) { 441 pathParameters := map[string]interface{}{ 442 "hostGroupName": autorest.Encode("path", hostGroupName), 443 "hostName": autorest.Encode("path", hostName), 444 "resourceGroupName": autorest.Encode("path", resourceGroupName), 445 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 446 } 447 448 const APIVersion = "2020-06-01" 449 queryParameters := map[string]interface{}{ 450 "api-version": APIVersion, 451 } 452 453 preparer := autorest.CreatePreparer( 454 autorest.AsContentType("application/json; charset=utf-8"), 455 autorest.AsPatch(), 456 autorest.WithBaseURL(client.BaseURI), 457 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/hostGroups/{hostGroupName}/hosts/{hostName}", pathParameters), 458 autorest.WithJSON(parameters), 459 autorest.WithQueryParameters(queryParameters)) 460 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 461} 462 463// UpdateSender sends the Update request. The method will close the 464// http.Response Body if it receives an error. 465func (client DedicatedHostsClient) UpdateSender(req *http.Request) (future DedicatedHostsUpdateFuture, err error) { 466 var resp *http.Response 467 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 468 if err != nil { 469 return 470 } 471 var azf azure.Future 472 azf, err = azure.NewFutureFromResponse(resp) 473 future.FutureAPI = &azf 474 future.Result = future.result 475 return 476} 477 478// UpdateResponder handles the response to the Update request. The method always 479// closes the http.Response Body. 480func (client DedicatedHostsClient) UpdateResponder(resp *http.Response) (result DedicatedHost, err error) { 481 err = autorest.Respond( 482 resp, 483 azure.WithErrorUnlessStatusCode(http.StatusOK), 484 autorest.ByUnmarshallingJSON(&result), 485 autorest.ByClosing()) 486 result.Response = autorest.Response{Response: resp} 487 return 488} 489