//go:build go1.18 // +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. // DO NOT EDIT. package armnetapp import ( "context" "errors" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "net/http" "net/url" "strings" ) // VolumeGroupsClient contains the methods for the VolumeGroups group. // Don't use this type directly, use NewVolumeGroupsClient() instead. type VolumeGroupsClient struct { host string subscriptionID string pl runtime.Pipeline } // NewVolumeGroupsClient creates a new instance of VolumeGroupsClient with the specified values. // subscriptionID - Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms // part of the URI for every service call. // credential - used to authorize requests. Usually a credential from azidentity. // options - pass nil to accept the default values. func NewVolumeGroupsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VolumeGroupsClient, error) { if options == nil { options = &arm.ClientOptions{} } ep := cloud.AzurePublic.Services[cloud.ResourceManager].Endpoint if c, ok := options.Cloud.Services[cloud.ResourceManager]; ok { ep = c.Endpoint } pl, err := armruntime.NewPipeline(moduleName, moduleVersion, credential, runtime.PipelineOptions{}, options) if err != nil { return nil, err } client := &VolumeGroupsClient{ subscriptionID: subscriptionID, host: ep, pl: pl, } return client, nil } // BeginCreate - Create a volume group along with specified volumes // If the operation fails it returns an *azcore.ResponseError type. // Generated from API version 2022-05-01 // resourceGroupName - The name of the resource group. // accountName - The name of the NetApp account // volumeGroupName - The name of the volumeGroup // body - Volume Group object supplied in the body of the operation. // options - VolumeGroupsClientBeginCreateOptions contains the optional parameters for the VolumeGroupsClient.BeginCreate // method. func (client *VolumeGroupsClient) BeginCreate(ctx context.Context, resourceGroupName string, accountName string, volumeGroupName string, body VolumeGroupDetails, options *VolumeGroupsClientBeginCreateOptions) (*runtime.Poller[VolumeGroupsClientCreateResponse], error) { if options == nil || options.ResumeToken == "" { resp, err := client.create(ctx, resourceGroupName, accountName, volumeGroupName, body, options) if err != nil { return nil, err } return runtime.NewPoller[VolumeGroupsClientCreateResponse](resp, client.pl, nil) } else { return runtime.NewPollerFromResumeToken[VolumeGroupsClientCreateResponse](options.ResumeToken, client.pl, nil) } } // Create - Create a volume group along with specified volumes // If the operation fails it returns an *azcore.ResponseError type. // Generated from API version 2022-05-01 func (client *VolumeGroupsClient) create(ctx context.Context, resourceGroupName string, accountName string, volumeGroupName string, body VolumeGroupDetails, options *VolumeGroupsClientBeginCreateOptions) (*http.Response, error) { req, err := client.createCreateRequest(ctx, resourceGroupName, accountName, volumeGroupName, body, options) if err != nil { return nil, err } resp, err := client.pl.Do(req) if err != nil { return nil, err } if !runtime.HasStatusCode(resp, http.StatusCreated) { return nil, runtime.NewResponseError(resp) } return resp, nil } // createCreateRequest creates the Create request. func (client *VolumeGroupsClient) createCreateRequest(ctx context.Context, resourceGroupName string, accountName string, volumeGroupName string, body VolumeGroupDetails, options *VolumeGroupsClientBeginCreateOptions) (*policy.Request, error) { urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetApp/netAppAccounts/{accountName}/volumeGroups/{volumeGroupName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) if resourceGroupName == "" { return nil, errors.New("parameter resourceGroupName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) if accountName == "" { return nil, errors.New("parameter accountName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{accountName}", url.PathEscape(accountName)) if volumeGroupName == "" { return nil, errors.New("parameter volumeGroupName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{volumeGroupName}", url.PathEscape(volumeGroupName)) req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.host, urlPath)) if err != nil { return nil, err } reqQP := req.Raw().URL.Query() reqQP.Set("api-version", "2022-05-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, runtime.MarshalAsJSON(req, body) } // BeginDelete - Delete the specified volume group only if there are no volumes under volume group. // If the operation fails it returns an *azcore.ResponseError type. // Generated from API version 2022-05-01 // resourceGroupName - The name of the resource group. // accountName - The name of the NetApp account // volumeGroupName - The name of the volumeGroup // options - VolumeGroupsClientBeginDeleteOptions contains the optional parameters for the VolumeGroupsClient.BeginDelete // method. func (client *VolumeGroupsClient) BeginDelete(ctx context.Context, resourceGroupName string, accountName string, volumeGroupName string, options *VolumeGroupsClientBeginDeleteOptions) (*runtime.Poller[VolumeGroupsClientDeleteResponse], error) { if options == nil || options.ResumeToken == "" { resp, err := client.deleteOperation(ctx, resourceGroupName, accountName, volumeGroupName, options) if err != nil { return nil, err } return runtime.NewPoller[VolumeGroupsClientDeleteResponse](resp, client.pl, nil) } else { return runtime.NewPollerFromResumeToken[VolumeGroupsClientDeleteResponse](options.ResumeToken, client.pl, nil) } } // Delete - Delete the specified volume group only if there are no volumes under volume group. // If the operation fails it returns an *azcore.ResponseError type. // Generated from API version 2022-05-01 func (client *VolumeGroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, accountName string, volumeGroupName string, options *VolumeGroupsClientBeginDeleteOptions) (*http.Response, error) { req, err := client.deleteCreateRequest(ctx, resourceGroupName, accountName, volumeGroupName, options) if err != nil { return nil, err } resp, err := client.pl.Do(req) if err != nil { return nil, err } if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { return nil, runtime.NewResponseError(resp) } return resp, nil } // deleteCreateRequest creates the Delete request. func (client *VolumeGroupsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, accountName string, volumeGroupName string, options *VolumeGroupsClientBeginDeleteOptions) (*policy.Request, error) { urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetApp/netAppAccounts/{accountName}/volumeGroups/{volumeGroupName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) if resourceGroupName == "" { return nil, errors.New("parameter resourceGroupName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) if accountName == "" { return nil, errors.New("parameter accountName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{accountName}", url.PathEscape(accountName)) if volumeGroupName == "" { return nil, errors.New("parameter volumeGroupName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{volumeGroupName}", url.PathEscape(volumeGroupName)) req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.host, urlPath)) if err != nil { return nil, err } reqQP := req.Raw().URL.Query() reqQP.Set("api-version", "2022-05-01") req.Raw().URL.RawQuery = reqQP.Encode() return req, nil } // Get - Get details of the specified volume group // If the operation fails it returns an *azcore.ResponseError type. // Generated from API version 2022-05-01 // resourceGroupName - The name of the resource group. // accountName - The name of the NetApp account // volumeGroupName - The name of the volumeGroup // options - VolumeGroupsClientGetOptions contains the optional parameters for the VolumeGroupsClient.Get method. func (client *VolumeGroupsClient) Get(ctx context.Context, resourceGroupName string, accountName string, volumeGroupName string, options *VolumeGroupsClientGetOptions) (VolumeGroupsClientGetResponse, error) { req, err := client.getCreateRequest(ctx, resourceGroupName, accountName, volumeGroupName, options) if err != nil { return VolumeGroupsClientGetResponse{}, err } resp, err := client.pl.Do(req) if err != nil { return VolumeGroupsClientGetResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { return VolumeGroupsClientGetResponse{}, runtime.NewResponseError(resp) } return client.getHandleResponse(resp) } // getCreateRequest creates the Get request. func (client *VolumeGroupsClient) getCreateRequest(ctx context.Context, resourceGroupName string, accountName string, volumeGroupName string, options *VolumeGroupsClientGetOptions) (*policy.Request, error) { urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetApp/netAppAccounts/{accountName}/volumeGroups/{volumeGroupName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) if resourceGroupName == "" { return nil, errors.New("parameter resourceGroupName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) if accountName == "" { return nil, errors.New("parameter accountName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{accountName}", url.PathEscape(accountName)) if volumeGroupName == "" { return nil, errors.New("parameter volumeGroupName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{volumeGroupName}", url.PathEscape(volumeGroupName)) req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.host, urlPath)) if err != nil { return nil, err } reqQP := req.Raw().URL.Query() reqQP.Set("api-version", "2022-05-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, nil } // getHandleResponse handles the Get response. func (client *VolumeGroupsClient) getHandleResponse(resp *http.Response) (VolumeGroupsClientGetResponse, error) { result := VolumeGroupsClientGetResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.VolumeGroupDetails); err != nil { return VolumeGroupsClientGetResponse{}, err } return result, nil } // NewListByNetAppAccountPager - List all volume groups for given account // Generated from API version 2022-05-01 // resourceGroupName - The name of the resource group. // accountName - The name of the NetApp account // options - VolumeGroupsClientListByNetAppAccountOptions contains the optional parameters for the VolumeGroupsClient.ListByNetAppAccount // method. func (client *VolumeGroupsClient) NewListByNetAppAccountPager(resourceGroupName string, accountName string, options *VolumeGroupsClientListByNetAppAccountOptions) *runtime.Pager[VolumeGroupsClientListByNetAppAccountResponse] { return runtime.NewPager(runtime.PagingHandler[VolumeGroupsClientListByNetAppAccountResponse]{ More: func(page VolumeGroupsClientListByNetAppAccountResponse) bool { return false }, Fetcher: func(ctx context.Context, page *VolumeGroupsClientListByNetAppAccountResponse) (VolumeGroupsClientListByNetAppAccountResponse, error) { req, err := client.listByNetAppAccountCreateRequest(ctx, resourceGroupName, accountName, options) if err != nil { return VolumeGroupsClientListByNetAppAccountResponse{}, err } resp, err := client.pl.Do(req) if err != nil { return VolumeGroupsClientListByNetAppAccountResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { return VolumeGroupsClientListByNetAppAccountResponse{}, runtime.NewResponseError(resp) } return client.listByNetAppAccountHandleResponse(resp) }, }) } // listByNetAppAccountCreateRequest creates the ListByNetAppAccount request. func (client *VolumeGroupsClient) listByNetAppAccountCreateRequest(ctx context.Context, resourceGroupName string, accountName string, options *VolumeGroupsClientListByNetAppAccountOptions) (*policy.Request, error) { urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetApp/netAppAccounts/{accountName}/volumeGroups" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) if resourceGroupName == "" { return nil, errors.New("parameter resourceGroupName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) if accountName == "" { return nil, errors.New("parameter accountName cannot be empty") } urlPath = strings.ReplaceAll(urlPath, "{accountName}", url.PathEscape(accountName)) req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.host, urlPath)) if err != nil { return nil, err } reqQP := req.Raw().URL.Query() reqQP.Set("api-version", "2022-05-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, nil } // listByNetAppAccountHandleResponse handles the ListByNetAppAccount response. func (client *VolumeGroupsClient) listByNetAppAccountHandleResponse(resp *http.Response) (VolumeGroupsClientListByNetAppAccountResponse, error) { result := VolumeGroupsClientListByNetAppAccountResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.VolumeGroupList); err != nil { return VolumeGroupsClientListByNetAppAccountResponse{}, err } return result, nil }