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

107 lines
3.1 KiB
Go
Raw Normal View History

2022-08-11 08:09:54 +00:00
package rg
import (
"context"
2022-10-03 16:56:47 +03:00
"net/http"
2022-08-11 08:09:54 +00:00
"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-08-11 08:09:54 +00:00
)
2023-10-25 17:37:18 +03:00
// CreateRequest struct to create resource group
2022-08-11 08:09:54 +00:00
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,min=2"`
2022-12-22 17:56:47 +03:00
2025-08-29 12:51:25 +03:00
// Storage policies
// Required: false
StoragePolicies []StoragePolicy `url:"storage_policies" json:"storage_policies"`
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 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.
// Allowed values are:
// - 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
// Private network IP CIDR if default network PRIVATE
// Required: false
2023-03-01 19:05:53 +03:00
IPCIDR string `url:"ipcidr,omitempty" json:"ipcidr,omitempty"`
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"`
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"`
2022-08-11 08:09:54 +00: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 resource group
2022-10-03 16:56:47 +03:00
func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-12-22 17:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return 0, validators.ValidationErrors(validators.GetErrors(err))
2022-08-11 08:09:54 +00:00
}
url := "/cloudapi/rg/create"
2022-12-22 17:56:47 +03:00
2025-08-29 12:51:25 +03:00
res, err := r.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
2022-08-11 08:09:54 +00:00
if err != nil {
return 0, err
}
2022-12-22 17:56:47 +03:00
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
2022-08-11 08:09:54 +00:00
}