Files
decort-golang-sdk/pkg/cloudapi/bservice/group_add.go

116 lines
3.3 KiB
Go
Raw Normal View History

2022-08-11 08:09:54 +00:00
package bservice
import (
"context"
2022-10-03 16:56:47 +03:00
"net/http"
2022-08-11 08:09:54 +00:00
"strconv"
2023-03-17 12:54:34 +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
// GroupAddRequest struct to create new compute group within BasicService
2022-08-11 08:09:54 +00:00
type GroupAddRequest struct {
2022-12-22 17:56:47 +03:00
// ID of the Basic Service to add a group to
// Required: true
2023-10-25 17:37:18 +03:00
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Name of the Compute Group to add
// Required: true
2023-10-25 17:37:18 +03:00
Name string `url:"name" json:"name" validate:"required"`
2022-12-22 17:56:47 +03:00
// Computes number. Defines how many computes must be there in the group
// Required: true
2023-10-25 17:37:18 +03:00
Count uint64 `url:"count" json:"count" validate:"required"`
2022-12-22 17:56:47 +03:00
// Compute CPU number. All computes in the group have the same CPU count
// Required: true
2023-10-25 17:37:18 +03:00
CPU uint64 `url:"cpu" json:"cpu" validate:"required"`
2022-12-22 17:56:47 +03:00
// Compute RAM volume in MB. All computes in the group have the same RAM volume
// Required: true
2023-10-25 17:37:18 +03:00
RAM uint64 `url:"ram" json:"ram" validate:"required"`
2022-12-22 17:56:47 +03:00
// Compute boot disk size in GB
// Required: true
2023-10-25 17:37:18 +03:00
Disk uint64 `url:"disk" json:"disk" validate:"required"`
2022-12-22 17:56:47 +03:00
// OS image ID to create computes from
// Required: true
2023-10-25 17:37:18 +03:00
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
2022-12-22 17:56:47 +03:00
2025-08-29 12:51:25 +03:00
// Compute driver like a KVM_X86, etc.
2022-12-22 17:56:47 +03:00
// Required: true
2025-08-29 12:51:25 +03:00
Driver string `url:"driver" json:"driver" validate:"required"`
2022-12-22 17:56:47 +03:00
2023-01-23 15:39:41 +03:00
// Storage endpoint provider ID
// Required: false
2023-03-01 19:05:53 +03:00
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
2023-01-23 15:39:41 +03:00
// Pool to use if sepId is set, can be also empty if needed to be chosen by system
// Required: false
2023-03-01 19:05:53 +03:00
SEPPool string `url:"sepPool,omitempty" json:"sepPool,omitempty"`
2023-01-23 15:39:41 +03:00
2022-12-22 17:56:47 +03:00
// Group role tag. Can be empty string, does not have to be unique
// Required: false
2023-03-01 19:05:53 +03:00
Role string `url:"role,omitempty" json:"role,omitempty"`
2022-12-22 17:56:47 +03:00
// List of ViNSes to connect computes to
// Required: false
2023-03-01 19:05:53 +03:00
VINSes []uint64 `url:"vinses,omitempty" json:"vinses,omitempty"`
2022-12-22 17:56:47 +03:00
// List of external networks to connect computes to
// Required: false
2023-03-01 19:05:53 +03:00
ExtNets []uint64 `url:"extnets,omitempty" json:"extnets,omitempty"`
2022-12-22 17:56:47 +03:00
// Time of Compute Group readiness
// Required: false
2023-03-17 12:54:34 +03:00
TimeoutStart uint64 `url:"timeoutStart,omitempty" json:"timeoutStart,omitempty"`
2023-09-24 12:11:31 +03:00
// Meta data for working group computes, format YAML "user_data": 1111
// Required: false
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
2025-04-09 11:21:07 +03:00
2025-12-08 16:16:35 +03:00
// Chipset "i440fx" or "Q35
// Default value : Q35
// Required: false
2025-05-07 13:15:39 +03:00
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"chipset,omitempty"`
2025-08-29 12:51:25 +03:00
// ID of the chosen storage policy
// Required: false
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
2022-08-11 08:09:54 +00:00
}
2024-04-16 14:26:06 +03:00
// GetRAM returns RAM field values
func (r GroupAddRequest) GetRAM() map[string]uint64 {
res := make(map[string]uint64, 1)
res["RAM"] = r.RAM
return res
}
2022-12-22 17:56:47 +03:00
// GroupAdd creates new Compute Group within BasicService.
// Compute Group is NOT started automatically,
// so you need to explicitly start it
2022-10-03 16:56:47 +03:00
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest) (uint64, error) {
2023-03-17 12:54:34 +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/bservice/groupAdd"
2022-12-22 17:56:47 +03:00
2022-10-03 16:56:47 +03:00
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, 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
}