This commit is contained in:
2023-07-24 15:13:04 +03:00
parent 8f152a2f63
commit c78b1348e3
10 changed files with 190 additions and 68 deletions

View File

@@ -64,6 +64,8 @@ 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,dive"`
@@ -110,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{

View File

@@ -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"`
// Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
// Required: false
@@ -68,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{