This commit is contained in:
stSolo
2023-01-23 15:39:41 +03:00
parent ef0dac9b3a
commit 7ddd8c5fbe
39 changed files with 869 additions and 301 deletions

View File

@@ -5,8 +5,6 @@ import (
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for create resource group
@@ -84,17 +82,6 @@ type CreateRequest struct {
// List of strings with pools i.e.: ["sep1_poolName1", "sep2_poolName2"]
// Required: false
UniqPools []string `url:"unuqPools,omitempty"`
// Resource types available to create in this account
// Each element in a resource type slice should be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: false
ResTypes []string `url:"resourceTypes,omitempty"`
}
func (rgrq CreateRequest) validate() error {
@@ -107,14 +94,6 @@ func (rgrq CreateRequest) validate() error {
if len(rgrq.Name) < 2 {
return errors.New("field Name can not be shorter than two bytes")
}
if len(rgrq.ResTypes) > 0 {
for _, value := range rgrq.ResTypes {
validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"})
if !validate {
return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]")
}
}
}
return nil
}

View File

@@ -29,6 +29,9 @@ type Reservation struct {
// Disk size
DiskSize uint64 `json:"disksize"`
// Max disk size
DiskSizeMax int64 `json:"disksizemax"`
// External IPs
ExtIPs uint64 `json:"extips"`
@@ -40,6 +43,18 @@ type Reservation struct {
// Number of RAM
RAM uint64 `json:"ram"`
// SEPs
SEPs map[string]map[string]DiskUsage `json:"seps"`
}
// Disk usage
type DiskUsage struct {
// Disk size
DiskSize float64 `json:"disksize"`
// Disk size max
DiskSizeMax float64 `json:"disksizemax"`
}
// Resources usage information
@@ -180,7 +195,7 @@ type ItemRG struct {
VMs []uint64 `json:"vms"`
// Resource types list
ResTypes []string `json:"resTypes"`
ResTypes []string `json:"resourceTypes"`
// Uniq pools
UniqPools []string `json:"uniqPools"`
@@ -217,7 +232,7 @@ type ItemAffinityGroupCompute struct {
type ListAffinityGroupCompute []ItemAffinityGroupCompute
// Main information about affinity rule
type ItemAffinityRule struct {
type ItemRule struct {
// GUID
GUID string `json:"guid"`
@@ -237,8 +252,8 @@ type ItemAffinityRule struct {
Value string `json:"value"`
}
// List affinity rules
type ListAffinityRules []ItemAffinityRule
// List rules
type ListRules []ItemRule
// Main information about compute
type ItemCompute struct {
@@ -252,13 +267,13 @@ type ItemCompute struct {
AffinityLabel string `json:"affinityLabel"`
// List affinity rules
AffinityRules ListAffinityRules `json:"affinityRules"`
AffinityRules ListRules `json:"affinityRules"`
// Affinity weight
AffinityWeight uint64 `json:"affinityWeight"`
// Anti affinity rules
AntiAffinityRules []interface{} `json:"antiAffinityRules"`
AntiAffinityRules ListRules `json:"antiAffinityRules"`
// Number of CPU
CPUs uint64 `json:"cpus"`

View File

@@ -5,8 +5,6 @@ import (
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for update resource group
@@ -54,31 +52,13 @@ type UpdateRequest struct {
// List of strings with pools i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,omitempty"`
// Resource types available to create in this account
// Each element in a resource type slice should be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: false
ResTypes []string `url:"resourceTypes,omitempty"`
}
func (rgrq UpdateRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if len(rgrq.ResTypes) > 0 {
for _, value := range rgrq.ResTypes {
validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"})
if !validate {
return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]")
}
}
}
return nil
}

View File

@@ -0,0 +1,65 @@
package rg
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for update resource types in account
type UpdateResourceTypesRequest struct {
// ID of resource group
// Required: true
RGID uint64 `url:"rgId"`
// Resource types available to create in this resource group
// Each element in a resource type slice must be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: true
ResTypes []string `url:"resourceTypes"`
}
func (rgrq UpdateResourceTypesRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if len(rgrq.ResTypes) > 0 {
for _, value := range rgrq.ResTypes {
validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"})
if !validate {
return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]")
}
}
}
return nil
}
func (r RG) UpdateResourceTypes(ctx context.Context, req UpdateResourceTypesRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/rg/updateResourceTypes"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}