parent
6271fa6d45
commit
5fd450382c
@ -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
|
package decortsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/rudecs/decort-sdk/pkg/cloudapi"
|
||||||
"github.com/rudecs/decort-sdk/config"
|
"github.com/rudecs/decort-sdk/pkg/cloudbroker"
|
||||||
"github.com/rudecs/decort-sdk/internal/client"
|
|
||||||
)
|
"github.com/google/go-querystring/query"
|
||||||
|
"github.com/rudecs/decort-sdk/config"
|
||||||
type Client struct {
|
"github.com/rudecs/decort-sdk/internal/client"
|
||||||
decortUrl string
|
)
|
||||||
client *http.Client
|
|
||||||
}
|
type Client struct {
|
||||||
|
decortURL string
|
||||||
func New(cfg config.Config) *Client {
|
client *http.Client
|
||||||
if cfg.Retries == 0 {
|
}
|
||||||
cfg.Retries = 5
|
|
||||||
}
|
func New(cfg config.Config) *Client {
|
||||||
|
if cfg.Retries == 0 {
|
||||||
return &Client{
|
cfg.Retries = 5
|
||||||
decortUrl: cfg.DecortURL,
|
}
|
||||||
client: client.NewHttpClient(cfg),
|
|
||||||
}
|
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
|
func (dc *Client) CloudApi() *cloudapi.CloudApi {
|
||||||
}
|
return cloudapi.New(dc)
|
||||||
|
}
|
||||||
body := strings.NewReader(values.Encode())
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortUrl+"/restmachine"+url, body)
|
func (dc *Client) CloudBroker() *cloudbroker.CloudBroker {
|
||||||
if err != nil {
|
return cloudbroker.New(dc)
|
||||||
return nil, err
|
}
|
||||||
}
|
|
||||||
|
func (dc *Client) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||||
resp, err := dc.client.Do(req)
|
values, err := query.Values(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
|
||||||
|
body := strings.NewReader(values.Encode())
|
||||||
respBytes, err := io.ReadAll(resp.Body)
|
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
resp, err := dc.client.Do(req)
|
||||||
return nil, errors.New(string(respBytes))
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
return respBytes, nil
|
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
|
package config
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AppID string
|
AppID string
|
||||||
AppSecret string
|
AppSecret string
|
||||||
SSOURL string
|
SSOURL string
|
||||||
DecortURL string
|
DecortURL string
|
||||||
Retries uint64
|
Retries uint64
|
||||||
SSLSkipVerify bool
|
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
|
package interfaces
|
||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
type Caller interface {
|
type Caller interface {
|
||||||
DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error)
|
DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,32 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rudecs/decort-sdk/config"
|
"github.com/rudecs/decort-sdk/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewHttpClient(cfg config.Config) *http.Client {
|
func NewHttpClient(cfg config.Config) *http.Client {
|
||||||
|
|
||||||
transCfg := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: cfg.SSLSkipVerify}}
|
transCfg := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
return &http.Client{
|
//nolint:gosec
|
||||||
Transport: &transport{
|
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||||
base: transCfg,
|
},
|
||||||
retries: cfg.Retries,
|
}
|
||||||
clientId: cfg.AppID,
|
|
||||||
clientSecret: cfg.AppSecret,
|
return &http.Client{
|
||||||
ssoUrl: cfg.SSOURL,
|
Transport: &transport{
|
||||||
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
base: transCfg,
|
||||||
},
|
retries: cfg.Retries,
|
||||||
|
clientID: cfg.AppID,
|
||||||
Timeout: 5 * time.Minute,
|
clientSecret: cfg.AppSecret,
|
||||||
}
|
SSOURL: cfg.SSOURL,
|
||||||
}
|
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
},
|
||||||
|
|
||||||
|
Timeout: 5 * time.Minute,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,67 +1,67 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type transport struct {
|
type transport struct {
|
||||||
base http.RoundTripper
|
base http.RoundTripper
|
||||||
retries uint64
|
retries uint64
|
||||||
clientId string
|
clientID string
|
||||||
clientSecret string
|
clientSecret string
|
||||||
token string
|
token string
|
||||||
ssoUrl string
|
SSOURL string
|
||||||
expiryTime time.Time
|
expiryTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
if t.token == "" || time.Now().After(t.expiryTime) {
|
if t.token == "" || time.Now().After(t.expiryTime) {
|
||||||
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientId, t.clientSecret)
|
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientID, t.clientSecret)
|
||||||
bodyReader := strings.NewReader(body)
|
bodyReader := strings.NewReader(body)
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", t.ssoUrl+"/v1/oauth/access_token", bodyReader)
|
req, _ := http.NewRequestWithContext(req.Context(), "POST", t.SSOURL+"/v1/oauth/access_token", bodyReader)
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
resp, err := t.base.RoundTrip(req)
|
resp, err := t.base.RoundTrip(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot get token: %v", err)
|
return nil, fmt.Errorf("cannot get token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return nil, fmt.Errorf("cannot get token: %s", tokenBytes)
|
return nil, fmt.Errorf("cannot get token: %s", tokenBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
token := string(tokenBytes)
|
token := string(tokenBytes)
|
||||||
|
|
||||||
t.token = token
|
t.token = token
|
||||||
t.expiryTime = time.Now().AddDate(0, 0, 1)
|
t.expiryTime = time.Now().AddDate(0, 0, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
req.Header.Add("Authorization", "bearer "+t.token)
|
req.Header.Add("Authorization", "bearer "+t.token)
|
||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var err error
|
var err error
|
||||||
for i := uint64(0); i < t.retries; i++ {
|
for i := uint64(0); i < t.retries; i++ {
|
||||||
resp, err = t.base.RoundTrip(req)
|
resp, err = t.base.RoundTrip(req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if resp.StatusCode == 200 {
|
if resp.StatusCode == 200 {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
err = fmt.Errorf("%s", respBytes)
|
err = fmt.Errorf("%s", respBytes)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
//logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries)
|
//logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries)
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("could not execute request: %v", err)
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package validators
|
package validators
|
||||||
|
|
||||||
func StringInSlice(str string, target []string) bool {
|
func StringInSlice(str string, target []string) bool {
|
||||||
for _, v := range target {
|
for _, v := range target {
|
||||||
if v == str {
|
if v == str {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rudecs/decort-sdk/interfaces"
|
"github.com/rudecs/decort-sdk/interfaces"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
client interfaces.Caller
|
client interfaces.Caller
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client interfaces.Caller) *Account {
|
func New(client interfaces.Caller) *Account {
|
||||||
return &Account{
|
return &Account{
|
||||||
client,
|
client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,68 +1,58 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/internal/validators"
|
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
"github.com/rudecs/decort-sdk/internal/validators"
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
)
|
||||||
)
|
|
||||||
|
type AddUserRequest struct {
|
||||||
type AddUserRequest struct {
|
AccountID uint64 `url:"accountId"`
|
||||||
AccountId uint64 `url:"accountId"`
|
UserID string `url:"userId"`
|
||||||
UserId string `url:"userId"`
|
AccessType string `url:"accesstype"`
|
||||||
AccessType string `url:"accesstype"`
|
}
|
||||||
}
|
|
||||||
|
func (arq AddUserRequest) Validate() error {
|
||||||
func (arq AddUserRequest) Validate() error {
|
if arq.AccountID == 0 {
|
||||||
if arq.AccountId == 0 {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
}
|
||||||
}
|
|
||||||
|
if arq.UserID == "" {
|
||||||
if arq.UserId == "" {
|
return errors.New("validation-error: field UserID can not be empty")
|
||||||
return errors.New("validation-error: field UserId can not be empty")
|
}
|
||||||
}
|
|
||||||
|
if arq.AccessType == "" {
|
||||||
if arq.AccessType == "" {
|
return errors.New("validation-error: field AccessType can not be empty")
|
||||||
return errors.New("validation-error: field AccessType can not be empty")
|
}
|
||||||
}
|
|
||||||
|
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
|
||||||
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
|
if !isValid {
|
||||||
if !isValid {
|
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
|
||||||
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
|
}
|
||||||
}
|
|
||||||
|
return nil
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
|
||||||
func (a Account) AddUser(ctx context.Context, req AddUserRequest, options ...opts.DecortOpts) (bool, error) {
|
err := req.Validate()
|
||||||
err := req.Validate()
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
}
|
||||||
}
|
|
||||||
|
url := "/cloudapi/account/addUser"
|
||||||
url := "/account/addUser"
|
|
||||||
prefix := "/cloudapi"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
option := opts.New(options)
|
return false, err
|
||||||
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AuditsRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type AuditsRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq AuditsRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq AuditsRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) Audits(ctx context.Context, req AuditsRequest) (AccountAuditsList, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AccountAuditsList, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/audits"
|
||||||
|
|
||||||
url := "/account/audits"
|
auditsRaw, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
audits := AccountAuditsList{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(auditsRaw, &audits)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
auditsRaw, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return audits, nil
|
||||||
return nil, err
|
}
|
||||||
}
|
|
||||||
|
|
||||||
audits := AccountAuditsList{}
|
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(auditsRaw), &audits)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return audits, nil
|
|
||||||
}
|
|
||||||
|
@ -1,65 +1,54 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type CreateRequest struct {
|
||||||
|
Name string `url:"name"`
|
||||||
type CreateRequest struct {
|
Username string `url:"username"`
|
||||||
Name string `url:"name"`
|
EmailAddress string `url:"emailaddress,omitempty"`
|
||||||
Username string `url:"username"`
|
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
|
||||||
EmailAddress string `url:"emailaddress,omitempty"`
|
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
|
||||||
MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"`
|
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
|
||||||
MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"`
|
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
|
||||||
MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"`
|
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
|
||||||
MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
|
||||||
MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"`
|
GPUUnits uint64 `url:"gpu_units,omitempty"`
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
|
}
|
||||||
GpuUnits uint `url:"gpu_units,omitempty"`
|
|
||||||
}
|
func (arq CreateRequest) Validate() error {
|
||||||
|
if arq.Name == "" {
|
||||||
func (arq CreateRequest) Validate() error {
|
return errors.New("validation-error: field Name can not be empty")
|
||||||
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")
|
||||||
if arq.Username == "" {
|
}
|
||||||
return errors.New("validation-error: field Username can not be empty")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return 0, err
|
||||||
if err != nil {
|
}
|
||||||
return 0, err
|
|
||||||
}
|
url := "/cloudbroker/account/create"
|
||||||
|
|
||||||
url := "/account/create"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
if option.IsAdmin {
|
if err != nil {
|
||||||
prefix = "/" + option.AdminValue
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
url = prefix + url
|
return result, nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,52 +1,36 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
)
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
type DeleteRequest struct {
|
||||||
)
|
AccountID uint64 `url:"accountId"`
|
||||||
|
Permanently bool `url:"permanently,omitempty"`
|
||||||
type DeleteRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
Permanently bool `url:"permanently,omitempty"`
|
func (arq DeleteRequest) Validate() error {
|
||||||
}
|
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq DeleteRequest) Validate() error {
|
return errors.New("validation-error: field AccountID must be set")
|
||||||
|
}
|
||||||
if arq.AccountId == 0 {
|
return nil
|
||||||
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 {
|
||||||
func (a Account) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
return false, err
|
||||||
err := req.Validate()
|
}
|
||||||
if err != nil {
|
|
||||||
return false, err
|
url := "/cloudapi/account/delete"
|
||||||
}
|
|
||||||
|
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
url := "/account/delete"
|
if err != nil {
|
||||||
prefix := "/cloudapi"
|
return false, err
|
||||||
|
}
|
||||||
option := opts.New(options)
|
|
||||||
if option != nil {
|
return true, 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
|
|
||||||
}
|
|
||||||
|
@ -1,58 +1,47 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type DeleteUserRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type DeleteUserRequest struct {
|
UserID string `url:"userId"`
|
||||||
AccountId uint64 `url:"accountId"`
|
RecursiveDelete bool `url:"recursivedelete,omitempty"`
|
||||||
UserId string `url:"userId"`
|
}
|
||||||
RecursiveDelete bool `url:"recursivedelete,omitempty"`
|
|
||||||
}
|
func (arq DeleteUserRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq DeleteUserRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
if arq.UserID == "" {
|
||||||
|
return errors.New("validation-error: field UserID can not be empty")
|
||||||
if arq.UserId == "" {
|
}
|
||||||
return errors.New("validation-error: field UserId can not be empty")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/account/deleteUser"
|
||||||
|
|
||||||
url := "/account/deleteUser"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
result, err := strconv.ParseBool(string(res))
|
||||||
if option.IsAdmin {
|
if err != nil {
|
||||||
prefix = "/" + option.AdminValue
|
return false, err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
url = prefix + url
|
return result, nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,80 +1,62 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type DisabelEnableRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type DisabelEnableRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq DisabelEnableRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq DisabelEnableRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/account/disable"
|
||||||
|
|
||||||
url := "/account/disable"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
result, err := strconv.ParseBool(string(res))
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
}
|
||||||
}
|
|
||||||
|
url := "/cloudapi/account/enable"
|
||||||
return result, nil
|
|
||||||
}
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
return false, err
|
||||||
err := req.Validate()
|
}
|
||||||
if err != nil {
|
|
||||||
return false, err
|
result, err := strconv.ParseBool(string(res))
|
||||||
}
|
if err != nil {
|
||||||
|
return false, err
|
||||||
url := "/account/enable"
|
}
|
||||||
prefix := "/cloudapi"
|
|
||||||
|
return result, nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,55 +1,44 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type GetRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type GetRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq GetRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq GetRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) Get(ctx context.Context, req GetRequest) (*AccountWithResources, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*AccountWithResources, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/get"
|
||||||
|
|
||||||
url := "/account/get"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
account := &AccountWithResources{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &account)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return account, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type GetConsumedAccountUnitsRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type GetConsumedAccountUnitsRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq GetConsumedAccountUnitsRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq GetConsumedAccountUnitsRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest) (*ResourceLimits, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/getConsumedAccountUnits"
|
||||||
|
|
||||||
url := "/account/getConsumedAccountUnits"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
rl := &ResourceLimits{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &rl)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return rl, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/internal/validators"
|
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
"github.com/rudecs/decort-sdk/internal/validators"
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
)
|
||||||
)
|
|
||||||
|
type GetConsumedCloudUnitsByTypeRequest struct {
|
||||||
type GetConsumedCloudUnitsByTypeRequest struct {
|
AccountID uint64 `url:"accountId"`
|
||||||
AccountId uint64 `url:"accountId"`
|
CUType string `url:"cutype"`
|
||||||
CUType string `url:"cutype"`
|
}
|
||||||
}
|
|
||||||
|
func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error {
|
||||||
func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error {
|
if arq.AccountID == 0 {
|
||||||
if arq.AccountId == 0 {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
}
|
||||||
}
|
|
||||||
|
if arq.CUType == "" {
|
||||||
if arq.CUType == "" {
|
return errors.New("validation-error: field CUType can not be empty")
|
||||||
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"})
|
||||||
isValid := validators.StringInSlice(arq.CUType, []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"})
|
if !isValid {
|
||||||
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 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
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest) (float64, error) {
|
||||||
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest, options ...opts.DecortOpts) (float64, error) {
|
err := req.Validate()
|
||||||
err := req.Validate()
|
if err != nil {
|
||||||
if err != nil {
|
return 0, err
|
||||||
return 0, err
|
}
|
||||||
}
|
|
||||||
|
url := "/cloudapi/account/getConsumedCloudUnitsByType"
|
||||||
url := "/account/getConsumedCloudUnitsByType"
|
|
||||||
prefix := "/cloudapi"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
option := opts.New(options)
|
return 0, err
|
||||||
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseFloat(string(res), 64)
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return 0, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type GetConsumtionRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type GetConsumtionRequest struct {
|
Start uint64 `url:"start"`
|
||||||
AccountId uint64 `url:"accountId"`
|
End uint64 `url:"end"`
|
||||||
Start uint64 `url:"start"`
|
}
|
||||||
End uint64 `url:"end"`
|
|
||||||
}
|
func (arq GetConsumtionRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq GetConsumtionRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
if arq.Start == 0 {
|
||||||
|
return errors.New("validation-error: field Start 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")
|
||||||
if arq.End == 0 {
|
}
|
||||||
return errors.New("validation-error: field End can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest) (string, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return "", err
|
||||||
if err != nil {
|
}
|
||||||
return "", err
|
|
||||||
}
|
url := "/cloudapi/account/getConsumtion"
|
||||||
|
|
||||||
url := "/account/getConsumtion"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return "", err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
return string(res), nil
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
}
|
||||||
}
|
|
||||||
}
|
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest) (string, error) {
|
||||||
url = prefix + url
|
err := req.Validate()
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
if err != nil {
|
||||||
if err != nil {
|
return "", err
|
||||||
return "", err
|
}
|
||||||
}
|
|
||||||
|
url := "/account/getConsumtion"
|
||||||
return string(res), nil
|
prefix := "/cloudapi"
|
||||||
|
|
||||||
}
|
url = prefix + url
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||||
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return "", err
|
||||||
if err != nil {
|
}
|
||||||
return "", err
|
|
||||||
}
|
return string(res), nil
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,55 +1,44 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type GetReservedAccountUnitsRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type GetReservedAccountUnitsRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq GetReservedAccountUnitsRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq GetReservedAccountUnitsRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest) (*ResourceLimits, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/getReservedAccountUnits"
|
||||||
|
|
||||||
url := "/account/getReservedAccountUnits"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
rl := &ResourceLimits{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &rl)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return rl, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type ListRequest struct {
|
||||||
|
Page uint64 `url:"page"`
|
||||||
type ListRequest struct {
|
Size uint64 `url:"size"`
|
||||||
Page uint64 `url:"page"`
|
}
|
||||||
Size uint64 `url:"size"`
|
|
||||||
}
|
func (a Account) List(ctx context.Context, req ListRequest) (AccountCloudApiList, error) {
|
||||||
|
url := "/cloudapi/account/list"
|
||||||
func (a Account) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
|
|
||||||
url := "/account/list"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
accountList := AccountCloudApiList{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &accountList)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return accountList, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type ListComputesRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type ListComputesRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq ListComputesRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq ListComputesRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (AccountComputesList, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (AccountComputesList, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/listComputes"
|
||||||
|
|
||||||
url := "/account/listComputes"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
accountComputesList := AccountComputesList{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &accountComputesList)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return accountComputesList, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type ListDeletedRequest struct {
|
||||||
|
Page uint64 `url:"page"`
|
||||||
type ListDeletedRequest struct {
|
Size uint64 `url:"size"`
|
||||||
Page uint64 `url:"page"`
|
}
|
||||||
Size uint64 `url:"size"`
|
|
||||||
}
|
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (AccountCloudApiList, error) {
|
||||||
|
url := "/cloudapi/account/listDeleted"
|
||||||
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
|
|
||||||
url := "/account/listDeleted"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
accountList := AccountCloudApiList{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &accountList)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return accountList, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type ListDisksRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type ListDisksRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq ListDisksRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq ListDisksRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (AccountDisksList, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest, options ...opts.DecortOpts) (AccountDisksList, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/listDisks"
|
||||||
|
|
||||||
url := "/account/listDisks"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
accountDisksList := AccountDisksList{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &accountDisksList)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return accountDisksList, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type ListFlipGroupsRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type ListFlipGroupsRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq ListFlipGroupsRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq ListFlipGroupsRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest) (AccountFlipGroupsList, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest, options ...opts.DecortOpts) (AccountFlipGroupsList, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/listFlipGroups"
|
||||||
|
|
||||||
url := "/account/listFlipGroups"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
accountFlipGroupsList := AccountFlipGroupsList{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &accountFlipGroupsList)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return accountFlipGroupsList, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type ListRGRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type ListRGRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq ListRGRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq ListRGRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (AccountRGList, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) ListRG(ctx context.Context, req ListRGRequest, options ...opts.DecortOpts) (AccountRGList, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/listRG"
|
||||||
|
|
||||||
url := "/account/listRG"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
accountRGList := AccountRGList{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &accountRGList)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return accountRGList, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type ListTemplatesRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type ListTemplatesRequest struct {
|
IncludeDeleted bool `url:"includedeleted"`
|
||||||
AccountId uint64 `url:"accountId"`
|
}
|
||||||
IncludeDeleted bool `url:"includedeleted"`
|
|
||||||
}
|
func (arq ListTemplatesRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq ListTemplatesRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (AccountTemplatesList, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest, options ...opts.DecortOpts) (AccountTemplatesList, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/listTemplates"
|
||||||
|
|
||||||
url := "/account/listTemplates"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
accountTemplatesList := AccountTemplatesList{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &accountTemplatesList)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return accountTemplatesList, 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
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type ListVINSRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type ListVinsRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq ListVINSRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq ListVinsRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (AccountVINSList, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) ListVins(ctx context.Context, req ListVinsRequest, options ...opts.DecortOpts) (AccountVinsList, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/account/listVins"
|
||||||
|
|
||||||
url := "/account/listVins"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
accountVINSList := AccountVINSList{}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
err = json.Unmarshal(res, &accountVINSList)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return accountVINSList, 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
|
package account
|
||||||
|
|
||||||
type AccountAclRecord struct {
|
type AccountACLRecord struct {
|
||||||
IsExplicit bool `json:"explicit"`
|
IsExplicit bool `json:"explicit"`
|
||||||
GUID string `json:"guid"`
|
GUID string `json:"guid"`
|
||||||
Rights string `json:"right"`
|
Rights string `json:"right"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
UgroupID string `json:"userGroupId"`
|
UgroupID string `json:"userGroupId"`
|
||||||
CanBeDeleted bool `json:"canBeDeleted"`
|
CanBeDeleted bool `json:"canBeDeleted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceLimits struct {
|
type ResourceLimits struct {
|
||||||
CUC float64 `json:"CU_C"`
|
CUC float64 `json:"CU_C"`
|
||||||
CUD float64 `json:"CU_D"`
|
CUD float64 `json:"CU_D"`
|
||||||
CUI float64 `json:"CU_I"`
|
CUI float64 `json:"CU_I"`
|
||||||
CUM float64 `json:"CU_M"`
|
CUM float64 `json:"CU_M"`
|
||||||
CUNP float64 `json:"CU_NP"`
|
CUNP float64 `json:"CU_NP"`
|
||||||
GpuUnits float64 `json:"gpu_units"`
|
GPUUnits float64 `json:"gpu_units"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountRecord struct {
|
type AccountRecord struct {
|
||||||
DCLocation string `json:"DCLocation"`
|
DCLocation string `json:"DCLocation"`
|
||||||
CKey string `jspn:"_ckey"`
|
CKey string `jspn:"_ckey"`
|
||||||
Meta []interface{} `json:"_meta"`
|
Meta []interface{} `json:"_meta"`
|
||||||
Acl []AccountAclRecord `json:"acl"`
|
ACL []AccountACLRecord `json:"acl"`
|
||||||
Company string `json:"company"`
|
Company string `json:"company"`
|
||||||
CompanyUrl string `json:"companyurl"`
|
CompanyURL string `json:"companyurl"`
|
||||||
CreatedBy string `jspn:"createdBy"`
|
CreatedBy string `jspn:"createdBy"`
|
||||||
CreatedTime int `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
DeactiovationTime float64 `json:"deactivationTime"`
|
DeactiovationTime float64 `json:"deactivationTime"`
|
||||||
DeletedBy string `json:"deletedBy"`
|
DeletedBy string `json:"deletedBy"`
|
||||||
DeletedTime int `json:"deletedTime"`
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
DisplayName string `json:"displayname"`
|
DisplayName string `json:"displayname"`
|
||||||
GUID int `json:"guid"`
|
GUID uint64 `json:"guid"`
|
||||||
ID int `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
SendAccessEmails bool `json:"sendAccessEmails"`
|
||||||
ServiceAccount bool `json:"serviceAccount"`
|
ServiceAccount bool `json:"serviceAccount"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
UpdatedTime int `json:"updatedTime"`
|
UpdatedTime uint64 `json:"updatedTime"`
|
||||||
Version int `json:"version"`
|
Version uint64 `json:"version"`
|
||||||
Vins []int `json:"vins"`
|
VINS []uint64 `json:"vins"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountList []AccountRecord
|
type AccountList []AccountRecord
|
||||||
|
|
||||||
type AccountCloudApi struct {
|
type AccountCloudApi struct {
|
||||||
Acl []AccountAclRecord `json:"acl"`
|
ACL []AccountACLRecord `json:"acl"`
|
||||||
CreatedTime int `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
DeletedTime int `json:"deletedTime"`
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
ID int `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
UpdatedTime int `json:"updatedTime"`
|
UpdatedTime uint64 `json:"updatedTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountCloudApiList []AccountCloudApi
|
type AccountCloudApiList []AccountCloudApi
|
||||||
|
|
||||||
type Resource struct {
|
type Resource struct {
|
||||||
CPU int `json:"cpu"`
|
CPU int64 `json:"cpu"`
|
||||||
Disksize int `json:"disksize"`
|
DiskSize int64 `json:"disksize"`
|
||||||
Extips int `json:"extips"`
|
ExtIPs int64 `json:"extips"`
|
||||||
Exttraffic int `json:"exttraffic"`
|
ExtTraffic int64 `json:"exttraffic"`
|
||||||
GPU int `json:"gpu"`
|
GPU int64 `json:"gpu"`
|
||||||
RAM int `json:"ram"`
|
RAM int64 `json:"ram"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Resources struct {
|
type Resources struct {
|
||||||
Current Resource `json:"Current"`
|
Current Resource `json:"Current"`
|
||||||
Reserved Resource `json:"Reserved"`
|
Reserved Resource `json:"Reserved"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Computes struct {
|
type Computes struct {
|
||||||
Started int `json:"started"`
|
Started uint64 `json:"started"`
|
||||||
Stopped int `json:"stopped"`
|
Stopped uint64 `json:"stopped"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Machines struct {
|
type Machines struct {
|
||||||
Running int `json:"running"`
|
Running uint64 `json:"running"`
|
||||||
Halted int `json:"halted"`
|
Halted uint64 `json:"halted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountWithResources struct {
|
type AccountWithResources struct {
|
||||||
Account
|
Account
|
||||||
Resources Resources `json:"Resources"`
|
Resources Resources `json:"Resources"`
|
||||||
Computes Computes `json:"computes"`
|
Computes Computes `json:"computes"`
|
||||||
Machines Machines `json:"machines"`
|
Machines Machines `json:"machines"`
|
||||||
Vinses int `json:"vinses"`
|
VINSes uint64 `json:"vinses"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountCompute struct {
|
type AccountCompute struct {
|
||||||
AccountId int `json:"accountId"`
|
AccountID uint64 `json:"accountId"`
|
||||||
AccountName string `json:"accountName"`
|
AccountName string `json:"accountName"`
|
||||||
CPUs int `json:"cpus"`
|
CPUs uint64 `json:"cpus"`
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
CreatedTime int `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
DeletedBy string `json:"deletedBy"`
|
DeletedBy string `json:"deletedBy"`
|
||||||
DeletedTime int `json:"deletedTime"`
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
ComputeId int `json:"id"`
|
ComputeID uint64 `json:"id"`
|
||||||
ComputeName string `json:"name"`
|
ComputeName string `json:"name"`
|
||||||
RAM int `json:"ram"`
|
RAM uint64 `json:"ram"`
|
||||||
Registered bool `json:"registered"`
|
Registered bool `json:"registered"`
|
||||||
RGId int `json:"rgId"`
|
RGID uint64 `json:"rgId"`
|
||||||
RGName string `json:"rgName"`
|
RGName string `json:"rgName"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
TechStatus string `json:"techStatus"`
|
TechStatus string `json:"techStatus"`
|
||||||
TotalDisksSize int `json:"totalDisksSize"`
|
TotalDisksSize uint64 `json:"totalDisksSize"`
|
||||||
UpdatedBy string `json:"updatedBy"`
|
UpdatedBy string `json:"updatedBy"`
|
||||||
UpdatedTime int `json:"updatedTime"`
|
UpdatedTime uint64 `json:"updatedTime"`
|
||||||
UserManaged bool `json:"userManaged"`
|
UserManaged bool `json:"userManaged"`
|
||||||
VinsConnected int `json:"vinsConnected"`
|
VINSConnected uint64 `json:"vinsConnected"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountComputesList []AccountCompute
|
type AccountComputesList []AccountCompute
|
||||||
|
|
||||||
type AccountDisk struct {
|
type AccountDisk struct {
|
||||||
ID int `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Pool string `json:"pool"`
|
Pool string `json:"pool"`
|
||||||
SepId int `json:"sepId"`
|
SepID uint64 `json:"sepId"`
|
||||||
SizeMax int `json:"sizeMax"`
|
SizeMax uint64 `json:"sizeMax"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountDisksList []AccountDisk
|
type AccountDisksList []AccountDisk
|
||||||
|
|
||||||
type AccountVin struct {
|
type AccountVIN struct {
|
||||||
AccountId int `json:"accountId"`
|
AccountID uint64 `json:"accountId"`
|
||||||
AccountName string `json:"accountName"`
|
AccountName string `json:"accountName"`
|
||||||
Computes int `json:"computes"`
|
Computes uint64 `json:"computes"`
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
CreatedTime int `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
DeletedBy string `json:"deletedBy"`
|
DeletedBy string `json:"deletedBy"`
|
||||||
DeletedTime int `json:"deletedTime"`
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
ExternalIP string `json:"externalIP"`
|
ExternalIP string `json:"externalIP"`
|
||||||
ID int `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
PriVnfDevId int `json:"priVnfDevId"`
|
PriVnfDevID uint64 `json:"priVnfDevId"`
|
||||||
RGId int `json:"rgId"`
|
RGID uint64 `json:"rgId"`
|
||||||
RGName string `json:"rgName"`
|
RGName string `json:"rgName"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
UpdatedBy string `json:"updatedBy"`
|
UpdatedBy string `json:"updatedBy"`
|
||||||
UpdatedTime int `json:"updatedTime"`
|
UpdatedTime uint64 `json:"updatedTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountVinsList []AccountVin
|
type AccountVINSList []AccountVIN
|
||||||
|
|
||||||
type AccountAudit struct {
|
type AccountAudit struct {
|
||||||
Call string `json:"call"`
|
Call string `json:"call"`
|
||||||
ResponseTime float64 `json:"responsetime"`
|
ResponseTime float64 `json:"responsetime"`
|
||||||
StatusCode int `json:"statuscode"`
|
StatusCode uint64 `json:"statuscode"`
|
||||||
Timestamp float64 `json:"timestamp"`
|
Timestamp float64 `json:"timestamp"`
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountAuditsList []AccountAudit
|
type AccountAuditsList []AccountAudit
|
||||||
|
|
||||||
type AccountRGComputes struct {
|
type AccountRGComputes struct {
|
||||||
Started int `json:"Started"`
|
Started uint64 `json:"Started"`
|
||||||
Stopped int `json:"Stopped"`
|
Stopped uint64 `json:"Stopped"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountRGResources struct {
|
type AccountRGResources struct {
|
||||||
Consumed Resource `json:"Consumed"`
|
Consumed Resource `json:"Consumed"`
|
||||||
Limits Resource `json:"Limits"`
|
Limits Resource `json:"Limits"`
|
||||||
Reserved Resource `json:"Reserved"`
|
Reserved Resource `json:"Reserved"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountRG struct {
|
type AccountRG struct {
|
||||||
Computes AccountRGComputes `json:"Computes"`
|
Computes AccountRGComputes `json:"Computes"`
|
||||||
Resources AccountRGResources `json:"Resources"`
|
Resources AccountRGResources `json:"Resources"`
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
CreatedTime int `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
DeletedBy string `json:"deletedBy"`
|
DeletedBy string `json:"deletedBy"`
|
||||||
DeletedTime int `json:"deletedTime"`
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
RGID int `json:"id"`
|
RGID uint64 `json:"id"`
|
||||||
Milestones int `json:"milestones"`
|
Milestones uint64 `json:"milestones"`
|
||||||
RGName string `json:"name"`
|
RGName string `json:"name"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
UpdatedBy string `json:"updatedBy"`
|
UpdatedBy string `json:"updatedBy"`
|
||||||
UpdatedTime int `json:"updatedTime"`
|
UpdatedTime uint64 `json:"updatedTime"`
|
||||||
Vinses int `json:"vinses"`
|
VINSes uint64 `json:"vinses"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountRGList []AccountRG
|
type AccountRGList []AccountRG
|
||||||
|
|
||||||
type AccountTemplate struct {
|
type AccountTemplate struct {
|
||||||
UNCPath string `json:"UNCPath"`
|
UNCPath string `json:"UNCPath"`
|
||||||
AccountId int `json:"accountId"`
|
AccountID uint64 `json:"accountId"`
|
||||||
Description string `json:"desc"`
|
Description string `json:"desc"`
|
||||||
ID int `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Public bool `json:"public"`
|
Public bool `json:"public"`
|
||||||
Size int `json:"size"`
|
Size uint64 `json:"size"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountTemplatesList []AccountTemplate
|
type AccountTemplatesList []AccountTemplate
|
||||||
|
|
||||||
type AccountFlipGroup struct {
|
type AccountFlipGroup struct {
|
||||||
AccountId int `json:"accountId"`
|
AccountID uint64 `json:"accountId"`
|
||||||
ClientType string `json:"clientType"`
|
ClientType string `json:"clientType"`
|
||||||
ConnType string `json:"connType"`
|
ConnType string `json:"connType"`
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
CreatedTime int `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
DefaultGW string `json:"defaultGW"`
|
DefaultGW string `json:"defaultGW"`
|
||||||
DeletedBy string `json:"deletedBy"`
|
DeletedBy string `json:"deletedBy"`
|
||||||
DeletedTime int `json:"deletedTime"`
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
Description string `json:"desc"`
|
Description string `json:"desc"`
|
||||||
GID int `json:"gid"`
|
GID uint64 `json:"gid"`
|
||||||
GUID int `json:"guid"`
|
GUID uint64 `json:"guid"`
|
||||||
ID int `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
Milestones int `json:"milestones"`
|
Milestones uint64 `json:"milestones"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
NetID int `json:"netId"`
|
NetID uint64 `json:"netId"`
|
||||||
NetType string `json:"netType"`
|
NetType string `json:"netType"`
|
||||||
NetMask int `json:"netmask"`
|
NetMask uint64 `json:"netmask"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
UpdatedBy string `json:"updatedBy"`
|
UpdatedBy string `json:"updatedBy"`
|
||||||
UpdatedTime int `json:"updatedTime"`
|
UpdatedTime uint64 `json:"updatedTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountFlipGroupsList []AccountFlipGroup
|
type AccountFlipGroupsList []AccountFlipGroup
|
||||||
|
@ -1,53 +1,42 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type RestoreRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type RestoreRequest struct {
|
}
|
||||||
AccountId uint64 `url:"accountId"`
|
|
||||||
}
|
func (arq RestoreRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq RestoreRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/account/restore"
|
||||||
|
|
||||||
url := "/account/restore"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
result, err := strconv.ParseBool(string(res))
|
||||||
if option.IsAdmin {
|
if err != nil {
|
||||||
prefix = "/" + option.AdminValue
|
return false, err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
url = prefix + url
|
return result, nil
|
||||||
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
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,60 +1,49 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type UpdateRequest struct {
|
||||||
|
AccountID uint64 `url:"accountId"`
|
||||||
type UpdateRequest struct {
|
Name string `url:"name,omitempty"`
|
||||||
AccountId uint64 `url:"accountId"`
|
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
|
||||||
Name string `url:"name,omitempty"`
|
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
|
||||||
MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"`
|
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
|
||||||
MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"`
|
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
|
||||||
MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"`
|
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
|
||||||
MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
|
||||||
MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"`
|
GPUUnits uint64 `url:"gpu_units,omitempty"`
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
|
}
|
||||||
GpuUnits uint `url:"gpu_units,omitempty"`
|
|
||||||
}
|
func (arq UpdateRequest) Validate() error {
|
||||||
|
if arq.AccountID == 0 {
|
||||||
func (arq UpdateRequest) Validate() error {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
if arq.AccountId == 0 {
|
}
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (a Account) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/account/update"
|
||||||
|
|
||||||
url := "/account/update"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
|
|
||||||
if option != nil {
|
result, err := strconv.ParseBool(string(res))
|
||||||
if option.IsAdmin {
|
if err != nil {
|
||||||
prefix = "/" + option.AdminValue
|
return false, err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
url = prefix + url
|
return result, nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,68 +1,58 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/internal/validators"
|
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
"github.com/rudecs/decort-sdk/internal/validators"
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
)
|
||||||
)
|
|
||||||
|
type UpdateUserRequest struct {
|
||||||
type UpdateUserRequest struct {
|
AccountID uint64 `url:"accountId"`
|
||||||
AccountId uint64 `url:"accountId"`
|
UserID string `url:"userId"`
|
||||||
UserId string `url:"userId"`
|
AccessType string `url:"accesstype"`
|
||||||
AccessType string `url:"accesstype"`
|
}
|
||||||
}
|
|
||||||
|
func (arq UpdateUserRequest) Validate() error {
|
||||||
func (arq UpdateUserRequest) Validate() error {
|
if arq.AccountID == 0 {
|
||||||
if arq.AccountId == 0 {
|
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
}
|
||||||
}
|
|
||||||
|
if arq.UserID == "" {
|
||||||
if arq.UserId == "" {
|
return errors.New("validation-error: field UserID can not be empty")
|
||||||
return errors.New("validation-error: field UserId can not be empty")
|
}
|
||||||
}
|
|
||||||
|
if arq.AccessType == "" {
|
||||||
if arq.AccessType == "" {
|
return errors.New("validation-error: field AccessType can not be empty")
|
||||||
return errors.New("validation-error: field AccessType can not be empty")
|
}
|
||||||
}
|
|
||||||
|
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
|
||||||
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
|
if !isValid {
|
||||||
if !isValid {
|
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
|
||||||
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
|
}
|
||||||
}
|
|
||||||
|
return nil
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
|
||||||
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest, options ...opts.DecortOpts) (bool, error) {
|
err := req.Validate()
|
||||||
err := req.Validate()
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
}
|
||||||
}
|
|
||||||
|
url := "/cloudapi/account/updateUser"
|
||||||
url := "/account/updateUser"
|
|
||||||
prefix := "/cloudapi"
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
option := opts.New(options)
|
return false, err
|
||||||
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
@ -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
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AffinityGroupCheckStartRequest struct {
|
||||||
|
RGID uint64 `url:"rgId"`
|
||||||
type AffinityGroupCheckStartRequest struct {
|
AffinityLabel string `url:"affinityLabel"`
|
||||||
RGID uint64 `url:"rgId"`
|
}
|
||||||
AffinityLabel string `url:"affinityLabel"`
|
|
||||||
}
|
func (crq AffinityGroupCheckStartRequest) Validate() error {
|
||||||
|
if crq.RGID == 0 {
|
||||||
func (crq AffinityGroupCheckStartRequest) Validate() error {
|
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||||
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")
|
||||||
if crq.AffinityLabel == "" {
|
}
|
||||||
return errors.New("validation-error: field AffinityLabel can not be empty")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest, options ...opts.DecortOpts) (string, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return "", err
|
||||||
if err != nil {
|
}
|
||||||
return "", err
|
|
||||||
}
|
url := "/cloudapi/compute/affinityGroupCheckStart"
|
||||||
|
|
||||||
url := "/compute/affinityGroupCheckStart"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return "", err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
return string(res), nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,51 +1,41 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AffinityLabelRemoveRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type AffinityLabelRemoveRequest struct {
|
}
|
||||||
ComputeId uint64 `url:"computeId"`
|
|
||||||
}
|
func (crq AffinityLabelRemoveRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq AffinityLabelRemoveRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/affinityLabelRemove"
|
||||||
|
|
||||||
url := "/compute/affinityLabelRemove"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
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
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AffinityLabelSetRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type AffinityLabelSetRequest struct {
|
AffinityLabel string `url:"affinityLabel"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
}
|
||||||
AffinityLabel string `url:"affinityLabel"`
|
|
||||||
}
|
func (crq AffinityLabelSetRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq AffinityLabelSetRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
if crq.AffinityLabel == "" {
|
||||||
}
|
return errors.New("validation-error: field AffinityLabel can not be empty")
|
||||||
if crq.AffinityLabel == "" {
|
}
|
||||||
return errors.New("validation-error: field AffinityLabel can not be empty")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/affinityLabelSet"
|
||||||
|
|
||||||
url := "/compute/affinityLabelSet"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
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
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AffinityRelationsRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type AffinityRelationsRequest struct {
|
AffinityLabel string `url:"affinityLabel"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
}
|
||||||
AffinityLabel string `url:"affinityLabel"`
|
|
||||||
}
|
func (crq AffinityRelationsRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq AffinityRelationsRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*AffinityRelations, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest, options ...opts.DecortOpts) (*AffinityRelations, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/compute/affinityRelations"
|
||||||
|
|
||||||
url := "/compute/affinityRelations"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
relations := &AffinityRelations{}
|
||||||
prefix = "/" + option.AdminValue
|
|
||||||
}
|
err = json.Unmarshal(res, relations)
|
||||||
}
|
if err != nil {
|
||||||
url = prefix + url
|
return nil, err
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return relations, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
relations := &AffinityRelations{}
|
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(res), relations)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return relations, nil
|
|
||||||
}
|
|
||||||
|
@ -1,91 +1,82 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/internal/validators"
|
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
"github.com/rudecs/decort-sdk/internal/validators"
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
)
|
||||||
)
|
|
||||||
|
type AffinityRuleAddRequest struct {
|
||||||
type AffinityRuleAddRequest struct {
|
ComputeID uint64 `url:"computeId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
Topology string `url:"topology"`
|
||||||
Topology string `url:"topology"`
|
Policy string `url:"policy"`
|
||||||
Policy string `url:"policy"`
|
Mode string `url:"mode"`
|
||||||
Mode string `url:"mode"`
|
Key string `url:"key"`
|
||||||
Key string `url:"key"`
|
Value string `url:"value"`
|
||||||
Value string `url:"value"`
|
}
|
||||||
}
|
|
||||||
|
func (crq AffinityRuleAddRequest) Validate() error {
|
||||||
func (crq AffinityRuleAddRequest) Validate() error {
|
if crq.ComputeID == 0 {
|
||||||
if crq.ComputeId == 0 {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
}
|
||||||
}
|
if crq.Topology == "" {
|
||||||
if crq.Topology == "" {
|
return errors.New("validation-error: field Topology can not be empty")
|
||||||
return errors.New("validation-error: field Topology can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
||||||
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Topology can be only compute or node")
|
||||||
return errors.New("validation-error: field Topology can be only compute or node")
|
}
|
||||||
}
|
|
||||||
|
if crq.Policy == "" {
|
||||||
if crq.Policy == "" {
|
return errors.New("validation-error: field Policy can not be empty")
|
||||||
return errors.New("validation-error: field Policy can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
||||||
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
||||||
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
}
|
||||||
}
|
|
||||||
|
if crq.Mode == "" {
|
||||||
if crq.Mode == "" {
|
return errors.New("validation-error: field Mode can not be empty")
|
||||||
return errors.New("validation-error: field Mode can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
||||||
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
||||||
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
}
|
||||||
}
|
|
||||||
|
if crq.Key == "" {
|
||||||
if crq.Key == "" {
|
return errors.New("validation-error: field Key can not be empty")
|
||||||
return errors.New("validation-error: field Key can not be empty")
|
}
|
||||||
}
|
|
||||||
|
if crq.Value == "" {
|
||||||
if crq.Value == "" {
|
return errors.New("validation-error: field Value can not be empty")
|
||||||
return errors.New("validation-error: field Value can not be empty")
|
}
|
||||||
}
|
|
||||||
|
return nil
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
|
||||||
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) {
|
err := req.Validate()
|
||||||
err := req.Validate()
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
}
|
||||||
}
|
|
||||||
|
url := "/cloudapi/compute/affinityRuleAdd"
|
||||||
url := "/compute/affinityRuleAdd"
|
|
||||||
prefix := "/cloudapi"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
option := opts.New(options)
|
return false, err
|
||||||
if option != nil {
|
}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
result, err := strconv.ParseBool(string(res))
|
||||||
}
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return result, 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
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/internal/validators"
|
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
"github.com/rudecs/decort-sdk/internal/validators"
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
)
|
||||||
)
|
|
||||||
|
type AffinityRuleRemoveRequest struct {
|
||||||
type AffinityRuleRemoveRequest struct {
|
ComputeID uint64 `url:"computeId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
Topology string `url:"topology"`
|
||||||
Topology string `url:"topology"`
|
Policy string `url:"policy"`
|
||||||
Policy string `url:"policy"`
|
Mode string `url:"mode"`
|
||||||
Mode string `url:"mode"`
|
Key string `url:"key"`
|
||||||
Key string `url:"key"`
|
Value string `url:"value"`
|
||||||
Value string `url:"value"`
|
}
|
||||||
}
|
|
||||||
|
func (crq AffinityRuleRemoveRequest) Validate() error {
|
||||||
func (crq AffinityRuleRemoveRequest) Validate() error {
|
if crq.ComputeID == 0 {
|
||||||
if crq.ComputeId == 0 {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
}
|
||||||
}
|
if crq.Topology == "" {
|
||||||
if crq.Topology == "" {
|
return errors.New("validation-error: field Topology can not be empty")
|
||||||
return errors.New("validation-error: field Topology can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
||||||
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Topology can be only compute or node")
|
||||||
return errors.New("validation-error: field Topology can be only compute or node")
|
}
|
||||||
}
|
|
||||||
|
if crq.Policy == "" {
|
||||||
if crq.Policy == "" {
|
return errors.New("validation-error: field Policy can not be empty")
|
||||||
return errors.New("validation-error: field Policy can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
||||||
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
||||||
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
}
|
||||||
}
|
|
||||||
|
if crq.Mode == "" {
|
||||||
if crq.Mode == "" {
|
return errors.New("validation-error: field Mode can not be empty")
|
||||||
return errors.New("validation-error: field Mode can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
||||||
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
||||||
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
}
|
||||||
}
|
|
||||||
|
if crq.Key == "" {
|
||||||
if crq.Key == "" {
|
return errors.New("validation-error: field Key can not be empty")
|
||||||
return errors.New("validation-error: field Key can not be empty")
|
}
|
||||||
}
|
|
||||||
|
if crq.Value == "" {
|
||||||
if crq.Value == "" {
|
return errors.New("validation-error: field Value can not be empty")
|
||||||
return errors.New("validation-error: field Value can not be empty")
|
}
|
||||||
}
|
|
||||||
|
return nil
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
|
||||||
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
err := req.Validate()
|
||||||
err := req.Validate()
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
}
|
||||||
}
|
|
||||||
|
url := "/cloudapi/compute/affinityRuleRemove"
|
||||||
url := "/compute/affinityRuleRemove"
|
|
||||||
prefix := "/cloudapi"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
option := opts.New(options)
|
return false, err
|
||||||
if option != nil {
|
}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
result, err := strconv.ParseBool(string(res))
|
||||||
}
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return result, 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
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AffinityRulesClearRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type AffinityRulesClearRequest struct {
|
}
|
||||||
ComputeId uint64 `url:"computeId"`
|
|
||||||
}
|
func (crq AffinityRulesClearRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq AffinityRulesClearRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/affinityRulesClear"
|
||||||
|
|
||||||
url := "/compute/affinityRulesClear"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
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
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/internal/validators"
|
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
"github.com/rudecs/decort-sdk/internal/validators"
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
)
|
||||||
)
|
|
||||||
|
type AntiAffinityRuleAddRequest struct {
|
||||||
type AntiAffinityRuleAddRequest struct {
|
ComputeID uint64 `url:"computeId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
Topology string `url:"topology"`
|
||||||
Topology string `url:"topology"`
|
Policy string `url:"policy"`
|
||||||
Policy string `url:"policy"`
|
Mode string `url:"mode"`
|
||||||
Mode string `url:"mode"`
|
Key string `url:"key"`
|
||||||
Key string `url:"key"`
|
Value string `url:"value"`
|
||||||
Value string `url:"value"`
|
}
|
||||||
}
|
|
||||||
|
func (crq AntiAffinityRuleAddRequest) Validate() error {
|
||||||
func (crq AntiAffinityRuleAddRequest) Validate() error {
|
if crq.ComputeID == 0 {
|
||||||
if crq.ComputeId == 0 {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
}
|
||||||
}
|
if crq.Topology == "" {
|
||||||
if crq.Topology == "" {
|
return errors.New("validation-error: field Topology can not be empty")
|
||||||
return errors.New("validation-error: field Topology can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
||||||
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Topology can be only compute or node")
|
||||||
return errors.New("validation-error: field Topology can be only compute or node")
|
}
|
||||||
}
|
|
||||||
|
if crq.Policy == "" {
|
||||||
if crq.Policy == "" {
|
return errors.New("validation-error: field Policy can not be empty")
|
||||||
return errors.New("validation-error: field Policy can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
||||||
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
||||||
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
}
|
||||||
}
|
|
||||||
|
if crq.Mode == "" {
|
||||||
if crq.Mode == "" {
|
return errors.New("validation-error: field Mode can not be empty")
|
||||||
return errors.New("validation-error: field Mode can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
||||||
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
||||||
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
}
|
||||||
}
|
|
||||||
|
if crq.Key == "" {
|
||||||
if crq.Key == "" {
|
return errors.New("validation-error: field Key can not be empty")
|
||||||
return errors.New("validation-error: field Key can not be empty")
|
}
|
||||||
}
|
|
||||||
|
if crq.Value == "" {
|
||||||
if crq.Value == "" {
|
return errors.New("validation-error: field Value can not be empty")
|
||||||
return errors.New("validation-error: field Value can not be empty")
|
}
|
||||||
}
|
|
||||||
|
return nil
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
|
||||||
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) {
|
err := req.Validate()
|
||||||
err := req.Validate()
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
}
|
||||||
}
|
|
||||||
|
url := "/cloudapi/compute/antiAffinityRuleAdd"
|
||||||
url := "/compute/antiAffinityRuleAdd"
|
|
||||||
prefix := "/cloudapi"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
option := opts.New(options)
|
return false, err
|
||||||
if option != nil {
|
}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
result, err := strconv.ParseBool(string(res))
|
||||||
}
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return result, 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
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/internal/validators"
|
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
"github.com/rudecs/decort-sdk/internal/validators"
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
)
|
||||||
)
|
|
||||||
|
type AntiAffinityRuleRemoveRequest struct {
|
||||||
type AntiAffinityRuleRemoveRequest struct {
|
ComputeID uint64 `url:"computeId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
Topology string `url:"topology"`
|
||||||
Topology string `url:"topology"`
|
Policy string `url:"policy"`
|
||||||
Policy string `url:"policy"`
|
Mode string `url:"mode"`
|
||||||
Mode string `url:"mode"`
|
Key string `url:"key"`
|
||||||
Key string `url:"key"`
|
Value string `url:"value"`
|
||||||
Value string `url:"value"`
|
}
|
||||||
}
|
|
||||||
|
func (crq AntiAffinityRuleRemoveRequest) Validate() error {
|
||||||
func (crq AntiAffinityRuleRemoveRequest) Validate() error {
|
if crq.ComputeID == 0 {
|
||||||
if crq.ComputeId == 0 {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
}
|
||||||
}
|
if crq.Topology == "" {
|
||||||
if crq.Topology == "" {
|
return errors.New("validation-error: field Topology can not be empty")
|
||||||
return errors.New("validation-error: field Topology can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
||||||
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Topology can be only compute or node")
|
||||||
return errors.New("validation-error: field Topology can be only compute or node")
|
}
|
||||||
}
|
|
||||||
|
if crq.Policy == "" {
|
||||||
if crq.Policy == "" {
|
return errors.New("validation-error: field Policy can not be empty")
|
||||||
return errors.New("validation-error: field Policy can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
||||||
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
||||||
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
}
|
||||||
}
|
|
||||||
|
if crq.Mode == "" {
|
||||||
if crq.Mode == "" {
|
return errors.New("validation-error: field Mode can not be empty")
|
||||||
return errors.New("validation-error: field Mode can not be empty")
|
}
|
||||||
}
|
|
||||||
|
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
||||||
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
if !validator {
|
||||||
if !validator {
|
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
||||||
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
}
|
||||||
}
|
|
||||||
|
if crq.Key == "" {
|
||||||
if crq.Key == "" {
|
return errors.New("validation-error: field Key can not be empty")
|
||||||
return errors.New("validation-error: field Key can not be empty")
|
}
|
||||||
}
|
|
||||||
|
if crq.Value == "" {
|
||||||
if crq.Value == "" {
|
return errors.New("validation-error: field Value can not be empty")
|
||||||
return errors.New("validation-error: field Value can not be empty")
|
}
|
||||||
}
|
|
||||||
|
return nil
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
|
||||||
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
err := req.Validate()
|
||||||
err := req.Validate()
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
}
|
||||||
}
|
|
||||||
|
url := "/cloudapi/compute/antiAffinityRuleRemove"
|
||||||
url := "/compute/antiAffinityRuleRemove"
|
|
||||||
prefix := "/cloudapi"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
option := opts.New(options)
|
return false, err
|
||||||
if option != nil {
|
}
|
||||||
if option.IsAdmin {
|
|
||||||
prefix = "/" + option.AdminValue
|
result, err := strconv.ParseBool(string(res))
|
||||||
}
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
url = prefix + url
|
}
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
|
||||||
if err != nil {
|
return result, 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
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AntiAffinityRulesClearRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type AntiAffinityRulesClearRequest struct {
|
}
|
||||||
ComputeId uint64 `url:"computeId"`
|
|
||||||
}
|
func (crq AntiAffinityRulesClearRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq AntiAffinityRulesClearRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/antiAffinityRulesClear"
|
||||||
|
|
||||||
url := "/compute/antiAffinityRulesClear"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
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
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AttachGPURequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type AttachGPURequest struct {
|
VGPUID uint64 `url:"vgpuId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
}
|
||||||
VGPUID uint64 `url:"vgpuId"`
|
|
||||||
}
|
func (crq AttachGPURequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq AttachGPURequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
if crq.VGPUID == 0 {
|
||||||
|
return errors.New("validation-error: field VGPUID 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
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest, options ...opts.DecortOpts) (uint64, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return 0, err
|
||||||
if err != nil {
|
}
|
||||||
return 0, err
|
|
||||||
}
|
url := "/cloudapi/compute/attachGpu"
|
||||||
|
|
||||||
url := "/compute/attachGpu"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return 0, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
@ -1,56 +1,46 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AttachPciDeviceRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type AttachPciDeviceRequest struct {
|
DeviceID uint64 `url:"deviceId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
}
|
||||||
DeviceID uint64 `url:"deviceId"`
|
|
||||||
}
|
func (crq AttachPciDeviceRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq AttachPciDeviceRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
if crq.DeviceID == 0 {
|
||||||
|
return errors.New("validation-error: field DeviceID 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
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/attachPciDevice"
|
||||||
|
|
||||||
url := "/compute/attachPciDevice"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
@ -1,41 +1,39 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type AuditsRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type AuditsRequest struct {
|
}
|
||||||
ComputeId uint64 `url:"computeId"`
|
|
||||||
}
|
func (crq AuditsRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq AuditsRequest) Validate() error {
|
return errors.New("field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (AuditList, error) {
|
||||||
|
if err := req.Validate(); err != nil {
|
||||||
func (c Compute) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AuditList, error) {
|
return nil, err
|
||||||
if err := req.Validate(); err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
url := "/cloudapi/compute/audits"
|
||||||
|
auditListRaw, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
url := "/cloudapi/compute/audits"
|
if err != nil {
|
||||||
auditListRaw, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
auditList := AuditList{}
|
||||||
|
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
|
||||||
auditList := AuditList{}
|
return nil, err
|
||||||
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
return auditList, nil
|
||||||
|
}
|
||||||
return auditList, nil
|
|
||||||
}
|
|
||||||
|
@ -1,50 +1,40 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type CDEjectRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type CDEjectRequest struct {
|
}
|
||||||
ComputeId uint64 `url:"computeId"`
|
|
||||||
}
|
func (crq CDEjectRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq CDEjectRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/cdEject"
|
||||||
|
|
||||||
url := "/compute/cdEject"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
return result, nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,54 +1,44 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type CDInsertRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type CDInsertRequest struct {
|
CDROMID uint64 `url:"cdromId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
}
|
||||||
CDROMID uint64 `url:"cdromId"`
|
|
||||||
}
|
func (crq CDInsertRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq CDInsertRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
if crq.CDROMID == 0 {
|
||||||
}
|
return errors.New("validation-error: field CDROMID can not be empty or equal to 0")
|
||||||
if crq.CDROMID == 0 {
|
}
|
||||||
return errors.New("validation-error: field CDROMID can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/cdInsert"
|
||||||
|
|
||||||
url := "/compute/cdInsert"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
return result, nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,56 +1,46 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type CloneRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type CloneRequest struct {
|
Name string `url:"name"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
SnapshotTimestamp uint64 `url:"snapshotTimestamp"`
|
||||||
Name string `url:"name"`
|
SnapshotName string `url:"snapshotName"`
|
||||||
SnapshotTimestamp uint64 `url:"snapshotTimestamp"`
|
}
|
||||||
SnapshotName string `url:"snapshotName"`
|
|
||||||
}
|
func (crq CloneRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq CloneRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
if crq.Name == "" {
|
||||||
}
|
return errors.New("validation-error: field Name can not be empty or equal to 0")
|
||||||
if crq.Name == "" {
|
}
|
||||||
return errors.New("validation-error: field Name can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) Clone(ctx context.Context, req CloneRequest, options ...opts.DecortOpts) (uint64, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return 0, err
|
||||||
if err != nil {
|
}
|
||||||
return 0, err
|
|
||||||
}
|
url := "/cloudapi/compute/clone"
|
||||||
|
|
||||||
url := "/compute/clone"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return 0, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
return result, nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rudecs/decort-sdk/interfaces"
|
"github.com/rudecs/decort-sdk/interfaces"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Compute struct {
|
type Compute struct {
|
||||||
client interfaces.Caller
|
client interfaces.Caller
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client interfaces.Caller) *Compute {
|
func New(client interfaces.Caller) *Compute {
|
||||||
return &Compute{
|
return &Compute{
|
||||||
client,
|
client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,88 +1,70 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
"strings"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type CreateTemplateRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type CreateTemplateRequest struct {
|
Name string `url:"name"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
Async bool `url:"async"`
|
||||||
Name string `url:"name"`
|
}
|
||||||
Async bool `url:"async"`
|
|
||||||
}
|
func (crq CreateTemplateRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq CreateTemplateRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
if crq.Name == "" {
|
||||||
|
return errors.New("validation-error: field Name can not be empty")
|
||||||
if crq.Name == "" {
|
}
|
||||||
return errors.New("validation-error: field Name can not be empty")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (uint64, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return 0, err
|
||||||
if err != nil {
|
}
|
||||||
return 0, err
|
|
||||||
}
|
req.Async = false
|
||||||
|
|
||||||
req.Async = false
|
url := "/cloudapi/compute/createTemplate"
|
||||||
|
|
||||||
url := "/compute/createTemplate"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return 0, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return 0, err
|
|
||||||
}
|
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) {
|
||||||
|
err := req.Validate()
|
||||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
if err != nil {
|
||||||
if err != nil {
|
return "", err
|
||||||
return 0, nil
|
}
|
||||||
}
|
|
||||||
|
req.Async = true
|
||||||
return result, nil
|
|
||||||
}
|
url := "/cloudapi/compute/createTemplate"
|
||||||
|
|
||||||
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (string, error) {
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
err := req.Validate()
|
if err != nil {
|
||||||
if err != nil {
|
return "", err
|
||||||
return "", err
|
}
|
||||||
}
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
req.Async = true
|
|
||||||
|
return result, nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,52 +1,42 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type DeleteRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type DeleteRequest struct {
|
Permanently bool `url:"permanently,omitempty"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
DetachDisks bool `url:"detachDisks,omitempty"`
|
||||||
Permanently bool `url:"permanently,omitempty"`
|
}
|
||||||
DetachDisks bool `url:"detachDisks,omitempty"`
|
|
||||||
}
|
func (crq DeleteRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq DeleteRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/delete"
|
||||||
|
|
||||||
url := "/compute/delete"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
return result, nil
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,52 +1,42 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type DetachGPURequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type DetachGPURequest struct {
|
VGPUID int64 `url:"vgpuId,omitempty"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
}
|
||||||
VGPUID int64 `url:"vgpuId,omitempty"`
|
|
||||||
}
|
func (crq DetachGPURequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq DetachGPURequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/detachGpu"
|
||||||
|
|
||||||
url := "/compute/detachGpu"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
@ -1,56 +1,46 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type DetachPciDeviceRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type DetachPciDeviceRequest struct {
|
DeviceID uint64 `url:"deviceId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
}
|
||||||
DeviceID uint64 `url:"deviceId"`
|
|
||||||
}
|
func (crq DetachPciDeviceRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq DetachPciDeviceRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
if crq.DeviceID == 0 {
|
||||||
|
return errors.New("validation-error: field DeviceID 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
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/detachPciDevice"
|
||||||
|
|
||||||
url := "/compute/detachPciDevice"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
@ -1,51 +1,41 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type DisableRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type DisableRequest struct {
|
}
|
||||||
ComputeId uint64 `url:"computeId"`
|
|
||||||
}
|
func (crq DisableRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq DisableRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/disable"
|
||||||
|
|
||||||
url := "/compute/disable"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
@ -1,66 +1,56 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type DiskAddRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type DiskAddRequest struct {
|
DiskName string `url:"diskName"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
Size uint64 `url:"size"`
|
||||||
DiskName string `url:"diskName"`
|
DiskType string `url:"diskType,omitempty"`
|
||||||
Size uint64 `url:"size"`
|
SepID uint64 `url:"sepId,omitempty"`
|
||||||
DiskType string `url:"diskType,omitempty"`
|
Pool string `url:"pool,omitempty"`
|
||||||
SepID uint64 `url:"sepId,omitempty"`
|
Description string `url:"desc,omitempty"`
|
||||||
Pool string `url:"pool,omitempty"`
|
ImageID uint64 `url:"imageId,omitempty"`
|
||||||
Description string `url:"desc,omitempty"`
|
}
|
||||||
ImageID uint64 `url:"imageId,omitempty"`
|
|
||||||
}
|
func (crq DiskAddRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq DiskAddRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
if crq.Size == 0 {
|
||||||
|
return errors.New("validation-error: field Size 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")
|
||||||
if crq.DiskName == "" {
|
}
|
||||||
return errors.New("validation-error: field DiskName can not be empty or equal to 0")
|
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest, options ...opts.DecortOpts) (uint64, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return 0, err
|
||||||
if err != nil {
|
}
|
||||||
return 0, err
|
|
||||||
}
|
url := "/cloudapi/compute/diskAdd"
|
||||||
|
|
||||||
url := "/compute/diskAdd"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return 0, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
@ -1,56 +1,46 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type DiskAttachRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type DiskAttachRequest struct {
|
DiskID uint64 `url:"diskId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
}
|
||||||
DiskID uint64 `url:"diskId"`
|
|
||||||
}
|
func (crq DiskAttachRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq DiskAttachRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
if crq.DiskID == 0 {
|
||||||
|
return errors.New("validation-error: field DiskID 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
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/diskAttach"
|
||||||
|
|
||||||
url := "/compute/diskAttach"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
@ -1,57 +1,47 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"github.com/rudecs/decort-sdk/opts"
|
)
|
||||||
"github.com/rudecs/decort-sdk/typed"
|
|
||||||
)
|
type DiskDelRequest struct {
|
||||||
|
ComputeID uint64 `url:"computeId"`
|
||||||
type DiskDelRequest struct {
|
DiskID uint64 `url:"diskId"`
|
||||||
ComputeId uint64 `url:"computeId"`
|
Permanently bool `url:"permanently"`
|
||||||
DiskID uint64 `url:"diskId"`
|
}
|
||||||
Permanently bool `url:"permanently"`
|
|
||||||
}
|
func (crq DiskDelRequest) Validate() error {
|
||||||
|
if crq.ComputeID == 0 {
|
||||||
func (crq DiskDelRequest) Validate() error {
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||||
if crq.ComputeId == 0 {
|
}
|
||||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
|
||||||
}
|
if crq.DiskID == 0 {
|
||||||
|
return errors.New("validation-error: field DiskID 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
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) {
|
||||||
|
err := req.Validate()
|
||||||
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest, options ...opts.DecortOpts) (bool, error) {
|
if err != nil {
|
||||||
err := req.Validate()
|
return false, err
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
url := "/cloudapi/compute/diskDel"
|
||||||
|
|
||||||
url := "/compute/diskDel"
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
prefix := "/cloudapi"
|
if err != nil {
|
||||||
|
return false, err
|
||||||
option := opts.New(options)
|
}
|
||||||
if option != nil {
|
|
||||||
if option.IsAdmin {
|
result, err := strconv.ParseBool(string(res))
|
||||||
prefix = "/" + option.AdminValue
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
}
|
}
|
||||||
url = prefix + url
|
|
||||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
return result, nil
|
||||||
if err != nil {
|
}
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue