1.5.8-k8s-extnet-branch
Nikita Sorokin 2 years ago
parent 8f152a2f63
commit c78b1348e3

@ -64,8 +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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false // 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 // Input data for cloud-init facility
// Required: false // 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 { if req.Interfaces != nil && len(req.Interfaces) != 0 {
b, err := json.Marshal(req.Interfaces[i]) interfaces = make([]string, 0, len(req.Interfaces))
if err != nil {
return 0, err 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{ reqWrapped := wrapperCreateRequest{

@ -41,9 +41,11 @@ type CreateBlankRequest struct {
// Required: true // Required: true
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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false // 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 // Text description of this VM
// Required: false // 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 { if req.Interfaces != nil && len(req.Interfaces) != 0 {
b, err := json.Marshal(req.Interfaces[i]) interfaces = make([]string, 0, len(req.Interfaces))
if err != nil {
return 0, err 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{ reqWrapped := wrapperCreateBlankRequest{

@ -64,6 +64,8 @@ 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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false // Required: false
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"` 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 { if req.Interfaces != nil && len(req.Interfaces) != 0 {
b, err := json.Marshal(req.Interfaces[i]) interfaces = make([]string, 0, len(req.Interfaces))
if err != nil {
return 0, err 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{ reqWrapped := wrapperCreateRequest{

@ -42,8 +42,10 @@ 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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false // 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) // Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
// Required: false // 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 { if req.Interfaces != nil && len(req.Interfaces) != 0 {
b, err := json.Marshal(req.Interfaces[i]) interfaces = make([]string, 0, len(req.Interfaces))
if err != nil {
return 0, err 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{ reqWrapped := wrapperCreateBlankRequest{

@ -64,8 +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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false // 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 // Input data for cloud-init facility
// Required: false // 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 { if req.Interfaces != nil && len(req.Interfaces) != 0 {
b, err := json.Marshal(req.Interfaces[i]) interfaces = make([]string, 0, len(req.Interfaces))
if err != nil {
return 0, err 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{ reqWrapped := wrapperCreateRequest{

@ -42,8 +42,10 @@ 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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false // 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 // Text description of this VM
// Required: false // 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 { if req.Interfaces != nil && len(req.Interfaces) != 0 {
b, err := json.Marshal(req.Interfaces[i]) interfaces = make([]string, 0, len(req.Interfaces))
if err != nil {
return 0, err 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{ reqWrapped := wrapperCreateBlankRequest{

@ -49,8 +49,10 @@ type MassCreateRequest 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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice.
// Required: false // 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 // Input data for cloud-init facility
// Required: false // Required: false
@ -69,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)
@ -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" 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
} }

@ -64,8 +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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false // 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 // Input data for cloud-init facility
// Required: false // 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 { if req.Interfaces != nil && len(req.Interfaces) != 0 {
b, err := json.Marshal(req.Interfaces[i]) interfaces = make([]string, 0, len(req.Interfaces))
if err != nil {
return 0, err 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{ reqWrapped := wrapperCreateRequest{

@ -42,8 +42,10 @@ 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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false // 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 // Text description of this VM
// Required: false // 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 { if req.Interfaces != nil && len(req.Interfaces) != 0 {
b, err := json.Marshal(req.Interfaces[i]) interfaces = make([]string, 0, len(req.Interfaces))
if err != nil {
return 0, err 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{ reqWrapped := wrapperCreateBlankRequest{

@ -49,8 +49,10 @@ type MassCreateRequest 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.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false // 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 // Input data for cloud-init facility
// Required: false // Required: false
@ -69,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)
@ -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" 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
} }

Loading…
Cancel
Save