Add new resources, extend fields in config
This commit is contained in:
70
pkg/cloudbroker/kvmppc/create.go
Normal file
70
pkg/cloudbroker/kvmppc/create.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package kvmppc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
Name string `url:"name"`
|
||||
CPU uint64 `url:"cpu"`
|
||||
RAM uint64 `url:"ram"`
|
||||
ImageID uint64 `url:"imageId"`
|
||||
BootDisk uint64 `url:"bootDisk,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
Pool string `url:"pool,omitempty"`
|
||||
NetType string `url:"netType,omitempty"`
|
||||
NetID uint64 `url:"netId,omitempty"`
|
||||
IPAddr string `url:"ipAddr,omitempty"`
|
||||
UserData string `url:"userdata,omitempty"`
|
||||
Desc string `url:"desc,omitempty"`
|
||||
Start bool `url:"start,omitempty"`
|
||||
StackID uint64 `url:"stackId,omitempty"`
|
||||
IS string `url:"IS,omitempty"`
|
||||
IpaType string `url:"ipaType,omitempty"`
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateRequest) Validate() error {
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID must be set")
|
||||
}
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if krq.CPU == 0 {
|
||||
return errors.New("validation-error: field CPU must be set")
|
||||
}
|
||||
if krq.RAM == 0 {
|
||||
return errors.New("validation-error: field RAM must be set")
|
||||
}
|
||||
if krq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/kvmppc/create"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
70
pkg/cloudbroker/kvmppc/create_blank.go
Normal file
70
pkg/cloudbroker/kvmppc/create_blank.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package kvmppc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CreateBlankRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
Name string `url:"name"`
|
||||
CPU uint64 `url:"cpu"`
|
||||
RAM uint64 `url:"ram"`
|
||||
BootDisk uint64 `url:"bootDisk"`
|
||||
SepID uint64 `url:"sepId"`
|
||||
Pool string `url:"pool"`
|
||||
NetType string `url:"netType,omitempty"`
|
||||
NetID uint64 `url:"netId,omitempty"`
|
||||
IPAddr string `url:"ipAddr,omitempty"`
|
||||
Desc string `url:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateBlankRequest) Validate() error {
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID must be set")
|
||||
}
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if krq.CPU == 0 {
|
||||
return errors.New("validation-error: field CPU must be set")
|
||||
}
|
||||
if krq.RAM == 0 {
|
||||
return errors.New("validation-error: field RAM must be set")
|
||||
}
|
||||
if krq.BootDisk == 0 {
|
||||
return errors.New("validation-error: field BootDisk must be set")
|
||||
}
|
||||
if krq.SepID == 0 {
|
||||
return errors.New("validation-error: field SepID must be set")
|
||||
}
|
||||
if krq.Pool == "" {
|
||||
return errors.New("validation-error: field Pool must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/kvmppc/createBlank"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
13
pkg/cloudbroker/kvmppc/kvmppc.go
Normal file
13
pkg/cloudbroker/kvmppc/kvmppc.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package kvmppc
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
|
||||
type KVMPPC struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *KVMPPC {
|
||||
return &KVMPPC{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
73
pkg/cloudbroker/kvmppc/mass_create.go
Normal file
73
pkg/cloudbroker/kvmppc/mass_create.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package kvmppc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type MassCreateRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
Name string `url:"name"`
|
||||
Count uint64 `url:"count"`
|
||||
CPU uint64 `url:"cpu"`
|
||||
RAM uint64 `url:"ram"`
|
||||
ImageID uint64 `url:"imageId"`
|
||||
BootDisk uint64 `url:"bootDisk,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
Pool string `url:"pool,omitempty"`
|
||||
NetType string `url:"netType,omitempty"`
|
||||
NetID uint64 `url:"netId,omitempty"`
|
||||
IPAddr string `url:"ipAddr,omitempty"`
|
||||
UserData string `url:"userdata,omitempty"`
|
||||
Desc string `url:"desc,omitempty"`
|
||||
Start bool `url:"start,omitempty"`
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (krq MassCreateRequest) Validate() error {
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID must be set")
|
||||
}
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if krq.Count == 0 {
|
||||
return errors.New("validation-error: field Count must be set")
|
||||
}
|
||||
if krq.CPU == 0 {
|
||||
return errors.New("validation-error: field CPU must be set")
|
||||
}
|
||||
if krq.RAM == 0 {
|
||||
return errors.New("validation-error: field RAM must be set")
|
||||
}
|
||||
if krq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k KVMPPC) MassCreate(ctx context.Context, req MassCreateRequest) ([]uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/kvmppc/massCreate"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
computes := make([]uint64, 0)
|
||||
|
||||
err = json.Unmarshal(res, &computes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return computes, nil
|
||||
}
|
||||
Reference in New Issue
Block a user