Merge 'dev' into 'main'

1.5.8-k8s-extnet-branch
stSolo 2 years ago
parent 6271fa6d45
commit 5fd450382c

@ -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)
}

@ -1,59 +1,70 @@
package decortsdk
import (
"context"
"errors"
"io"
"net/http"
"strings"
"github.com/google/go-querystring/query"
"github.com/rudecs/decort-sdk/config"
"github.com/rudecs/decort-sdk/internal/client"
)
type Client struct {
decortUrl string
client *http.Client
}
func New(cfg config.Config) *Client {
if cfg.Retries == 0 {
cfg.Retries = 5
}
return &Client{
decortUrl: cfg.DecortURL,
client: client.NewHttpClient(cfg),
}
}
func (dc *Client) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
values, err := query.Values(params)
if err != nil {
return nil, err
}
body := strings.NewReader(values.Encode())
req, err := http.NewRequestWithContext(ctx, method, dc.decortUrl+"/restmachine"+url, body)
if err != nil {
return nil, err
}
resp, err := dc.client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, errors.New(string(respBytes))
}
return respBytes, nil
}
package decortsdk
import (
"context"
"errors"
"io"
"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
client *http.Client
}
func New(cfg config.Config) *Client {
if cfg.Retries == 0 {
cfg.Retries = 5
}
return &Client{
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 {
return nil, err
}
body := strings.NewReader(values.Encode())
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, body)
if err != nil {
return nil, err
}
resp, err := dc.client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, errors.New(string(respBytes))
}
return respBytes, nil
}

@ -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)
}

@ -1,10 +1,10 @@
package config
type Config struct {
AppID string
AppSecret string
SSOURL string
DecortURL string
Retries uint64
SSLSkipVerify bool
}
package config
type Config struct {
AppID string
AppSecret string
SSOURL string
DecortURL string
Retries uint64
SSLSkipVerify bool
}

@ -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)
}

@ -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)
}

@ -1,7 +1,7 @@
package interfaces
import "context"
type Caller interface {
DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error)
}
package interfaces
import "context"
type Caller interface {
DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error)
}

@ -1,27 +1,32 @@
package client
import (
"crypto/tls"
"net/http"
"time"
"github.com/rudecs/decort-sdk/config"
)
func NewHttpClient(cfg config.Config) *http.Client {
transCfg := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: cfg.SSLSkipVerify}}
return &http.Client{
Transport: &transport{
base: transCfg,
retries: cfg.Retries,
clientId: cfg.AppID,
clientSecret: cfg.AppSecret,
ssoUrl: cfg.SSOURL,
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Timeout: 5 * time.Minute,
}
}
package client
import (
"crypto/tls"
"net/http"
"time"
"github.com/rudecs/decort-sdk/config"
)
func NewHttpClient(cfg config.Config) *http.Client {
transCfg := &http.Transport{
TLSClientConfig: &tls.Config{
//nolint:gosec
InsecureSkipVerify: cfg.SSLSkipVerify,
},
}
return &http.Client{
Transport: &transport{
base: transCfg,
retries: cfg.Retries,
clientID: cfg.AppID,
clientSecret: cfg.AppSecret,
SSOURL: cfg.SSOURL,
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Timeout: 5 * time.Minute,
}
}

@ -1,67 +1,67 @@
package client
import (
"fmt"
"io"
"net/http"
"strings"
"time"
)
type transport struct {
base http.RoundTripper
retries uint64
clientId string
clientSecret string
token 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)
bodyReader := strings.NewReader(body)
req, _ := http.NewRequest("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)
}
tokenBytes, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("cannot get token: %s", tokenBytes)
}
token := string(tokenBytes)
t.token = token
t.expiryTime = time.Now().AddDate(0, 0, 1)
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "bearer "+t.token)
req.Header.Set("Accept", "application/json")
var resp *http.Response
var err error
for i := uint64(0); i < t.retries; i++ {
resp, err = t.base.RoundTrip(req)
if err == nil {
if resp.StatusCode == 200 {
return resp, nil
}
respBytes, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("%s", respBytes)
resp.Body.Close()
}
//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)
}
package client
import (
"fmt"
"io"
"net/http"
"strings"
"time"
)
type transport struct {
base http.RoundTripper
retries uint64
clientID string
clientSecret string
token 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)
bodyReader := strings.NewReader(body)
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: %w", err)
}
tokenBytes, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("cannot get token: %s", tokenBytes)
}
token := string(tokenBytes)
t.token = token
t.expiryTime = time.Now().AddDate(0, 0, 1)
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "bearer "+t.token)
req.Header.Set("Accept", "application/json")
var resp *http.Response
var err error
for i := uint64(0); i < t.retries; i++ {
resp, err = t.base.RoundTrip(req)
if err == nil {
if resp.StatusCode == 200 {
return resp, nil
}
respBytes, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("%s", respBytes)
resp.Body.Close()
}
//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: %w", err)
}

@ -1,10 +1,10 @@
package validators
func StringInSlice(str string, target []string) bool {
for _, v := range target {
if v == str {
return true
}
}
return false
}
package validators
func StringInSlice(str string, target []string) bool {
for _, v := range target {
if v == str {
return true
}
}
return false
}

@ -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)
}

@ -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)
}

@ -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
}

@ -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
}

@ -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)
}

@ -1,15 +1,15 @@
package account
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type Account struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *Account {
return &Account{
client,
}
}
package account
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type Account struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *Account {
return &Account{
client,
}
}

@ -1,68 +1,58 @@
package account
import (
"context"
"errors"
"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"`
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.UserId == "" {
return errors.New("validation-error: field UserId can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
}
func (a Account) AddUser(ctx context.Context, req AddUserRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/addUser"
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.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package account
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
type AddUserRequest struct {
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.UserID == "" {
return errors.New("validation-error: field UserID can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
}
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/account/addUser"
res, 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
}

@ -1,54 +1,43 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AuditsRequest struct {
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")
}
return nil
}
func (a Account) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AccountAuditsList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/audits"
prefix := "/cloudapi"
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)
if err != nil {
return nil, err
}
audits := AccountAuditsList{}
err = json.Unmarshal([]byte(auditsRaw), &audits)
if err != nil {
return nil, err
}
return audits, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type AuditsRequest struct {
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")
}
return nil
}
func (a Account) Audits(ctx context.Context, req AuditsRequest) (AccountAuditsList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/audits"
auditsRaw, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
audits := AccountAuditsList{}
err = json.Unmarshal(auditsRaw, &audits)
if err != nil {
return nil, err
}
return audits, nil
}

@ -1,65 +1,54 @@
package account
import (
"context"
"errors"
"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"`
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
GpuUnits uint `url:"gpu_units,omitempty"`
}
func (arq CreateRequest) Validate() error {
if arq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
if arq.Username == "" {
return errors.New("validation-error: field Username can not be empty")
}
return nil
}
func (a Account) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/account/create"
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.POST, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}
package account
import (
"context"
"errors"
"net/http"
"strconv"
)
type CreateRequest struct {
Name string `url:"name"`
Username string `url:"username"`
EmailAddress string `url:"emailaddress,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 uint64 `url:"gpu_units,omitempty"`
}
func (arq CreateRequest) Validate() error {
if arq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
if arq.Username == "" {
return errors.New("validation-error: field Username can not be empty")
}
return nil
}
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/account/create"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

@ -1,52 +1,36 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DeleteRequest struct {
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")
}
return nil
}
func (a Account) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/delete"
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.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package account
import (
"context"
"errors"
"net/http"
)
type DeleteRequest struct {
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")
}
return nil
}
func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/account/delete"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

@ -1,58 +1,47 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DeleteUserRequest struct {
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.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) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/deleteUser"
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.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package account
import (
"context"
"errors"
"net/http"
"strconv"
)
type DeleteUserRequest struct {
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.UserID == "" {
return errors.New("validation-error: field UserID can not be empty")
}
return nil
}
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/account/deleteUser"
res, 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
}

@ -1,80 +1,62 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DisabelEnableRequest struct {
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")
}
return nil
}
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/disable"
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.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/enable"
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.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package account
import (
"context"
"errors"
"net/http"
"strconv"
)
type DisabelEnableRequest struct {
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")
}
return nil
}
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/account/disable"
res, 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
}
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/account/enable"
res, 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
}

@ -1,55 +1,44 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetRequest struct {
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")
}
return nil
}
func (a Account) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*AccountWithResources, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/get"
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.POST, url, req)
if err != nil {
return nil, err
}
account := &AccountWithResources{}
err = json.Unmarshal(res, &account)
if err != nil {
return nil, err
}
return account, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type GetRequest struct {
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")
}
return nil
}
func (a Account) Get(ctx context.Context, req GetRequest) (*AccountWithResources, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/get"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
account := &AccountWithResources{}
err = json.Unmarshal(res, &account)
if err != nil {
return nil, err
}
return account, nil
}

@ -1,55 +1,44 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetConsumedAccountUnitsRequest struct {
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")
}
return nil
}
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/getConsumedAccountUnits"
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.POST, url, req)
if err != nil {
return nil, err
}
rl := &ResourceLimits{}
err = json.Unmarshal(res, &rl)
if err != nil {
return nil, err
}
return rl, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type GetConsumedAccountUnitsRequest struct {
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")
}
return nil
}
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest) (*ResourceLimits, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/getConsumedAccountUnits"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
rl := &ResourceLimits{}
err = json.Unmarshal(res, &rl)
if err != nil {
return nil, err
}
return rl, nil
}

@ -1,64 +1,54 @@
package account
import (
"context"
"errors"
"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"`
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.CUType == "" {
return errors.New("validation-error: field CUType can not be empty")
}
isValid := validators.StringInSlice(arq.CUType, []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"})
if !isValid {
return errors.New("validation-error: field AccessType can be only CU_M, CU_C, CU_D, CU_S, CU_A, CU_NO, CU_I or CU_NP")
}
return nil
}
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest, options ...opts.DecortOpts) (float64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/account/getConsumedCloudUnitsByType"
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.POST, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseFloat(string(res), 64)
if err != nil {
return 0, err
}
return result, nil
}
package account
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
type GetConsumedCloudUnitsByTypeRequest struct {
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.CUType == "" {
return errors.New("validation-error: field CUType can not be empty")
}
isValid := validators.StringInSlice(arq.CUType, []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"})
if !isValid {
return errors.New("validation-error: field AccessType can be only CU_M, CU_C, CU_D, CU_S, CU_A, CU_NO, CU_I or CU_NP")
}
return nil
}
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest) (float64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudapi/account/getConsumedCloudUnitsByType"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseFloat(string(res), 64)
if err != nil {
return 0, err
}
return result, nil
}

@ -1,83 +1,65 @@
package account
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetConsumtionRequest struct {
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.Start == 0 {
return errors.New("validation-error: field Start can not be empty or equal to 0")
}
if arq.End == 0 {
return errors.New("validation-error: field End can not be empty or equal to 0")
}
return nil
}
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
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.POST, url, req)
if err != nil {
return "", err
}
return string(res), nil
}
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
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)
if err != nil {
return "", err
}
return string(res), nil
}
package account
import (
"context"
"errors"
"net/http"
)
type GetConsumtionRequest struct {
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.Start == 0 {
return errors.New("validation-error: field Start can not be empty or equal to 0")
}
if arq.End == 0 {
return errors.New("validation-error: field End can not be empty or equal to 0")
}
return nil
}
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/cloudapi/account/getConsumtion"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/account/getConsumtion"
prefix := "/cloudapi"
url = prefix + url
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

@ -1,55 +1,44 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetReservedAccountUnitsRequest struct {
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")
}
return nil
}
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/getReservedAccountUnits"
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.POST, url, req)
if err != nil {
return nil, err
}
rl := &ResourceLimits{}
err = json.Unmarshal(res, &rl)
if err != nil {
return nil, err
}
return rl, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type GetReservedAccountUnitsRequest struct {
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")
}
return nil
}
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest) (*ResourceLimits, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/getReservedAccountUnits"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
rl := &ResourceLimits{}
err = json.Unmarshal(res, &rl)
if err != nil {
return nil, err
}
return rl, nil
}

@ -1,42 +1,31 @@
package account
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListRequest struct {
Page uint64 `url:"page"`
Size uint64 `url:"size"`
}
func (a Account) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
url := "/account/list"
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.POST, url, req)
if err != nil {
return nil, err
}
accountList := AccountCloudApiList{}
err = json.Unmarshal(res, &accountList)
if err != nil {
return nil, err
}
return accountList, nil
}
package account
import (
"context"
"encoding/json"
"net/http"
)
type ListRequest struct {
Page uint64 `url:"page"`
Size uint64 `url:"size"`
}
func (a Account) List(ctx context.Context, req ListRequest) (AccountCloudApiList, error) {
url := "/cloudapi/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
accountList := AccountCloudApiList{}
err = json.Unmarshal(res, &accountList)
if err != nil {
return nil, err
}
return accountList, nil
}

@ -1,55 +1,44 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListComputesRequest struct {
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")
}
return nil
}
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (AccountComputesList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listComputes"
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.POST, url, req)
if err != nil {
return nil, err
}
accountComputesList := AccountComputesList{}
err = json.Unmarshal(res, &accountComputesList)
if err != nil {
return nil, err
}
return accountComputesList, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type ListComputesRequest struct {
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")
}
return nil
}
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (AccountComputesList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/listComputes"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
accountComputesList := AccountComputesList{}
err = json.Unmarshal(res, &accountComputesList)
if err != nil {
return nil, err
}
return accountComputesList, nil
}

@ -1,42 +1,31 @@
package account
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListDeletedRequest struct {
Page uint64 `url:"page"`
Size uint64 `url:"size"`
}
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
url := "/account/listDeleted"
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.POST, url, req)
if err != nil {
return nil, err
}
accountList := AccountCloudApiList{}
err = json.Unmarshal(res, &accountList)
if err != nil {
return nil, err
}
return accountList, nil
}
package account
import (
"context"
"encoding/json"
"net/http"
)
type ListDeletedRequest struct {
Page uint64 `url:"page"`
Size uint64 `url:"size"`
}
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (AccountCloudApiList, error) {
url := "/cloudapi/account/listDeleted"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
accountList := AccountCloudApiList{}
err = json.Unmarshal(res, &accountList)
if err != nil {
return nil, err
}
return accountList, nil
}

@ -1,55 +1,44 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListDisksRequest struct {
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")
}
return nil
}
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest, options ...opts.DecortOpts) (AccountDisksList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listDisks"
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.POST, url, req)
if err != nil {
return nil, err
}
accountDisksList := AccountDisksList{}
err = json.Unmarshal(res, &accountDisksList)
if err != nil {
return nil, err
}
return accountDisksList, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type ListDisksRequest struct {
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")
}
return nil
}
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (AccountDisksList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/listDisks"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
accountDisksList := AccountDisksList{}
err = json.Unmarshal(res, &accountDisksList)
if err != nil {
return nil, err
}
return accountDisksList, nil
}

@ -1,55 +1,44 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListFlipGroupsRequest struct {
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")
}
return nil
}
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest, options ...opts.DecortOpts) (AccountFlipGroupsList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listFlipGroups"
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.POST, url, req)
if err != nil {
return nil, err
}
accountFlipGroupsList := AccountFlipGroupsList{}
err = json.Unmarshal(res, &accountFlipGroupsList)
if err != nil {
return nil, err
}
return accountFlipGroupsList, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type ListFlipGroupsRequest struct {
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")
}
return nil
}
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest) (AccountFlipGroupsList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/listFlipGroups"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
accountFlipGroupsList := AccountFlipGroupsList{}
err = json.Unmarshal(res, &accountFlipGroupsList)
if err != nil {
return nil, err
}
return accountFlipGroupsList, nil
}

@ -1,55 +1,44 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListRGRequest struct {
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")
}
return nil
}
func (a Account) ListRG(ctx context.Context, req ListRGRequest, options ...opts.DecortOpts) (AccountRGList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listRG"
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.POST, url, req)
if err != nil {
return nil, err
}
accountRGList := AccountRGList{}
err = json.Unmarshal(res, &accountRGList)
if err != nil {
return nil, err
}
return accountRGList, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type ListRGRequest struct {
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")
}
return nil
}
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (AccountRGList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/listRG"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
accountRGList := AccountRGList{}
err = json.Unmarshal(res, &accountRGList)
if err != nil {
return nil, err
}
return accountRGList, nil
}

@ -1,56 +1,45 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListTemplatesRequest struct {
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")
}
return nil
}
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest, options ...opts.DecortOpts) (AccountTemplatesList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listTemplates"
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.POST, url, req)
if err != nil {
return nil, err
}
accountTemplatesList := AccountTemplatesList{}
err = json.Unmarshal(res, &accountTemplatesList)
if err != nil {
return nil, err
}
return accountTemplatesList, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type ListTemplatesRequest struct {
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")
}
return nil
}
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (AccountTemplatesList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/listTemplates"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
accountTemplatesList := AccountTemplatesList{}
err = json.Unmarshal(res, &accountTemplatesList)
if err != nil {
return nil, err
}
return accountTemplatesList, nil
}

@ -1,55 +1,44 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
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")
}
return nil
}
func (a Account) ListVins(ctx context.Context, req ListVinsRequest, options ...opts.DecortOpts) (AccountVinsList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listVins"
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.POST, url, req)
if err != nil {
return nil, err
}
accountVinsList := AccountVinsList{}
err = json.Unmarshal(res, &accountVinsList)
if err != nil {
return nil, err
}
return accountVinsList, nil
}
package account
import (
"context"
"encoding/json"
"errors"
"net/http"
)
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")
}
return nil
}
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (AccountVINSList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/listVins"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
accountVINSList := AccountVINSList{}
err = json.Unmarshal(res, &accountVINSList)
if err != nil {
return nil, err
}
return accountVINSList, nil
}

@ -1,229 +1,229 @@
package account
type AccountAclRecord struct {
IsExplicit bool `json:"explicit"`
GUID string `json:"guid"`
Rights string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
UgroupID string `json:"userGroupId"`
CanBeDeleted bool `json:"canBeDeleted"`
}
type ResourceLimits struct {
CUC float64 `json:"CU_C"`
CUD float64 `json:"CU_D"`
CUI float64 `json:"CU_I"`
CUM float64 `json:"CU_M"`
CUNP float64 `json:"CU_NP"`
GpuUnits float64 `json:"gpu_units"`
}
type AccountRecord struct {
DCLocation string `json:"DCLocation"`
CKey string `jspn:"_ckey"`
Meta []interface{} `json:"_meta"`
Acl []AccountAclRecord `json:"acl"`
Company string `json:"company"`
CompanyUrl string `json:"companyurl"`
CreatedBy string `jspn:"createdBy"`
CreatedTime int `json:"createdTime"`
DeactiovationTime float64 `json:"deactivationTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
DisplayName string `json:"displayname"`
GUID int `json:"guid"`
ID int `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"`
}
type AccountList []AccountRecord
type AccountCloudApi struct {
Acl []AccountAclRecord `json:"acl"`
CreatedTime int `json:"createdTime"`
DeletedTime int `json:"deletedTime"`
ID int `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
UpdatedTime int `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"`
}
type Resources struct {
Current Resource `json:"Current"`
Reserved Resource `json:"Reserved"`
}
type Computes struct {
Started int `json:"started"`
Stopped int `json:"stopped"`
}
type Machines struct {
Running int `json:"running"`
Halted int `json:"halted"`
}
type AccountWithResources struct {
Account
Resources Resources `json:"Resources"`
Computes Computes `json:"computes"`
Machines Machines `json:"machines"`
Vinses int `json:"vinses"`
}
type AccountCompute struct {
AccountId int `json:"accountId"`
AccountName string `json:"accountName"`
CPUs int `json:"cpus"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
ComputeId int `json:"id"`
ComputeName string `json:"name"`
RAM int `json:"ram"`
Registered bool `json:"registered"`
RGId int `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
TotalDisksSize int `json:"totalDisksSize"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
UserManaged bool `json:"userManaged"`
VinsConnected int `json:"vinsConnected"`
}
type AccountComputesList []AccountCompute
type AccountDisk struct {
ID int `json:"id"`
Name string `json:"name"`
Pool string `json:"pool"`
SepId int `json:"sepId"`
SizeMax int `json:"sizeMax"`
Type string `json:"type"`
}
type AccountDisksList []AccountDisk
type AccountVin struct {
AccountId int `json:"accountId"`
AccountName string `json:"accountName"`
Computes int `json:"computes"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
ExternalIP string `json:"externalIP"`
ID int `json:"id"`
Name string `json:"name"`
Network string `json:"network"`
PriVnfDevId int `json:"priVnfDevId"`
RGId int `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
}
type AccountVinsList []AccountVin
type AccountAudit struct {
Call string `json:"call"`
ResponseTime float64 `json:"responsetime"`
StatusCode int `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
}
type AccountAuditsList []AccountAudit
type AccountRGComputes struct {
Started int `json:"Started"`
Stopped int `json:"Stopped"`
}
type AccountRGResources struct {
Consumed Resource `json:"Consumed"`
Limits Resource `json:"Limits"`
Reserved Resource `json:"Reserved"`
}
type AccountRG struct {
Computes AccountRGComputes `json:"Computes"`
Resources AccountRGResources `json:"Resources"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
RGID int `json:"id"`
Milestones int `json:"milestones"`
RGName string `json:"name"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
Vinses int `json:"vinses"`
}
type AccountRGList []AccountRG
type AccountTemplate struct {
UNCPath string `json:"UNCPath"`
AccountId int `json:"accountId"`
Description string `json:"desc"`
ID int `json:"id"`
Name string `json:"name"`
Public bool `json:"public"`
Size int `json:"size"`
Status string `json:"status"`
Type string `json:"type"`
Username string `json:"username"`
}
type AccountTemplatesList []AccountTemplate
type AccountFlipGroup struct {
AccountId int `json:"accountId"`
ClientType string `json:"clientType"`
ConnType string `json:"connType"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DefaultGW string `json:"defaultGW"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
Description string `json:"desc"`
GID int `json:"gid"`
GUID int `json:"guid"`
ID int `json:"id"`
IP string `json:"ip"`
Milestones int `json:"milestones"`
Name string `json:"name"`
NetID int `json:"netId"`
NetType string `json:"netType"`
NetMask int `json:"netmask"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
}
type AccountFlipGroupsList []AccountFlipGroup
package account
type AccountACLRecord struct {
IsExplicit bool `json:"explicit"`
GUID string `json:"guid"`
Rights string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
UgroupID string `json:"userGroupId"`
CanBeDeleted bool `json:"canBeDeleted"`
}
type ResourceLimits struct {
CUC float64 `json:"CU_C"`
CUD float64 `json:"CU_D"`
CUI float64 `json:"CU_I"`
CUM float64 `json:"CU_M"`
CUNP float64 `json:"CU_NP"`
GPUUnits float64 `json:"gpu_units"`
}
type AccountRecord struct {
DCLocation string `json:"DCLocation"`
CKey string `jspn:"_ckey"`
Meta []interface{} `json:"_meta"`
ACL []AccountACLRecord `json:"acl"`
Company string `json:"company"`
CompanyURL string `json:"companyurl"`
CreatedBy string `jspn:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeactiovationTime float64 `json:"deactivationTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
DisplayName string `json:"displayname"`
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 uint64 `json:"updatedTime"`
Version uint64 `json:"version"`
VINS []uint64 `json:"vins"`
}
type AccountList []AccountRecord
type AccountCloudApi struct {
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 uint64 `json:"updatedTime"`
}
type AccountCloudApiList []AccountCloudApi
type Resource struct {
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 {
Current Resource `json:"Current"`
Reserved Resource `json:"Reserved"`
}
type Computes struct {
Started uint64 `json:"started"`
Stopped uint64 `json:"stopped"`
}
type Machines struct {
Running uint64 `json:"running"`
Halted uint64 `json:"halted"`
}
type AccountWithResources struct {
Account
Resources Resources `json:"Resources"`
Computes Computes `json:"computes"`
Machines Machines `json:"machines"`
VINSes uint64 `json:"vinses"`
}
type AccountCompute struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
CPUs uint64 `json:"cpus"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
ComputeID uint64 `json:"id"`
ComputeName string `json:"name"`
RAM uint64 `json:"ram"`
Registered bool `json:"registered"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
TotalDisksSize uint64 `json:"totalDisksSize"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
UserManaged bool `json:"userManaged"`
VINSConnected uint64 `json:"vinsConnected"`
}
type AccountComputesList []AccountCompute
type AccountDisk struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Pool string `json:"pool"`
SepID uint64 `json:"sepId"`
SizeMax uint64 `json:"sizeMax"`
Type string `json:"type"`
}
type AccountDisksList []AccountDisk
type AccountVIN struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
Computes uint64 `json:"computes"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
ExternalIP string `json:"externalIP"`
ID uint64 `json:"id"`
Name string `json:"name"`
Network string `json:"network"`
PriVnfDevID uint64 `json:"priVnfDevId"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
}
type AccountVINSList []AccountVIN
type AccountAudit struct {
Call string `json:"call"`
ResponseTime float64 `json:"responsetime"`
StatusCode uint64 `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
}
type AccountAuditsList []AccountAudit
type AccountRGComputes struct {
Started uint64 `json:"Started"`
Stopped uint64 `json:"Stopped"`
}
type AccountRGResources struct {
Consumed Resource `json:"Consumed"`
Limits Resource `json:"Limits"`
Reserved Resource `json:"Reserved"`
}
type AccountRG struct {
Computes AccountRGComputes `json:"Computes"`
Resources AccountRGResources `json:"Resources"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
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 uint64 `json:"updatedTime"`
VINSes uint64 `json:"vinses"`
}
type AccountRGList []AccountRG
type AccountTemplate struct {
UNCPath string `json:"UNCPath"`
AccountID uint64 `json:"accountId"`
Description string `json:"desc"`
ID uint64 `json:"id"`
Name string `json:"name"`
Public bool `json:"public"`
Size uint64 `json:"size"`
Status string `json:"status"`
Type string `json:"type"`
Username string `json:"username"`
}
type AccountTemplatesList []AccountTemplate
type AccountFlipGroup struct {
AccountID uint64 `json:"accountId"`
ClientType string `json:"clientType"`
ConnType string `json:"connType"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DefaultGW string `json:"defaultGW"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
Description string `json:"desc"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
IP string `json:"ip"`
Milestones uint64 `json:"milestones"`
Name string `json:"name"`
NetID uint64 `json:"netId"`
NetType string `json:"netType"`
NetMask uint64 `json:"netmask"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
}
type AccountFlipGroupsList []AccountFlipGroup

@ -1,53 +1,42 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RestoreRequest struct {
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")
}
return nil
}
func (a Account) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/restore"
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.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package account
import (
"context"
"errors"
"net/http"
"strconv"
)
type RestoreRequest struct {
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")
}
return nil
}
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/account/restore"
res, 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
}

@ -1,60 +1,49 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type UpdateRequest struct {
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"`
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
GpuUnits uint `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")
}
return nil
}
func (a Account) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/update"
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.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package account
import (
"context"
"errors"
"net/http"
"strconv"
)
type UpdateRequest struct {
AccountID uint64 `url:"accountId"`
Name string `url:"name,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 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")
}
return nil
}
func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/account/update"
res, 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
}

@ -1,68 +1,58 @@
package account
import (
"context"
"errors"
"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"`
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.UserId == "" {
return errors.New("validation-error: field UserId can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
}
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/updateUser"
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.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package account
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
type UpdateUserRequest struct {
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.UserID == "" {
return errors.New("validation-error: field UserID can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
}
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/account/updateUser"
res, 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
}

@ -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
}

@ -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,
}
}

@ -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)
}

@ -1,49 +1,39 @@
package compute
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AffinityGroupCheckStartRequest struct {
RGID uint64 `url:"rgId"`
AffinityLabel string `url:"affinityLabel"`
}
func (crq AffinityGroupCheckStartRequest) Validate() error {
if crq.RGID == 0 {
return errors.New("validation-error: field RGID can not be empty or equal to 0")
}
if crq.AffinityLabel == "" {
return errors.New("validation-error: field AffinityLabel can not be empty")
}
return nil
}
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/compute/affinityGroupCheckStart"
prefix := "/cloudapi"
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)
if err != nil {
return "", err
}
return string(res), nil
}
package compute
import (
"context"
"errors"
"net/http"
)
type AffinityGroupCheckStartRequest struct {
RGID uint64 `url:"rgId"`
AffinityLabel string `url:"affinityLabel"`
}
func (crq AffinityGroupCheckStartRequest) Validate() error {
if crq.RGID == 0 {
return errors.New("validation-error: field RGID can not be empty or equal to 0")
}
if crq.AffinityLabel == "" {
return errors.New("validation-error: field AffinityLabel can not be empty")
}
return nil
}
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/cloudapi/compute/affinityGroupCheckStart"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

@ -1,51 +1,41 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AffinityLabelRemoveRequest struct {
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")
}
return nil
}
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/affinityLabelRemove"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type AffinityLabelRemoveRequest struct {
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")
}
return nil
}
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/affinityLabelRemove"
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, err
}
return result, nil
}

@ -1,55 +1,45 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AffinityLabelSetRequest struct {
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.AffinityLabel == "" {
return errors.New("validation-error: field AffinityLabel can not be empty")
}
return nil
}
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/affinityLabelSet"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type AffinityLabelSetRequest struct {
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.AffinityLabel == "" {
return errors.New("validation-error: field AffinityLabel can not be empty")
}
return nil
}
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/affinityLabelSet"
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, err
}
return result, nil
}

@ -1,54 +1,44 @@
package compute
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AffinityRelationsRequest struct {
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")
}
return nil
}
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest, options ...opts.DecortOpts) (*AffinityRelations, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/compute/affinityRelations"
prefix := "/cloudapi"
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)
if err != nil {
return nil, err
}
relations := &AffinityRelations{}
err = json.Unmarshal([]byte(res), relations)
if err != nil {
return nil, err
}
return relations, nil
}
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type AffinityRelationsRequest struct {
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")
}
return nil
}
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*AffinityRelations, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/compute/affinityRelations"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
relations := &AffinityRelations{}
err = json.Unmarshal(res, relations)
if err != nil {
return nil, err
}
return relations, nil
}

@ -1,91 +1,82 @@
package compute
import (
"context"
"errors"
"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"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
}
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.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
}
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/affinityRuleAdd"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
type AffinityRuleAddRequest struct {
ComputeID uint64 `url:"computeId"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
}
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.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
}
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/affinityRuleAdd"
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, err
}
return result, nil
}

@ -1,91 +1,82 @@
package compute
import (
"context"
"errors"
"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"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
}
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.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
}
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/affinityRuleRemove"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
type AffinityRuleRemoveRequest struct {
ComputeID uint64 `url:"computeId"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
}
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.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
}
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/affinityRuleRemove"
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, err
}
return result, nil
}

@ -1,51 +1,41 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AffinityRulesClearRequest struct {
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")
}
return nil
}
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/affinityRulesClear"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type AffinityRulesClearRequest struct {
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")
}
return nil
}
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/affinityRulesClear"
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, err
}
return result, nil
}

@ -1,91 +1,82 @@
package compute
import (
"context"
"errors"
"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"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
}
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.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
}
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/antiAffinityRuleAdd"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
type AntiAffinityRuleAddRequest struct {
ComputeID uint64 `url:"computeId"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
}
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.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
}
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/antiAffinityRuleAdd"
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, err
}
return result, nil
}

@ -1,91 +1,82 @@
package compute
import (
"context"
"errors"
"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"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
}
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.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
}
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/antiAffinityRuleRemove"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
type AntiAffinityRuleRemoveRequest struct {
ComputeID uint64 `url:"computeId"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
}
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.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
}
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/antiAffinityRuleRemove"
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, err
}
return result, nil
}

@ -1,51 +1,41 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AntiAffinityRulesClearRequest struct {
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")
}
return nil
}
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/antiAffinityRulesClear"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type AntiAffinityRulesClearRequest struct {
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")
}
return nil
}
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/antiAffinityRulesClear"
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, err
}
return result, nil
}

@ -1,56 +1,46 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AttachGPURequest struct {
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.VGPUID == 0 {
return errors.New("validation-error: field VGPUID can not be empty or equal to 0")
}
return nil
}
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/compute/attachGpu"
prefix := "/cloudapi"
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)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, nil
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type AttachGPURequest struct {
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.VGPUID == 0 {
return errors.New("validation-error: field VGPUID can not be empty or equal to 0")
}
return nil
}
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudapi/compute/attachGpu"
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, err
}
return result, nil
}

@ -1,56 +1,46 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AttachPciDeviceRequest struct {
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.DeviceID == 0 {
return errors.New("validation-error: field DeviceID can not be empty or equal to 0")
}
return nil
}
func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/attachPciDevice"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type AttachPciDeviceRequest struct {
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.DeviceID == 0 {
return errors.New("validation-error: field DeviceID can not be empty or equal to 0")
}
return nil
}
func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/attachPciDevice"
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, err
}
return result, nil
}

@ -1,41 +1,39 @@
package compute
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AuditsRequest struct {
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")
}
return nil
}
func (c Compute) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (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)
if err != nil {
return nil, err
}
auditList := AuditList{}
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
return nil, err
}
return auditList, nil
}
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type AuditsRequest struct {
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")
}
return nil
}
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, http.MethodPost, url, req)
if err != nil {
return nil, err
}
auditList := AuditList{}
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
return nil, err
}
return auditList, nil
}

@ -1,50 +1,40 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type CDEjectRequest struct {
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")
}
return nil
}
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/cdEject"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type CDEjectRequest struct {
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")
}
return nil
}
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/cdEject"
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, err
}
return result, nil
}

@ -1,54 +1,44 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type CDInsertRequest struct {
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.CDROMID == 0 {
return errors.New("validation-error: field CDROMID can not be empty or equal to 0")
}
return nil
}
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/cdInsert"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type CDInsertRequest struct {
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.CDROMID == 0 {
return errors.New("validation-error: field CDROMID can not be empty or equal to 0")
}
return nil
}
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/cdInsert"
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, err
}
return result, nil
}

@ -1,56 +1,46 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type CloneRequest struct {
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.Name == "" {
return errors.New("validation-error: field Name can not be empty or equal to 0")
}
return nil
}
func (c Compute) Clone(ctx context.Context, req CloneRequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/compute/clone"
prefix := "/cloudapi"
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)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type CloneRequest struct {
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.Name == "" {
return errors.New("validation-error: field Name can not be empty or equal to 0")
}
return nil
}
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudapi/compute/clone"
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, err
}
return result, nil
}

@ -1,15 +1,15 @@
package compute
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type Compute struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *Compute {
return &Compute{
client,
}
}
package compute
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type Compute struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *Compute {
return &Compute{
client,
}
}

@ -1,88 +1,70 @@
package compute
import (
"context"
"errors"
"strconv"
"strings"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type CreateTemplateRequest struct {
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.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
return nil
}
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
req.Async = false
url := "/compute/createTemplate"
prefix := "/cloudapi"
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)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, nil
}
return result, nil
}
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
req.Async = true
url := "/compute/createTemplate"
prefix := "/cloudapi"
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)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"strings"
)
type CreateTemplateRequest struct {
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.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
return nil
}
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
req.Async = false
url := "/cloudapi/compute/createTemplate"
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, err
}
return result, nil
}
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
req.Async = true
url := "/cloudapi/compute/createTemplate"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

@ -1,52 +1,42 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DeleteRequest struct {
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")
}
return nil
}
func (c Compute) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/delete"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type DeleteRequest struct {
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")
}
return nil
}
func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/delete"
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, err
}
return result, nil
}

@ -1,52 +1,42 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DetachGPURequest struct {
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")
}
return nil
}
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/detachGpu"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type DetachGPURequest struct {
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")
}
return nil
}
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/detachGpu"
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, err
}
return result, nil
}

@ -1,56 +1,46 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DetachPciDeviceRequest struct {
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.DeviceID == 0 {
return errors.New("validation-error: field DeviceID can not be empty or equal to 0")
}
return nil
}
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/detachPciDevice"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type DetachPciDeviceRequest struct {
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.DeviceID == 0 {
return errors.New("validation-error: field DeviceID can not be empty or equal to 0")
}
return nil
}
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/detachPciDevice"
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, err
}
return result, nil
}

@ -1,51 +1,41 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DisableRequest struct {
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")
}
return nil
}
func (c Compute) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/disable"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type DisableRequest struct {
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")
}
return nil
}
func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/disable"
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, err
}
return result, nil
}

@ -1,66 +1,56 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DiskAddRequest struct {
ComputeId uint64 `url:"computeId"`
DiskName string `url:"diskName"`
Size uint64 `url:"size"`
DiskType string `url:"diskType,omitempty"`
SepID uint64 `url:"sepId,omitempty"`
Pool string `url:"pool,omitempty"`
Description string `url:"desc,omitempty"`
ImageID uint64 `url:"imageId,omitempty"`
}
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.Size == 0 {
return errors.New("validation-error: field Size can not be empty or equal to 0")
}
if crq.DiskName == "" {
return errors.New("validation-error: field DiskName can not be empty or equal to 0")
}
return nil
}
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/compute/diskAdd"
prefix := "/cloudapi"
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)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, nil
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type DiskAddRequest struct {
ComputeID uint64 `url:"computeId"`
DiskName string `url:"diskName"`
Size uint64 `url:"size"`
DiskType string `url:"diskType,omitempty"`
SepID uint64 `url:"sepId,omitempty"`
Pool string `url:"pool,omitempty"`
Description string `url:"desc,omitempty"`
ImageID uint64 `url:"imageId,omitempty"`
}
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.Size == 0 {
return errors.New("validation-error: field Size can not be empty or equal to 0")
}
if crq.DiskName == "" {
return errors.New("validation-error: field DiskName can not be empty or equal to 0")
}
return nil
}
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudapi/compute/diskAdd"
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, err
}
return result, nil
}

@ -1,56 +1,46 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DiskAttachRequest struct {
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.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
return nil
}
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/diskAttach"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type DiskAttachRequest struct {
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.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
return nil
}
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/diskAttach"
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, err
}
return result, nil
}

@ -1,57 +1,47 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DiskDelRequest struct {
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.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
return nil
}
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/diskDel"
prefix := "/cloudapi"
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)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
type DiskDelRequest struct {
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.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
return nil
}
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/compute/diskDel"
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, err
}
return result, nil
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save