Files
decort-golang-sdk/pkg/cloudbroker/account/create.go

104 lines
3.0 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package account
import (
"context"
"net/http"
"strconv"
2023-03-24 17:09:30 +03:00
2025-08-29 12:51:25 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// CreateRequest struct for creating account
2022-10-03 16:56:47 +03:00
type CreateRequest struct {
2022-12-22 17:56:47 +03:00
// Display name
// Required: true
2023-03-24 17:09:30 +03:00
Name string `url:"name" json:"name" validate:"required"`
2022-12-22 17:56:47 +03:00
2025-04-09 11:21:07 +03:00
// Description
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
2022-12-22 17:56:47 +03:00
// Name of the account
// Required: true
2023-03-24 17:09:30 +03:00
Username string `url:"username" json:"username" validate:"required"`
2022-12-22 17:56:47 +03:00
// Email
// Required: false
2023-03-24 17:09:30 +03:00
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
2022-12-22 17:56:47 +03:00
2025-08-29 12:51:25 +03:00
// Storage policies
// Required: false
2025-09-11 15:56:44 +03:00
StoragePolicies []StoragePolicy `url:"-" json:"storage_policies,omitempty"`
2025-08-29 12:51:25 +03:00
2022-12-22 17:56:47 +03:00
// Max size of memory in MB
// Required: false
2023-03-01 19:05:53 +03:00
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
2022-12-22 17:56:47 +03:00
// Max size of aggregated vdisks in GB
// Required: false
2023-03-01 19:05:53 +03:00
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
2022-12-22 17:56:47 +03:00
// Max number of CPU cores
// Required: false
2023-03-01 19:05:53 +03:00
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
2022-12-22 17:56:47 +03:00
// Max number of assigned public IPs
// Required: false
2023-03-01 19:05:53 +03:00
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
2022-12-22 17:56:47 +03:00
// If true send emails when a user is granted access to resources
// Required: false
2023-05-04 16:15:35 +03:00
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
2022-12-22 17:56:47 +03:00
// Limit (positive) or disable (0) GPU resources
// Required: false
2023-03-01 19:05:53 +03:00
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
2022-12-22 17:56:47 +03:00
// List of strings with pools
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
2023-03-01 19:05:53 +03:00
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
2024-04-16 14:26:06 +03:00
// Advanced compute features,
2025-07-15 17:39:18 +03:00
// one of: hugepages, numa, cpupin, vfnic, dpdk, changemac, trunk
2024-04-16 14:26:06 +03:00
// Required: false
ComputeFeatures []string `url:"computeFeatures,omitempty" json:"computeFeatures,omitempty" validate:"omitempty,computeFeatures"`
2025-07-15 17:39:18 +03:00
// Default zone ID
// Required: false
DefaultZoneID uint64 `url:"defaultZoneId,omitempty" json:"defaultZoneId,omitempty"`
// Zones
// Required: false
ZoneIDs []uint64 `url:"zoneIds,omitempty" json:"zoneIds,omitempty"`
2022-10-03 16:56:47 +03:00
}
2025-08-29 12:51:25 +03:00
type StoragePolicy struct {
2025-09-11 15:56:44 +03:00
ID uint64 `url:"id" json:"id"`
Limit int `url:"limit" json:"limit"`
2025-08-29 12:51:25 +03:00
}
2022-12-22 17:56:47 +03:00
// Create creates account
// Setting a cloud unit maximum to -1 or empty will not put any restrictions on the resource
2022-10-03 16:56:47 +03:00
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return 0, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudbroker/account/create"
2025-08-29 12:51:25 +03:00
res, err := a.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
2022-10-03 16:56:47 +03:00
if err != nil {
return 0, err
}
2022-12-22 17:56:47 +03:00
result, err := strconv.ParseUint(string(res), 10, 64)
2022-10-03 16:56:47 +03:00
if err != nil {
return 0, err
}
2022-12-22 17:56:47 +03:00
return result, nil
2022-10-03 16:56:47 +03:00
}