From 0be4d8fb0cf83e4c2599c87f44edae11fe13af22 Mon Sep 17 00:00:00 2001 From: Nikita Sorokin Date: Thu, 13 Jul 2023 18:32:21 +0300 Subject: [PATCH] v1.5.0-epsilon --- pkg/cloudapi/kvmppc/create.go | 26 ++++++++++++++++++++++++-- pkg/cloudapi/kvmppc/create_blank.go | 26 ++++++++++++++++++++++++-- pkg/cloudapi/kvmx86/create.go | 26 ++++++++++++++++++++++++-- pkg/cloudapi/kvmx86/create_blank.go | 26 ++++++++++++++++++++++++-- pkg/cloudbroker/kvmppc/create.go | 26 ++++++++++++++++++++++++-- pkg/cloudbroker/kvmppc/create_blank.go | 26 ++++++++++++++++++++++++-- pkg/cloudbroker/kvmx86/create.go | 26 ++++++++++++++++++++++++-- pkg/cloudbroker/kvmx86/create_blank.go | 26 ++++++++++++++++++++++++-- 8 files changed, 192 insertions(+), 16 deletions(-) diff --git a/pkg/cloudapi/kvmppc/create.go b/pkg/cloudapi/kvmppc/create.go index 1363045..d385319 100644 --- a/pkg/cloudapi/kvmppc/create.go +++ b/pkg/cloudapi/kvmppc/create.go @@ -2,6 +2,7 @@ package kvmppc import ( "context" + "encoding/json" "net/http" "strconv" @@ -64,7 +65,7 @@ type CreateRequest struct { // Slice of structs with net interface description. // Required: false - Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` + Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // Input data for cloud-init facility // Required: false @@ -87,6 +88,11 @@ type CreateRequest struct { 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 func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) { err := validators.ValidateRequest(req) @@ -96,9 +102,25 @@ func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) { } } + 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)) + } + + reqWrapped := wrapperCreateRequest{ + CreateRequest: req, + Interfaces: interfaces, + } + 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 { return 0, err } diff --git a/pkg/cloudapi/kvmppc/create_blank.go b/pkg/cloudapi/kvmppc/create_blank.go index 45526a5..6367189 100644 --- a/pkg/cloudapi/kvmppc/create_blank.go +++ b/pkg/cloudapi/kvmppc/create_blank.go @@ -2,6 +2,7 @@ package kvmppc import ( "context" + "encoding/json" "net/http" "strconv" @@ -42,13 +43,18 @@ type CreateBlankRequest struct { // Slice of structs with net interface description // Required: false - Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` + Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // Text description of this VM // Required: false Description string `url:"desc,omitempty" json:"desc,omitempty"` } +type wrapperCreateBlankRequest struct { + CreateBlankRequest + Interfaces []string `url:"interfaces,omitempty"` +} + // CreateBlank creates KVM PowerPC VM from scratch func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { err := validators.ValidateRequest(req) @@ -58,9 +64,25 @@ func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64 } } + 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)) + } + + reqWrapped := wrapperCreateBlankRequest{ + CreateBlankRequest: req, + Interfaces: interfaces, + } + 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 { return 0, err } diff --git a/pkg/cloudapi/kvmx86/create.go b/pkg/cloudapi/kvmx86/create.go index ccb69c7..8d5bc02 100644 --- a/pkg/cloudapi/kvmx86/create.go +++ b/pkg/cloudapi/kvmx86/create.go @@ -2,6 +2,7 @@ package kvmx86 import ( "context" + "encoding/json" "net/http" "strconv" @@ -64,7 +65,7 @@ type CreateRequest struct { // Slice of structs with net interface description. // Required: false - Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` + Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // Input data for cloud-init facility // Required: false @@ -87,6 +88,11 @@ type CreateRequest struct { IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"` } +type wrapperCreateRequest struct { + CreateRequest + Interfaces []string `url:"interfaces,omitempty"` +} + // Create creates KVM x86 VM based on specified OS image func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) { err := validators.ValidateRequest(req) @@ -96,9 +102,25 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) { } } + 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)) + } + + reqWrapped := wrapperCreateRequest{ + CreateRequest: req, + Interfaces: interfaces, + } + 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 { return 0, err } diff --git a/pkg/cloudapi/kvmx86/create_blank.go b/pkg/cloudapi/kvmx86/create_blank.go index 5f2cd69..e7c92b6 100644 --- a/pkg/cloudapi/kvmx86/create_blank.go +++ b/pkg/cloudapi/kvmx86/create_blank.go @@ -2,6 +2,7 @@ package kvmx86 import ( "context" + "encoding/json" "net/http" "strconv" @@ -42,13 +43,18 @@ type CreateBlankRequest struct { // Slice of structs with net interface description. // Required: false - Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` + Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // Text description of this VM // Required: false Description string `url:"desc,omitempty" json:"desc,omitempty"` } +type wrapperCreateBlankRequest struct { + CreateBlankRequest + Interfaces []string `url:"interfaces,omitempty"` +} + // CreateBlank creates KVM x86 VM from scratch func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { err := validators.ValidateRequest(req) @@ -58,9 +64,25 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64 } } + 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)) + } + + reqWrapped := wrapperCreateBlankRequest{ + CreateBlankRequest: req, + Interfaces: interfaces, + } + 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 { return 0, err } diff --git a/pkg/cloudbroker/kvmppc/create.go b/pkg/cloudbroker/kvmppc/create.go index ab31cd3..bdd2bcc 100644 --- a/pkg/cloudbroker/kvmppc/create.go +++ b/pkg/cloudbroker/kvmppc/create.go @@ -2,6 +2,7 @@ package kvmppc import ( "context" + "encoding/json" "net/http" "strconv" @@ -64,7 +65,7 @@ type CreateRequest struct { // Slice of structs with net interface description. // Required: false - Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` + Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // Input data for cloud-init facility // Required: false @@ -87,6 +88,11 @@ type CreateRequest struct { 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 func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) { err := validators.ValidateRequest(req) @@ -96,9 +102,25 @@ func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) { } } + 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)) + } + + reqWrapped := wrapperCreateRequest{ + CreateRequest: req, + Interfaces: interfaces, + } + 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 { return 0, err } diff --git a/pkg/cloudbroker/kvmppc/create_blank.go b/pkg/cloudbroker/kvmppc/create_blank.go index 851d9a7..352ee2a 100644 --- a/pkg/cloudbroker/kvmppc/create_blank.go +++ b/pkg/cloudbroker/kvmppc/create_blank.go @@ -2,6 +2,7 @@ package kvmppc import ( "context" + "encoding/json" "net/http" "strconv" @@ -42,13 +43,18 @@ type CreateBlankRequest struct { // Slice of structs with net interface description. // Required: false - Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` + Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // Text description of this VM // Required: false Description string `url:"desc,omitempty" json:"desc,omitempty"` } +type wrapperCreateBlankRequest struct { + CreateBlankRequest + Interfaces []string `url:"interfaces,omitempty"` +} + // CreateBlank creates KVM PowerPC VM from scratch func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { err := validators.ValidateRequest(req) @@ -58,9 +64,25 @@ func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64 } } + 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)) + } + + reqWrapped := wrapperCreateBlankRequest{ + CreateBlankRequest: req, + Interfaces: interfaces, + } + 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 { return 0, err } diff --git a/pkg/cloudbroker/kvmx86/create.go b/pkg/cloudbroker/kvmx86/create.go index 42c0cb6..e5be33e 100644 --- a/pkg/cloudbroker/kvmx86/create.go +++ b/pkg/cloudbroker/kvmx86/create.go @@ -2,6 +2,7 @@ package kvmx86 import ( "context" + "encoding/json" "net/http" "strconv" @@ -64,7 +65,7 @@ type CreateRequest struct { // Slice of structs with net interface description. // Required: false - Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` + Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // Input data for cloud-init facility // Required: false @@ -99,6 +100,11 @@ type CreateRequest struct { 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 func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) { err := validators.ValidateRequest(req) @@ -108,9 +114,25 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) { } } + 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)) + } + + reqWrapped := wrapperCreateRequest{ + CreateRequest: req, + Interfaces: interfaces, + } + 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 { return 0, err } diff --git a/pkg/cloudbroker/kvmx86/create_blank.go b/pkg/cloudbroker/kvmx86/create_blank.go index 7016686..52e808e 100644 --- a/pkg/cloudbroker/kvmx86/create_blank.go +++ b/pkg/cloudbroker/kvmx86/create_blank.go @@ -2,6 +2,7 @@ package kvmx86 import ( "context" + "encoding/json" "net/http" "strconv" @@ -42,13 +43,18 @@ type CreateBlankRequest struct { // Slice of structs with net interface description. // Required: false - Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` + Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"` // Text description of this VM // Required: false Description string `url:"desc,omitempty" json:"desc,omitempty"` } +type wrapperCreateBlankRequest struct { + CreateBlankRequest + Interfaces []string `url:"interfaces,omitempty"` +} + // CreateBlank creates KVM x86 VM from scratch func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) { err := validators.ValidateRequest(req) @@ -58,9 +64,25 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64 } } + 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)) + } + + reqWrapped := wrapperCreateBlankRequest{ + CreateBlankRequest: req, + Interfaces: interfaces, + } + 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 { return 0, err }