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 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
}

View File

@@ -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

View File

@@ -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
}

View 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
}

View File

@@ -27,7 +27,7 @@ func (crq ListGPURequest) validate() error {
}
// ListVGPU gets list GPU for compute
func (c Compute) ListVGPU(ctx context.Context, req ListGPURequest) ([]interface{}, error) {
func (c Compute) ListGPU(ctx context.Context, req ListGPURequest) ([]interface{}, error) {
err := req.validate()
if err != nil {
return nil, err

View File

@@ -401,6 +401,9 @@ type ItemDisk struct {
// Pool
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
// Purge attempts
PurgeAttempts uint64 `json:"purgeAttempts"`
@@ -425,6 +428,9 @@ type ItemDisk struct {
// SEP ID
SEPID uint64 `json:"sepId"`
// Shareable
Shareable bool `json:"shareable"`
// Size max
SizeMax uint64 `json:"sizeMax"`
@@ -677,6 +683,9 @@ type InfoCompute struct {
// Tech status
TechStatus string `json:"techStatus"`
// Total disk size
TotalDiskSize uint64 `json:"totalDisksSize"`
// Updated by
UpdatedBy string `json:"updatedBy"`
@@ -692,6 +701,9 @@ type InfoCompute struct {
// List VGPU IDs
VGPUs []uint64 `json:"vgpus"`
// VINS connected
VINSConnected uint64 `json:"vinsConnected"`
// Virtual image ID
VirtualImageID uint64 `json:"virtualImageId"`
}
@@ -708,7 +720,7 @@ type RecordCompute struct {
// Main information about compute for list
type ItemCompute struct {
// List of disk IDs
Disks []uint64 `json:"disks"`
Disks []InfoDisk `json:"disks"`
// Main information about compute
InfoCompute
@@ -720,6 +732,15 @@ type ItemCompute struct {
VINSConnected uint64 `json:"vinsConnected"`
}
// Information Disk
type InfoDisk struct {
// ID
ID uint64 `json:"id"`
// PCISlot
PCISlot uint64 `json:"pciSlot"`
}
// List computes
type ListComputes []ItemCompute

View File

@@ -56,6 +56,9 @@ type InfoDisk struct {
// Boot partition
BootPartition uint64 `json:"bootPartition"`
// Computes
Computes map[string]string `json:"computes"`
// Created time
CreatedTime uint64 `json:"createdTime"`
@@ -119,6 +122,9 @@ type InfoDisk struct {
// Pool
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
// Purge attempts
PurgeAttempts uint64 `json:"purgeAttempts"`
@@ -143,11 +149,14 @@ type InfoDisk struct {
// SEP ID
SEPID uint64 `json:"sepId"`
// Shareable
Shareable bool `json:"shareable"`
// Size max
SizeMax uint64 `json:"sizeMax"`
// Size used
SizeUsed uint64 `json:"sizeUsed"`
SizeUsed float64 `json:"sizeUsed"`
// List snapshots
Snapshots ListSnapshots `json:"snapshots"`
@@ -179,12 +188,6 @@ type RecordDisk struct {
// Main information for list disks
type ItemDisk struct {
// Compute ID
ComputeID uint64 `json:"computeId"`
// Compute name
ComputeName string `json:"computeName"`
// Machine ID
MachineID uint64 `json:"machineId"`
@@ -200,12 +203,6 @@ type ListDisks []ItemDisk
// Main information about deleted disk
type ItemDeletedDisk struct {
// Compute ID
ComputeID uint64 `json:"computeId"`
// Compute name
ComputeName string `json:"computeName"`
// Machine ID
MachineID uint64 `json:"machineId"`
@@ -254,6 +251,9 @@ type ItemSnapshot struct {
// Label
Label string `json:"label"`
// Reference ID
ReferenceID string `json:"referenceId"`
// Resource ID
ResID string `json:"resId"`

View File

@@ -12,12 +12,18 @@ type DeviceMigrateRequest struct {
// ID of external network
// Required: true
NetID uint64 `url:"net_id"`
// Target stack ID to migrate to
StackID uint64 `url:"stackId"`
}
func (erq DeviceMigrateRequest) validate() error {
if erq.NetID == 0 {
return errors.New("validation-error: field NetID must be set")
}
if erq.StackID == 0 {
return errors.New("validation-error: field StackID must be set")
}
return nil
}

View File

@@ -127,6 +127,9 @@ type RecordExtNet struct {
// CheckIPs
CheckIPs []string `json:"checkIPs"`
// CheckIps
CheckIps []string `json:"checkIps"`
// List DNS
DNS []string `json:"dns"`

View File

@@ -17,6 +17,9 @@ type RecordResource struct {
// Disk size
DiskSize uint64 `json:"disksize"`
// Disk size max
DiskSizeMax int64 `json:"disksizemax"`
// External IPs
ExtIPs uint64 `json:"extips"`
@@ -28,6 +31,18 @@ type RecordResource 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"`
}
// Detailed information about grid

View File

@@ -74,6 +74,9 @@ type RecordImage struct {
// Pool
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
// Provider name
ProviderName string `json:"provider_name"`

View File

@@ -62,9 +62,9 @@ type MassCreateRequest struct {
// Required: false
NetID uint64 `url:"netId,omitempty"`
// IP address to assign to this VM when connecting to the specified network
// Input data for cloud-init facility
// Required: false
IPAddr string `url:"ipAddr,omitempty"`
UserData string `url:"userdata,omitempty"`
// Text description of this VM
// Required: false

View File

@@ -66,7 +66,7 @@ type MassCreateRequest struct {
// Required: false
IPAddr string `url:"ipAddr,omitempty"`
// User data
// Input data for cloud-init facility
// Required: false
UserData string `url:"userdata,omitempty"`

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
}