1.1.0
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for creating account
|
||||
@@ -55,17 +53,6 @@ type CreateRequest struct {
|
||||
// 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 must be one of:
|
||||
// - compute
|
||||
// - vins
|
||||
// - k8s
|
||||
// - openshift
|
||||
// - lb
|
||||
// - flipgroup
|
||||
// Required: false
|
||||
ResTypes []string `url:"resourceTypes,omitempty"`
|
||||
}
|
||||
|
||||
func (arq CreateRequest) validate() error {
|
||||
@@ -75,14 +62,6 @@ func (arq CreateRequest) validate() error {
|
||||
if arq.Username == "" {
|
||||
return errors.New("validation-error: field Username can not be empty")
|
||||
}
|
||||
if len(arq.ResTypes) > 0 {
|
||||
for _, value := range arq.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
|
||||
}
|
||||
|
||||
@@ -36,6 +36,9 @@ type Resource struct {
|
||||
// Disk size
|
||||
DiskSize int64 `json:"disksize"`
|
||||
|
||||
// Disk size max
|
||||
DiskSizeMax int64 `json:"disksizemax"`
|
||||
|
||||
// Number of External IPs
|
||||
ExtIPs int64 `json:"extips"`
|
||||
|
||||
@@ -47,6 +50,18 @@ type Resource struct {
|
||||
|
||||
// Number of RAM
|
||||
RAM int64 `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"`
|
||||
}
|
||||
|
||||
// Access Control List
|
||||
@@ -138,12 +153,18 @@ type InfoAccount struct {
|
||||
// Resource limits
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
|
||||
// Resource types
|
||||
ResourceTypes []string `json:"resourceTypes"`
|
||||
|
||||
// Send access emails
|
||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// UniqPools
|
||||
UniqPools []string `json:"uniqPools"`
|
||||
|
||||
// UpdatedTime
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
@@ -258,6 +279,9 @@ type ItemDisk struct {
|
||||
// SepID
|
||||
SepID uint64 `json:"sepId"`
|
||||
|
||||
// Shareable
|
||||
Shareable bool `json:"shareable"`
|
||||
|
||||
// Size max
|
||||
SizeMax uint64 `json:"sizeMax"`
|
||||
|
||||
@@ -351,6 +375,9 @@ type Consumed struct {
|
||||
// Disk size
|
||||
DiskSize uint64 `json:"disksize"`
|
||||
|
||||
// Disk size max
|
||||
DiskSizeMax int64 `json:"disksizemax"`
|
||||
|
||||
// External IPs
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
|
||||
@@ -362,6 +389,9 @@ type Consumed struct {
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// SEPs
|
||||
SEPs map[string]map[string]DiskUsage `json:"seps"`
|
||||
}
|
||||
|
||||
// Limits
|
||||
@@ -372,6 +402,9 @@ type Limits struct {
|
||||
// Disk size
|
||||
DiskSize int64 `json:"disksize"`
|
||||
|
||||
// Disk size max
|
||||
DiskSizeMax int64 `json:"disksizemax"`
|
||||
|
||||
// External IPs
|
||||
ExtIPs int64 `json:"extips"`
|
||||
|
||||
@@ -383,6 +416,9 @@ type Limits struct {
|
||||
|
||||
// Number of RAM
|
||||
RAM int64 `json:"ram"`
|
||||
|
||||
// SEPs number
|
||||
SEPs uint64 `json:"seps"`
|
||||
}
|
||||
|
||||
// Resources of resource group
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update account
|
||||
@@ -59,17 +57,6 @@ type UpdateRequest struct {
|
||||
// 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 must be one of:
|
||||
// - compute
|
||||
// - vins
|
||||
// - k8s
|
||||
// - openshift
|
||||
// - lb
|
||||
// - flipgroup
|
||||
// Required: false
|
||||
ResTypes []string `url:"resourceTypes,omitempty"`
|
||||
}
|
||||
|
||||
func (arq UpdateRequest) validate() error {
|
||||
@@ -79,14 +66,6 @@ func (arq UpdateRequest) validate() error {
|
||||
if arq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if len(arq.ResTypes) > 0 {
|
||||
for _, value := range arq.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
|
||||
}
|
||||
|
||||
65
pkg/cloudbroker/account/update_resource_types.go
Normal file
65
pkg/cloudbroker/account/update_resource_types.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package account
|
||||
|
||||
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 account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId"`
|
||||
|
||||
// Resource types available to create in this account
|
||||
// Each element in a resource type slice must be one of:
|
||||
// - compute
|
||||
// - vins
|
||||
// - k8s
|
||||
// - openshift
|
||||
// - lb
|
||||
// - flipgroup
|
||||
// Required: true
|
||||
ResTypes []string `url:"resourceTypes"`
|
||||
}
|
||||
|
||||
func (arq UpdateResourceTypesRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if len(arq.ResTypes) > 0 {
|
||||
for _, value := range arq.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 (a Account) UpdateResourceTypes(ctx context.Context, req UpdateResourceTypesRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/updateResourceTypes"
|
||||
|
||||
res, err := a.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
|
||||
}
|
||||
Reference in New Issue
Block a user