Merge 'dev' into 'main'
This commit is contained in:
@@ -4,18 +4,20 @@ linters:
|
||||
- decorder
|
||||
- dogsled
|
||||
- errorlint
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
- gocognit
|
||||
- exhaustive
|
||||
#- gocognit
|
||||
- goconst
|
||||
- gocyclo
|
||||
#- gocyclo
|
||||
- gosec
|
||||
- ifshort
|
||||
- makezero
|
||||
- nestif
|
||||
#- nestif
|
||||
- nilerr
|
||||
- prealloc
|
||||
- unconvert
|
||||
- unparam
|
||||
- noctx
|
||||
|
||||
issues:
|
||||
max-same-issues: 0
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/account"
|
||||
)
|
||||
|
||||
func (dc *Client) Account() *account.Account {
|
||||
return account.New(dc)
|
||||
}
|
||||
17
client.go
17
client.go
@@ -7,13 +7,16 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudbroker"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
"github.com/rudecs/decort-sdk/config"
|
||||
"github.com/rudecs/decort-sdk/internal/client"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
decortUrl string
|
||||
decortURL string
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
@@ -23,11 +26,19 @@ func New(cfg config.Config) *Client {
|
||||
}
|
||||
|
||||
return &Client{
|
||||
decortUrl: cfg.DecortURL,
|
||||
decortURL: cfg.DecortURL,
|
||||
client: client.NewHttpClient(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (dc *Client) CloudApi() *cloudapi.CloudApi {
|
||||
return cloudapi.New(dc)
|
||||
}
|
||||
|
||||
func (dc *Client) CloudBroker() *cloudbroker.CloudBroker {
|
||||
return cloudbroker.New(dc)
|
||||
}
|
||||
|
||||
func (dc *Client) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||
values, err := query.Values(params)
|
||||
if err != nil {
|
||||
@@ -35,7 +46,7 @@ func (dc *Client) DecortApiCall(ctx context.Context, method, url string, params
|
||||
}
|
||||
|
||||
body := strings.NewReader(values.Encode())
|
||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortUrl+"/restmachine"+url, body)
|
||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/compute"
|
||||
)
|
||||
|
||||
func (dc *Client) Compute() *compute.Compute {
|
||||
return compute.New(dc)
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/computeci"
|
||||
)
|
||||
|
||||
func (dc *Client) ComputeCI() *computeci.ComputeCI {
|
||||
return computeci.New(dc)
|
||||
}
|
||||
9
disks.go
9
disks.go
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/disks"
|
||||
)
|
||||
|
||||
func (dc *Client) Disks() *disks.Disks {
|
||||
return disks.New(dc)
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/extnet"
|
||||
)
|
||||
|
||||
func (dc *Client) Extnet() *extnet.Extnet {
|
||||
return extnet.New(dc)
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/flipgroup"
|
||||
)
|
||||
|
||||
func (dc *Client) FlipGroup() *flipgroup.FlipGroup {
|
||||
return flipgroup.New(dc)
|
||||
}
|
||||
9
image.go
9
image.go
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/image"
|
||||
)
|
||||
|
||||
func (dc *Client) Image() *image.Image {
|
||||
return image.New(dc)
|
||||
}
|
||||
@@ -10,15 +10,20 @@ import (
|
||||
|
||||
func NewHttpClient(cfg config.Config) *http.Client {
|
||||
|
||||
transCfg := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: cfg.SSLSkipVerify}}
|
||||
transCfg := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
//nolint:gosec
|
||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||
},
|
||||
}
|
||||
|
||||
return &http.Client{
|
||||
Transport: &transport{
|
||||
base: transCfg,
|
||||
retries: cfg.Retries,
|
||||
clientId: cfg.AppID,
|
||||
clientID: cfg.AppID,
|
||||
clientSecret: cfg.AppSecret,
|
||||
ssoUrl: cfg.SSOURL,
|
||||
SSOURL: cfg.SSOURL,
|
||||
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
|
||||
|
||||
@@ -11,24 +11,24 @@ import (
|
||||
type transport struct {
|
||||
base http.RoundTripper
|
||||
retries uint64
|
||||
clientId string
|
||||
clientID string
|
||||
clientSecret string
|
||||
token string
|
||||
ssoUrl string
|
||||
SSOURL string
|
||||
expiryTime time.Time
|
||||
}
|
||||
|
||||
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if t.token == "" || time.Now().After(t.expiryTime) {
|
||||
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientId, t.clientSecret)
|
||||
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientID, t.clientSecret)
|
||||
bodyReader := strings.NewReader(body)
|
||||
|
||||
req, _ := http.NewRequest("POST", t.ssoUrl+"/v1/oauth/access_token", bodyReader)
|
||||
req, _ := http.NewRequestWithContext(req.Context(), "POST", t.SSOURL+"/v1/oauth/access_token", bodyReader)
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
resp, err := t.base.RoundTrip(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get token: %v", err)
|
||||
return nil, fmt.Errorf("cannot get token: %w", err)
|
||||
}
|
||||
|
||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||
@@ -63,5 +63,5 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
//logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries)
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
return nil, fmt.Errorf("could not execute request: %v", err)
|
||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||
}
|
||||
|
||||
9
k8ci.go
9
k8ci.go
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/k8ci"
|
||||
)
|
||||
|
||||
func (dc *Client) K8CI() *k8ci.K8CI {
|
||||
return k8ci.New(dc)
|
||||
}
|
||||
9
k8s.go
9
k8s.go
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/k8s"
|
||||
)
|
||||
|
||||
func (dc *Client) K8S() *k8s.K8S {
|
||||
return k8s.New(dc)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmppc"
|
||||
|
||||
func (dc *Client) KVMPPC() *kvmppc.KVMPPC {
|
||||
return kvmppc.New(dc)
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86"
|
||||
)
|
||||
|
||||
func (dc *Client) KVMX86() *kvmx86.KVMX86 {
|
||||
return kvmx86.New(dc)
|
||||
}
|
||||
7
lb.go
7
lb.go
@@ -1,7 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/lb"
|
||||
|
||||
func (dc *Client) LB() *lb.LB {
|
||||
return lb.New(dc)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package decortsdk
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/locations"
|
||||
|
||||
func (dc *Client) Locations() *locations.Locations {
|
||||
return locations.New(dc)
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package opts
|
||||
|
||||
type DecortOpts struct {
|
||||
Type string
|
||||
Value string
|
||||
}
|
||||
26
opts/opts.go
26
opts/opts.go
@@ -1,26 +0,0 @@
|
||||
package opts
|
||||
|
||||
import "github.com/rudecs/decort-sdk/typed"
|
||||
|
||||
type Opts struct {
|
||||
IsAdmin bool
|
||||
AdminValue string
|
||||
}
|
||||
|
||||
func New(options []DecortOpts) *Opts {
|
||||
if len(options) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
option := &Opts{}
|
||||
|
||||
for _, v := range options {
|
||||
if v.Type == typed.TypeAdmin {
|
||||
option.IsAdmin = true
|
||||
option.AdminValue = v.Value
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return option
|
||||
}
|
||||
9
pkg/cloudapi/account.go
Normal file
9
pkg/cloudapi/account.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/account"
|
||||
)
|
||||
|
||||
func (ca *CloudApi) Account() *account.Account {
|
||||
return account.New(ca.client)
|
||||
}
|
||||
@@ -3,26 +3,25 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AddUserRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
UserId string `url:"userId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
UserID string `url:"userId"`
|
||||
AccessType string `url:"accesstype"`
|
||||
}
|
||||
|
||||
func (arq AddUserRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.UserId == "" {
|
||||
return errors.New("validation-error: field UserId can not be empty")
|
||||
if arq.UserID == "" {
|
||||
return errors.New("validation-error: field UserID can not be empty")
|
||||
}
|
||||
|
||||
if arq.AccessType == "" {
|
||||
@@ -37,24 +36,15 @@ func (arq AddUserRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) AddUser(ctx context.Context, req AddUserRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/addUser"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/addUser"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -4,48 +4,37 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type AuditsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq AuditsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AccountAuditsList, error) {
|
||||
func (a Account) Audits(ctx context.Context, req AuditsRequest) (AccountAuditsList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/audits"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/audits"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
auditsRaw, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
auditsRaw, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
audits := AccountAuditsList{}
|
||||
|
||||
err = json.Unmarshal([]byte(auditsRaw), &audits)
|
||||
err = json.Unmarshal(auditsRaw, &audits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,23 +3,21 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
Name string `url:"name"`
|
||||
Username string `url:"username"`
|
||||
EmailAddress string `url:"emailaddress,omitempty"`
|
||||
MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"`
|
||||
MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"`
|
||||
MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"`
|
||||
MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"`
|
||||
MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"`
|
||||
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
|
||||
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
|
||||
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
|
||||
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
|
||||
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
|
||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
|
||||
GpuUnits uint `url:"gpu_units,omitempty"`
|
||||
GPUUnits uint64 `url:"gpu_units,omitempty"`
|
||||
}
|
||||
|
||||
func (arq CreateRequest) Validate() error {
|
||||
@@ -34,24 +32,15 @@ func (arq CreateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/account/create"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudbroker/account/create"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -3,50 +3,34 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DeleteRequest) Validate() error {
|
||||
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId must be set")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/delete"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/delete"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -3,48 +3,37 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteUserRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
UserId string `url:"userId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
UserID string `url:"userId"`
|
||||
RecursiveDelete bool `url:"recursivedelete,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DeleteUserRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.UserId == "" {
|
||||
return errors.New("validation-error: field UserId can not be empty")
|
||||
if arq.UserID == "" {
|
||||
return errors.New("validation-error: field UserID can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/deleteUser"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/deleteUser"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,41 +3,31 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DisabelEnableRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq DisabelEnableRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/disable"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/disable"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -50,23 +40,15 @@ func (a Account) Disable(ctx context.Context, req DisabelEnableRequest, options
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/enable"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/enable"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -4,41 +4,30 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq GetRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*AccountWithResources, error) {
|
||||
func (a Account) Get(ctx context.Context, req GetRequest) (*AccountWithResources, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/get"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/get"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,41 +4,30 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetConsumedAccountUnitsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq GetConsumedAccountUnitsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
|
||||
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest) (*ResourceLimits, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/getConsumedAccountUnits"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/getConsumedAccountUnits"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,21 +3,20 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetConsumedCloudUnitsByTypeRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
CUType string `url:"cutype"`
|
||||
}
|
||||
|
||||
func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.CUType == "" {
|
||||
@@ -32,24 +31,15 @@ func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest, options ...opts.DecortOpts) (float64, error) {
|
||||
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest) (float64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/account/getConsumedCloudUnitsByType"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/getConsumedCloudUnitsByType"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -3,20 +3,18 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetConsumtionRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Start uint64 `url:"start"`
|
||||
End uint64 `url:"end"`
|
||||
}
|
||||
|
||||
func (arq GetConsumtionRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.Start == 0 {
|
||||
@@ -30,24 +28,15 @@ func (arq GetConsumtionRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
|
||||
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/account/getConsumtion"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/getConsumtion"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -56,7 +45,7 @@ func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest, op
|
||||
|
||||
}
|
||||
|
||||
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
|
||||
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -65,15 +54,8 @@ func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest,
|
||||
url := "/account/getConsumtion"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.GET, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -4,41 +4,30 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetReservedAccountUnitsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq GetReservedAccountUnitsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
|
||||
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest) (*ResourceLimits, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/getReservedAccountUnits"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/getReservedAccountUnits"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
@@ -13,19 +11,10 @@ type ListRequest struct {
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (a Account) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
|
||||
url := "/account/list"
|
||||
prefix := "/cloudapi"
|
||||
func (a Account) List(ctx context.Context, req ListRequest) (AccountCloudApiList, error) {
|
||||
url := "/cloudapi/account/list"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,41 +4,30 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListComputesRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListComputesRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (AccountComputesList, error) {
|
||||
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (AccountComputesList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listComputes"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/listComputes"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListDeletedRequest struct {
|
||||
@@ -13,19 +11,10 @@ type ListDeletedRequest struct {
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
|
||||
url := "/account/listDeleted"
|
||||
prefix := "/cloudapi"
|
||||
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (AccountCloudApiList, error) {
|
||||
url := "/cloudapi/account/listDeleted"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,41 +4,30 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListDisksRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListDisksRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest, options ...opts.DecortOpts) (AccountDisksList, error) {
|
||||
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (AccountDisksList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listDisks"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/listDisks"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,41 +4,30 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListFlipGroupsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListFlipGroupsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest, options ...opts.DecortOpts) (AccountFlipGroupsList, error) {
|
||||
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest) (AccountFlipGroupsList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listFlipGroups"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/listFlipGroups"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,41 +4,30 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListRGRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListRGRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListRG(ctx context.Context, req ListRGRequest, options ...opts.DecortOpts) (AccountRGList, error) {
|
||||
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (AccountRGList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listRG"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/listRG"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,42 +4,31 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListTemplatesRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
IncludeDeleted bool `url:"includedeleted"`
|
||||
}
|
||||
|
||||
func (arq ListTemplatesRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest, options ...opts.DecortOpts) (AccountTemplatesList, error) {
|
||||
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (AccountTemplatesList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listTemplates"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/listTemplates"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,52 +4,41 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListVinsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
type ListVINSRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListVinsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
func (arq ListVINSRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListVins(ctx context.Context, req ListVinsRequest, options ...opts.DecortOpts) (AccountVinsList, error) {
|
||||
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (AccountVINSList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listVins"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/listVins"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountVinsList := AccountVinsList{}
|
||||
accountVINSList := AccountVINSList{}
|
||||
|
||||
err = json.Unmarshal(res, &accountVinsList)
|
||||
err = json.Unmarshal(res, &accountVINSList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountVinsList, nil
|
||||
return accountVINSList, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package account
|
||||
|
||||
type AccountAclRecord struct {
|
||||
type AccountACLRecord struct {
|
||||
IsExplicit bool `json:"explicit"`
|
||||
GUID string `json:"guid"`
|
||||
Rights string `json:"right"`
|
||||
@@ -16,55 +16,55 @@ type ResourceLimits struct {
|
||||
CUI float64 `json:"CU_I"`
|
||||
CUM float64 `json:"CU_M"`
|
||||
CUNP float64 `json:"CU_NP"`
|
||||
GpuUnits float64 `json:"gpu_units"`
|
||||
GPUUnits float64 `json:"gpu_units"`
|
||||
}
|
||||
|
||||
type AccountRecord struct {
|
||||
DCLocation string `json:"DCLocation"`
|
||||
CKey string `jspn:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
Acl []AccountAclRecord `json:"acl"`
|
||||
ACL []AccountACLRecord `json:"acl"`
|
||||
Company string `json:"company"`
|
||||
CompanyUrl string `json:"companyurl"`
|
||||
CompanyURL string `json:"companyurl"`
|
||||
CreatedBy string `jspn:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeactiovationTime float64 `json:"deactivationTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
DisplayName string `json:"displayname"`
|
||||
GUID int `json:"guid"`
|
||||
ID int `json:"id"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
||||
ServiceAccount bool `json:"serviceAccount"`
|
||||
Status string `json:"status"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
Version int `json:"version"`
|
||||
Vins []int `json:"vins"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
Version uint64 `json:"version"`
|
||||
VINS []uint64 `json:"vins"`
|
||||
}
|
||||
|
||||
type AccountList []AccountRecord
|
||||
|
||||
type AccountCloudApi struct {
|
||||
Acl []AccountAclRecord `json:"acl"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ID int `json:"id"`
|
||||
ACL []AccountACLRecord `json:"acl"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountCloudApiList []AccountCloudApi
|
||||
|
||||
type Resource struct {
|
||||
CPU int `json:"cpu"`
|
||||
Disksize int `json:"disksize"`
|
||||
Extips int `json:"extips"`
|
||||
Exttraffic int `json:"exttraffic"`
|
||||
GPU int `json:"gpu"`
|
||||
RAM int `json:"ram"`
|
||||
CPU int64 `json:"cpu"`
|
||||
DiskSize int64 `json:"disksize"`
|
||||
ExtIPs int64 `json:"extips"`
|
||||
ExtTraffic int64 `json:"exttraffic"`
|
||||
GPU int64 `json:"gpu"`
|
||||
RAM int64 `json:"ram"`
|
||||
}
|
||||
|
||||
type Resources struct {
|
||||
@@ -73,13 +73,13 @@ type Resources struct {
|
||||
}
|
||||
|
||||
type Computes struct {
|
||||
Started int `json:"started"`
|
||||
Stopped int `json:"stopped"`
|
||||
Started uint64 `json:"started"`
|
||||
Stopped uint64 `json:"stopped"`
|
||||
}
|
||||
|
||||
type Machines struct {
|
||||
Running int `json:"running"`
|
||||
Halted int `json:"halted"`
|
||||
Running uint64 `json:"running"`
|
||||
Halted uint64 `json:"halted"`
|
||||
}
|
||||
|
||||
type AccountWithResources struct {
|
||||
@@ -87,71 +87,71 @@ type AccountWithResources struct {
|
||||
Resources Resources `json:"Resources"`
|
||||
Computes Computes `json:"computes"`
|
||||
Machines Machines `json:"machines"`
|
||||
Vinses int `json:"vinses"`
|
||||
VINSes uint64 `json:"vinses"`
|
||||
}
|
||||
|
||||
type AccountCompute struct {
|
||||
AccountId int `json:"accountId"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
CPUs int `json:"cpus"`
|
||||
CPUs uint64 `json:"cpus"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ComputeId int `json:"id"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
ComputeID uint64 `json:"id"`
|
||||
ComputeName string `json:"name"`
|
||||
RAM int `json:"ram"`
|
||||
RAM uint64 `json:"ram"`
|
||||
Registered bool `json:"registered"`
|
||||
RGId int `json:"rgId"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
TotalDisksSize int `json:"totalDisksSize"`
|
||||
TotalDisksSize uint64 `json:"totalDisksSize"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
VinsConnected int `json:"vinsConnected"`
|
||||
VINSConnected uint64 `json:"vinsConnected"`
|
||||
}
|
||||
|
||||
type AccountComputesList []AccountCompute
|
||||
|
||||
type AccountDisk struct {
|
||||
ID int `json:"id"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Pool string `json:"pool"`
|
||||
SepId int `json:"sepId"`
|
||||
SizeMax int `json:"sizeMax"`
|
||||
SepID uint64 `json:"sepId"`
|
||||
SizeMax uint64 `json:"sizeMax"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type AccountDisksList []AccountDisk
|
||||
|
||||
type AccountVin struct {
|
||||
AccountId int `json:"accountId"`
|
||||
type AccountVIN struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Computes int `json:"computes"`
|
||||
Computes uint64 `json:"computes"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
ExternalIP string `json:"externalIP"`
|
||||
ID int `json:"id"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Network string `json:"network"`
|
||||
PriVnfDevId int `json:"priVnfDevId"`
|
||||
RGId int `json:"rgId"`
|
||||
PriVnfDevID uint64 `json:"priVnfDevId"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountVinsList []AccountVin
|
||||
type AccountVINSList []AccountVIN
|
||||
|
||||
type AccountAudit struct {
|
||||
Call string `json:"call"`
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
StatusCode int `json:"statuscode"`
|
||||
StatusCode uint64 `json:"statuscode"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
@@ -159,8 +159,8 @@ type AccountAudit struct {
|
||||
type AccountAuditsList []AccountAudit
|
||||
|
||||
type AccountRGComputes struct {
|
||||
Started int `json:"Started"`
|
||||
Stopped int `json:"Stopped"`
|
||||
Started uint64 `json:"Started"`
|
||||
Stopped uint64 `json:"Stopped"`
|
||||
}
|
||||
|
||||
type AccountRGResources struct {
|
||||
@@ -173,28 +173,28 @@ type AccountRG struct {
|
||||
Computes AccountRGComputes `json:"Computes"`
|
||||
Resources AccountRGResources `json:"Resources"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
RGID int `json:"id"`
|
||||
Milestones int `json:"milestones"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
RGID uint64 `json:"id"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
RGName string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
Vinses int `json:"vinses"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
VINSes uint64 `json:"vinses"`
|
||||
}
|
||||
|
||||
type AccountRGList []AccountRG
|
||||
|
||||
type AccountTemplate struct {
|
||||
UNCPath string `json:"UNCPath"`
|
||||
AccountId int `json:"accountId"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
Description string `json:"desc"`
|
||||
ID int `json:"id"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Public bool `json:"public"`
|
||||
Size int `json:"size"`
|
||||
Size uint64 `json:"size"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
Username string `json:"username"`
|
||||
@@ -203,27 +203,27 @@ type AccountTemplate struct {
|
||||
type AccountTemplatesList []AccountTemplate
|
||||
|
||||
type AccountFlipGroup struct {
|
||||
AccountId int `json:"accountId"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
ClientType string `json:"clientType"`
|
||||
ConnType string `json:"connType"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DefaultGW string `json:"defaultGW"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Description string `json:"desc"`
|
||||
GID int `json:"gid"`
|
||||
GUID int `json:"guid"`
|
||||
ID int `json:"id"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
IP string `json:"ip"`
|
||||
Milestones int `json:"milestones"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
NetID int `json:"netId"`
|
||||
NetID uint64 `json:"netId"`
|
||||
NetType string `json:"netType"`
|
||||
NetMask int `json:"netmask"`
|
||||
NetMask uint64 `json:"netmask"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountFlipGroupsList []AccountFlipGroup
|
||||
|
||||
@@ -3,42 +3,31 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type RestoreRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq RestoreRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/restore"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/restore"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,50 +3,39 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type UpdateRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Name string `url:"name,omitempty"`
|
||||
MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"`
|
||||
MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"`
|
||||
MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"`
|
||||
MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"`
|
||||
MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"`
|
||||
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
|
||||
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
|
||||
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
|
||||
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
|
||||
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
|
||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
|
||||
GpuUnits uint `url:"gpu_units,omitempty"`
|
||||
GPUUnits uint64 `url:"gpu_units,omitempty"`
|
||||
}
|
||||
|
||||
func (arq UpdateRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/update"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/update"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,26 +3,25 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type UpdateUserRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
UserId string `url:"userId"`
|
||||
AccountID uint64 `url:"accountId"`
|
||||
UserID string `url:"userId"`
|
||||
AccessType string `url:"accesstype"`
|
||||
}
|
||||
|
||||
func (arq UpdateUserRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.UserId == "" {
|
||||
return errors.New("validation-error: field UserId can not be empty")
|
||||
if arq.UserID == "" {
|
||||
return errors.New("validation-error: field UserID can not be empty")
|
||||
}
|
||||
|
||||
if arq.AccessType == "" {
|
||||
@@ -37,24 +36,15 @@ func (arq UpdateUserRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/updateUser"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/account/updateUser"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
@@ -28,13 +26,13 @@ func (bsrq CreateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
func (b BService) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/create"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
@@ -22,13 +20,13 @@ func (bsrq DeleteRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/delete"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DisableRequest struct {
|
||||
@@ -21,13 +19,13 @@ func (bsrq DisableRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/delete"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type EnableRequest struct {
|
||||
@@ -21,13 +19,13 @@ func (bsrq EnableRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/enable"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
@@ -21,13 +19,13 @@ func (bsrq GetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*BasicService, error) {
|
||||
func (b BService) Get(ctx context.Context, req GetRequest) (*BasicService, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/get"
|
||||
bsRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
bsRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupAddRequest struct {
|
||||
@@ -20,7 +18,7 @@ type GroupAddRequest struct {
|
||||
Driver string `url:"driver"`
|
||||
Role string `url:"role,omitempty"`
|
||||
VINSes []uint64 `url:"vinses,omitempty"`
|
||||
Extnets []uint64 `url:"extnets,omitempty"`
|
||||
ExtNets []uint64 `url:"extnets,omitempty"`
|
||||
TimeoutStart uint64 `url:"timeoutStart"`
|
||||
}
|
||||
|
||||
@@ -60,13 +58,13 @@ func (bsrq GroupAddRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest) (uint64, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupAdd"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupComputeRemoveRequest struct {
|
||||
@@ -31,13 +29,13 @@ func (bsrq GroupComputeRemoveRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupComputeRemove"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GroupGetRequest struct {
|
||||
@@ -26,13 +24,13 @@ func (bsrq GroupGetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupGet(ctx context.Context, req GroupGetRequest, options ...opts.DecortOpts) (*Group, error) {
|
||||
func (b BService) GroupGet(ctx context.Context, req GroupGetRequest) (*Group, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupGet"
|
||||
groupRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
groupRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupParentAddRequest struct {
|
||||
@@ -31,13 +29,13 @@ func (bsrq GroupParentAddRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupParentAdd"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupParentRemoveRequest struct {
|
||||
@@ -31,13 +29,13 @@ func (bsrq GroupParentRemoveRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupParentRemove"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupRemoveRequest struct {
|
||||
@@ -26,13 +24,13 @@ func (bsrq GroupRemoveRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupRemove"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
|
||||
@@ -3,11 +3,10 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupResizeRequest struct {
|
||||
@@ -37,13 +36,13 @@ func (bsrq GroupResizeRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest) (uint64, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupResize"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupStartRequest struct {
|
||||
@@ -26,13 +24,13 @@ func (bsrq GroupStartRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupStart(ctx context.Context, req GroupStartRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) GroupStart(ctx context.Context, req GroupStartRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupStart"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupStopRequest struct {
|
||||
@@ -27,13 +25,13 @@ func (bsrq GroupStopRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupStop(ctx context.Context, req GroupStopRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) GroupStop(ctx context.Context, req GroupStopRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupStop"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupUpdateRequest struct {
|
||||
@@ -32,13 +30,13 @@ func (bsrq GroupUpdateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdate"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,19 +3,17 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupUpdateExtnetRequest struct {
|
||||
type GroupUpdateExtNetRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
Extnets []uint64 `url:"extnets,omitempty"`
|
||||
ExtNets []uint64 `url:"extnets,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq GroupUpdateExtnetRequest) Validate() error {
|
||||
func (bsrq GroupUpdateExtNetRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -27,13 +25,13 @@ func (bsrq GroupUpdateExtnetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupUpdateExtnet(ctx context.Context, req GroupUpdateExtnetRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) GroupUpdateExtNet(ctx context.Context, req GroupUpdateExtNetRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdateExtnet"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupUpdateVINSRequest struct {
|
||||
@@ -27,13 +25,13 @@ func (bsrq GroupUpdateVINSRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdateVins"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
@@ -15,9 +13,9 @@ type ListRequest struct {
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (b BService) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (BasicServiceList, error) {
|
||||
func (b BService) List(ctx context.Context, req ListRequest) (BasicServiceList, error) {
|
||||
url := "/cloudapi/bservice/list"
|
||||
bsListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
bsListRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -30,9 +28,9 @@ func (b BService) List(ctx context.Context, req ListRequest, options ...opts.Dec
|
||||
return bsList, nil
|
||||
}
|
||||
|
||||
func (b BService) ListDeleted(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (BasicServiceList, error) {
|
||||
func (b BService) ListDeleted(ctx context.Context, req ListRequest) (BasicServiceList, error) {
|
||||
url := "/cloudapi/bservice/listDeleted"
|
||||
bsListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
bsListRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ type Group struct {
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Disk uint64 `json:"disk"`
|
||||
Driver string `json:"driver"`
|
||||
Extnets []uint64 `json:"extnets"`
|
||||
ExtNets []uint64 `json:"extnets"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type RestoreRequest struct {
|
||||
@@ -21,13 +19,13 @@ func (bsrq RestoreRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/restore"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type SnapshotCreateRequest struct {
|
||||
@@ -26,13 +24,13 @@ func (bsrq SnapshotCreateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotCreate"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type SnapshotDeleteRequest struct {
|
||||
@@ -26,13 +24,13 @@ func (bsrq SnapshotDeleteRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotDelete"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SnapshotListRequest struct {
|
||||
@@ -21,13 +19,13 @@ func (bsrq SnapshotListRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest, options ...opts.DecortOpts) ([]Snapshot, error) {
|
||||
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) ([]Snapshot, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotList"
|
||||
snapshotListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
snapshotListRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type SnapshotRollbackRequest struct {
|
||||
@@ -26,13 +24,13 @@ func (bsrq SnapshotRollbackRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotRollback"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type StartRequest struct {
|
||||
@@ -21,13 +19,13 @@ func (bsrq StartRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Start(ctx context.Context, req StartRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/start"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package bservice
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type StopRequest struct {
|
||||
@@ -21,13 +19,13 @@ func (bsrq StopRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Stop(ctx context.Context, req StopRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (b BService) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/stop"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
15
pkg/cloudapi/cloudapi.go
Normal file
15
pkg/cloudapi/cloudapi.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
type CloudApi struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *CloudApi {
|
||||
return &CloudApi{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
9
pkg/cloudapi/compute.go
Normal file
9
pkg/cloudapi/compute.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/compute"
|
||||
)
|
||||
|
||||
func (ca *CloudApi) Compute() *compute.Compute {
|
||||
return compute.New(ca.client)
|
||||
}
|
||||
@@ -3,9 +3,7 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type AffinityGroupCheckStartRequest struct {
|
||||
@@ -24,23 +22,15 @@ func (crq AffinityGroupCheckStartRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest, options ...opts.DecortOpts) (string, error) {
|
||||
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/compute/affinityGroupCheckStart"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/affinityGroupCheckStart"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -3,41 +3,31 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityLabelRemoveRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq AffinityLabelRemoveRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityLabelRemove"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/affinityLabelRemove"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,20 +3,18 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityLabelSetRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
AffinityLabel string `url:"affinityLabel"`
|
||||
}
|
||||
|
||||
func (crq AffinityLabelSetRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
if crq.AffinityLabel == "" {
|
||||
return errors.New("validation-error: field AffinityLabel can not be empty")
|
||||
@@ -25,23 +23,15 @@ func (crq AffinityLabelSetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityLabelSet"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/affinityLabelSet"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -4,48 +4,38 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type AffinityRelationsRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
AffinityLabel string `url:"affinityLabel"`
|
||||
}
|
||||
|
||||
func (crq AffinityRelationsRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest, options ...opts.DecortOpts) (*AffinityRelations, error) {
|
||||
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*AffinityRelations, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityRelations"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/affinityRelations"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
relations := &AffinityRelations{}
|
||||
|
||||
err = json.Unmarshal([]byte(res), relations)
|
||||
err = json.Unmarshal(res, relations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,15 +3,14 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityRuleAddRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
Topology string `url:"topology"`
|
||||
Policy string `url:"policy"`
|
||||
Mode string `url:"mode"`
|
||||
@@ -20,8 +19,8 @@ type AffinityRuleAddRequest struct {
|
||||
}
|
||||
|
||||
func (crq AffinityRuleAddRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Topology == "" {
|
||||
return errors.New("validation-error: field Topology can not be empty")
|
||||
@@ -61,23 +60,15 @@ func (crq AffinityRuleAddRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityRuleAdd"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/affinityRuleAdd"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,15 +3,14 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityRuleRemoveRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
Topology string `url:"topology"`
|
||||
Policy string `url:"policy"`
|
||||
Mode string `url:"mode"`
|
||||
@@ -20,8 +19,8 @@ type AffinityRuleRemoveRequest struct {
|
||||
}
|
||||
|
||||
func (crq AffinityRuleRemoveRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Topology == "" {
|
||||
return errors.New("validation-error: field Topology can not be empty")
|
||||
@@ -61,23 +60,15 @@ func (crq AffinityRuleRemoveRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityRuleRemove"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/affinityRuleRemove"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,41 +3,31 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityRulesClearRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq AffinityRulesClearRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityRulesClear"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/affinityRulesClear"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,15 +3,14 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AntiAffinityRuleAddRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
Topology string `url:"topology"`
|
||||
Policy string `url:"policy"`
|
||||
Mode string `url:"mode"`
|
||||
@@ -20,8 +19,8 @@ type AntiAffinityRuleAddRequest struct {
|
||||
}
|
||||
|
||||
func (crq AntiAffinityRuleAddRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Topology == "" {
|
||||
return errors.New("validation-error: field Topology can not be empty")
|
||||
@@ -61,23 +60,15 @@ func (crq AntiAffinityRuleAddRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/antiAffinityRuleAdd"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/antiAffinityRuleAdd"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,15 +3,14 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AntiAffinityRuleRemoveRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
Topology string `url:"topology"`
|
||||
Policy string `url:"policy"`
|
||||
Mode string `url:"mode"`
|
||||
@@ -20,8 +19,8 @@ type AntiAffinityRuleRemoveRequest struct {
|
||||
}
|
||||
|
||||
func (crq AntiAffinityRuleRemoveRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Topology == "" {
|
||||
return errors.New("validation-error: field Topology can not be empty")
|
||||
@@ -61,23 +60,15 @@ func (crq AntiAffinityRuleRemoveRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/antiAffinityRuleRemove"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/antiAffinityRuleRemove"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,41 +3,31 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AntiAffinityRulesClearRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq AntiAffinityRulesClearRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/antiAffinityRulesClear"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/antiAffinityRulesClear"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,20 +3,18 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AttachGPURequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
VGPUID uint64 `url:"vgpuId"`
|
||||
}
|
||||
|
||||
func (crq AttachGPURequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.VGPUID == 0 {
|
||||
@@ -26,30 +24,22 @@ func (crq AttachGPURequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/compute/attachGpu"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/attachGpu"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.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, nil
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,20 +3,18 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AttachPciDeviceRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
DeviceID uint64 `url:"deviceId"`
|
||||
}
|
||||
|
||||
func (crq AttachPciDeviceRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DeviceID == 0 {
|
||||
@@ -26,30 +24,22 @@ func (crq AttachPciDeviceRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/attachPciDevice"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/attachPciDevice"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -4,30 +4,28 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type AuditsRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq AuditsRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AuditList, error) {
|
||||
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (AuditList, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/audits"
|
||||
auditListRaw, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
auditListRaw, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,41 +3,31 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CDEjectRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq CDEjectRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/cdEject"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/cdEject"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,20 +3,18 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CDInsertRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
CDROMID uint64 `url:"cdromId"`
|
||||
}
|
||||
|
||||
func (crq CDInsertRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
if crq.CDROMID == 0 {
|
||||
return errors.New("validation-error: field CDROMID can not be empty or equal to 0")
|
||||
@@ -25,23 +23,15 @@ func (crq CDInsertRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/cdInsert"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/cdInsert"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,22 +3,20 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CloneRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
Name string `url:"name"`
|
||||
SnapshotTimestamp uint64 `url:"snapshotTimestamp"`
|
||||
SnapshotName string `url:"snapshotName"`
|
||||
}
|
||||
|
||||
func (crq CloneRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty or equal to 0")
|
||||
@@ -27,23 +25,15 @@ func (crq CloneRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Clone(ctx context.Context, req CloneRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/compute/clone"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/clone"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -3,22 +3,20 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateTemplateRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
Name string `url:"name"`
|
||||
Async bool `url:"async"`
|
||||
}
|
||||
|
||||
func (crq CreateTemplateRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.Name == "" {
|
||||
@@ -28,7 +26,7 @@ func (crq CreateTemplateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -36,30 +34,22 @@ func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest,
|
||||
|
||||
req.Async = false
|
||||
|
||||
url := "/compute/createTemplate"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/createTemplate"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.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, nil
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (string, error) {
|
||||
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -67,17 +57,9 @@ func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequ
|
||||
|
||||
req.Async = true
|
||||
|
||||
url := "/compute/createTemplate"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/createTemplate"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -3,43 +3,33 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
DetachDisks bool `url:"detachDisks,omitempty"`
|
||||
}
|
||||
|
||||
func (crq DeleteRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/delete"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/delete"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -3,49 +3,39 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DetachGPURequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
VGPUID int64 `url:"vgpuId,omitempty"`
|
||||
}
|
||||
|
||||
func (crq DetachGPURequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/detachGpu"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/detachGpu"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,20 +3,18 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DetachPciDeviceRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
DeviceID uint64 `url:"deviceId"`
|
||||
}
|
||||
|
||||
func (crq DetachPciDeviceRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DeviceID == 0 {
|
||||
@@ -26,30 +24,22 @@ func (crq DetachPciDeviceRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/detachPciDevice"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/detachPciDevice"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,48 +3,38 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DisableRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq DisableRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/disable"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/disable"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,14 +3,12 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskAddRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
DiskName string `url:"diskName"`
|
||||
Size uint64 `url:"size"`
|
||||
DiskType string `url:"diskType,omitempty"`
|
||||
@@ -21,8 +19,8 @@ type DiskAddRequest struct {
|
||||
}
|
||||
|
||||
func (crq DiskAddRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.Size == 0 {
|
||||
@@ -36,30 +34,22 @@ func (crq DiskAddRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/compute/diskAdd"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/diskAdd"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.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, nil
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,20 +3,18 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskAttachRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
}
|
||||
|
||||
func (crq DiskAttachRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
@@ -26,30 +24,22 @@ func (crq DiskAttachRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskAttach"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/diskAttach"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,21 +3,19 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskDelRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Permanently bool `url:"permanently"`
|
||||
}
|
||||
|
||||
func (crq DiskDelRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
@@ -27,30 +25,22 @@ func (crq DiskDelRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskDel"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/diskDel"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,20 +3,18 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskDetachRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
}
|
||||
|
||||
func (crq DiskDetachRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
@@ -26,30 +24,22 @@ func (crq DiskDetachRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskDetach"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/diskDetach"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,21 +3,19 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskQOSRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Limits string `url:"limits"`
|
||||
}
|
||||
|
||||
func (crq DiskQOSRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
@@ -31,30 +29,22 @@ func (crq DiskQOSRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskQos"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/diskQos"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,21 +3,19 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskResizeRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (crq DiskResizeRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
@@ -31,30 +29,22 @@ func (crq DiskResizeRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskResize"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/diskResize"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -3,48 +3,38 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type EnableRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq EnableRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
func (c Compute) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/enable"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/enable"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -4,40 +4,30 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq GetRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ComputeRecord, error) {
|
||||
func (c Compute) Get(ctx context.Context, req GetRequest) (*ComputeRecord, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/compute/get"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/compute/get"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user