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

112 lines
3.3 KiB
Go
Raw Normal View History

package rg
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"
)
2023-10-25 17:37:18 +03:00
// CreateRequest struct to create resource group
type CreateRequest struct {
2022-12-22 17:56:47 +03:00
// Account, which will own this resource group
// Required: true
2023-03-24 17:09:30 +03:00
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Grid ID
// Required: true
2023-03-24 17:09:30 +03:00
GID uint64 `url:"gid" json:"gid" validate:"required"`
2022-12-22 17:56:47 +03:00
// Name of this resource group. Must be unique within the account
// 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
// 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
2025-08-29 12:51:25 +03:00
// Storage policies
// Required: false
StoragePolicies []StoragePolicy `url:"-" json:"storage_policies,omitempty"`
2022-12-22 17:56:47 +03:00
// Max size of aggregated virtual disks 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
// Username - owner of this resource group.
// Leave blank to set current user as owner
// Required: false
2023-03-01 19:05:53 +03:00
Owner string `url:"owner,omitempty" json:"owner,omitempty"`
2022-12-22 17:56:47 +03:00
// Type of the default network for this resource group.
// virtual machines created in this resource group will be by default connected to this network.
// Should be one of:
// - PRIVATE
// - PUBLIC
// - NONE
// Required: false
2023-03-24 17:09:30 +03:00
DefNet string `url:"def_net,omitempty" json:"def_net,omitempty" validate:"omitempty,rgDefNet"`
2022-12-22 17:56:47 +03:00
// Text description of this resource group
// Required: false
2023-03-01 19:05:53 +03:00
Description string `url:"desc,omitempty" json:"desc,omitempty"`
2022-12-22 17:56:47 +03:00
// External network ID
// Required: false
2023-03-01 19:05:53 +03:00
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
2022-12-22 17:56:47 +03:00
// External IP address
// Required: false
2023-03-01 19:05:53 +03:00
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
2022-12-22 17:56:47 +03:00
// List of strings with pools i.e.: ["sep1_poolName1", "sep2_poolName2"]
// Required: false
2024-04-16 14:26:06 +03:00
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
// 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
// SDN access group id
// Required: false
SDNAccessGroupID string `url:"sdn_access_group_id,omitempty" json:"sdn_access_group_id,omitempty"`
}
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 resource group
func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
if err != nil {
2023-10-25 17:37:18 +03:00
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/rg/create"
2025-08-29 12:51:25 +03:00
res, err := r.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}