1package avs 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// AddonsClient is the azure VMware Solution API 19type AddonsClient struct { 20 BaseClient 21} 22 23// NewAddonsClient creates an instance of the AddonsClient client. 24func NewAddonsClient(subscriptionID string) AddonsClient { 25 return NewAddonsClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewAddonsClientWithBaseURI creates an instance of the AddonsClient client using a custom endpoint. Use this when 29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewAddonsClientWithBaseURI(baseURI string, subscriptionID string) AddonsClient { 31 return AddonsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate sends the create or update request. 35// Parameters: 36// resourceGroupName - the name of the resource group. The name is case insensitive. 37// privateCloudName - the name of the private cloud. 38// addonName - name of the addon for the private cloud 39// addon - a addon in the private cloud 40func (client AddonsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, privateCloudName string, addonName string, addon Addon) (result AddonsCreateOrUpdateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.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: client.SubscriptionID, 53 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 54 {TargetValue: resourceGroupName, 55 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 56 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 57 return result, validation.NewError("avs.AddonsClient", "CreateOrUpdate", err.Error()) 58 } 59 60 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, privateCloudName, addonName, addon) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "CreateOrUpdate", nil, "Failure preparing request") 63 return 64 } 65 66 result, err = client.CreateOrUpdateSender(req) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "CreateOrUpdate", nil, "Failure sending request") 69 return 70 } 71 72 return 73} 74 75// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 76func (client AddonsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, privateCloudName string, addonName string, addon Addon) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "addonName": autorest.Encode("path", addonName), 79 "privateCloudName": autorest.Encode("path", privateCloudName), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2021-06-01" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 preparer := autorest.CreatePreparer( 90 autorest.AsContentType("application/json; charset=utf-8"), 91 autorest.AsPut(), 92 autorest.WithBaseURL(client.BaseURI), 93 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AVS/privateClouds/{privateCloudName}/addons/{addonName}", pathParameters), 94 autorest.WithJSON(addon), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 100// http.Response Body if it receives an error. 101func (client AddonsClient) CreateOrUpdateSender(req *http.Request) (future AddonsCreateOrUpdateFuture, err error) { 102 var resp *http.Response 103 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 104 if err != nil { 105 return 106 } 107 var azf azure.Future 108 azf, err = azure.NewFutureFromResponse(resp) 109 future.FutureAPI = &azf 110 future.Result = future.result 111 return 112} 113 114// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 115// closes the http.Response Body. 116func (client AddonsClient) CreateOrUpdateResponder(resp *http.Response) (result Addon, err error) { 117 err = autorest.Respond( 118 resp, 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 sends the delete request. 127// Parameters: 128// resourceGroupName - the name of the resource group. The name is case insensitive. 129// privateCloudName - name of the private cloud 130// addonName - name of the addon for the private cloud 131func (client AddonsClient) Delete(ctx context.Context, resourceGroupName string, privateCloudName string, addonName string) (result AddonsDeleteFuture, err error) { 132 if tracing.IsEnabled() { 133 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.Delete") 134 defer func() { 135 sc := -1 136 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 137 sc = result.FutureAPI.Response().StatusCode 138 } 139 tracing.EndSpan(ctx, sc, err) 140 }() 141 } 142 if err := validation.Validate([]validation.Validation{ 143 {TargetValue: client.SubscriptionID, 144 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 145 {TargetValue: resourceGroupName, 146 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 147 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 148 return result, validation.NewError("avs.AddonsClient", "Delete", err.Error()) 149 } 150 151 req, err := client.DeletePreparer(ctx, resourceGroupName, privateCloudName, addonName) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "Delete", nil, "Failure preparing request") 154 return 155 } 156 157 result, err = client.DeleteSender(req) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "Delete", nil, "Failure sending request") 160 return 161 } 162 163 return 164} 165 166// DeletePreparer prepares the Delete request. 167func (client AddonsClient) DeletePreparer(ctx context.Context, resourceGroupName string, privateCloudName string, addonName string) (*http.Request, error) { 168 pathParameters := map[string]interface{}{ 169 "addonName": autorest.Encode("path", addonName), 170 "privateCloudName": autorest.Encode("path", privateCloudName), 171 "resourceGroupName": autorest.Encode("path", resourceGroupName), 172 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 173 } 174 175 const APIVersion = "2021-06-01" 176 queryParameters := map[string]interface{}{ 177 "api-version": APIVersion, 178 } 179 180 preparer := autorest.CreatePreparer( 181 autorest.AsDelete(), 182 autorest.WithBaseURL(client.BaseURI), 183 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AVS/privateClouds/{privateCloudName}/addons/{addonName}", pathParameters), 184 autorest.WithQueryParameters(queryParameters)) 185 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 186} 187 188// DeleteSender sends the Delete request. The method will close the 189// http.Response Body if it receives an error. 190func (client AddonsClient) DeleteSender(req *http.Request) (future AddonsDeleteFuture, err error) { 191 var resp *http.Response 192 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 193 if err != nil { 194 return 195 } 196 var azf azure.Future 197 azf, err = azure.NewFutureFromResponse(resp) 198 future.FutureAPI = &azf 199 future.Result = future.result 200 return 201} 202 203// DeleteResponder handles the response to the Delete request. The method always 204// closes the http.Response Body. 205func (client AddonsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 206 err = autorest.Respond( 207 resp, 208 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 209 autorest.ByClosing()) 210 result.Response = resp 211 return 212} 213 214// Get sends the get request. 215// Parameters: 216// resourceGroupName - the name of the resource group. The name is case insensitive. 217// privateCloudName - name of the private cloud 218// addonName - name of the addon for the private cloud 219func (client AddonsClient) Get(ctx context.Context, resourceGroupName string, privateCloudName string, addonName string) (result Addon, err error) { 220 if tracing.IsEnabled() { 221 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.Get") 222 defer func() { 223 sc := -1 224 if result.Response.Response != nil { 225 sc = result.Response.Response.StatusCode 226 } 227 tracing.EndSpan(ctx, sc, err) 228 }() 229 } 230 if err := validation.Validate([]validation.Validation{ 231 {TargetValue: client.SubscriptionID, 232 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 233 {TargetValue: resourceGroupName, 234 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 235 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 236 return result, validation.NewError("avs.AddonsClient", "Get", err.Error()) 237 } 238 239 req, err := client.GetPreparer(ctx, resourceGroupName, privateCloudName, addonName) 240 if err != nil { 241 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "Get", nil, "Failure preparing request") 242 return 243 } 244 245 resp, err := client.GetSender(req) 246 if err != nil { 247 result.Response = autorest.Response{Response: resp} 248 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "Get", resp, "Failure sending request") 249 return 250 } 251 252 result, err = client.GetResponder(resp) 253 if err != nil { 254 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "Get", resp, "Failure responding to request") 255 return 256 } 257 258 return 259} 260 261// GetPreparer prepares the Get request. 262func (client AddonsClient) GetPreparer(ctx context.Context, resourceGroupName string, privateCloudName string, addonName string) (*http.Request, error) { 263 pathParameters := map[string]interface{}{ 264 "addonName": autorest.Encode("path", addonName), 265 "privateCloudName": autorest.Encode("path", privateCloudName), 266 "resourceGroupName": autorest.Encode("path", resourceGroupName), 267 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 268 } 269 270 const APIVersion = "2021-06-01" 271 queryParameters := map[string]interface{}{ 272 "api-version": APIVersion, 273 } 274 275 preparer := autorest.CreatePreparer( 276 autorest.AsGet(), 277 autorest.WithBaseURL(client.BaseURI), 278 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AVS/privateClouds/{privateCloudName}/addons/{addonName}", pathParameters), 279 autorest.WithQueryParameters(queryParameters)) 280 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 281} 282 283// GetSender sends the Get request. The method will close the 284// http.Response Body if it receives an error. 285func (client AddonsClient) GetSender(req *http.Request) (*http.Response, error) { 286 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 287} 288 289// GetResponder handles the response to the Get request. The method always 290// closes the http.Response Body. 291func (client AddonsClient) GetResponder(resp *http.Response) (result Addon, err error) { 292 err = autorest.Respond( 293 resp, 294 azure.WithErrorUnlessStatusCode(http.StatusOK), 295 autorest.ByUnmarshallingJSON(&result), 296 autorest.ByClosing()) 297 result.Response = autorest.Response{Response: resp} 298 return 299} 300 301// List sends the list request. 302// Parameters: 303// resourceGroupName - the name of the resource group. The name is case insensitive. 304// privateCloudName - name of the private cloud 305func (client AddonsClient) List(ctx context.Context, resourceGroupName string, privateCloudName string) (result AddonListPage, err error) { 306 if tracing.IsEnabled() { 307 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.List") 308 defer func() { 309 sc := -1 310 if result.al.Response.Response != nil { 311 sc = result.al.Response.Response.StatusCode 312 } 313 tracing.EndSpan(ctx, sc, err) 314 }() 315 } 316 if err := validation.Validate([]validation.Validation{ 317 {TargetValue: client.SubscriptionID, 318 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 319 {TargetValue: resourceGroupName, 320 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 321 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 322 return result, validation.NewError("avs.AddonsClient", "List", err.Error()) 323 } 324 325 result.fn = client.listNextResults 326 req, err := client.ListPreparer(ctx, resourceGroupName, privateCloudName) 327 if err != nil { 328 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "List", nil, "Failure preparing request") 329 return 330 } 331 332 resp, err := client.ListSender(req) 333 if err != nil { 334 result.al.Response = autorest.Response{Response: resp} 335 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "List", resp, "Failure sending request") 336 return 337 } 338 339 result.al, err = client.ListResponder(resp) 340 if err != nil { 341 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "List", resp, "Failure responding to request") 342 return 343 } 344 if result.al.hasNextLink() && result.al.IsEmpty() { 345 err = result.NextWithContext(ctx) 346 return 347 } 348 349 return 350} 351 352// ListPreparer prepares the List request. 353func (client AddonsClient) ListPreparer(ctx context.Context, resourceGroupName string, privateCloudName string) (*http.Request, error) { 354 pathParameters := map[string]interface{}{ 355 "privateCloudName": autorest.Encode("path", privateCloudName), 356 "resourceGroupName": autorest.Encode("path", resourceGroupName), 357 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 358 } 359 360 const APIVersion = "2021-06-01" 361 queryParameters := map[string]interface{}{ 362 "api-version": APIVersion, 363 } 364 365 preparer := autorest.CreatePreparer( 366 autorest.AsGet(), 367 autorest.WithBaseURL(client.BaseURI), 368 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AVS/privateClouds/{privateCloudName}/addons", pathParameters), 369 autorest.WithQueryParameters(queryParameters)) 370 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 371} 372 373// ListSender sends the List request. The method will close the 374// http.Response Body if it receives an error. 375func (client AddonsClient) ListSender(req *http.Request) (*http.Response, error) { 376 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 377} 378 379// ListResponder handles the response to the List request. The method always 380// closes the http.Response Body. 381func (client AddonsClient) ListResponder(resp *http.Response) (result AddonList, err error) { 382 err = autorest.Respond( 383 resp, 384 azure.WithErrorUnlessStatusCode(http.StatusOK), 385 autorest.ByUnmarshallingJSON(&result), 386 autorest.ByClosing()) 387 result.Response = autorest.Response{Response: resp} 388 return 389} 390 391// listNextResults retrieves the next set of results, if any. 392func (client AddonsClient) listNextResults(ctx context.Context, lastResults AddonList) (result AddonList, err error) { 393 req, err := lastResults.addonListPreparer(ctx) 394 if err != nil { 395 return result, autorest.NewErrorWithError(err, "avs.AddonsClient", "listNextResults", nil, "Failure preparing next results request") 396 } 397 if req == nil { 398 return 399 } 400 resp, err := client.ListSender(req) 401 if err != nil { 402 result.Response = autorest.Response{Response: resp} 403 return result, autorest.NewErrorWithError(err, "avs.AddonsClient", "listNextResults", resp, "Failure sending next results request") 404 } 405 result, err = client.ListResponder(resp) 406 if err != nil { 407 err = autorest.NewErrorWithError(err, "avs.AddonsClient", "listNextResults", resp, "Failure responding to next results request") 408 } 409 return 410} 411 412// ListComplete enumerates all values, automatically crossing page boundaries as required. 413func (client AddonsClient) ListComplete(ctx context.Context, resourceGroupName string, privateCloudName string) (result AddonListIterator, err error) { 414 if tracing.IsEnabled() { 415 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.List") 416 defer func() { 417 sc := -1 418 if result.Response().Response.Response != nil { 419 sc = result.page.Response().Response.Response.StatusCode 420 } 421 tracing.EndSpan(ctx, sc, err) 422 }() 423 } 424 result.page, err = client.List(ctx, resourceGroupName, privateCloudName) 425 return 426} 427