Compare commits
3 Commits
v1.5.0-eps
...
v1.5.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a152cb44c | |||
| c78b1348e3 | |||
| 8f152a2f63 |
19
CHANGELOG.md
19
CHANGELOG.md
@@ -76,6 +76,16 @@
|
||||
- - cloudbroker/vins/extnetList
|
||||
- - cloudbroker/vins/IpList
|
||||
- - cloudbroker/vins/natRuleList
|
||||
- - cloudapi/account/listTemplates
|
||||
- - cloudapi/compute/pfwList
|
||||
- - cloudapi/compute/sanpshotList
|
||||
- - cloudapi/compute/userList
|
||||
- - cloudapi/vins/extnetList
|
||||
- - cloudapi/vins/ipList
|
||||
- - cloudapi/vins/natRuleList
|
||||
- - cloudapi/sizes/list
|
||||
- - cloudapi/rg/affinityGroupsList
|
||||
- - cloudapi/extnet/listComputes
|
||||
|
||||
- Added new endpoints:
|
||||
- - cloudapi/rg/getResourceConsumption
|
||||
@@ -88,6 +98,9 @@
|
||||
- - cloudbroker/account/listResourceConsumption
|
||||
- - cloudbroker/grid/getResourceConsumption
|
||||
- - cloudbroker/grid/listResourceConsumption
|
||||
- - cloudapi/compute/getCustomFields
|
||||
- - cloudapi/compute/deleteCustomFields
|
||||
- - cloudapi/compute/setCustomFields
|
||||
|
||||
- Added field CU_DM to ResourceLimits model (account, rg)
|
||||
|
||||
@@ -139,5 +152,11 @@
|
||||
|
||||
- Deleted field Reason from cloudbroker/vins/extnetList request
|
||||
|
||||
- Added field CustomFields to cloudapi/kvmx86/create request
|
||||
|
||||
- Added field Driver to cloudapi/kvmx86/create request
|
||||
|
||||
- Added field Driver to cloudapi/kvmx86/createBlank request
|
||||
|
||||
### Bugfix
|
||||
- Changed the Excluded field type in cloudbroker/extnet/get response model
|
||||
|
||||
@@ -6,6 +6,13 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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.
|
||||
func protoValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
@@ -107,6 +107,12 @@ func errorMessage(fe validator.FieldError) string {
|
||||
fe.Field(),
|
||||
joinValues(computeDataDisksValues))
|
||||
|
||||
case "computeDriver":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(computeDriverValues))
|
||||
|
||||
// Disk Validators
|
||||
case "diskType":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
|
||||
@@ -30,6 +30,11 @@ func registerAllValidators(validate *validator.Validate) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("computeDriver", computeDriverValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("accessType", accessTypeValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -17,6 +17,7 @@ var (
|
||||
computeNetTypeValues = []string{"EXTNET", "VINS"}
|
||||
computeOrderValues = []string{"cdrom", "network", "hd"}
|
||||
computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"}
|
||||
computeDriverValues = []string{"KVM_X86", "SVA_KVM_X86"}
|
||||
|
||||
diskTypeValues = []string{"B", "T", "D"}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ type GetResourceConsumptionRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -26,7 +26,7 @@ func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceCons
|
||||
|
||||
url := "/cloudapi/account/getResourceConsumption"
|
||||
|
||||
info := ItemResourceConsumption{}
|
||||
info := RecordResourceConsumption{}
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,15 +12,35 @@ import (
|
||||
type ListTemplatesRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Include deleted images
|
||||
// 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
|
||||
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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -42,5 +62,5 @@ func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (L
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ type ResourceLimits struct {
|
||||
CUD float64 `json:"CU_D"`
|
||||
|
||||
// Max disk size, GB
|
||||
CU_DM float64 `json:"CU_DM"`
|
||||
CUDM float64 `json:"CU_DM"`
|
||||
|
||||
// Number of public IP addresses
|
||||
CUI float64 `json:"CU_I"`
|
||||
@@ -115,6 +115,14 @@ type DiskUsage struct {
|
||||
DiskSizeMax float64 `json:"disksizemax"`
|
||||
}
|
||||
|
||||
// Information about resource consumption
|
||||
type RecordResourceConsumption struct {
|
||||
ItemResourceConsumption
|
||||
|
||||
// Resource limits
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
}
|
||||
|
||||
// Information about resources
|
||||
type ItemResourceConsumption struct {
|
||||
// Current information about resources
|
||||
@@ -557,7 +565,13 @@ type ItemTemplate struct {
|
||||
}
|
||||
|
||||
// List of templates
|
||||
type ListTemplates []ItemTemplate
|
||||
type ListTemplates struct {
|
||||
// Data
|
||||
Data []ItemTemplate `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about FLIPGroup
|
||||
type ItemFLIPGroup struct {
|
||||
|
||||
40
pkg/cloudapi/compute/delete_custom_fields.go
Normal file
40
pkg/cloudapi/compute/delete_custom_fields.go
Normal 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
|
||||
}
|
||||
@@ -22,11 +22,6 @@ type DiskAddRequest struct {
|
||||
// Required: true
|
||||
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
|
||||
// Should be one of:
|
||||
// - D
|
||||
@@ -34,6 +29,11 @@ type DiskAddRequest struct {
|
||||
// Required: false
|
||||
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
|
||||
// By default will be chosen automatically
|
||||
// Required: false
|
||||
|
||||
42
pkg/cloudapi/compute/get_custom_fields.go
Normal file
42
pkg/cloudapi/compute/get_custom_fields.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for getting Compute's customFields
|
||||
type GetCustomFieldsRequest struct {
|
||||
// Compute ID
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// GetCustomFields gets Compute's customFields
|
||||
func (c Compute) GetCustomFields(ctx context.Context, req GetCustomFieldsRequest) (interface{}, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/getCustomFields"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var info interface{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
@@ -14,6 +14,14 @@ type RecordACL struct {
|
||||
RGACL ListACL `json:"rgAcl"`
|
||||
}
|
||||
|
||||
type ListUsers struct {
|
||||
// Data
|
||||
Data RecordACL `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
type Explicit bool
|
||||
|
||||
func (e *Explicit) UnmarshalJSON(b []byte) error {
|
||||
@@ -89,7 +97,13 @@ type ItemSnapshot struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
type ItemPFW struct {
|
||||
@@ -116,7 +130,13 @@ type ItemPFW struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
type RecordAffinityRelations struct {
|
||||
@@ -403,7 +423,7 @@ type RecordCompute struct {
|
||||
SnapSets ListSnapSets `json:"snapSets"`
|
||||
|
||||
// Stateless SepID
|
||||
StatelessSepID uint64 `json:"statelessSepId"`
|
||||
StatelessSepID int64 `json:"statelessSepId"`
|
||||
|
||||
// Stateless SepType
|
||||
StatelessSepType string `json:"statelessSepType"`
|
||||
@@ -862,7 +882,7 @@ type ItemCompute struct {
|
||||
SnapSets ListSnapSets `json:"snapSets"`
|
||||
|
||||
// Stateless SepID
|
||||
StatelessSepID uint64 `json:"statelessSepId"`
|
||||
StatelessSepID int64 `json:"statelessSepId"`
|
||||
|
||||
// Stateless SepType
|
||||
StatelessSepType string `json:"statelessSepType"`
|
||||
|
||||
@@ -16,7 +16,7 @@ type PFWListRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
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 list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
43
pkg/cloudapi/compute/set_custom_fields.go
Normal file
43
pkg/cloudapi/compute/set_custom_fields.go
Normal 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
|
||||
}
|
||||
@@ -16,7 +16,7 @@ type SnapshotListRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -38,5 +38,5 @@ func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (Lis
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ type UserListRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -31,7 +31,7 @@ func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := RecordACL{}
|
||||
list := ListUsers{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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]
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -24,10 +24,6 @@ type ListUnattachedRequest struct {
|
||||
// Required: false
|
||||
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
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||
|
||||
@@ -13,10 +13,26 @@ type ListComputesRequest struct {
|
||||
// Filter by account ID
|
||||
// Required: true
|
||||
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
|
||||
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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -38,5 +54,5 @@ func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (List
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -59,7 +59,13 @@ type ItemExtNetCompute struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
type QOS struct {
|
||||
@@ -118,6 +124,12 @@ type Excluded struct {
|
||||
// ClientType
|
||||
ClientType string `json:"clientType"`
|
||||
|
||||
// Domain name
|
||||
DomainName string `json:"domainname"`
|
||||
|
||||
// Host name
|
||||
HostName string `json:"hostname"`
|
||||
|
||||
// IP
|
||||
IP string `json:"ip"`
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ type CreateRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -60,7 +60,7 @@ func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGr
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordFLIPGroup{}
|
||||
info := RecordFLIPGroupCreated{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ type GetRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -31,7 +31,7 @@ func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*ItemFLIPGroup, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := ItemFLIPGroup{}
|
||||
info := RecordFLIPGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package flipgroup
|
||||
|
||||
// Main information about FLIPGroup
|
||||
type RecordFLIPGroup struct {
|
||||
type RecordFLIPGroupCreated struct {
|
||||
// Default GW
|
||||
DefaultGW string `json:"defaultGW"`
|
||||
|
||||
@@ -18,6 +18,89 @@ type RecordFLIPGroup struct {
|
||||
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
|
||||
type ItemFLIPGroup struct {
|
||||
// CKey
|
||||
|
||||
@@ -64,8 +64,10 @@ type CreateRequest struct {
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// 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,min=1,dive"`
|
||||
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Input data for cloud-init facility
|
||||
// Required: false
|
||||
@@ -102,15 +104,21 @@ func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
interfaces := make([]string, 0, len(req.Interfaces))
|
||||
var interfaces []string
|
||||
|
||||
for i := range req.Interfaces {
|
||||
b, err := json.Marshal(req.Interfaces[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
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))
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, string(b))
|
||||
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateRequest{
|
||||
|
||||
@@ -41,9 +41,11 @@ type CreateBlankRequest struct {
|
||||
// Required: true
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
|
||||
// Slice of structs with net interface description
|
||||
// Slice of structs with net interface description.
|
||||
// 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,min=1,dive"`
|
||||
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Text description of this VM
|
||||
// Required: false
|
||||
@@ -64,15 +66,21 @@ func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
|
||||
}
|
||||
}
|
||||
|
||||
interfaces := make([]string, 0, len(req.Interfaces))
|
||||
var interfaces []string
|
||||
|
||||
for i := range req.Interfaces {
|
||||
b, err := json.Marshal(req.Interfaces[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
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))
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, string(b))
|
||||
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateBlankRequest{
|
||||
|
||||
@@ -64,8 +64,10 @@ type CreateRequest struct {
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// 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,min=1,dive"`
|
||||
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Input data for cloud-init facility
|
||||
// Required: false
|
||||
@@ -86,6 +88,14 @@ type CreateRequest struct {
|
||||
// Compute purpose
|
||||
// Required: false
|
||||
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 {
|
||||
@@ -102,15 +112,21 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
interfaces := make([]string, 0, len(req.Interfaces))
|
||||
var interfaces []string
|
||||
|
||||
for i := range req.Interfaces {
|
||||
b, err := json.Marshal(req.Interfaces[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
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))
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, string(b))
|
||||
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateRequest{
|
||||
|
||||
@@ -42,8 +42,14 @@ type CreateBlankRequest struct {
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// 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,min=1,dive"`
|
||||
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
|
||||
// Required: false
|
||||
@@ -64,15 +70,21 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
|
||||
}
|
||||
}
|
||||
|
||||
interfaces := make([]string, 0, len(req.Interfaces))
|
||||
var interfaces []string
|
||||
|
||||
for i := range req.Interfaces {
|
||||
b, err := json.Marshal(req.Interfaces[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
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))
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, string(b))
|
||||
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateBlankRequest{
|
||||
|
||||
@@ -20,7 +20,7 @@ type AffinityGroupComputesRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -35,7 +35,7 @@ func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputes
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListAffinityGroups{}
|
||||
list := ListAffinityGroupsComputes{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ type AffinityGroupsListRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -31,7 +31,7 @@ func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListReques
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := map[string][]uint64{}
|
||||
list := &ListAffinityGroups{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -53,6 +53,9 @@ type ItemResourceConsumption struct {
|
||||
// Reserved information about resources
|
||||
Reserved Resource `json:"Reserved"`
|
||||
|
||||
// Resource limits
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgid"`
|
||||
}
|
||||
@@ -302,7 +305,7 @@ type ResourceLimits struct {
|
||||
}
|
||||
|
||||
// Main information about affinity group
|
||||
type ItemAffinityGroup struct {
|
||||
type ItemAffinityGroupComputes struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
@@ -326,7 +329,15 @@ type ItemAffinityGroup struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
type ItemAudit struct {
|
||||
|
||||
@@ -37,6 +37,7 @@ func (r RG) Usage(ctx context.Context, req UsageRequest) (*RecordResourceUsage,
|
||||
|
||||
info := RecordResourceUsage{}
|
||||
err = json.Unmarshal(res, &info)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -22,21 +22,23 @@ func (ls ListSizes) FilterByName(name string) ListSizes {
|
||||
func (ls ListSizes) FilterFunc(predicate func(ItemSize) bool) ListSizes {
|
||||
var result ListSizes
|
||||
|
||||
for _, item := range ls {
|
||||
for _, item := range ls.Data {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemSize
|
||||
// If none was found, returns an empty struct.
|
||||
func (ls ListSizes) FindOne() ItemSize {
|
||||
if len(ls) == 0 {
|
||||
if len(ls.Data) == 0 {
|
||||
return ItemSize{}
|
||||
}
|
||||
|
||||
return ls[0]
|
||||
return ls.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,30 +3,33 @@ package sizes
|
||||
import "testing"
|
||||
|
||||
var sizeItems = ListSizes{
|
||||
{
|
||||
Description: "",
|
||||
Disks: []uint64{},
|
||||
ID: 1,
|
||||
Memory: 512,
|
||||
Name: "size_1",
|
||||
VCPUs: 2,
|
||||
},
|
||||
{
|
||||
Description: "",
|
||||
Disks: []uint64{},
|
||||
ID: 2,
|
||||
Memory: 1024,
|
||||
Name: "size_2",
|
||||
VCPUs: 4,
|
||||
},
|
||||
{
|
||||
Description: "",
|
||||
Disks: []uint64{},
|
||||
ID: 2,
|
||||
Memory: 2048,
|
||||
Name: "size_3",
|
||||
VCPUs: 6,
|
||||
Data: []ItemSize{
|
||||
{
|
||||
Description: "",
|
||||
Disks: []uint64{},
|
||||
ID: 1,
|
||||
Memory: 512,
|
||||
Name: "size_1",
|
||||
VCPUs: 2,
|
||||
},
|
||||
{
|
||||
Description: "",
|
||||
Disks: []uint64{},
|
||||
ID: 2,
|
||||
Memory: 1024,
|
||||
Name: "size_2",
|
||||
VCPUs: 4,
|
||||
},
|
||||
{
|
||||
Description: "",
|
||||
Disks: []uint64{},
|
||||
ID: 2,
|
||||
Memory: 2048,
|
||||
Name: "size_3",
|
||||
VCPUs: 6,
|
||||
},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
@@ -50,11 +53,11 @@ func TestFilterFunc(t *testing.T) {
|
||||
return is.Memory > 512
|
||||
})
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.Memory <= 512 {
|
||||
t.Fatal("expected Memory greater than 512, found: ", item.Memory)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
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"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
list := ListSizes{}
|
||||
list := &ListSizes{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,4 +22,10 @@ type ItemSize struct {
|
||||
}
|
||||
|
||||
// List of configured available flavors
|
||||
type ListSizes []ItemSize
|
||||
type ListSizes struct {
|
||||
// Data
|
||||
Data []ItemSize `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ls ListSizes) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(ls) == 0 {
|
||||
if len(ls.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ type ExtNetListRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -31,7 +31,7 @@ func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (ListExtNet
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListExtNets{}
|
||||
list := &ListExtNets{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ type IPListRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -31,7 +31,7 @@ func (v VINS) IPList(ctx context.Context, req IPListRequest) (ListIPs, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListIPs{}
|
||||
list := &ListIPs{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -104,7 +104,13 @@ type ItemExtNet struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
type ItemIP struct {
|
||||
@@ -131,7 +137,13 @@ type ItemIP struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
type RecordVNFDev struct {
|
||||
@@ -671,7 +683,13 @@ type ItemNATRule struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
type ItemReservation struct {
|
||||
|
||||
@@ -16,7 +16,7 @@ type NATRuleListRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -31,7 +31,7 @@ func (v VINS) NATRuleList(ctx context.Context, req NATRuleListRequest) (ListNATR
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListNATRules{}
|
||||
list := &ListNATRules{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ type GetResourceConsumptionRequest struct {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -26,7 +26,7 @@ func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceCons
|
||||
|
||||
url := "/cloudbroker/account/getResourceConsumption"
|
||||
|
||||
info := RecordResources{}
|
||||
info := RecordResourceConsumption{}
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -21,7 +21,13 @@ type ItemAudit struct {
|
||||
// List of audits
|
||||
type ListAudits []ItemAudit
|
||||
|
||||
type RecordResources struct {
|
||||
type RecordResourceConsumption struct {
|
||||
ItemResourceConsumption
|
||||
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
}
|
||||
|
||||
type ItemResourceConsumption struct {
|
||||
// Current information about resources
|
||||
Current Resource `json:"Current"`
|
||||
|
||||
@@ -34,7 +40,7 @@ type RecordResources struct {
|
||||
|
||||
type ListResources struct {
|
||||
// Data
|
||||
Data []RecordResources `json:"data"`
|
||||
Data []ItemResourceConsumption `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
|
||||
@@ -64,8 +64,10 @@ type CreateRequest struct {
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// 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,min=1,dive"`
|
||||
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Input data for cloud-init facility
|
||||
// Required: false
|
||||
@@ -102,15 +104,21 @@ func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
interfaces := make([]string, 0, len(req.Interfaces))
|
||||
var interfaces []string
|
||||
|
||||
for i := range req.Interfaces {
|
||||
b, err := json.Marshal(req.Interfaces[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
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))
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, string(b))
|
||||
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateRequest{
|
||||
|
||||
@@ -42,8 +42,10 @@ type CreateBlankRequest struct {
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// 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,min=1,dive"`
|
||||
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Text description of this VM
|
||||
// Required: false
|
||||
@@ -64,15 +66,21 @@ func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
|
||||
}
|
||||
}
|
||||
|
||||
interfaces := make([]string, 0, len(req.Interfaces))
|
||||
var interfaces []string
|
||||
|
||||
for i := range req.Interfaces {
|
||||
b, err := json.Marshal(req.Interfaces[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
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))
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, string(b))
|
||||
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateBlankRequest{
|
||||
|
||||
@@ -49,8 +49,10 @@ type MassCreateRequest struct {
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// 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:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"`
|
||||
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Input data for cloud-init facility
|
||||
// Required: false
|
||||
@@ -69,6 +71,11 @@ type MassCreateRequest struct {
|
||||
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
|
||||
func (k KVMPPC) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
@@ -78,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"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -64,8 +64,10 @@ type CreateRequest struct {
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// 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,min=1,dive"`
|
||||
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Input data for cloud-init facility
|
||||
// Required: false
|
||||
@@ -114,15 +116,21 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
interfaces := make([]string, 0, len(req.Interfaces))
|
||||
var interfaces []string
|
||||
|
||||
for i := range req.Interfaces {
|
||||
b, err := json.Marshal(req.Interfaces[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
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))
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, string(b))
|
||||
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateRequest{
|
||||
|
||||
@@ -42,8 +42,10 @@ type CreateBlankRequest struct {
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// 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,min=1,dive"`
|
||||
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Text description of this VM
|
||||
// Required: false
|
||||
@@ -64,15 +66,21 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
|
||||
}
|
||||
}
|
||||
|
||||
interfaces := make([]string, 0, len(req.Interfaces))
|
||||
var interfaces []string
|
||||
|
||||
for i := range req.Interfaces {
|
||||
b, err := json.Marshal(req.Interfaces[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
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))
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, string(b))
|
||||
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateBlankRequest{
|
||||
|
||||
@@ -49,8 +49,10 @@ type MassCreateRequest struct {
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// 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:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"`
|
||||
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Input data for cloud-init facility
|
||||
// Required: false
|
||||
@@ -69,6 +71,11 @@ type MassCreateRequest struct {
|
||||
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
|
||||
func (k KVMX86) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
@@ -78,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"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user