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