This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -7,18 +7,29 @@ import (
"strconv"
)
// Request struct for BasicService
type CreateRequest struct {
Name string `url:"name"`
RGID uint64 `url:"rgId"`
// Name of the service
// Required: true
Name string `url:"name"`
// ID of the Resource Group where this service will be placed
// Required: true
RGID uint64 `url:"rgId"`
// Name of the user to deploy SSH key for. Pass empty string if no SSH key deployment is required
// Required: false
SSHUser string `url:"sshUser,omitempty"`
SSHKey string `url:"sshKey,omitempty"`
// SSH key to deploy for the specified user. Same key will be deployed to all computes of the service
// Required: false
SSHKey string `url:"sshKey,omitempty"`
}
func (bsrq CreateRequest) Validate() error {
func (bsrq CreateRequest) validate() error {
if bsrq.Name == "" {
return errors.New("field Name can not be empty")
}
if bsrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
@@ -26,16 +37,24 @@ func (bsrq CreateRequest) Validate() error {
return nil
}
// Create creates blank BasicService instance
func (b BService) Create(ctx context.Context, req CreateRequest) (uint64, error) {
if err := req.Validate(); err != nil {
err := req.validate()
if err != nil {
return 0, err
}
url := "/cloudapi/bservice/create"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
return strconv.ParseUint(string(res), 10, 64)
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}