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/cloudapi/rg/create.go

111 lines
3.2 KiB

3 years ago
package rg
import (
"context"
"net/http"
3 years ago
"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"
3 years ago
)
2 years ago
// CreateRequest struct to create resource group
3 years ago
type CreateRequest struct {
3 years ago
// Account, which will own this resource group
// Required: true
3 years ago
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
3 years ago
// Grid ID
// Required: true
3 years ago
GID uint64 `url:"gid" json:"gid" validate:"required"`
3 years ago
// Name of this resource group. Must be unique within the account
// Required: true
3 years ago
Name string `url:"name" json:"name" validate:"required,min=2"`
3 years ago
3 months ago
// Storage policies
// Required: false
StoragePolicies []StoragePolicy `url:"storage_policies" json:"storage_policies"`
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 virtual disks 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
// Username - owner of this resource group.
// Leave blank to set current user as owner
// Required: false
3 years ago
Owner string `url:"owner,omitempty" json:"owner,omitempty"`
3 years ago
// 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
3 years ago
DefNet string `url:"def_net,omitempty" json:"def_net,omitempty" validate:"omitempty,rgDefNet"`
3 years ago
// Private network IP CIDR if default network PRIVATE
// Required: false
3 years ago
IPCIDR string `url:"ipcidr,omitempty" json:"ipcidr,omitempty"`
3 years ago
// Text description of this resource group
// Required: false
3 years ago
Description string `url:"desc,omitempty" json:"desc,omitempty"`
3 years ago
// External network ID
// Required: false
3 years ago
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
3 years ago
// External IP address
// Required: false
3 years ago
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
4 months ago
// SDN access group id
// Required: false
SDNAccessGroupID string `url:"sdn_access_group_id,omitempty" json:"sdn_access_group_id,omitempty"`
3 years ago
}
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 resource group
func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) {
3 years ago
err := validators.ValidateRequest(req)
3 years ago
if err != nil {
2 years ago
return 0, validators.ValidationErrors(validators.GetErrors(err))
3 years ago
}
url := "/cloudapi/rg/create"
3 years ago
3 months ago
res, err := r.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
3 years ago
if err != nil {
return 0, err
}
3 years ago
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
3 years ago
}