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/bservice/group_add.go

115 lines
3.3 KiB

3 years ago
package bservice
import (
"context"
"net/http"
3 years ago
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
3 years ago
)
2 years ago
// GroupAddRequest struct to create new compute group within BasicService
3 years ago
type GroupAddRequest struct {
3 years ago
// ID of the Basic Service to add a group to
// Required: true
2 years ago
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
3 years ago
// Name of the Compute Group to add
// Required: true
2 years ago
Name string `url:"name" json:"name" validate:"required"`
3 years ago
// Computes number. Defines how many computes must be there in the group
// Required: true
2 years ago
Count uint64 `url:"count" json:"count" validate:"required"`
3 years ago
// Compute CPU number. All computes in the group have the same CPU count
// Required: true
2 years ago
CPU uint64 `url:"cpu" json:"cpu" validate:"required"`
3 years ago
// Compute RAM volume in MB. All computes in the group have the same RAM volume
// Required: true
2 years ago
RAM uint64 `url:"ram" json:"ram" validate:"required"`
3 years ago
// Compute boot disk size in GB
// Required: true
2 years ago
Disk uint64 `url:"disk" json:"disk" validate:"required"`
3 years ago
// OS image ID to create computes from
// Required: true
2 years ago
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
3 years ago
3 months ago
// Compute driver like a KVM_X86, etc.
3 years ago
// Required: true
3 months ago
Driver string `url:"driver" json:"driver" validate:"required"`
3 years ago
3 years ago
// Storage endpoint provider ID
// Required: false
3 years ago
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
3 years ago
// Pool to use if sepId is set, can be also empty if needed to be chosen by system
// Required: false
3 years ago
SEPPool string `url:"sepPool,omitempty" json:"sepPool,omitempty"`
3 years ago
3 years ago
// Group role tag. Can be empty string, does not have to be unique
// Required: false
3 years ago
Role string `url:"role,omitempty" json:"role,omitempty"`
3 years ago
// List of ViNSes to connect computes to
// Required: false
3 years ago
VINSes []uint64 `url:"vinses,omitempty" json:"vinses,omitempty"`
3 years ago
// List of external networks to connect computes to
// Required: false
3 years ago
ExtNets []uint64 `url:"extnets,omitempty" json:"extnets,omitempty"`
3 years ago
// Time of Compute Group readiness
// Required: false
TimeoutStart uint64 `url:"timeoutStart,omitempty" json:"timeoutStart,omitempty"`
2 years ago
// Meta data for working group computes, format YAML "user_data": 1111
// Required: false
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
7 months ago
//Chipset "i440fx" or "Q35
//Required: false
6 months ago
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"chipset,omitempty"`
3 months ago
// ID of the chosen storage policy
// Required: false
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
3 years ago
}
2 years ago
// GetRAM returns RAM field values
func (r GroupAddRequest) GetRAM() map[string]uint64 {
res := make(map[string]uint64, 1)
res["RAM"] = r.RAM
return res
}
3 years ago
// GroupAdd creates new Compute Group within BasicService.
// Compute Group is NOT started automatically,
// so you need to explicitly start it
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest) (uint64, error) {
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/bservice/groupAdd"
3 years ago
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, 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
}