Compare commits

..

8 Commits

Author SHA1 Message Date
1c59ca338a v1.5.3 2023-08-15 11:42:30 +03:00
f1529c9aac v1.5.2 2023-08-09 19:33:50 +03:00
040235f92f v1.5.1 2023-07-24 18:13:52 +03:00
4a152cb44c v1.5.0 2023-07-24 16:43:10 +03:00
c78b1348e3 v1.5.0 2023-07-24 15:13:04 +03:00
8f152a2f63 v1.5.0 2023-07-21 15:14:10 +03:00
0be4d8fb0c v1.5.0-epsilon 2023-07-13 18:32:21 +03:00
Никита Сорокин
5025a17ea4 v1.5.0-delta 2023-07-13 15:28:07 +03:00
127 changed files with 2285 additions and 1382 deletions

View File

@@ -1,4 +1,10 @@
## Version 1.4.7 ## Version 1.5.3
### Bugfix ### Bugfix
- Deleted validate:"required" tag from IPCIDR field in cloudapi/vins/createInRg request struct - Add a fields SEPID and Pool in ListUnattachedRequest struct in cloudbroker/disks/listUnattached and cloudapi/disks/listUnattached
- Delete a field Shared in ListUnattachedRequest struct in cloudbroker/disks/listUnattached
- Delete tag Required at field Permanently in DiskDelRequest struct in cloudbroker/compute/disk_del and cloudapi/compute/disk_del
- Delete tag omitempty at field Permanently in DeleteRequest struct in cloudbroker/image/delete

View File

@@ -9,6 +9,7 @@ Decort SDK - это библиотека, написанная на языке G
- Версия 1.2.x Decort-SDK соответствует 3.8.5 версии платформы - Версия 1.2.x Decort-SDK соответствует 3.8.5 версии платформы
- Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы - Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы
- Версия 1.4.x Decort-SDK соответствует 3.8.6 версии платформы - Версия 1.4.x Decort-SDK соответствует 3.8.6 версии платформы
- Версия 1.5.x Decort-SDK соответствует 3.8.7 версии платформы
## Оглавление ## Оглавление

View File

@@ -4,6 +4,7 @@ import (
"crypto/tls" "crypto/tls"
"net/http" "net/http"
"net/url" "net/url"
"time"
"repository.basistech.ru/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
) )
@@ -17,14 +18,21 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
}, },
} }
var expiredTime time.Time
if cfg.Token != "" {
expiredTime = time.Now().AddDate(0, 0, 1)
}
return &http.Client{ return &http.Client{
Transport: &transportLegacy{ Transport: &transportLegacy{
base: transCfg, base: transCfg,
username: url.QueryEscape(cfg.Username), username: url.QueryEscape(cfg.Username),
password: url.QueryEscape(cfg.Password), password: url.QueryEscape(cfg.Password),
retries: cfg.Retries, retries: cfg.Retries,
token: cfg.Token, token: cfg.Token,
decortURL: cfg.DecortURL, decortURL: cfg.DecortURL,
expiryTime: expiredTime,
}, },
Timeout: cfg.Timeout.Get(), Timeout: cfg.Timeout.Get(),

View File

@@ -9,16 +9,17 @@ import (
) )
type transportLegacy struct { type transportLegacy struct {
base http.RoundTripper base http.RoundTripper
username string username string
password string password string
retries uint64 retries uint64
token string token string
decortURL string decortURL string
expiryTime time.Time
} }
func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, error) { func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, error) {
if t.token == "" { if t.token == "" || time.Now().After(t.expiryTime) {
body := fmt.Sprintf("username=%s&password=%s", t.username, t.password) body := fmt.Sprintf("username=%s&password=%s", t.username, t.password)
bodyReader := strings.NewReader(body) bodyReader := strings.NewReader(body)
@@ -39,6 +40,7 @@ func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, erro
token := string(tokenBytes) token := string(tokenBytes)
t.token = token t.token = token
t.expiryTime = time.Now().AddDate(0, 0, 1)
} }
tokenValue := fmt.Sprintf("&authkey=%s", t.token) tokenValue := fmt.Sprintf("&authkey=%s", t.token)
@@ -63,7 +65,9 @@ func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, erro
err = fmt.Errorf("%s", respBytes) err = fmt.Errorf("%s", respBytes)
resp.Body.Close() resp.Body.Close()
} }
if err != nil {
return nil, fmt.Errorf("could not execute request: %w", err)
}
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
} }
return nil, fmt.Errorf("could not execute request: %w", err) return nil, fmt.Errorf("could not execute request: %w", err)

View File

@@ -1,11 +1,19 @@
package validators package validators
import ( import (
"github.com/go-playground/validator/v10"
"regexp" "regexp"
"strings" "strings"
"github.com/go-playground/validator/v10"
) )
// computeDriverValidator is used to validate Driver field in kvmx86/kvmppc create.
func computeDriverValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeDriverValues)
}
// protoValidator is used to validate Proto fields. // protoValidator is used to validate Proto fields.
func protoValidator(fe validator.FieldLevel) bool { func protoValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
@@ -256,3 +264,11 @@ func strictLooseValidator(fe validator.FieldLevel) bool {
return StringInSlice(fieldValue, strictLooseValues) return StringInSlice(fieldValue, strictLooseValues)
} }
// name workerGroup must be more 3 symbol
func workerGroupNameValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
fieldValue = strings.Trim(fieldValue, " ")
return len(fieldValue) >= 3
}

View File

@@ -107,6 +107,12 @@ func errorMessage(fe validator.FieldError) string {
fe.Field(), fe.Field(),
joinValues(computeDataDisksValues)) joinValues(computeDataDisksValues))
case "computeDriver":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeDriverValues))
// Disk Validators // Disk Validators
case "diskType": case "diskType":
return fmt.Sprintf("%s %s must be one of the following: %s", return fmt.Sprintf("%s %s must be one of the following: %s",
@@ -121,6 +127,12 @@ func errorMessage(fe validator.FieldError) string {
fe.Field(), fe.Field(),
joinValues(flipgroupClientTypeValues)) joinValues(flipgroupClientTypeValues))
// k8s Validators
case "workerGroupName":
return fmt.Sprintf("%s %s must be more 3 symbol",
prefix,
fe.Field())
// KVM_X86/KVM_PPC Validators // KVM_X86/KVM_PPC Validators
case "kvmNetType": case "kvmNetType":
return fmt.Sprintf("%s %s must be one of the following: %s", return fmt.Sprintf("%s %s must be one of the following: %s",

View File

@@ -30,6 +30,11 @@ func registerAllValidators(validate *validator.Validate) error {
return err return err
} }
err = validate.RegisterValidation("computeDriver", computeDriverValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("accessType", accessTypeValidator) err = validate.RegisterValidation("accessType", accessTypeValidator)
if err != nil { if err != nil {
return err return err
@@ -175,5 +180,10 @@ func registerAllValidators(validate *validator.Validate) error {
return err return err
} }
err = validate.RegisterValidation("workerGroupName", workerGroupNameValidator)
if err != nil {
return err
}
return nil return nil
} }

View File

@@ -17,6 +17,7 @@ var (
computeNetTypeValues = []string{"EXTNET", "VINS"} computeNetTypeValues = []string{"EXTNET", "VINS"}
computeOrderValues = []string{"cdrom", "network", "hd"} computeOrderValues = []string{"cdrom", "network", "hd"}
computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"} computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"}
computeDriverValues = []string{"KVM_X86", "SVA_KVM_X86"}
diskTypeValues = []string{"B", "T", "D"} diskTypeValues = []string{"B", "T", "D"}

View File

@@ -16,7 +16,7 @@ type GetResourceConsumptionRequest struct {
} }
// GetResourceConsumption show amount of consumed and reserved resources (cpu, ram, disk) by specific account // GetResourceConsumption show amount of consumed and reserved resources (cpu, ram, disk) by specific account
func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*ItemResourceConsumption, error) { func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResourceConsumption, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -26,7 +26,7 @@ func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceCons
url := "/cloudapi/account/getResourceConsumption" url := "/cloudapi/account/getResourceConsumption"
info := ItemResourceConsumption{} info := RecordResourceConsumption{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil { if err != nil {

View File

@@ -12,15 +12,35 @@ import (
type ListTemplatesRequest struct { type ListTemplatesRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Include deleted images // Include deleted images
// Required: false // Required: false
IncludeDeleted bool `url:"includedeleted" json:"includedeleted"` IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
// Find by image id
// Required: false
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by type
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
} }
// ListTemplates gets list templates which can be managed by this account // ListTemplates gets list templates which can be managed by this account
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (ListTemplates, error) { func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (*ListTemplates, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -42,5 +62,5 @@ func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (L
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -33,7 +33,7 @@ type ResourceLimits struct {
CUD float64 `json:"CU_D"` CUD float64 `json:"CU_D"`
// Max disk size, GB // Max disk size, GB
CU_DM float64 `json:"CU_DM"` CUDM float64 `json:"CU_DM"`
// Number of public IP addresses // Number of public IP addresses
CUI float64 `json:"CU_I"` CUI float64 `json:"CU_I"`
@@ -115,6 +115,14 @@ type DiskUsage struct {
DiskSizeMax float64 `json:"disksizemax"` DiskSizeMax float64 `json:"disksizemax"`
} }
// Information about resource consumption
type RecordResourceConsumption struct {
ItemResourceConsumption
// Resource limits
ResourceLimits ResourceLimits `json:"resourceLimits"`
}
// Information about resources // Information about resources
type ItemResourceConsumption struct { type ItemResourceConsumption struct {
// Current information about resources // Current information about resources
@@ -557,7 +565,13 @@ type ItemTemplate struct {
} }
// List of templates // List of templates
type ListTemplates []ItemTemplate type ListTemplates struct {
// Data
Data []ItemTemplate `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about FLIPGroup // Main information about FLIPGroup
type ItemFLIPGroup struct { type ItemFLIPGroup struct {

View File

@@ -0,0 +1,40 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for deleting compute's custome fields
type DeleteCustomFieldsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// DeleteCustomFields deletes computes custom fields
func (c Compute) DeleteCustomFields(ctx context.Context, req DeleteCustomFieldsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/deleteCustomFields"
res, err := c.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

@@ -22,11 +22,6 @@ type DiskAddRequest struct {
// Required: true // Required: true
Size uint64 `url:"size" json:"size" validate:"required"` Size uint64 `url:"size" json:"size" validate:"required"`
// Storage endpoint provider ID
// By default the same with boot disk
// Required: false
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Type of the disk // Type of the disk
// Should be one of: // Should be one of:
// - D // - D
@@ -34,6 +29,11 @@ type DiskAddRequest struct {
// Required: false // Required: false
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"` DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
// Storage endpoint provider ID
// By default the same with boot disk
// Required: false
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Pool name // Pool name
// By default will be chosen automatically // By default will be chosen automatically
// Required: false // Required: false

View File

@@ -20,7 +20,7 @@ type DiskDelRequest struct {
// False if disk is to be deleted to recycle bin // False if disk is to be deleted to recycle bin
// Required: true // Required: true
Permanently bool `url:"permanently" json:"permanently" validate:"required"` Permanently bool `url:"permanently" json:"permanently"`
} }
// DiskDel delete disk and detach from compute // DiskDel delete disk and detach from compute

View File

@@ -8,19 +8,15 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get list GPU for compute // Request struct for getting Compute's customFields
type ListGPURequest struct { type GetCustomFieldsRequest struct {
// ID of compute instance // Compute ID
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Also list destroyed
// Required: false
ListDestroyed bool `url:"list_destroyed,omitempty" json:"list_destroyed,omitempty"`
} }
// ListVGPU gets list GPU for compute // GetCustomFields gets Compute's customFields
func (c Compute) ListGPU(ctx context.Context, req ListGPURequest) ([]interface{}, error) { func (c Compute) GetCustomFields(ctx context.Context, req GetCustomFieldsRequest) (interface{}, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -28,19 +24,19 @@ func (c Compute) ListGPU(ctx context.Context, req ListGPURequest) ([]interface{}
} }
} }
url := "/cloudbroker/compute/listGpu" url := "/cloudapi/compute/getCustomFields"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
list := make([]interface{}, 0) var info interface{}
err = json.Unmarshal(res, &list) err = json.Unmarshal(res, &info)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return list, nil return &info, nil
} }

View File

@@ -14,6 +14,14 @@ type RecordACL struct {
RGACL ListACL `json:"rgAcl"` RGACL ListACL `json:"rgAcl"`
} }
type ListUsers struct {
// Data
Data RecordACL `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
type Explicit bool type Explicit bool
func (e *Explicit) UnmarshalJSON(b []byte) error { func (e *Explicit) UnmarshalJSON(b []byte) error {
@@ -89,7 +97,13 @@ type ItemSnapshot struct {
} }
// List of snapshots // List of snapshots
type ListSnapShots []ItemSnapshot type ListSnapShots struct {
// Data
Data []ItemSnapshot `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about port forward // Main information about port forward
type ItemPFW struct { type ItemPFW struct {
@@ -116,7 +130,13 @@ type ItemPFW struct {
} }
// List port forwards // List port forwards
type ListPFWs []ItemPFW type ListPFWs struct {
// Data
Data []ItemPFW `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about affinity relations // Main information about affinity relations
type RecordAffinityRelations struct { type RecordAffinityRelations struct {
@@ -403,7 +423,7 @@ type RecordCompute struct {
SnapSets ListSnapSets `json:"snapSets"` SnapSets ListSnapSets `json:"snapSets"`
// Stateless SepID // Stateless SepID
StatelessSepID uint64 `json:"statelessSepId"` StatelessSepID int64 `json:"statelessSepId"`
// Stateless SepType // Stateless SepType
StatelessSepType string `json:"statelessSepType"` StatelessSepType string `json:"statelessSepType"`
@@ -862,7 +882,7 @@ type ItemCompute struct {
SnapSets ListSnapSets `json:"snapSets"` SnapSets ListSnapSets `json:"snapSets"`
// Stateless SepID // Stateless SepID
StatelessSepID uint64 `json:"statelessSepId"` StatelessSepID int64 `json:"statelessSepId"`
// Stateless SepType // Stateless SepType
StatelessSepType string `json:"statelessSepType"` StatelessSepType string `json:"statelessSepType"`

View File

@@ -16,7 +16,7 @@ type PFWListRequest struct {
} }
// PFWList gets compute port forwards list // PFWList gets compute port forwards list
func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (ListPFWs, error) { func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (*ListPFWs, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -38,5 +38,5 @@ func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (ListPFWs, err
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -0,0 +1,43 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for setting customFields values for the Compute
type SetCustomFieldsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Custom fields for Compute. Must be dict.
// Required: true
CustomFields string `url:"customFields" json:"customFields" validate:"required"`
}
// SetCustomFields sets customFields values for the Compute
func (c Compute) SetCustomFields(ctx context.Context, req SetCustomFieldsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/setCustomFields"
res, err := c.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

@@ -16,7 +16,7 @@ type SnapshotListRequest struct {
} }
// SnapshotList gets list compute snapshots // SnapshotList gets list compute snapshots
func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapShots, error) { func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (*ListSnapShots, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -38,5 +38,5 @@ func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (Lis
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -16,7 +16,7 @@ type UserListRequest struct {
} }
// UserList gets users list for compute // UserList gets users list for compute
func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL, error) { func (c Compute) UserList(ctx context.Context, req UserListRequest) (*ListUsers, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -31,7 +31,7 @@ func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL,
return nil, err return nil, err
} }
list := RecordACL{} list := ListUsers{}
err = json.Unmarshal(res, &list) err = json.Unmarshal(res, &list)
if err != nil { if err != nil {

View File

@@ -1,10 +0,0 @@
package cloudapi
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/computeci"
)
// Accessing the ComputeCI method group
func (ca *CloudAPI) ComputeCI() *computeci.ComputeCI {
return computeci.New(ca.client)
}

View File

@@ -1,18 +0,0 @@
// API Actor for managing ComputeCI. This actor is a final API for admin to manage ComputeCI
package computeci
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
)
// Structure for creating request to computeci
type ComputeCI struct {
client interfaces.Caller
}
// Builder for computeci endpoints
func New(client interfaces.Caller) *ComputeCI {
return &ComputeCI{
client,
}
}

View File

@@ -1,53 +0,0 @@
package computeci
// FilterByID returns ListComputeCI with specified ID.
func (lci ListComputeCI) FilterByID(id uint64) ListComputeCI {
predicate := func(ic ItemComputeCI) bool {
return ic.ID == id
}
return lci.FilterFunc(predicate)
}
// FilterByName returns ListComputeCI with specified Name.
func (lci ListComputeCI) FilterByName(name string) ListComputeCI {
predicate := func(ic ItemComputeCI) bool {
return ic.Name == name
}
return lci.FilterFunc(predicate)
}
// FilterByStatus returns ListComputeCI with specified Status.
func (lci ListComputeCI) FilterByStatus(status string) ListComputeCI {
predicate := func(ic ItemComputeCI) bool {
return ic.Status == status
}
return lci.FilterFunc(predicate)
}
// FilterFunc allows filtering ListComputeCI based on a user-specified predicate.
func (lci ListComputeCI) FilterFunc(predicate func(ItemComputeCI) bool) ListComputeCI {
var result ListComputeCI
for _, item := range lci.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemComputeCI
// If none was found, returns an empty struct.
func (lci ListComputeCI) FindOne() ItemComputeCI {
if lci.EntryCount == 0 {
return ItemComputeCI{}
}
return lci.Data[0]
}

View File

@@ -1,98 +0,0 @@
package computeci
import "testing"
var computeciItems = ListComputeCI{
Data: []ItemComputeCI{
{
CustomFields: map[string]interface{}{},
Description: "",
Drivers: []string{
"KVM_X86",
},
GUID: 1,
ID: 1,
Name: "computeci_1",
Status: "ENABLED",
Template: "",
},
{
CustomFields: map[string]interface{}{},
Description: "",
Drivers: []string{
"KVM_X86",
},
GUID: 2,
ID: 2,
Name: "computeci_2",
Status: "ENABLED",
Template: "",
},
{
CustomFields: map[string]interface{}{},
Description: "",
Drivers: []string{
"SVA_KVM_X86",
},
GUID: 3,
ID: 3,
Name: "computeci_3",
Status: "DISABLED",
Template: "",
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
actual := computeciItems.FilterByID(2).FindOne()
if actual.ID != 2 {
t.Fatal("expected ID 2, found: ", actual.ID)
}
}
func TestFilterByName(t *testing.T) {
actual := computeciItems.FilterByName("computeci_3").FindOne()
if actual.Name != "computeci_3" {
t.Fatal("expected Name 'computeci_2', found: ", actual.Name)
}
}
func TestFilterByStatus(t *testing.T) {
actual := computeciItems.FilterByStatus("ENABLED")
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.Status != "ENABLED" {
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
}
}
}
func TestFilterFunc(t *testing.T) {
actual := computeciItems.FilterFunc(func(icc ItemComputeCI) bool {
for _, item := range icc.Drivers {
if item == "KVM_X86" {
return true
}
}
return false
})
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
for _, driver := range item.Drivers {
if driver != "KVM_X86" {
t.Fatal("expected 'KVM_X86' Driver, found: ", driver)
}
}
}
}

View File

@@ -1,42 +0,0 @@
package computeci
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for information about computeci
type GetRequest struct {
// ID of the Compute CI
// Required: true
ComputeCIID uint64 `url:"computeciId" json:"computeciId" validate:"required"`
}
// Get gets information about computeci by ID
func (c ComputeCI) Get(ctx context.Context, req GetRequest) (*ItemComputeCI, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validatonError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validatonError)
}
}
url := "/cloudapi/computeci/get"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := ItemComputeCI{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -1,53 +0,0 @@
package computeci
import (
"context"
"encoding/json"
"net/http"
)
// Request struct for get list of computeci
type ListRequest struct {
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by computeci ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by drivers
// Find by computeci ID
Drivers []string `url:"drivers,omitempty" json:"drivers,omitempty"`
// If true list deleted instances as well
// Required: false
IncludeDeleted bool `url:"includeDeleted,omitempty" json:"includeDeleted,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of computeci instances
func (c ComputeCI) List(ctx context.Context, req ListRequest) (*ListComputeCI, error) {
url := "/cloudapi/computeci/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListComputeCI{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -1,35 +0,0 @@
package computeci
// Main information about computeci
type ItemComputeCI struct {
// Custom fields
CustomFields map[string]interface{} `json:"customFields"`
// Description
Description string `json:"desc"`
// List drivers
Drivers []string `json:"drivers"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Template
Template string `json:"template"`
}
// List of computeci instances
type ListComputeCI struct {
Data []ItemComputeCI `json:"data"`
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -1,43 +0,0 @@
package computeci
import (
"encoding/json"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (lci ListComputeCI) Serialize(params ...string) (serialization.Serialized, error) {
if lci.EntryCount == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(lci, prefix, indent)
}
return json.Marshal(lci)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (ic ItemComputeCI) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(ic, prefix, indent)
}
return json.Marshal(ic)
}

View File

@@ -40,6 +40,14 @@ type ListRequest struct {
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -24,10 +24,6 @@ type ListUnattachedRequest struct {
// Required: false // Required: false
Status string `url:"status,omitempty" json:"status,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by shared, true or false
// Required: false
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
// Type of the disks // Type of the disks
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
@@ -36,6 +32,14 @@ type ListUnattachedRequest struct {
// Required: false // Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -13,10 +13,26 @@ type ListComputesRequest struct {
// Filter by account ID // Filter by account ID
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Find by rg ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by compute ID
// Required: false
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
} }
// ListComputes gets computes from account with extnets // ListComputes gets computes from account with extnets
func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (ListExtNetComputes, error) { func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (*ListExtNetComputes, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -38,5 +54,5 @@ func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (List
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -59,7 +59,13 @@ type ItemExtNetCompute struct {
} }
// List of information about computes with external network // List of information about computes with external network
type ListExtNetComputes []ItemExtNetCompute type ListExtNetComputes struct {
// Data
Data []ItemExtNetCompute `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// QOS // QOS
type QOS struct { type QOS struct {
@@ -118,6 +124,12 @@ type Excluded struct {
// ClientType // ClientType
ClientType string `json:"clientType"` ClientType string `json:"clientType"`
// Domain name
DomainName string `json:"domainname"`
// Host name
HostName string `json:"hostname"`
// IP // IP
IP string `json:"ip"` IP string `json:"ip"`

View File

@@ -45,7 +45,7 @@ type CreateRequest struct {
} }
// Create method will create a new FLIPGorup in the specified Account // Create method will create a new FLIPGorup in the specified Account
func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGroup, error) { func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGroupCreated, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -60,7 +60,7 @@ func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGr
return nil, err return nil, err
} }
info := RecordFLIPGroup{} info := RecordFLIPGroupCreated{}
err = json.Unmarshal(res, &info) err = json.Unmarshal(res, &info)
if err != nil { if err != nil {

View File

@@ -16,7 +16,7 @@ type GetRequest struct {
} }
// Get gets details of the specified Floating IP group // Get gets details of the specified Floating IP group
func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*ItemFLIPGroup, error) { func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*RecordFLIPGroup, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -31,7 +31,7 @@ func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*ItemFLIPGroup, err
return nil, err return nil, err
} }
info := ItemFLIPGroup{} info := RecordFLIPGroup{}
err = json.Unmarshal(res, &info) err = json.Unmarshal(res, &info)
if err != nil { if err != nil {

View File

@@ -1,7 +1,7 @@
package flipgroup package flipgroup
// Main information about FLIPGroup // Main information about FLIPGroup
type RecordFLIPGroup struct { type RecordFLIPGroupCreated struct {
// Default GW // Default GW
DefaultGW string `json:"defaultGW"` DefaultGW string `json:"defaultGW"`
@@ -18,6 +18,89 @@ type RecordFLIPGroup struct {
NetMask uint64 `json:"netmask"` NetMask uint64 `json:"netmask"`
} }
type RecordFLIPGroup struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// List of client IDs
ClientIDs []uint64 `json:"clientIds"`
// Client names
ClientNames []string `json:"clientNames"`
// Client type
ClientType string `json:"clientType"`
// Connection ID
ConnID uint64 `json:"connId"`
// Connection type
ConnType string `json:"connType"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Default GW
DefaultGW string `json:"defaultGW"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// IP
IP string `json:"ip"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Network ID
NetID uint64 `json:"netId"`
// Network type
NetType string `json:"netType"`
// Network
Network string `json:"network"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RGName string `json:"rgName"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
// Detailed information about FLIPGroup // Detailed information about FLIPGroup
type ItemFLIPGroup struct { type ItemFLIPGroup struct {
// CKey // CKey

View File

@@ -24,7 +24,7 @@ type CreateRequest struct {
// Name for first worker group created with cluster // Name for first worker group created with cluster
// Required: true // Required: true
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"` WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required,workerGroupName"`
// Network plugin // Network plugin
// Must be one of these values: flannel, weawenet, calico // Must be one of these values: flannel, weawenet, calico

View File

@@ -2,12 +2,30 @@ package kvmppc
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
type Interface struct {
// Network type
// Should be one of:
// - VINS
// - EXTNET
NetType string `url:"netType" json:"netType" validate:"required,kvmNetType"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
NetID uint64 `url:"netId" json:"netId" validate:"required"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
}
// Request struct for create KVM PowerPC VM // Request struct for create KVM PowerPC VM
type CreateRequest struct { type CreateRequest struct {
// ID of the resource group, which will own this VM // ID of the resource group, which will own this VM
@@ -45,24 +63,11 @@ type CreateRequest struct {
// Required: false // Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"` Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Network type // Slice of structs with net interface description.
// Should be one of: // If not specified, compute will be created with default interface from RG.
// - VINS // To create compute without interfaces, pass initialized empty slice .
// - EXTNET
// - NONE
// Required: false // Required: false
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"` Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for ViNS - ViNS ID,
// when netType is not "NONE"
// Required: false
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// Input data for cloud-init facility // Input data for cloud-init facility
// Required: false // Required: false
@@ -85,6 +90,11 @@ type CreateRequest struct {
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"` IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
} }
type wrapperCreateRequest struct {
CreateRequest
Interfaces []string `url:"interfaces,omitempty"`
}
// Create creates KVM PowerPC VM based on specified OS image // Create creates KVM PowerPC VM based on specified OS image
func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) { func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
@@ -94,9 +104,31 @@ func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateRequest{
CreateRequest: req,
Interfaces: interfaces,
}
url := "/cloudapi/kvmppc/create" url := "/cloudapi/kvmppc/create"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@@ -2,6 +2,7 @@ package kvmppc
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"strconv" "strconv"
@@ -31,7 +32,7 @@ type CreateBlankRequest struct {
// Required: true // Required: true
BootDisk uint64 `url:"bootDisk" json:"bootDisk" validate:"required"` BootDisk uint64 `url:"bootDisk" json:"bootDisk" validate:"required"`
// ID of SEP to create boot disk on. // ID of SEP to create boot disk on
// Uses images SEP ID if not set // Uses images SEP ID if not set
// Required: true // Required: true
SEPID uint64 `url:"sepId" json:"sepId" validate:"required"` SEPID uint64 `url:"sepId" json:"sepId" validate:"required"`
@@ -40,30 +41,22 @@ type CreateBlankRequest struct {
// Required: true // Required: true
Pool string `url:"pool" json:"pool" validate:"required"` Pool string `url:"pool" json:"pool" validate:"required"`
// Network type // Slice of structs with net interface description.
// Should be one of: // If not specified, compute will be created with default interface from RG.
// - VINS // To create compute without interfaces, pass initialized empty slice .
// - EXTNET
// - NONE
// Required: false // Required: false
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"` Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
// when network type is not "NONE"
// Required: false
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// Text description of this VM // Text description of this VM
// Required: false // Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"` Description string `url:"desc,omitempty" json:"desc,omitempty"`
} }
type wrapperCreateBlankRequest struct {
CreateBlankRequest
Interfaces []string `url:"interfaces,omitempty"`
}
// CreateBlank creates KVM PowerPC VM from scratch // CreateBlank creates KVM PowerPC VM from scratch
func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
@@ -73,9 +66,31 @@ func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateBlankRequest{
CreateBlankRequest: req,
Interfaces: interfaces,
}
url := "/cloudapi/kvmppc/createBlank" url := "/cloudapi/kvmppc/createBlank"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@@ -2,6 +2,7 @@ package kvmx86
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"strconv" "strconv"
@@ -63,7 +64,10 @@ type CreateRequest struct {
Pool string `url:"pool,omitempty" json:"pool,omitempty"` Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Slice of structs with net interface description. // Slice of structs with net interface description.
Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Input data for cloud-init facility // Input data for cloud-init facility
// Required: false // Required: false
@@ -84,6 +88,19 @@ type CreateRequest struct {
// Compute purpose // Compute purpose
// Required: false // Required: false
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"` IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
// Custom fields for compute. Must be a dict
// Required: false
CustomFields string `url:"customFields,omitempty" json:"customFields,omitempty"`
// Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
// Required: false
Driver string `url:"driver,omitempty" json:"driver,omitempty" validate:"omitempty,computeDriver"`
}
type wrapperCreateRequest struct {
CreateRequest
Interfaces []string `url:"interfaces,omitempty"`
} }
// Create creates KVM x86 VM based on specified OS image // Create creates KVM x86 VM based on specified OS image
@@ -95,9 +112,31 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateRequest{
CreateRequest: req,
Interfaces: interfaces,
}
url := "/cloudapi/kvmx86/create" url := "/cloudapi/kvmx86/create"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@@ -2,6 +2,7 @@ package kvmx86
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"strconv" "strconv"
@@ -41,12 +42,25 @@ type CreateBlankRequest struct {
Pool string `url:"pool" json:"pool" validate:"required"` Pool string `url:"pool" json:"pool" validate:"required"`
// Slice of structs with net interface description. // Slice of structs with net interface description.
Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
// Required: false
Driver string `url:"driver,omitempty" json:"driver,omitempty" validate:"omitempty,computeDriver"`
// Text description of this VM // Text description of this VM
// Required: false // Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"` Description string `url:"desc,omitempty" json:"desc,omitempty"`
} }
type wrapperCreateBlankRequest struct {
CreateBlankRequest
Interfaces []string `url:"interfaces,omitempty"`
}
// CreateBlank creates KVM x86 VM from scratch // CreateBlank creates KVM x86 VM from scratch
func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
@@ -56,9 +70,31 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateBlankRequest{
CreateBlankRequest: req,
Interfaces: interfaces,
}
url := "/cloudapi/kvmx86/createBlank" url := "/cloudapi/kvmx86/createBlank"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@@ -20,7 +20,7 @@ type AffinityGroupComputesRequest struct {
} }
// AffinityGroupComputes gets list of all computes with their relationships to another computes // AffinityGroupComputes gets list of all computes with their relationships to another computes
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (ListAffinityGroups, error) { func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (ListAffinityGroupsComputes, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -35,7 +35,7 @@ func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputes
return nil, err return nil, err
} }
list := ListAffinityGroups{} list := ListAffinityGroupsComputes{}
err = json.Unmarshal(res, &list) err = json.Unmarshal(res, &list)
if err != nil { if err != nil {

View File

@@ -16,7 +16,7 @@ type AffinityGroupsListRequest struct {
} }
// AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs // AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (map[string][]uint64, error) { func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (*ListAffinityGroups, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -31,7 +31,7 @@ func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListReques
return nil, err return nil, err
} }
list := map[string][]uint64{} list := &ListAffinityGroups{}
err = json.Unmarshal(res, &list) err = json.Unmarshal(res, &list)
if err != nil { if err != nil {

View File

@@ -53,6 +53,9 @@ type ItemResourceConsumption struct {
// Reserved information about resources // Reserved information about resources
Reserved Resource `json:"Reserved"` Reserved Resource `json:"Reserved"`
// Resource limits
ResourceLimits ResourceLimits `json:"resourceLimits"`
// Resource group ID // Resource group ID
RGID uint64 `json:"rgid"` RGID uint64 `json:"rgid"`
} }
@@ -302,7 +305,7 @@ type ResourceLimits struct {
} }
// Main information about affinity group // Main information about affinity group
type ItemAffinityGroup struct { type ItemAffinityGroupComputes struct {
// Compute ID // Compute ID
ComputeID uint64 `json:"computeId"` ComputeID uint64 `json:"computeId"`
@@ -326,7 +329,15 @@ type ItemAffinityGroup struct {
} }
// List of affinity groups // List of affinity groups
type ListAffinityGroups []ItemAffinityGroup type ListAffinityGroupsComputes []ItemAffinityGroupComputes
type ListAffinityGroups struct {
// Data
Data map[string][]uint64 `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about audit // Main information about audit
type ItemAudit struct { type ItemAudit struct {

View File

@@ -37,6 +37,7 @@ func (r RG) Usage(ctx context.Context, req UsageRequest) (*RecordResourceUsage,
info := RecordResourceUsage{} info := RecordResourceUsage{}
err = json.Unmarshal(res, &info) err = json.Unmarshal(res, &info)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -22,21 +22,23 @@ func (ls ListSizes) FilterByName(name string) ListSizes {
func (ls ListSizes) FilterFunc(predicate func(ItemSize) bool) ListSizes { func (ls ListSizes) FilterFunc(predicate func(ItemSize) bool) ListSizes {
var result ListSizes var result ListSizes
for _, item := range ls { for _, item := range ls.Data {
if predicate(item) { if predicate(item) {
result = append(result, item) result.Data = append(result.Data, item)
} }
} }
result.EntryCount = uint64(len(result.Data))
return result return result
} }
// FindOne returns first found ItemSize // FindOne returns first found ItemSize
// If none was found, returns an empty struct. // If none was found, returns an empty struct.
func (ls ListSizes) FindOne() ItemSize { func (ls ListSizes) FindOne() ItemSize {
if len(ls) == 0 { if len(ls.Data) == 0 {
return ItemSize{} return ItemSize{}
} }
return ls[0] return ls.Data[0]
} }

View File

@@ -3,30 +3,33 @@ package sizes
import "testing" import "testing"
var sizeItems = ListSizes{ var sizeItems = ListSizes{
{ Data: []ItemSize{
Description: "", {
Disks: []uint64{}, Description: "",
ID: 1, Disks: []uint64{},
Memory: 512, ID: 1,
Name: "size_1", Memory: 512,
VCPUs: 2, Name: "size_1",
}, VCPUs: 2,
{ },
Description: "", {
Disks: []uint64{}, Description: "",
ID: 2, Disks: []uint64{},
Memory: 1024, ID: 2,
Name: "size_2", Memory: 1024,
VCPUs: 4, Name: "size_2",
}, VCPUs: 4,
{ },
Description: "", {
Disks: []uint64{}, Description: "",
ID: 2, Disks: []uint64{},
Memory: 2048, ID: 2,
Name: "size_3", Memory: 2048,
VCPUs: 6, Name: "size_3",
VCPUs: 6,
},
}, },
EntryCount: 3,
} }
func TestFilterByID(t *testing.T) { func TestFilterByID(t *testing.T) {
@@ -50,11 +53,11 @@ func TestFilterFunc(t *testing.T) {
return is.Memory > 512 return is.Memory > 512
}) })
if len(actual) != 2 { if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual)) t.Fatal("expected 2 found, actual: ", len(actual.Data))
} }
for _, item := range actual { for _, item := range actual.Data {
if item.Memory <= 512 { if item.Memory <= 512 {
t.Fatal("expected Memory greater than 512, found: ", item.Memory) t.Fatal("expected Memory greater than 512, found: ", item.Memory)
} }

View File

@@ -26,7 +26,7 @@ type ListRequest struct {
} }
// List gets list the available flavors, filtering can be based on the user which is doing the request // List gets list the available flavors, filtering can be based on the user which is doing the request
func (s Sizes) List(ctx context.Context, req ListRequest) (ListSizes, error) { func (s Sizes) List(ctx context.Context, req ListRequest) (*ListSizes, error) {
url := "/cloudapi/sizes/list" url := "/cloudapi/sizes/list"
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -34,7 +34,7 @@ func (s Sizes) List(ctx context.Context, req ListRequest) (ListSizes, error) {
return nil, err return nil, err
} }
list := ListSizes{} list := &ListSizes{}
err = json.Unmarshal(res, &list) err = json.Unmarshal(res, &list)
if err != nil { if err != nil {

View File

@@ -22,4 +22,10 @@ type ItemSize struct {
} }
// List of configured available flavors // List of configured available flavors
type ListSizes []ItemSize type ListSizes struct {
// Data
Data []ItemSize `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix // - First argument -> prefix
// - Second argument -> indent // - Second argument -> indent
func (ls ListSizes) Serialize(params ...string) (serialization.Serialized, error) { func (ls ListSizes) Serialize(params ...string) (serialization.Serialized, error) {
if len(ls) == 0 { if len(ls.Data) == 0 {
return []byte{}, nil return []byte{}, nil
} }

View File

@@ -16,7 +16,7 @@ type ExtNetListRequest struct {
} }
// ExtNetList show list of VINS external network connections // ExtNetList show list of VINS external network connections
func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (ListExtNets, error) { func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (*ListExtNets, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -31,7 +31,7 @@ func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (ListExtNet
return nil, err return nil, err
} }
list := ListExtNets{} list := &ListExtNets{}
err = json.Unmarshal(res, &list) err = json.Unmarshal(res, &list)
if err != nil { if err != nil {

View File

@@ -16,7 +16,7 @@ type IPListRequest struct {
} }
// IPList show DHCP IP reservations on VINS // IPList show DHCP IP reservations on VINS
func (v VINS) IPList(ctx context.Context, req IPListRequest) (ListIPs, error) { func (v VINS) IPList(ctx context.Context, req IPListRequest) (*ListIPs, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -31,7 +31,7 @@ func (v VINS) IPList(ctx context.Context, req IPListRequest) (ListIPs, error) {
return nil, err return nil, err
} }
list := ListIPs{} list := &ListIPs{}
err = json.Unmarshal(res, &list) err = json.Unmarshal(res, &list)
if err != nil { if err != nil {

View File

@@ -104,7 +104,13 @@ type ItemExtNet struct {
} }
// List of external networks // List of external networks
type ListExtNets []ItemExtNet type ListExtNets struct {
// Data
Data []ItemExtNet `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about IP // Main information about IP
type ItemIP struct { type ItemIP struct {
@@ -131,7 +137,13 @@ type ItemIP struct {
} }
// List of IPs // List of IPs
type ListIPs []ItemIP type ListIPs struct {
// Data
Data []ItemIP `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about VNF device // Main information about VNF device
type RecordVNFDev struct { type RecordVNFDev struct {
@@ -671,7 +683,13 @@ type ItemNATRule struct {
} }
// List of NAT rules // List of NAT rules
type ListNATRules []ItemNATRule type ListNATRules struct {
// Data
Data []ItemNATRule `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about reservation // Main information about reservation
type ItemReservation struct { type ItemReservation struct {

View File

@@ -16,7 +16,7 @@ type NATRuleListRequest struct {
} }
// NATRuleList gets list of NAT (port forwarding) rules // NATRuleList gets list of NAT (port forwarding) rules
func (v VINS) NATRuleList(ctx context.Context, req NATRuleListRequest) (ListNATRules, error) { func (v VINS) NATRuleList(ctx context.Context, req NATRuleListRequest) (*ListNATRules, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -31,7 +31,7 @@ func (v VINS) NATRuleList(ctx context.Context, req NATRuleListRequest) (ListNATR
return nil, err return nil, err
} }
list := ListNATRules{} list := &ListNATRules{}
err = json.Unmarshal(res, &list) err = json.Unmarshal(res, &list)
if err != nil { if err != nil {

View File

@@ -20,7 +20,7 @@ type DeleteUserRequest struct {
// Recursively revoke access rights from owned cloudspaces and vmachines // Recursively revoke access rights from owned cloudspaces and vmachines
// Required: false // Required: false
RecursiveDelete bool `url:"recursivedelete,omitempty" json:"recursivedelete,omitempty"` RecursiveDelete bool `url:"recursivedelete" json:"recursivedelete" validate:"required"`
} }
// DeleteUser revokes user access from the account // DeleteUser revokes user access from the account

View File

@@ -16,7 +16,7 @@ type DisableRequest struct {
// Reason to disable // Reason to disable
// Required: true // Required: true
Reason string `url:"reason" json:"reason" validate:"required"` Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
// Disable disables an account // Disable disables an account

View File

@@ -16,7 +16,7 @@ type EnableRequest struct {
// Reason to enable // Reason to enable
// Required: true // Required: true
Reason string `url:"reason" json:"reason" validate:"required"` Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
// Enable enables an account // Enable enables an account

View File

@@ -16,7 +16,7 @@ type GetResourceConsumptionRequest struct {
} }
// GetResourceConsumption show amount of consumed and reserved resources (cpu, ram, disk) by specific account // GetResourceConsumption show amount of consumed and reserved resources (cpu, ram, disk) by specific account
func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResources, error) { func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResourceConsumption, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -26,7 +26,7 @@ func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceCons
url := "/cloudbroker/account/getResourceConsumption" url := "/cloudbroker/account/getResourceConsumption"
info := RecordResources{} info := RecordResourceConsumption{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil { if err != nil {

View File

@@ -16,7 +16,7 @@ type ListVINSRequest struct {
// Find by VINS ID // Find by VINS ID
// Required: false // Required: false
VINSID uint64 `url:"vins,omitempty" json:"vinsId,omitempty"` VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
// Find by name // Find by name
// Required: false // Required: false

View File

@@ -21,7 +21,13 @@ type ItemAudit struct {
// List of audits // List of audits
type ListAudits []ItemAudit type ListAudits []ItemAudit
type RecordResources struct { type RecordResourceConsumption struct {
ItemResourceConsumption
ResourceLimits ResourceLimits `json:"resourceLimits"`
}
type ItemResourceConsumption struct {
// Current information about resources // Current information about resources
Current Resource `json:"Current"` Current Resource `json:"Current"`
@@ -34,7 +40,7 @@ type RecordResources struct {
type ListResources struct { type ListResources struct {
// Data // Data
Data []RecordResources `json:"data"` Data []ItemResourceConsumption `json:"data"`
// Entry count // Entry count
EntryCount uint64 `json:"entryCount"` EntryCount uint64 `json:"entryCount"`

View File

@@ -20,7 +20,7 @@ type DiskDelRequest struct {
// False if disk is to be deleted to recycle bin // False if disk is to be deleted to recycle bin
// Required: true // Required: true
Permanently bool `url:"permanently" json:"permanently" validate:"required"` Permanently bool `url:"permanently" json:"permanently"`
// Reason for action // Reason for action
// Required: false // Required: false

View File

@@ -40,6 +40,14 @@ type ListRequest struct {
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -24,10 +24,6 @@ type ListUnattachedRequest struct {
// Required: false // Required: false
Status string `url:"status,omitempty" json:"status,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by shared, true or false
// Required: false
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
// Type of the disks // Type of the disks
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
@@ -36,6 +32,14 @@ type ListUnattachedRequest struct {
// Required: false // Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -137,7 +137,7 @@ type RecordExtNet struct {
DNS []string `json:"dns"` DNS []string `json:"dns"`
// List excludes // List excludes
Excluded []string `json:"excluded"` Excluded ListReservations `json:"excluded"`
// Gateway // Gateway
Gateway string `json:"gateway"` Gateway string `json:"gateway"`

View File

@@ -20,7 +20,7 @@ type DeleteRequest struct {
// Whether to completely delete the image // Whether to completely delete the image
// Required: false // Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"` Permanently bool `url:"permanently" json:"permanently"`
} }
// Delete deletes image by ID // Delete deletes image by ID

View File

@@ -24,7 +24,7 @@ type CreateRequest struct {
// Name for first worker group created with cluster // Name for first worker group created with cluster
// Required: true // Required: true
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"` WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required, workerGroupName"`
// Network plugin // Network plugin
// Must be one of these values: flunnel, weawenet, calico // Must be one of these values: flunnel, weawenet, calico
@@ -103,7 +103,7 @@ type CreateRequest struct {
// Create kubernetes cluster with masters nodes behind load balancer if true. // Create kubernetes cluster with masters nodes behind load balancer if true.
// Otherwise give all cluster nodes direct external addresses from selected external network // Otherwise give all cluster nodes direct external addresses from selected external network
// Required: false // Required: false
WithLB bool `url:"withLB,omitempty" json:"withLB,omitempty"` WithLB bool `url:"withLB" json:"withLB"`
// Text description of this kubernetes cluster // Text description of this kubernetes cluster
// Required: false // Required: false

View File

@@ -76,21 +76,23 @@ func (lkc ListK8S) FilterByDeletedBy(deletedBy string) ListK8S {
func (lkc ListK8S) FilterFunc(predicate func(ItemK8S) bool) ListK8S { func (lkc ListK8S) FilterFunc(predicate func(ItemK8S) bool) ListK8S {
var result ListK8S var result ListK8S
for _, item := range lkc { for _, item := range lkc.Data {
if predicate(item) { if predicate(item) {
result = append(result, item) result.Data = append(result.Data, item)
} }
} }
result.EntryCount = uint64(len(result.Data))
return result return result
} }
// FindOne returns first found ItemK8S // FindOne returns first found ItemK8S
// If none was found, returns an empty struct. // If none was found, returns an empty struct.
func (lkc ListK8S) FindOne() ItemK8S { func (lkc ListK8S) FindOne() ItemK8S {
if len(lkc) == 0 { if len(lkc.Data) == 0 {
return ItemK8S{} return ItemK8S{}
} }
return lkc[0] return lkc.Data[0]
} }

View File

@@ -3,96 +3,99 @@ package k8s
import "testing" import "testing"
var k8sItems = ListK8S{ var k8sItems = ListK8S{
ItemK8S{ Data: []ItemK8S{
AccountID: 1, {
AccountName: "test_1", AccountID: 1,
ACL: []interface{}{}, AccountName: "test_1",
BServiceID: 1, ACL: []interface{}{},
CIID: 1, BServiceID: 1,
Config: nil, CIID: 1,
CreatedBy: "test_user", Config: nil,
CreatedTime: 132454563, CreatedBy: "test_user",
DeletedBy: "", CreatedTime: 132454563,
DeletedTime: 0, DeletedBy: "",
Description: "", DeletedTime: 0,
ExtNetID: 1, Description: "",
GID: 0, ExtNetID: 1,
GUID: 1, GID: 0,
ID: 1, GUID: 1,
LBID: 1, ID: 1,
Milestones: 999999, LBID: 1,
Name: "k8s_1", Milestones: 999999,
RGID: 1, Name: "k8s_1",
RGName: "rg_1", RGID: 1,
ServiceAccount: ServiceAccount{}, RGName: "rg_1",
SSHKey: "sample_key", ServiceAccount: ServiceAccount{},
Status: "ENABLED", SSHKey: "sample_key",
TechStatus: "STARTED", Status: "ENABLED",
UpdatedBy: "", TechStatus: "STARTED",
UpdatedTime: 0, UpdatedBy: "",
VINSID: 0, UpdatedTime: 0,
WorkersGroup: []RecordK8SGroup{}, VINSID: 0,
}, WorkersGroup: []RecordK8SGroup{},
ItemK8S{ },
AccountID: 2, {
AccountName: "test_2", AccountID: 2,
ACL: []interface{}{}, AccountName: "test_2",
BServiceID: 2, ACL: []interface{}{},
CIID: 2, BServiceID: 2,
Config: nil, CIID: 2,
CreatedBy: "test_user", Config: nil,
CreatedTime: 132454638, CreatedBy: "test_user",
DeletedBy: "", CreatedTime: 132454638,
DeletedTime: 0, DeletedBy: "",
Description: "", DeletedTime: 0,
ExtNetID: 2, Description: "",
GID: 0, ExtNetID: 2,
GUID: 2, GID: 0,
ID: 2, GUID: 2,
LBID: 2, ID: 2,
Milestones: 999999, LBID: 2,
Name: "k8s_2", Milestones: 999999,
RGID: 2, Name: "k8s_2",
RGName: "rg_2", RGID: 2,
ServiceAccount: ServiceAccount{}, RGName: "rg_2",
SSHKey: "sample_key", ServiceAccount: ServiceAccount{},
Status: "ENABLED", SSHKey: "sample_key",
TechStatus: "STARTED", Status: "ENABLED",
UpdatedBy: "", TechStatus: "STARTED",
UpdatedTime: 0, UpdatedBy: "",
VINSID: 0, UpdatedTime: 0,
WorkersGroup: []RecordK8SGroup{}, VINSID: 0,
}, WorkersGroup: []RecordK8SGroup{},
ItemK8S{ },
AccountID: 3, {
AccountName: "test_3", AccountID: 3,
ACL: []interface{}{}, AccountName: "test_3",
BServiceID: 3, ACL: []interface{}{},
CIID: 3, BServiceID: 3,
Config: nil, CIID: 3,
CreatedBy: "test_user", Config: nil,
CreatedTime: 132454682, CreatedBy: "test_user",
DeletedBy: "", CreatedTime: 132454682,
DeletedTime: 0, DeletedBy: "",
Description: "", DeletedTime: 0,
ExtNetID: 3, Description: "",
GID: 0, ExtNetID: 3,
GUID: 3, GID: 0,
ID: 3, GUID: 3,
LBID: 3, ID: 3,
Milestones: 999999, LBID: 3,
Name: "k8s_3", Milestones: 999999,
RGID: 3, Name: "k8s_3",
RGName: "rg_3", RGID: 3,
ServiceAccount: ServiceAccount{}, RGName: "rg_3",
SSHKey: "sample_key", ServiceAccount: ServiceAccount{},
Status: "DISABLED", SSHKey: "sample_key",
TechStatus: "STOPPED", Status: "DISABLED",
UpdatedBy: "", TechStatus: "STOPPED",
UpdatedTime: 0, UpdatedBy: "",
VINSID: 0, UpdatedTime: 0,
WorkersGroup: []RecordK8SGroup{}, VINSID: 0,
WorkersGroup: []RecordK8SGroup{},
},
}, },
EntryCount: 3,
} }
func TestFilterByID(t *testing.T) { func TestFilterByID(t *testing.T) {
@@ -130,11 +133,11 @@ func TestFilterByRGID(t *testing.T) {
func TestFilterByStatus(t *testing.T) { func TestFilterByStatus(t *testing.T) {
actual := k8sItems.FilterByStatus("ENABLED") actual := k8sItems.FilterByStatus("ENABLED")
if len(actual) != 2 { if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual)) t.Fatal("expected 2 found, actual: ", len(actual.Data))
} }
for _, item := range actual { for _, item := range actual.Data {
if item.Status != "ENABLED" { if item.Status != "ENABLED" {
t.Fatal("expected Status 'ENABLED', found: ", item.Status) t.Fatal("expected Status 'ENABLED', found: ", item.Status)
} }
@@ -144,11 +147,11 @@ func TestFilterByStatus(t *testing.T) {
func TestFilterByTechStatus(t *testing.T) { func TestFilterByTechStatus(t *testing.T) {
actual := k8sItems.FilterByTechStatus("STARTED") actual := k8sItems.FilterByTechStatus("STARTED")
if len(actual) != 2 { if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual)) t.Fatal("expected 2 found, actual: ", len(actual.Data))
} }
for _, item := range actual { for _, item := range actual.Data {
if item.TechStatus != "STARTED" { if item.TechStatus != "STARTED" {
t.Fatal("expected TechStatus 'STARTED', found: ", item.TechStatus) t.Fatal("expected TechStatus 'STARTED', found: ", item.TechStatus)
} }
@@ -158,11 +161,11 @@ func TestFilterByTechStatus(t *testing.T) {
func TestFilterByCreatedBy(t *testing.T) { func TestFilterByCreatedBy(t *testing.T) {
actual := k8sItems.FilterByCreatedBy("test_user") actual := k8sItems.FilterByCreatedBy("test_user")
if len(actual) != 3 { if len(actual.Data) != 3 {
t.Fatal("expected 3 found, actual: ", len(actual)) t.Fatal("expected 3 found, actual: ", len(actual.Data))
} }
for _, item := range actual { for _, item := range actual.Data {
if item.CreatedBy != "test_user" { if item.CreatedBy != "test_user" {
t.Fatal("expected CreatedBy 'test_user', found: ", item.CreatedBy) t.Fatal("expected CreatedBy 'test_user', found: ", item.CreatedBy)
} }
@@ -172,8 +175,8 @@ func TestFilterByCreatedBy(t *testing.T) {
func TestFilterByDeletedBy(t *testing.T) { func TestFilterByDeletedBy(t *testing.T) {
actual := k8sItems.FilterByDeletedBy("test_user") actual := k8sItems.FilterByDeletedBy("test_user")
if len(actual) != 0 { if len(actual.Data) != 0 {
t.Fatal("expected 0 found, actual: ", len(actual)) t.Fatal("expected 0 found, actual: ", len(actual.Data))
} }
} }
@@ -191,7 +194,7 @@ func TestFilterFunc(t *testing.T) {
func TestSortByCreatedTime(t *testing.T) { func TestSortByCreatedTime(t *testing.T) {
actual := k8sItems.SortByCreatedTime(false) actual := k8sItems.SortByCreatedTime(false)
if actual[0].CreatedTime != 132454563 || actual[2].CreatedTime != 132454682 { if actual.Data[0].CreatedTime != 132454563 || actual.Data[2].CreatedTime != 132454682 {
t.Fatal("expected ascending sort, seems to be inversed") t.Fatal("expected ascending sort, seems to be inversed")
} }
} }

View File

@@ -8,6 +8,38 @@ import (
// Request struct for get list information K8S // Request struct for get list information K8S
type ListRequest struct { type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by IP address
// Required: false
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by lbId
// Required: false
LBID uint64 `url:"lbId,omitempty" json:"lbId,omitempty"`
// Find by basicServiceId
// Required: false
BasicServiceID uint64 `url:"basicServiceId,omitempty" json:"basicServiceId,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by techStatus
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Include deleted clusters in result // Include deleted clusters in result
// Required: false // Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"` IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
@@ -22,7 +54,7 @@ type ListRequest struct {
} }
// List gets list all kubernetes clusters // List gets list all kubernetes clusters
func (k K8S) List(ctx context.Context, req ListRequest) (ListK8S, error) { func (k K8S) List(ctx context.Context, req ListRequest) (*ListK8S, error) {
url := "/cloudbroker/k8s/list" url := "/cloudbroker/k8s/list"
@@ -38,5 +70,5 @@ func (k K8S) List(ctx context.Context, req ListRequest) (ListK8S, error) {
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -8,6 +8,34 @@ import (
// Request struct for get list deleted kubernetes cluster // Request struct for get list deleted kubernetes cluster
type ListDeletedRequest struct { type ListDeletedRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by IP address
// Required: false
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by lbId
// Required: false
LBID uint64 `url:"lbId,omitempty" json:"lbId,omitempty"`
// Find by basicServiceId
// Required: false
BasicServiceID uint64 `url:"basicServiceId,omitempty" json:"basicServiceId,omitempty"`
// Find by techStatus
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -18,7 +46,7 @@ type ListDeletedRequest struct {
} }
// ListDeleted gets all deleted kubernetes clusters // ListDeleted gets all deleted kubernetes clusters
func (k K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8S, error) { func (k K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8S, error) {
url := "/cloudbroker/k8s/listDeleted" url := "/cloudbroker/k8s/listDeleted"
@@ -34,5 +62,5 @@ func (k K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8S,
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -295,4 +295,10 @@ type ServiceAccount struct {
} }
// List K8S // List K8S
type ListK8S []ItemK8S type ListK8S struct {
// Data
Data []ItemK8S `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix // - First argument -> prefix
// - Second argument -> indent // - Second argument -> indent
func (lkc ListK8S) Serialize(params ...string) (serialization.Serialized, error) { func (lkc ListK8S) Serialize(params ...string) (serialization.Serialized, error) {
if len(lkc) == 0 { if len(lkc.Data) == 0 {
return []byte{}, nil return []byte{}, nil
} }

View File

@@ -6,16 +6,16 @@ import "sort"
// //
// If inverse param is set to true, the order is reversed. // If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByCreatedTime(inverse bool) ListK8S { func (lkc ListK8S) SortByCreatedTime(inverse bool) ListK8S {
if len(lkc) < 2 { if len(lkc.Data) < 2 {
return lkc return lkc
} }
sort.Slice(lkc, func(i, j int) bool { sort.Slice(lkc.Data, func(i, j int) bool {
if inverse { if inverse {
return lkc[i].CreatedTime > lkc[j].CreatedTime return lkc.Data[i].CreatedTime > lkc.Data[j].CreatedTime
} }
return lkc[i].CreatedTime < lkc[j].CreatedTime return lkc.Data[i].CreatedTime < lkc.Data[j].CreatedTime
}) })
return lkc return lkc
@@ -25,16 +25,16 @@ func (lkc ListK8S) SortByCreatedTime(inverse bool) ListK8S {
// //
// If inverse param is set to true, the order is reversed. // If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByUpdatedTime(inverse bool) ListK8S { func (lkc ListK8S) SortByUpdatedTime(inverse bool) ListK8S {
if len(lkc) < 2 { if len(lkc.Data) < 2 {
return lkc return lkc
} }
sort.Slice(lkc, func(i, j int) bool { sort.Slice(lkc.Data, func(i, j int) bool {
if inverse { if inverse {
return lkc[i].UpdatedTime > lkc[j].UpdatedTime return lkc.Data[i].UpdatedTime > lkc.Data[j].UpdatedTime
} }
return lkc[i].UpdatedTime < lkc[j].UpdatedTime return lkc.Data[i].UpdatedTime < lkc.Data[j].UpdatedTime
}) })
return lkc return lkc
@@ -44,16 +44,16 @@ func (lkc ListK8S) SortByUpdatedTime(inverse bool) ListK8S {
// //
// If inverse param is set to true, the order is reversed. // If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByDeletedTime(inverse bool) ListK8S { func (lkc ListK8S) SortByDeletedTime(inverse bool) ListK8S {
if len(lkc) < 2 { if len(lkc.Data) < 2 {
return lkc return lkc
} }
sort.Slice(lkc, func(i, j int) bool { sort.Slice(lkc.Data, func(i, j int) bool {
if inverse { if inverse {
return lkc[i].DeletedTime > lkc[j].DeletedTime return lkc.Data[i].DeletedTime > lkc.Data[j].DeletedTime
} }
return lkc[i].DeletedTime < lkc[j].DeletedTime return lkc.Data[i].DeletedTime < lkc.Data[j].DeletedTime
}) })
return lkc return lkc

View File

@@ -2,12 +2,30 @@ package kvmppc
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
type Interface struct {
// Network type
// Should be one of:
// - VINS
// - EXTNET
NetType string `url:"netType" json:"netType" validate:"required,kvmNetType"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
NetID uint64 `url:"netId" json:"netId" validate:"required"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
}
// Request struct for create KVM PowerPC VM // Request struct for create KVM PowerPC VM
type CreateRequest struct { type CreateRequest struct {
// ID of the resource group, which will own this VM // ID of the resource group, which will own this VM
@@ -45,24 +63,11 @@ type CreateRequest struct {
// Required: false // Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"` Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Network type // Slice of structs with net interface description.
// Should be one of: // If not specified, compute will be created with default interface from RG.
// - VINS // To create compute without interfaces, pass initialized empty slice .
// - EXTNET
// - NONE
// Required: false // Required: false
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"` Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
// when network type is not "NONE"
// Required: false
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// Input data for cloud-init facility // Input data for cloud-init facility
// Required: false // Required: false
@@ -76,10 +81,6 @@ type CreateRequest struct {
// Required: false // Required: false
Start bool `url:"start,omitempty" json:"start,omitempty"` Start bool `url:"start,omitempty" json:"start,omitempty"`
// Stack ID
// Required: false
StackID uint64 `url:"stackId,omitempty" json:"stackId,omitempty"`
// System name // System name
// Required: false // Required: false
IS string `url:"IS,omitempty" json:"IS,omitempty"` IS string `url:"IS,omitempty" json:"IS,omitempty"`
@@ -87,10 +88,11 @@ type CreateRequest struct {
// Compute purpose // Compute purpose
// Required: false // Required: false
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"` IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
}
// Reason for action type wrapperCreateRequest struct {
// Required: false CreateRequest
Reason string `url:"reason,omitempty" json:"reason,omitempty"` Interfaces []string `url:"interfaces,omitempty"`
} }
// Create creates KVM PowerPC VM based on specified OS image // Create creates KVM PowerPC VM based on specified OS image
@@ -102,9 +104,31 @@ func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateRequest{
CreateRequest: req,
Interfaces: interfaces,
}
url := "/cloudbroker/kvmppc/create" url := "/cloudbroker/kvmppc/create"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@@ -2,6 +2,7 @@ package kvmppc
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"strconv" "strconv"
@@ -40,30 +41,22 @@ type CreateBlankRequest struct {
// Required: true // Required: true
Pool string `url:"pool" json:"pool" validate:"required"` Pool string `url:"pool" json:"pool" validate:"required"`
// Network type // Slice of structs with net interface description.
// Should be one of: // If not specified, compute will be created with default interface from RG.
// - VINS // To create compute without interfaces, pass initialized empty slice .
// - EXTNET
// - NONE
// Required: false // Required: false
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"` Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
// when network type is not "NONE"
// Required: false
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// Text description of this VM // Text description of this VM
// Required: false // Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"` Description string `url:"desc,omitempty" json:"desc,omitempty"`
} }
type wrapperCreateBlankRequest struct {
CreateBlankRequest
Interfaces []string `url:"interfaces,omitempty"`
}
// CreateBlank creates KVM PowerPC VM from scratch // CreateBlank creates KVM PowerPC VM from scratch
func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
@@ -73,9 +66,31 @@ func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateBlankRequest{
CreateBlankRequest: req,
Interfaces: interfaces,
}
url := "/cloudbroker/kvmppc/createBlank" url := "/cloudbroker/kvmppc/createBlank"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@@ -48,20 +48,11 @@ type MassCreateRequest struct {
// Required: false // Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"` Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Network type // Slice of structs with net interface description.
// Should be one of: // If not specified, compute will be created with default interface from RG.
// - VINS // To create compute without interfaces, pass initialized empty slice.
// - EXTNET
// - NONE
// Required: false // Required: false
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"` Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
// when network type is not "NONE"
// Required: false
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// Input data for cloud-init facility // Input data for cloud-init facility
// Required: false // Required: false
@@ -80,6 +71,11 @@ type MassCreateRequest struct {
Reason string `url:"reason,omitempty" json:"reason,omitempty"` Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
type wrapperMassCreateRequest struct {
MassCreateRequest
Interfaces []string `url:"interfaces,omitempty"`
}
// MassCreate creates KVM PPC computes based on specified OS image // MassCreate creates KVM PPC computes based on specified OS image
func (k KVMPPC) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) { func (k KVMPPC) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
@@ -89,9 +85,31 @@ func (k KVMPPC) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return nil, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperMassCreateRequest{
MassCreateRequest: req,
Interfaces: interfaces,
}
url := "/cloudbroker/kvmppc/massCreate" url := "/cloudbroker/kvmppc/massCreate"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -2,12 +2,30 @@ package kvmx86
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
type Interface struct {
// Network type
// Should be one of:
// - VINS
// - EXTNET
NetType string `url:"netType" json:"netType" validate:"required,kvmNetType"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
NetID uint64 `url:"netId" json:"netId" validate:"required"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
}
// Request struct for create KVM x86 VM // Request struct for create KVM x86 VM
type CreateRequest struct { type CreateRequest struct {
// ID of the resource group, which will own this VM // ID of the resource group, which will own this VM
@@ -45,24 +63,11 @@ type CreateRequest struct {
// Required: false // Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"` Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Network type // Slice of structs with net interface description.
// Should be one of: // If not specified, compute will be created with default interface from RG.
// - VINS // To create compute without interfaces, pass initialized empty slice .
// - EXTNET
// - NONE
// Required: false // Required: false
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"` Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
// when network type is not "NONE"
// Required: false
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// Input data for cloud-init facility // Input data for cloud-init facility
// Required: false // Required: false
@@ -88,11 +93,20 @@ type CreateRequest struct {
// Required: false // Required: false
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"` IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
// Custom fields for Compute. Must be dict
// Required: false
CustomField string `url:"customFields,omitempty" json:"customFields,omitempty"`
// Reason for action // Reason for action
// Required: false // Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"` Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
type wrapperCreateRequest struct {
CreateRequest
Interfaces []string `url:"interfaces,omitempty"`
}
// Create creates KVM PowerPC VM based on specified OS image // Create creates KVM PowerPC VM based on specified OS image
func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) { func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
@@ -102,9 +116,31 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateRequest{
CreateRequest: req,
Interfaces: interfaces,
}
url := "/cloudbroker/kvmx86/create" url := "/cloudbroker/kvmx86/create"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@@ -2,6 +2,7 @@ package kvmx86
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"strconv" "strconv"
@@ -40,30 +41,22 @@ type CreateBlankRequest struct {
// Required: true // Required: true
Pool string `url:"pool" json:"pool" validate:"required"` Pool string `url:"pool" json:"pool" validate:"required"`
// Network type // Slice of structs with net interface description.
// Should be one of: // If not specified, compute will be created with default interface from RG.
// - VINS // To create compute without interfaces, pass initialized empty slice .
// - EXTNET
// - NONE
// Required: false // Required: false
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"` Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
// when network type is not "NONE"
// Required: false
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// Text description of this VM // Text description of this VM
// Required: false // Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"` Description string `url:"desc,omitempty" json:"desc,omitempty"`
} }
type wrapperCreateBlankRequest struct {
CreateBlankRequest
Interfaces []string `url:"interfaces,omitempty"`
}
// CreateBlank creates KVM x86 VM from scratch // CreateBlank creates KVM x86 VM from scratch
func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
@@ -73,9 +66,31 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateBlankRequest{
CreateBlankRequest: req,
Interfaces: interfaces,
}
url := "/cloudbroker/kvmx86/createBlank" url := "/cloudbroker/kvmx86/createBlank"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@@ -48,24 +48,11 @@ type MassCreateRequest struct {
// Required: false // Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"` Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Network type // Slice of structs with net interface description.
// Should be one of: // If not specified, compute will be created with default interface from RG.
// - VINS // To create compute without interfaces, pass initialized empty slice .
// - EXTNET
// - NONE
// Required: false // Required: false
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"` Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Network ID for connect to,
// for EXTNET - external network ID,
// for VINS - VINS ID,
// when network type is not "NONE"
// Required: false
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// IP address to assign to this VM when connecting to the specified network
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// Input data for cloud-init facility // Input data for cloud-init facility
// Required: false // Required: false
@@ -84,6 +71,11 @@ type MassCreateRequest struct {
Reason string `url:"reason,omitempty" json:"reason,omitempty"` Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
type wrapperMassCreateRequest struct {
MassCreateRequest
Interfaces []string `url:"interfaces,omitempty"`
}
// MassCreate creates KVM x86 computes based on specified OS image // MassCreate creates KVM x86 computes based on specified OS image
func (k KVMX86) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) { func (k KVMX86) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
@@ -93,9 +85,31 @@ func (k KVMX86) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64
} }
} }
var interfaces []string
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return nil, err
}
interfaces = append(interfaces, string(b))
}
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperMassCreateRequest{
MassCreateRequest: req,
Interfaces: interfaces,
}
url := "/cloudbroker/kvmx86/massCreate" url := "/cloudbroker/kvmx86/massCreate"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -67,7 +67,7 @@ type BackendCreateRequest struct {
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"` Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
} }
// BackendCreate creates new backend on the specified load balancer // BackendCreate creates new backend on the specified load balancer
func (lb LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (bool, error) { func (lb LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (bool, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {

View File

@@ -19,10 +19,6 @@ type CreateRequest struct {
// Required: true // Required: true
Name string `url:"name" json:"name" validate:"required"` Name string `url:"name" json:"name" validate:"required"`
// OS image ID to create load balancer from
// Required: false
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
// External network to connect this load balancer to // External network to connect this load balancer to
// Required: true // Required: true
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"` ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`

View File

@@ -44,7 +44,7 @@ func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
} }
// FilterByK8SID returns ListLB used by specified K8S cluster. // FilterByK8SID returns ListLB used by specified K8S cluster.
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListLB, error) { func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListLB, error) {
caller := k8s.New(decortClient) caller := k8s.New(decortClient)
req := k8s.GetRequest{ req := k8s.GetRequest{
@@ -60,28 +60,32 @@ func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient i
return cluster.LBID == rlb.ID return cluster.LBID == rlb.ID
} }
return ll.FilterFunc(predicate), nil res := ll.FilterFunc(predicate)
return &res, nil
} }
// FilterFunc allows filtering ListLB based on a user-specified predicate. // FilterFunc allows filtering ListLB based on a user-specified predicate.
func (ll ListLB) FilterFunc(predicate func(RecordLB) bool) ListLB { func (ll ListLB) FilterFunc(predicate func(RecordLB) bool) ListLB {
var result ListLB var result ListLB
for _, item := range ll { for _, item := range ll.Data {
if predicate(item) { if predicate(item) {
result = append(result, item) result.Data = append(result.Data, item)
} }
} }
result.EntryCount = uint64(len(result.Data))
return result return result
} }
// FindOne returns first found RecordLB // FindOne returns first found RecordLB
// If none was found, returns an empty struct. // If none was found, returns an empty struct.
func (ll ListLB) FindOne() RecordLB { func (ll ListLB) FindOne() RecordLB {
if len(ll) == 0 { if len(ll.Data) == 0 {
return RecordLB{} return RecordLB{}
} }
return ll[0] return ll.Data[0]
} }

View File

@@ -3,99 +3,102 @@ package lb
import "testing" import "testing"
var lbs = ListLB{ var lbs = ListLB{
RecordLB{ Data: []RecordLB{
HAMode: true, {
CKey: "", HAMode: true,
Meta: []interface{}{}, CKey: "",
ACL: []interface{}{}, Meta: []interface{}{},
Backends: []ItemBackend{}, ACL: []interface{}{},
CreatedBy: "test_user_1", Backends: []ItemBackend{},
CreatedTime: 1636667448, CreatedBy: "test_user_1",
DeletedBy: "", CreatedTime: 1636667448,
DeletedTime: 0, DeletedBy: "",
Description: "", DeletedTime: 0,
DPAPIPassword: "0000", Description: "",
DPAPIUser: "api_user", DPAPIPassword: "0000",
ExtNetID: 2522, DPAPIUser: "api_user",
Frontends: []ItemFrontend{}, ExtNetID: 2522,
GID: 212, Frontends: []ItemFrontend{},
GUID: 1, GID: 212,
ID: 1, GUID: 1,
ImageID: 2121, ID: 1,
Milestones: 129000, ImageID: 2121,
Name: "k8s-lb-test-1", Milestones: 129000,
PrimaryNode: Node{}, Name: "k8s-lb-test-1",
RGID: 25090, PrimaryNode: Node{},
RGName: "", RGID: 25090,
SecondaryNode: Node{}, RGName: "",
Status: "ENABLED", SecondaryNode: Node{},
TechStatus: "STARTED", Status: "ENABLED",
UpdatedBy: "", TechStatus: "STARTED",
UpdatedTime: 0, UpdatedBy: "",
VINSID: 101, UpdatedTime: 0,
}, VINSID: 101,
RecordLB{ },
HAMode: false, {
CKey: "", HAMode: false,
Meta: []interface{}{}, CKey: "",
ACL: []interface{}{}, Meta: []interface{}{},
Backends: []ItemBackend{}, ACL: []interface{}{},
CreatedBy: "test_user_2", Backends: []ItemBackend{},
CreatedTime: 1636667506, CreatedBy: "test_user_2",
DeletedBy: "", CreatedTime: 1636667506,
DeletedTime: 0, DeletedBy: "",
Description: "", DeletedTime: 0,
DPAPIPassword: "0000", Description: "",
DPAPIUser: "api_user_2", DPAPIPassword: "0000",
ExtNetID: 2524, DPAPIUser: "api_user_2",
Frontends: []ItemFrontend{}, ExtNetID: 2524,
GID: 212, Frontends: []ItemFrontend{},
GUID: 2, GID: 212,
ID: 2, GUID: 2,
ImageID: 2129, ID: 2,
Milestones: 129013, ImageID: 2129,
Name: "k8s-lb-test-2", Milestones: 129013,
PrimaryNode: Node{}, Name: "k8s-lb-test-2",
RGID: 25092, PrimaryNode: Node{},
RGName: "", RGID: 25092,
SecondaryNode: Node{}, RGName: "",
Status: "ENABLED", SecondaryNode: Node{},
TechStatus: "STOPPED", Status: "ENABLED",
UpdatedBy: "", TechStatus: "STOPPED",
UpdatedTime: 0, UpdatedBy: "",
VINSID: 102, UpdatedTime: 0,
}, VINSID: 102,
RecordLB{ },
HAMode: true, {
CKey: "", HAMode: true,
Meta: []interface{}{}, CKey: "",
ACL: []interface{}{}, Meta: []interface{}{},
Backends: []ItemBackend{}, ACL: []interface{}{},
CreatedBy: "te2t_user_3", Backends: []ItemBackend{},
CreatedTime: 1636667534, CreatedBy: "te2t_user_3",
DeletedBy: "", CreatedTime: 1636667534,
DeletedTime: 0, DeletedBy: "",
Description: "", DeletedTime: 0,
DPAPIPassword: "0000", Description: "",
DPAPIUser: "api_user_3", DPAPIPassword: "0000",
ExtNetID: 2536, DPAPIUser: "api_user_3",
Frontends: []ItemFrontend{}, ExtNetID: 2536,
GID: 212, Frontends: []ItemFrontend{},
GUID: 3, GID: 212,
ID: 3, GUID: 3,
ImageID: 2139, ID: 3,
Milestones: 129025, ImageID: 2139,
Name: "k8s-lb-test-3", Milestones: 129025,
PrimaryNode: Node{}, Name: "k8s-lb-test-3",
RGID: 25106, PrimaryNode: Node{},
RGName: "", RGID: 25106,
SecondaryNode: Node{}, RGName: "",
Status: "DISABLED", SecondaryNode: Node{},
TechStatus: "STOPPED", Status: "DISABLED",
UpdatedBy: "", TechStatus: "STOPPED",
UpdatedTime: 0, UpdatedBy: "",
VINSID: 118, UpdatedTime: 0,
VINSID: 118,
},
}, },
EntryCount: 3,
} }
func TestFilterByID(t *testing.T) { func TestFilterByID(t *testing.T) {
@@ -135,7 +138,7 @@ func TestFilterFunc(t *testing.T) {
return rl.Status == "DISABLED" return rl.Status == "DISABLED"
}) })
for _, item := range actual { for _, item := range actual.Data {
if item.Status != "DISABLED" { if item.Status != "DISABLED" {
t.Fatal("expected Status 'DISABLED', found: ", item.Status) t.Fatal("expected Status 'DISABLED', found: ", item.Status)
} }
@@ -145,7 +148,7 @@ func TestFilterFunc(t *testing.T) {
func TestSortByCreatedTime(t *testing.T) { func TestSortByCreatedTime(t *testing.T) {
actual := lbs.SortByCreatedTime(true) actual := lbs.SortByCreatedTime(true)
if actual[0].CreatedTime != 1636667534 || actual[2].CreatedTime != 1636667448 { if actual.Data[0].CreatedTime != 1636667534 || actual.Data[2].CreatedTime != 1636667448 {
t.Fatal("expected descending order, found ascending") t.Fatal("expected descending order, found ascending")
} }
} }

View File

@@ -8,6 +8,38 @@ import (
// Request struct for get list of load balancers // Request struct for get list of load balancers
type ListRequest struct { type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by tech status
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by frontend Ip
// Required: false
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
// Find by backend Ip
// Required: false
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
// Included deleted load balancers // Included deleted load balancers
// Required: false // Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"` IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
@@ -22,7 +54,7 @@ type ListRequest struct {
} }
// List gets list all load balancers // List gets list all load balancers
func (lb LB) List(ctx context.Context, req ListRequest) (ListLB, error) { func (lb LB) List(ctx context.Context, req ListRequest) (*ListLB, error) {
url := "/cloudbroker/lb/list" url := "/cloudbroker/lb/list"
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -37,6 +69,6 @@ func (lb LB) List(ctx context.Context, req ListRequest) (ListLB, error) {
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -8,6 +8,34 @@ import (
// Request struct for get list of deleted load balancers // Request struct for get list of deleted load balancers
type ListDeletedRequest struct { type ListDeletedRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by tech status
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Find by frontend Ip
// Required: false
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
// Find by backend Ip
// Required: false
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -18,7 +46,7 @@ type ListDeletedRequest struct {
} }
// ListDeleted gets list of deleted load balancers // ListDeleted gets list of deleted load balancers
func (lb LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, error) { func (lb LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListLB, error) {
url := "/cloudbroker/lb/listDeleted" url := "/cloudbroker/lb/listDeleted"
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -33,6 +61,6 @@ func (lb LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, e
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -134,7 +134,13 @@ type Node struct {
} }
// List of load balancers // List of load balancers
type ListLB []RecordLB type ListLB struct {
// Data
Data []RecordLB `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Detailed information about load balancer // Detailed information about load balancer
type RecordLB struct { type RecordLB struct {

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix // - First argument -> prefix
// - Second argument -> indent // - Second argument -> indent
func (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) { func (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) {
if len(ll) == 0 { if len(ll.Data) == 0 {
return []byte{}, nil return []byte{}, nil
} }

View File

@@ -6,16 +6,16 @@ import "sort"
// //
// If inverse param is set to true, the order is reversed. // If inverse param is set to true, the order is reversed.
func (ll ListLB) SortByCreatedTime(inverse bool) ListLB { func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
if len(ll) < 2 { if len(ll.Data) < 2 {
return ll return ll
} }
sort.Slice(ll, func(i, j int) bool { sort.Slice(ll.Data, func(i, j int) bool {
if inverse { if inverse {
return ll[i].CreatedTime > ll[j].CreatedTime return ll.Data[i].CreatedTime > ll.Data[j].CreatedTime
} }
return ll[i].CreatedTime < ll[j].CreatedTime return ll.Data[i].CreatedTime < ll.Data[j].CreatedTime
}) })
return ll return ll
@@ -25,16 +25,16 @@ func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
// //
// If inverse param is set to true, the order is reversed. // If inverse param is set to true, the order is reversed.
func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB { func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
if len(ll) < 2 { if len(ll.Data) < 2 {
return ll return ll
} }
sort.Slice(ll, func(i, j int) bool { sort.Slice(ll.Data, func(i, j int) bool {
if inverse { if inverse {
return ll[i].UpdatedTime > ll[j].UpdatedTime return ll.Data[i].UpdatedTime > ll.Data[j].UpdatedTime
} }
return ll[i].UpdatedTime < ll[j].UpdatedTime return ll.Data[i].UpdatedTime < ll.Data[j].UpdatedTime
}) })
return ll return ll
@@ -44,16 +44,16 @@ func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
// //
// If inverse param is set to true, the order is reversed. // If inverse param is set to true, the order is reversed.
func (ll ListLB) SortByDeletedTime(inverse bool) ListLB { func (ll ListLB) SortByDeletedTime(inverse bool) ListLB {
if len(ll) < 2 { if len(ll.Data) < 2 {
return ll return ll
} }
sort.Slice(ll, func(i, j int) bool { sort.Slice(ll.Data, func(i, j int) bool {
if inverse { if inverse {
return ll[i].DeletedTime > ll[j].DeletedTime return ll.Data[i].DeletedTime > ll.Data[j].DeletedTime
} }
return ll[i].DeletedTime < ll[j].DeletedTime return ll.Data[i].DeletedTime < ll.Data[j].DeletedTime
}) })
return ll return ll

View File

@@ -6,11 +6,41 @@ import (
"net/http" "net/http"
) )
type ListRequest struct {
// Find by id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by computeId
// Required: false
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by rgId
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list all pci devices // List gets list all pci devices
func (p PCIDevice) List(ctx context.Context) (ListPCIDevices, error) { func (p PCIDevice) List(ctx context.Context, req ListRequest) (*ListPCIDevices, error) {
url := "/cloudbroker/pcidevice/list" url := "/cloudbroker/pcidevice/list"
res, err := p.client.DecortApiCall(ctx, http.MethodPost, url, nil) res, err := p.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -22,5 +52,5 @@ func (p PCIDevice) List(ctx context.Context) (ListPCIDevices, error) {
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -40,4 +40,11 @@ type ItemPCIDevice struct {
} }
// List PCI devices // List PCI devices
type ListPCIDevices []ItemPCIDevice type ListPCIDevices struct {
// Data
Data []ItemPCIDevice `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -11,7 +11,7 @@ import (
// - First argument -> prefix // - First argument -> prefix
// - Second argument -> indent // - Second argument -> indent
func (l ListPCIDevices) Serialize(params ...string) (serialization.Serialized, error) { func (l ListPCIDevices) Serialize(params ...string) (serialization.Serialized, error) {
if len(l) == 0 { if len(l.Data) == 0 {
return []byte{}, nil return []byte{}, nil
} }

View File

@@ -16,7 +16,7 @@ type AffinityGroupsListRequest struct {
} }
// AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs // AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (map[string][]uint64, error) { func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (*ListAffinityGroup, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -31,12 +31,12 @@ func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListReques
return nil, err return nil, err
} }
list := make(map[string][]uint64) list := ListAffinityGroup{}
err = json.Unmarshal(res, &list) err = json.Unmarshal(res, &list)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -67,21 +67,23 @@ func (lrg ListRG) FilterByDefNetID(defNetID int64) ListRG {
func (lrg ListRG) FilterFunc(predicate func(ItemRG) bool) ListRG { func (lrg ListRG) FilterFunc(predicate func(ItemRG) bool) ListRG {
var result ListRG var result ListRG
for _, item := range lrg { for _, item := range lrg.Data {
if predicate(item) { if predicate(item) {
result = append(result, item) result.Data = append(result.Data, item)
} }
} }
result.EntryCount = uint64(len(result.Data))
return result return result
} }
// FindOne returns first found ItemRG. // FindOne returns first found ItemRG.
// If none was found, returns an empty struct. // If none was found, returns an empty struct.
func (lrg ListRG) FindOne() ItemRG { func (lrg ListRG) FindOne() ItemRG {
if len(lrg) == 0 { if len(lrg.Data) == 0 {
return ItemRG{} return ItemRG{}
} }
return lrg[0] return lrg.Data[0]
} }

View File

@@ -3,140 +3,143 @@ package rg
import "testing" import "testing"
var rgs = ListRG{ var rgs = ListRG{
{ Data: []ItemRG{
AccountID: 1, {
AccountName: "std", AccountID: 1,
ACL: []ACL{ AccountName: "std",
{ ACL: []ACL{
Explicit: true, {
GUID: "", Explicit: true,
Right: "ARCXDU", GUID: "",
Status: "CONFIRMED", Right: "ARCXDU",
Type: "U", Status: "CONFIRMED",
UserGroupID: "sample_user_1@decs3o", Type: "U",
UserGroupID: "sample_user_1@decs3o",
},
}, },
}, CreatedBy: "sample_user_1@decs3o",
CreatedBy: "sample_user_1@decs3o", CreatedTime: 1676645305,
CreatedTime: 1676645305, DefNetID: 1,
DefNetID: 1, DefNetType: "NONE",
DefNetType: "NONE", DeletedBy: "",
DeletedBy: "", DeletedTime: 0,
DeletedTime: 0, Description: "",
Description: "", GID: 212,
GID: 212, GUID: 7971,
GUID: 7971, ID: 7971,
ID: 7971, LockStatus: "UNLOCKED",
LockStatus: "UNLOCKED", Milestones: 363459,
Milestones: 363459, Name: "rg_1",
Name: "rg_1", RegisterComputes: false,
RegisterComputes: false, ResourceLimits: ResourceLimits{
ResourceLimits: ResourceLimits{ CUC: -1,
CUC: -1, CuD: -1,
CuD: -1, CUI: -1,
CUI: -1, CUM: -1,
CUM: -1, CUNP: -1,
CUNP: -1, GPUUnits: -1,
GPUUnits: -1,
},
Secret: "",
Status: "CREATED",
UpdatedBy: "",
UpdatedTime: 0,
VINS: []uint64{},
VMs: []uint64{},
ResTypes: []string{},
UniqPools: []string{},
},
{
AccountID: 2,
AccountName: "std_2",
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "ARCXDU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "sample_user_1@decs3o",
}, },
Secret: "",
Status: "CREATED",
UpdatedBy: "",
UpdatedTime: 0,
VINS: []uint64{},
VMs: []uint64{},
ResTypes: []string{},
UniqPools: []string{},
}, },
CreatedBy: "sample_user_1@decs3o", {
CreatedTime: 1676645461, AccountID: 2,
DefNetID: 2, AccountName: "std_2",
DefNetType: "NONE", ACL: []ACL{
DeletedBy: "", {
DeletedTime: 0, Explicit: true,
Description: "", GUID: "",
GID: 212, Right: "ARCXDU",
GUID: 7972, Status: "CONFIRMED",
ID: 7972, Type: "U",
LockStatus: "UNLOCKED", UserGroupID: "sample_user_1@decs3o",
Milestones: 363468, },
Name: "rg_2",
RegisterComputes: false,
ResourceLimits: ResourceLimits{
CUC: -1,
CuD: -1,
CUI: -1,
CUM: -1,
CUNP: -1,
GPUUnits: -1,
},
Secret: "",
Status: "CREATED",
UpdatedBy: "",
UpdatedTime: 0,
VINS: []uint64{},
VMs: []uint64{},
ResTypes: []string{},
UniqPools: []string{},
},
{
AccountID: 3,
AccountName: "std_3",
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "ARCXDU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "sample_user_2@decs3o",
}, },
CreatedBy: "sample_user_1@decs3o",
CreatedTime: 1676645461,
DefNetID: 2,
DefNetType: "NONE",
DeletedBy: "",
DeletedTime: 0,
Description: "",
GID: 212,
GUID: 7972,
ID: 7972,
LockStatus: "UNLOCKED",
Milestones: 363468,
Name: "rg_2",
RegisterComputes: false,
ResourceLimits: ResourceLimits{
CUC: -1,
CuD: -1,
CUI: -1,
CUM: -1,
CUNP: -1,
GPUUnits: -1,
},
Secret: "",
Status: "CREATED",
UpdatedBy: "",
UpdatedTime: 0,
VINS: []uint64{},
VMs: []uint64{},
ResTypes: []string{},
UniqPools: []string{},
}, },
CreatedBy: "sample_user_2@decs3o", {
CreatedTime: 1676645548, AccountID: 3,
DefNetID: 3, AccountName: "std_3",
DefNetType: "NONE", ACL: []ACL{
DeletedBy: "", {
DeletedTime: 0, Explicit: true,
Description: "", GUID: "",
GID: 212, Right: "ARCXDU",
GUID: 7973, Status: "CONFIRMED",
ID: 7973, Type: "U",
LockStatus: "kjLOCKED", UserGroupID: "sample_user_2@decs3o",
Milestones: 363471, },
Name: "rg_3", },
RegisterComputes: false, CreatedBy: "sample_user_2@decs3o",
ResourceLimits: ResourceLimits{ CreatedTime: 1676645548,
CUC: -1, DefNetID: 3,
CuD: -1, DefNetType: "NONE",
CUI: -1, DeletedBy: "",
CUM: -1, DeletedTime: 0,
CUNP: -1, Description: "",
GPUUnits: -1, GID: 212,
GUID: 7973,
ID: 7973,
LockStatus: "kjLOCKED",
Milestones: 363471,
Name: "rg_3",
RegisterComputes: false,
ResourceLimits: ResourceLimits{
CUC: -1,
CuD: -1,
CUI: -1,
CUM: -1,
CUNP: -1,
GPUUnits: -1,
},
Secret: "",
Status: "DISABLED",
UpdatedBy: "",
UpdatedTime: 0,
VINS: []uint64{},
VMs: []uint64{
48500,
},
ResTypes: []string{},
UniqPools: []string{},
}, },
Secret: "",
Status: "DISABLED",
UpdatedBy: "",
UpdatedTime: 0,
VINS: []uint64{},
VMs: []uint64{
48500,
},
ResTypes: []string{},
UniqPools: []string{},
}, },
EntryCount: 3,
} }
func TestFilterByID(t *testing.T) { func TestFilterByID(t *testing.T) {
@@ -158,11 +161,11 @@ func TestFilterByName(t *testing.T) {
func TestFilterByCreatedBy(t *testing.T) { func TestFilterByCreatedBy(t *testing.T) {
actual := rgs.FilterByCreatedBy("sample_user_1@decs3o") actual := rgs.FilterByCreatedBy("sample_user_1@decs3o")
if len(actual) != 2 { if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual)) t.Fatal("expected 2 found, actual: ", len(actual.Data))
} }
for _, item := range actual { for _, item := range actual.Data {
if item.CreatedBy != "sample_user_1@decs3o" { if item.CreatedBy != "sample_user_1@decs3o" {
t.Fatal("expected CreatedBy 'sample_user_1@decs3o', found: ", item.CreatedBy) t.Fatal("expected CreatedBy 'sample_user_1@decs3o', found: ", item.CreatedBy)
} }
@@ -172,11 +175,11 @@ func TestFilterByCreatedBy(t *testing.T) {
func TestFilterByStatus(t *testing.T) { func TestFilterByStatus(t *testing.T) {
actual := rgs.FilterByStatus("CREATED") actual := rgs.FilterByStatus("CREATED")
if len(actual) != 2 { if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual)) t.Fatal("expected 2 found, actual: ", len(actual.Data))
} }
for _, item := range actual { for _, item := range actual.Data {
if item.Status != "CREATED" { if item.Status != "CREATED" {
t.Fatal("expected Status 'ENABLED', found: ", item.Status) t.Fatal("expected Status 'ENABLED', found: ", item.Status)
} }
@@ -186,11 +189,11 @@ func TestFilterByStatus(t *testing.T) {
func TestFilterByLockStatus(t *testing.T) { func TestFilterByLockStatus(t *testing.T) {
actual := rgs.FilterByLockStatus("UNLOCKED") actual := rgs.FilterByLockStatus("UNLOCKED")
if len(actual) != 2 { if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual)) t.Fatal("expected 2 found, actual: ", len(actual.Data))
} }
for _, item := range actual { for _, item := range actual.Data {
if item.LockStatus != "UNLOCKED" { if item.LockStatus != "UNLOCKED" {
t.Fatal("expected LockStatus 'UNLOCKED', found: ", item.LockStatus) t.Fatal("expected LockStatus 'UNLOCKED', found: ", item.LockStatus)
} }
@@ -200,11 +203,11 @@ func TestFilterByLockStatus(t *testing.T) {
func TestFilterByDefNetType(t *testing.T) { func TestFilterByDefNetType(t *testing.T) {
actual := rgs.FilterByDefNetType("NONE") actual := rgs.FilterByDefNetType("NONE")
if len(actual) != 3 { if len(actual.Data) != 3 {
t.Fatal("expected 3 found, actual: ", len(actual)) t.Fatal("expected 3 found, actual: ", len(actual.Data))
} }
for _, item := range actual { for _, item := range actual.Data {
if item.DefNetType != "NONE" { if item.DefNetType != "NONE" {
t.Fatal("expected DefNetType 'NONE', found: ", item.DefNetType) t.Fatal("expected DefNetType 'NONE', found: ", item.DefNetType)
} }
@@ -224,11 +227,11 @@ func TestFilterFunc(t *testing.T) {
return len(ir.VMs) > 0 return len(ir.VMs) > 0
}) })
if len(actual) < 1 { if len(actual.Data) < 1 {
t.Fatal("expected 1 found, actual: ", len(actual)) t.Fatal("expected 1 found, actual: ", len(actual.Data))
} }
for _, item := range actual { for _, item := range actual.Data {
if len(item.VMs) < 1 { if len(item.VMs) < 1 {
t.Fatal("expected VMs to contain at least 1 element, found empty") t.Fatal("expected VMs to contain at least 1 element, found empty")
} }
@@ -238,7 +241,7 @@ func TestFilterFunc(t *testing.T) {
func TestSortByCreatedTime(t *testing.T) { func TestSortByCreatedTime(t *testing.T) {
actual := rgs.SortByCreatedTime(true) actual := rgs.SortByCreatedTime(true)
if actual[0].CreatedTime != 1676645548 || actual[2].CreatedTime != 1676645305 { if actual.Data[0].CreatedTime != 1676645548 || actual.Data[2].CreatedTime != 1676645305 {
t.Fatal("expected descending order, found ascending") t.Fatal("expected descending order, found ascending")
} }
} }

View File

@@ -0,0 +1,42 @@
package rg
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get detailed information about resource consumption for ResGroup
type GetResourceConsumptionRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
}
// GetResourceConsumption gets resource consumption of the resource group
func (r RG) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*ItemResourceConsumption, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudbroker/rg/getResourceConsumption"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := ItemResourceConsumption{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -8,6 +8,34 @@ import (
// Request struct for get list of resource groups // Request struct for get list of resource groups
type ListRequest struct { type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by name account
// Required: false
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
// Find by created after time (unix timestamp)
// Required: false
CreatedAfter uint64 `url:"createdAfter,omitempty" json:"createdAfter,omitempty"`
// Find by created before time (unix timestamp)
// Required: false
CreatedBefore uint64 `url:"createdBefore,omitempty" json:"createdBefore,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Included deleted resource groups // Included deleted resource groups
// Required: false // Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"` IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
@@ -22,7 +50,7 @@ type ListRequest struct {
} }
// List gets list of all resource groups the user has access to // List gets list of all resource groups the user has access to
func (r RG) List(ctx context.Context, req ListRequest) (ListRG, error) { func (r RG) List(ctx context.Context, req ListRequest) (*ListRG, error) {
url := "/cloudbroker/rg/list" url := "/cloudbroker/rg/list"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -37,5 +65,5 @@ func (r RG) List(ctx context.Context, req ListRequest) (ListRG, error) {
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -14,13 +14,49 @@ type ListComputesRequest struct {
// Required: true // Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"` RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Reason for action // Find by compute id
// Required: false // Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"` ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// ID an account
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by tech status
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by ip address
// Required: false
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
// Find by external network name
// Required: false
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
// Find by external network id
// Required: false
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
} }
// ListComputes gets list of all compute instances under specified resource group, accessible by the user // ListComputes gets list of all compute instances under specified resource group, accessible by the user
func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) { func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -42,5 +78,5 @@ func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComp
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -8,6 +8,34 @@ import (
// Request struct for get list deleted resource groups // Request struct for get list deleted resource groups
type ListDeletedRequest struct { type ListDeletedRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by name account
// Required: false
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
// Find by created after time (unix timestamp)
// Required: false
CreatedAfter uint64 `url:"createdAfter,omitempty" json:"createdAfter,omitempty"`
// Find by created before time (unix timestamp)
// Required: false
CreatedBefore uint64 `url:"createdBefore,omitempty" json:"createdBefore,omitempty"`
// Find by status lock
// Required: false
LockStatus string `url:"lockStatus,omitempty" json:"lockStatus,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -18,7 +46,7 @@ type ListDeletedRequest struct {
} }
// ListDeleted gets list all deleted resource groups the user has access to // ListDeleted gets list all deleted resource groups the user has access to
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListRG, error) { func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListRG, error) {
url := "/cloudbroker/rg/listDeleted" url := "/cloudbroker/rg/listDeleted"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -33,5 +61,5 @@ func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListRG, er
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -13,10 +13,46 @@ type ListLBRequest struct {
// Resource group ID // Resource group ID
// Required: true // Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"` RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
// Find by tech status
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by frontend Ip
// Required: false
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
// Find by backend Ip
// Required: false
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
} }
// ListLB gets list all load balancers in the specified resource group, accessible by the user // ListLB gets list all load balancers in the specified resource group, accessible by the user
func (r RG) ListLB(ctx context.Context, req ListLBRequest) (ListLB, error) { func (r RG) ListLB(ctx context.Context, req ListLBRequest) (*ListLB, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -38,5 +74,5 @@ func (r RG) ListLB(ctx context.Context, req ListLBRequest) (ListLB, error) {
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -16,7 +16,7 @@ type ListPFWRequest struct {
} }
// ListPFW gets list port forward rules for the specified resource group // ListPFW gets list port forward rules for the specified resource group
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPFW, error) { func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (*ListPFW, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
for _, validationError := range validators.GetErrors(err) { for _, validationError := range validators.GetErrors(err) {
@@ -38,5 +38,5 @@ func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPFW, error) {
return nil, err return nil, err
} }
return list, nil return &list, nil
} }

View File

@@ -0,0 +1,26 @@
package rg
import (
"context"
"encoding/json"
"net/http"
)
// ListResourceConsumption gets resource consumptions of the resource groups
func (r RG) ListResourceConsumption(ctx context.Context) (*ListResourceConsumption, error) {
url := "/cloudbroker/rg/listResourceConsumption"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, nil)
if err != nil {
return nil, err
}
list := ListResourceConsumption{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

Some files were not shown because too many files have changed in this diff Show More