Files
decort-golang-sdk/pkg/cloudbroker/sep/create.go

59 lines
1.3 KiB
Go
Raw Normal View History

2022-12-22 17:56:47 +03:00
package sep
import (
"context"
"net/http"
"strconv"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-12-22 17:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// CreateRequest struct to create SEP object
2022-12-22 17:56:47 +03:00
type CreateRequest struct {
// Grid ID
// Required: true
2023-03-24 17:09:30 +03:00
GID uint64 `url:"gid" json:"gid" validate:"required"`
2022-12-22 17:56:47 +03:00
// SEP name
// Required: true
2023-03-24 17:09:30 +03:00
Name string `url:"name" json:"name" validate:"required"`
2022-12-22 17:56:47 +03:00
// Type of storage
// Required: true
2025-12-29 14:16:28 +03:00
SEPType string `url:"sep_type" json:"sep_type" validate:"required,sepType"`
2022-12-22 17:56:47 +03:00
2024-04-16 14:26:06 +03:00
// SEP config
// Required: true
Config string `url:"config" json:"config" validate:"required"`
2022-12-22 17:56:47 +03:00
// Description
// Required: false
2023-03-01 19:05:53 +03:00
Description string `url:"description,omitempty" json:"description,omitempty"`
2022-12-22 17:56:47 +03:00
// Enable SEP after creation
// Required: false
2023-03-01 19:05:53 +03:00
Enable bool `url:"enable,omitempty" json:"enable,omitempty"`
2022-12-22 17:56:47 +03:00
}
// Create creates SEP object
func (s SEP) Create(ctx context.Context, req CreateRequest) (uint64, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-12-22 17:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return 0, validators.ValidationErrors(validators.GetErrors(err))
2022-12-22 17:56:47 +03:00
}
url := "/cloudbroker/sep/create"
res, err := s.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
}