You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudbroker/account/create.go

108 lines
3.2 KiB

package account
import (
"context"
"net/http"
"strconv"
3 years ago
3 months ago
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
3 years ago
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
2 years ago
// CreateRequest struct for creating account
type CreateRequest struct {
3 years ago
// Display name
// Required: true
3 years ago
Name string `url:"name" json:"name" validate:"required"`
3 years ago
7 months ago
// Description
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
3 years ago
// Name of the account
// Required: true
3 years ago
Username string `url:"username" json:"username" validate:"required"`
3 years ago
// Email
// Required: false
3 years ago
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
3 years ago
3 months ago
// Storage policies
// Required: false
2 months ago
StoragePolicies []StoragePolicy `url:"-" json:"storage_policies,omitempty"`
3 months ago
3 years ago
// Max size of memory in MB
// Required: false
3 years ago
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
3 years ago
// Max size of aggregated vdisks in GB
// Required: false
3 years ago
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
3 years ago
// Max number of CPU cores
// Required: false
3 years ago
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
3 years ago
// Max sent/received network transfer peering
// Required: false
3 years ago
MaxNetworkPeerTransfer int64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
3 years ago
// Max number of assigned public IPs
// Required: false
3 years ago
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
3 years ago
// If true send emails when a user is granted access to resources
// Required: false
3 years ago
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
3 years ago
// Limit (positive) or disable (0) GPU resources
// Required: false
3 years ago
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
3 years ago
// List of strings with pools
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
3 years ago
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
2 years ago
// Advanced compute features,
4 months ago
// one of: hugepages, numa, cpupin, vfnic, dpdk, changemac, trunk
2 years ago
// Required: false
ComputeFeatures []string `url:"computeFeatures,omitempty" json:"computeFeatures,omitempty" validate:"omitempty,computeFeatures"`
4 months ago
// Default zone ID
// Required: false
DefaultZoneID uint64 `url:"defaultZoneId,omitempty" json:"defaultZoneId,omitempty"`
// Zones
// Required: false
ZoneIDs []uint64 `url:"zoneIds,omitempty" json:"zoneIds,omitempty"`
}
3 months ago
type StoragePolicy struct {
2 months ago
ID uint64 `url:"id" json:"id"`
Limit int `url:"limit" json:"limit"`
3 months ago
}
3 years ago
// Create creates account
// Setting a cloud unit maximum to -1 or empty will not put any restrictions on the resource
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
3 years ago
err := validators.ValidateRequest(req)
if err != nil {
2 years ago
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/create"
3 months ago
res, err := a.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return 0, err
}
3 years ago
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
3 years ago
return result, nil
}