parent
c95208ee97
commit
68d24d41c4
@ -0,0 +1,21 @@
|
||||
linters:
|
||||
enable:
|
||||
- bodyclose
|
||||
- decorder
|
||||
- dogsled
|
||||
- errorlint
|
||||
- exportloopref
|
||||
- gocognit
|
||||
- goconst
|
||||
- gocyclo
|
||||
- gosec
|
||||
- ifshort
|
||||
- makezero
|
||||
- nestif
|
||||
- nilerr
|
||||
- prealloc
|
||||
- unconvert
|
||||
- unparam
|
||||
|
||||
issues:
|
||||
max-same-issues: 0
|
@ -0,0 +1,9 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/account"
|
||||
)
|
||||
|
||||
func (dc *decortClient) Account() *account.Account {
|
||||
return account.New(dc)
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *Account {
|
||||
return &Account{
|
||||
client,
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AddUserRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
UserId string `url:"userId"`
|
||||
AccessType string `url:"accesstype"`
|
||||
}
|
||||
|
||||
func (arq AddUserRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.UserId == "" {
|
||||
return errors.New("validation-error: field UserId can not be empty")
|
||||
}
|
||||
|
||||
if arq.AccessType == "" {
|
||||
return errors.New("validation-error: field AccessType can not be empty")
|
||||
}
|
||||
|
||||
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
|
||||
if !isValid {
|
||||
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) AddUser(ctx context.Context, req AddUserRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/addUser"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AuditsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq AuditsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AccountAuditsList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/audits"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
auditsRaw, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
audits := AccountAuditsList{}
|
||||
|
||||
err = json.Unmarshal([]byte(auditsRaw), &audits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return audits, nil
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
Name string `url:"name"`
|
||||
Username string `url:"username"`
|
||||
EmailAddress string `url:"emailaddress,omitempty"`
|
||||
MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"`
|
||||
MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"`
|
||||
MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"`
|
||||
MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"`
|
||||
MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"`
|
||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
|
||||
GpuUnits uint `url:"gpu_units,omitempty"`
|
||||
}
|
||||
|
||||
func (arq CreateRequest) Validate() error {
|
||||
if arq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
if arq.Username == "" {
|
||||
return errors.New("validation-error: field Username can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/account/create"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DeleteRequest) Validate() error {
|
||||
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/delete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteUserRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
UserId string `url:"userId"`
|
||||
RecursiveDelete bool `url:"recursivedelete,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DeleteUserRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.UserId == "" {
|
||||
return errors.New("validation-error: field UserId can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/deleteUser"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DisabelEnableRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq DisabelEnableRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/disable"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/enable"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq GetRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*AccountWithResources, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/get"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
account := &AccountWithResources{}
|
||||
|
||||
err = json.Unmarshal(res, &account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return account, nil
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetConsumedAccountUnitsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq GetConsumedAccountUnitsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/getConsumedAccountUnits"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rl := &ResourceLimits{}
|
||||
|
||||
err = json.Unmarshal(res, &rl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rl, nil
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetConsumedCloudUnitsByTypeRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
CUType string `url:"cutype"`
|
||||
}
|
||||
|
||||
func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.CUType == "" {
|
||||
return errors.New("validation-error: field CUType can not be empty")
|
||||
}
|
||||
|
||||
isValid := validators.StringInSlice(arq.CUType, []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"})
|
||||
if !isValid {
|
||||
return errors.New("validation-error: field AccessType can be only CU_M, CU_C, CU_D, CU_S, CU_A, CU_NO, CU_I or CU_NP")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest, options ...opts.DecortOpts) (float64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/account/getConsumedCloudUnitsByType"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseFloat(string(res), 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetConsumtionRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
Start uint64 `url:"start"`
|
||||
End uint64 `url:"end"`
|
||||
}
|
||||
|
||||
func (arq GetConsumtionRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.Start == 0 {
|
||||
return errors.New("validation-error: field Start can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.End == 0 {
|
||||
return errors.New("validation-error: field End can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/account/getConsumtion"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
|
||||
}
|
||||
|
||||
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/account/getConsumtion"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.GET, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetReservedAccountUnitsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq GetReservedAccountUnitsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/getReservedAccountUnits"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rl := &ResourceLimits{}
|
||||
|
||||
err = json.Unmarshal(res, &rl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rl, nil
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
Page uint64 `url:"page"`
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (a Account) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
|
||||
url := "/account/list"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountList := AccountCloudApiList{}
|
||||
|
||||
err = json.Unmarshal(res, &accountList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountList, nil
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListComputesRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListComputesRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (AccountComputesList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listComputes"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountComputesList := AccountComputesList{}
|
||||
|
||||
err = json.Unmarshal(res, &accountComputesList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountComputesList, nil
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListDeletedRequest struct {
|
||||
Page uint64 `url:"page"`
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
|
||||
url := "/account/listDeleted"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountList := AccountCloudApiList{}
|
||||
|
||||
err = json.Unmarshal(res, &accountList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountList, nil
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListDisksRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListDisksRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest, options ...opts.DecortOpts) (AccountDisksList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listDisks"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountDisksList := AccountDisksList{}
|
||||
|
||||
err = json.Unmarshal(res, &accountDisksList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountDisksList, nil
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListFlipGroupsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListFlipGroupsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest, options ...opts.DecortOpts) (AccountFlipGroupsList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listFlipGroups"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountFlipGroupsList := AccountFlipGroupsList{}
|
||||
|
||||
err = json.Unmarshal(res, &accountFlipGroupsList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountFlipGroupsList, nil
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListRGRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListRGRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListRG(ctx context.Context, req ListRGRequest, options ...opts.DecortOpts) (AccountRGList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listRG"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountRGList := AccountRGList{}
|
||||
|
||||
err = json.Unmarshal(res, &accountRGList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountRGList, nil
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListTemplatesRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
IncludeDeleted bool `url:"includedeleted"`
|
||||
}
|
||||
|
||||
func (arq ListTemplatesRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest, options ...opts.DecortOpts) (AccountTemplatesList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listTemplates"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountTemplatesList := AccountTemplatesList{}
|
||||
|
||||
err = json.Unmarshal(res, &accountTemplatesList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountTemplatesList, nil
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListVinsRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListVinsRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListVins(ctx context.Context, req ListVinsRequest, options ...opts.DecortOpts) (AccountVinsList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/account/listVins"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountVinsList := AccountVinsList{}
|
||||
|
||||
err = json.Unmarshal(res, &accountVinsList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountVinsList, nil
|
||||
|
||||
}
|
@ -0,0 +1,229 @@
|
||||
package account
|
||||
|
||||
type AccountAclRecord struct {
|
||||
IsExplicit bool `json:"explicit"`
|
||||
GUID string `json:"guid"`
|
||||
Rights string `json:"right"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
UgroupID string `json:"userGroupId"`
|
||||
CanBeDeleted bool `json:"canBeDeleted"`
|
||||
}
|
||||
|
||||
type ResourceLimits struct {
|
||||
CUC float64 `json:"CU_C"`
|
||||
CUD float64 `json:"CU_D"`
|
||||
CUI float64 `json:"CU_I"`
|
||||
CUM float64 `json:"CU_M"`
|
||||
CUNP float64 `json:"CU_NP"`
|
||||
GpuUnits float64 `json:"gpu_units"`
|
||||
}
|
||||
|
||||
type AccountRecord struct {
|
||||
DCLocation string `json:"DCLocation"`
|
||||
CKey string `jspn:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
Acl []AccountAclRecord `json:"acl"`
|
||||
Company string `json:"company"`
|
||||
CompanyUrl string `json:"companyurl"`
|
||||
CreatedBy string `jspn:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeactiovationTime float64 `json:"deactivationTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
DisplayName string `json:"displayname"`
|
||||
GUID int `json:"guid"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
||||
ServiceAccount bool `json:"serviceAccount"`
|
||||
Status string `json:"status"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
Version int `json:"version"`
|
||||
Vins []int `json:"vins"`
|
||||
}
|
||||
|
||||
type AccountList []AccountRecord
|
||||
|
||||
type AccountCloudApi struct {
|
||||
Acl []AccountAclRecord `json:"acl"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountCloudApiList []AccountCloudApi
|
||||
|
||||
type Resource struct {
|
||||
CPU int `json:"cpu"`
|
||||
Disksize int `json:"disksize"`
|
||||
Extips int `json:"extips"`
|
||||
Exttraffic int `json:"exttraffic"`
|
||||
GPU int `json:"gpu"`
|
||||
RAM int `json:"ram"`
|
||||
}
|
||||
|
||||
type Resources struct {
|
||||
Current Resource `json:"Current"`
|
||||
Reserved Resource `json:"Reserved"`
|
||||
}
|
||||
|
||||
type Computes struct {
|
||||
Started int `json:"started"`
|
||||
Stopped int `json:"stopped"`
|
||||
}
|
||||
|
||||
type Machines struct {
|
||||
Running int `json:"running"`
|
||||
Halted int `json:"halted"`
|
||||
}
|
||||
|
||||
type AccountWithResources struct {
|
||||
Account
|
||||
Resources Resources `json:"Resources"`
|
||||
Computes Computes `json:"computes"`
|
||||
Machines Machines `json:"machines"`
|
||||
Vinses int `json:"vinses"`
|
||||
}
|
||||
|
||||
type AccountCompute struct {
|
||||
AccountId int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
CPUs int `json:"cpus"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ComputeId int `json:"id"`
|
||||
ComputeName string `json:"name"`
|
||||
RAM int `json:"ram"`
|
||||
Registered bool `json:"registered"`
|
||||
RGId int `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
TotalDisksSize int `json:"totalDisksSize"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
VinsConnected int `json:"vinsConnected"`
|
||||
}
|
||||
|
||||
type AccountComputesList []AccountCompute
|
||||
|
||||
type AccountDisk struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Pool string `json:"pool"`
|
||||
SepId int `json:"sepId"`
|
||||
SizeMax int `json:"sizeMax"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type AccountDisksList []AccountDisk
|
||||
|
||||
type AccountVin struct {
|
||||
AccountId int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Computes int `json:"computes"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ExternalIP string `json:"externalIP"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Network string `json:"network"`
|
||||
PriVnfDevId int `json:"priVnfDevId"`
|
||||
RGId int `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountVinsList []AccountVin
|
||||
|
||||
type AccountAudit struct {
|
||||
Call string `json:"call"`
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
StatusCode int `json:"statuscode"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
type AccountAuditsList []AccountAudit
|
||||
|
||||
type AccountRGComputes struct {
|
||||
Started int `json:"Started"`
|
||||
Stopped int `json:"Stopped"`
|
||||
}
|
||||
|
||||
type AccountRGResources struct {
|
||||
Consumed Resource `json:"Consumed"`
|
||||
Limits Resource `json:"Limits"`
|
||||
Reserved Resource `json:"Reserved"`
|
||||
}
|
||||
|
||||
type AccountRG struct {
|
||||
Computes AccountRGComputes `json:"Computes"`
|
||||
Resources AccountRGResources `json:"Resources"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
RGID int `json:"id"`
|
||||
Milestones int `json:"milestones"`
|
||||
RGName string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
Vinses int `json:"vinses"`
|
||||
}
|
||||
|
||||
type AccountRGList []AccountRG
|
||||
|
||||
type AccountTemplate struct {
|
||||
UNCPath string `json:"UNCPath"`
|
||||
AccountId int `json:"accountId"`
|
||||
Description string `json:"desc"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Public bool `json:"public"`
|
||||
Size int `json:"size"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type AccountTemplatesList []AccountTemplate
|
||||
|
||||
type AccountFlipGroup struct {
|
||||
AccountId int `json:"accountId"`
|
||||
ClientType string `json:"clientType"`
|
||||
ConnType string `json:"connType"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DefaultGW string `json:"defaultGW"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
Description string `json:"desc"`
|
||||
GID int `json:"gid"`
|
||||
GUID int `json:"guid"`
|
||||
ID int `json:"id"`
|
||||
IP string `json:"ip"`
|
||||
Milestones int `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
NetID int `json:"netId"`
|
||||
NetType string `json:"netType"`
|
||||
NetMask int `json:"netmask"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountFlipGroupsList []AccountFlipGroup
|
@ -0,0 +1,53 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type RestoreRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq RestoreRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/restore"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type UpdateRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
Name string `url:"name,omitempty"`
|
||||
MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"`
|
||||
MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"`
|
||||
MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"`
|
||||
MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"`
|
||||
MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"`
|
||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
|
||||
GpuUnits uint `url:"gpu_units,omitempty"`
|
||||
}
|
||||
|
||||
func (arq UpdateRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/update"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type UpdateUserRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
UserId string `url:"userId"`
|
||||
AccessType string `url:"accesstype"`
|
||||
}
|
||||
|
||||
func (arq UpdateUserRequest) Validate() error {
|
||||
if arq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if arq.UserId == "" {
|
||||
return errors.New("validation-error: field UserId can not be empty")
|
||||
}
|
||||
|
||||
if arq.AccessType == "" {
|
||||
return errors.New("validation-error: field AccessType can not be empty")
|
||||
}
|
||||
|
||||
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
|
||||
if !isValid {
|
||||
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/account/updateUser"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package bservice
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
|
||||
type BService struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *BService {
|
||||
return &BService{
|
||||
client,
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
Name string `url:"name"`
|
||||
RGID uint64 `url:"rgId"`
|
||||
SSHUser string `url:"sshUser,omitempty"`
|
||||
SSHKey string `url:"sshKey,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq CreateRequest) Validate() error {
|
||||
if bsrq.Name == "" {
|
||||
return errors.New("field Name can not be empty")
|
||||
}
|
||||
|
||||
if bsrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/create"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseUint(string(res), 10, 64)
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq DeleteRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/delete"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DisableRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq DisableRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/delete"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type EnableRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq EnableRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/enable"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq GetRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*BasicService, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/get"
|
||||
bsRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bs := &BasicService{}
|
||||
if err := json.Unmarshal(bsRaw, bs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bs, nil
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupAddRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Name string `url:"name"`
|
||||
Count uint64 `url:"count"`
|
||||
CPU uint64 `url:"cpu"`
|
||||
RAM uint64 `url:"ram"`
|
||||
Disk uint64 `url:"disk"`
|
||||
ImageID uint64 `url:"imageId"`
|
||||
Driver string `url:"driver"`
|
||||
Role string `url:"role,omitempty"`
|
||||
VINSes []uint64 `url:"vinses,omitempty"`
|
||||
Extnets []uint64 `url:"extnets,omitempty"`
|
||||
TimeoutStart uint64 `url:"timeoutStart"`
|
||||
}
|
||||
|
||||
func (bsrq GroupAddRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Name == "" {
|
||||
return errors.New("field Name can not be empty")
|
||||
}
|
||||
|
||||
if bsrq.Count == 0 {
|
||||
return errors.New("field Count can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CPU == 0 {
|
||||
return errors.New("field CPU can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.RAM == 0 {
|
||||
return errors.New("field RAM can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Disk == 0 {
|
||||
return errors.New("field Disk can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.ImageID == 0 {
|
||||
return errors.New("field ImageID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Driver == "" {
|
||||
return errors.New("field Driver can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupAdd"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseUint(string(res), 10, 64)
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupComputeRemoveRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
ComputeID uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupComputeRemoveRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.ComputeID == 0 {
|
||||
return errors.New("field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupComputeRemove"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupGetRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupGetRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupGet(ctx context.Context, req GroupGetRequest, options ...opts.DecortOpts) (*Group, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupGet"
|
||||
groupRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
group := &Group{}
|
||||
if err := json.Unmarshal(groupRaw, group); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return group, nil
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupParentAddRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
ParentID uint64 `url:"parentId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupParentAddRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.ParentID == 0 {
|
||||
return errors.New("field ParentID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupParentAdd"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupParentRemoveRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
ParentID uint64 `url:"parentId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupParentRemoveRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.ParentID == 0 {
|
||||
return errors.New("field ParentID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupParentRemove"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupRemoveRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupRemoveRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupRemove"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupResizeRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
Count int64 `url:"count"`
|
||||
Mode string `url:"mode"`
|
||||
}
|
||||
|
||||
func (bsrq GroupResizeRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Mode == "RELATIVE" && bsrq.Count == 0 {
|
||||
return errors.New("field Count can not be equal to 0 if Mode if 'RELATIVE'")
|
||||
}
|
||||
|
||||
if !validators.StringInSlice(bsrq.Mode, []string{"RELATIVE", "ABSOLUTE"}) {
|
||||
return errors.New("field Mode can only be one of 'RELATIVE' or 'ABSOLUTE'")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupResize"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseUint(string(res), 10, 64)
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupStartRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
}
|
||||
|
||||
func (bsrq GroupStartRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupStart(ctx context.Context, req GroupStartRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupStart"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupStopRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
Force bool `url:"force,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq GroupStopRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupStop(ctx context.Context, req GroupStopRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupStop"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupUpdateRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
Name string `url:"name,omitempty"`
|
||||
Role string `url:"role,omitempty"`
|
||||
CPU uint64 `url:"cpu,omitempty"`
|
||||
RAM uint64 `url:"ram,omitempty"`
|
||||
Disk uint64 `url:"disk,omitempty"`
|
||||
Force bool `url:"force,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq GroupUpdateRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdate"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupUpdateExtnetRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
Extnets []uint64 `url:"extnets,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq GroupUpdateExtnetRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupUpdateExtnet(ctx context.Context, req GroupUpdateExtnetRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdateExtnet"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GroupUpdateVINSRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
CompGroupID uint64 `url:"compgroupId"`
|
||||
VINSes []uint64 `url:"vinses,omitempty"`
|
||||
}
|
||||
|
||||
func (bsrq GroupUpdateVINSRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.CompGroupID == 0 {
|
||||
return errors.New("field CompGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdateVins"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
RGID uint64 `url:"rgId,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (b BService) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (BasicServiceList, error) {
|
||||
url := "/cloudapi/bservice/list"
|
||||
bsListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bsList := BasicServiceList{}
|
||||
if err := json.Unmarshal(bsListRaw, &bsList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bsList, nil
|
||||
}
|
||||
|
||||
func (b BService) ListDeleted(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (BasicServiceList, error) {
|
||||
url := "/cloudapi/bservice/listDeleted"
|
||||
bsListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bsList := BasicServiceList{}
|
||||
if err := json.Unmarshal(bsListRaw, &bsList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bsList, nil
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package bservice
|
||||
|
||||
type BasicService struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
BaseDomain string `json:"baseDomain"`
|
||||
Computes []Compute `json:"computes"`
|
||||
CPUTotal uint64 `json:"cpuTotal"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
DiskTotal uint64 `json:"diskTotal"`
|
||||
GID uint64 `json:"gid"`
|
||||
Groups []uint64 `json:"groups"`
|
||||
GroupsName []string `json:"groupsName"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
ParentSrvID uint64 `json:"parentSrvId"`
|
||||
ParentSrvType string `json:"parentSrvType"`
|
||||
RAMTotal uint64 `json:"ramTotal"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Snapshots []Snapshot `json:"snapshots"`
|
||||
SSHKey string `json:"sshKey"`
|
||||
SSHUser string `json:"sshUser"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
}
|
||||
|
||||
type Compute struct {
|
||||
CompGroupID uint64 `json:"compgroupId"`
|
||||
CompGroupName string `json:"compgroupName"`
|
||||
CompGroupRole string `json:"compgroupRole"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
GUID string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
Valid bool `json:"valid"`
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Computes []GroupCompute `json:"computes"`
|
||||
Consistency bool `json:"consistency"`
|
||||
CPU uint64 `json:"cpu"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Disk uint64 `json:"disk"`
|
||||
Driver string `json:"driver"`
|
||||
Extnets []uint64 `json:"extnets"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
ImageID uint64 `json:"imageId"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Parents []uint64 `json:"parents"`
|
||||
RAM uint64 `json:"ram"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Role string `json:"role"`
|
||||
SepID uint64 `json:"sepId"`
|
||||
SeqNo uint64 `json:"seqNo"`
|
||||
ServiceID uint64 `json:"serviceId"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
TimeoutStart uint64 `json:"timeoutStart"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
VINSes []uint64 `json:"vinses"`
|
||||
}
|
||||
|
||||
type GroupCompute struct {
|
||||
ID uint64 `json:"id"`
|
||||
IPAddresses []string `json:"ipAddresses"`
|
||||
Name string `json:"name"`
|
||||
OSUsers []OSUser `json:"osUsers"`
|
||||
}
|
||||
|
||||
type OSUser struct {
|
||||
Login string `json:"login"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type BasicServiceShort struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
BaseDomain string `json:"baseDomain"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
GID uint64 `json:"gid"`
|
||||
Groups []uint64 `json:"groups"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ParentSrvID uint64 `json:"parentSrvId"`
|
||||
ParentSrvType string `json:"parentSrvType"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
SSHUser string `json:"sshUser"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
}
|
||||
|
||||
type BasicServiceList []BasicServiceShort
|
@ -0,0 +1,36 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type RestoreRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq RestoreRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/restore"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type SnapshotCreateRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Label string `url:"label"`
|
||||
}
|
||||
|
||||
func (bsrq SnapshotCreateRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Label == "" {
|
||||
return errors.New("field Label can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotCreate"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type SnapshotDeleteRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Label string `url:"label"`
|
||||
}
|
||||
|
||||
func (bsrq SnapshotDeleteRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Label == "" {
|
||||
return errors.New("field Label can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotDelete"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type SnapshotListRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq SnapshotListRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest, options ...opts.DecortOpts) ([]Snapshot, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotList"
|
||||
snapshotListRaw, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
snapshotList := []Snapshot{}
|
||||
if err := json.Unmarshal(snapshotListRaw, &snapshotList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return snapshotList, nil
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type SnapshotRollbackRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
Label string `url:"label"`
|
||||
}
|
||||
|
||||
func (bsrq SnapshotRollbackRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if bsrq.Label == "" {
|
||||
return errors.New("field Label can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotRollback"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type StartRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq StartRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Start(ctx context.Context, req StartRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/start"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package bservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type StopRequest struct {
|
||||
ServiceID uint64 `url:"serviceId"`
|
||||
}
|
||||
|
||||
func (bsrq StopRequest) Validate() error {
|
||||
if bsrq.ServiceID == 0 {
|
||||
return errors.New("field ServiceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b BService) Stop(ctx context.Context, req StopRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/stop"
|
||||
res, err := b.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return strconv.ParseBool(string(res))
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
)
|
||||
|
||||
type decortClient struct {
|
||||
decortUrl string
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func New(config Config) *decortClient {
|
||||
return &decortClient{
|
||||
decortUrl: config.DecortUrl,
|
||||
client: newHttpClient(config),
|
||||
}
|
||||
}
|
||||
|
||||
func (dc *decortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||
values, err := query.Values(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body := strings.NewReader(values.Encode())
|
||||
req, _ := http.NewRequestWithContext(ctx, method, dc.decortUrl+"/restmachine"+url, body)
|
||||
|
||||
resp, err := dc.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, errors.New(string(respBytes))
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/compute"
|
||||
)
|
||||
|
||||
func (dc *decortClient) Compute() *compute.Compute {
|
||||
return compute.New(dc)
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityGroupCheckStartRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
AffinityLabel string `url:"affinityLabel"`
|
||||
}
|
||||
|
||||
func (crq AffinityGroupCheckStartRequest) Validate() error {
|
||||
if crq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if crq.AffinityLabel == "" {
|
||||
return errors.New("validation-error: field AffinityLabel can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/compute/affinityGroupCheckStart"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityLabelRemoveRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq AffinityLabelRemoveRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityLabelRemove"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityLabelSetRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
AffinityLabel string `url:"affinityLabel"`
|
||||
}
|
||||
|
||||
func (crq AffinityLabelSetRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
if crq.AffinityLabel == "" {
|
||||
return errors.New("validation-error: field AffinityLabel can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityLabelSet"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityRelationsRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
AffinityLabel string `url:"affinityLabel"`
|
||||
}
|
||||
|
||||
func (crq AffinityRelationsRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest, options ...opts.DecortOpts) (*AffinityRelations, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityRelations"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
relations := &AffinityRelations{}
|
||||
|
||||
err = json.Unmarshal([]byte(res), relations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return relations, nil
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityRuleAddRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
Topology string `url:"topology"`
|
||||
Policy string `url:"policy"`
|
||||
Mode string `url:"mode"`
|
||||
Key string `url:"key"`
|
||||
Value string `url:"value"`
|
||||
}
|
||||
|
||||
func (crq AffinityRuleAddRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Topology == "" {
|
||||
return errors.New("validation-error: field Topology can not be empty")
|
||||
}
|
||||
|
||||
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Topology can be only compute or node")
|
||||
}
|
||||
|
||||
if crq.Policy == "" {
|
||||
return errors.New("validation-error: field Policy can not be empty")
|
||||
}
|
||||
|
||||
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
||||
}
|
||||
|
||||
if crq.Mode == "" {
|
||||
return errors.New("validation-error: field Mode can not be empty")
|
||||
}
|
||||
|
||||
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
||||
}
|
||||
|
||||
if crq.Key == "" {
|
||||
return errors.New("validation-error: field Key can not be empty")
|
||||
}
|
||||
|
||||
if crq.Value == "" {
|
||||
return errors.New("validation-error: field Value can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityRuleAdd"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityRuleRemoveRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
Topology string `url:"topology"`
|
||||
Policy string `url:"policy"`
|
||||
Mode string `url:"mode"`
|
||||
Key string `url:"key"`
|
||||
Value string `url:"value"`
|
||||
}
|
||||
|
||||
func (crq AffinityRuleRemoveRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Topology == "" {
|
||||
return errors.New("validation-error: field Topology can not be empty")
|
||||
}
|
||||
|
||||
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Topology can be only compute or node")
|
||||
}
|
||||
|
||||
if crq.Policy == "" {
|
||||
return errors.New("validation-error: field Policy can not be empty")
|
||||
}
|
||||
|
||||
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
||||
}
|
||||
|
||||
if crq.Mode == "" {
|
||||
return errors.New("validation-error: field Mode can not be empty")
|
||||
}
|
||||
|
||||
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
||||
}
|
||||
|
||||
if crq.Key == "" {
|
||||
return errors.New("validation-error: field Key can not be empty")
|
||||
}
|
||||
|
||||
if crq.Value == "" {
|
||||
return errors.New("validation-error: field Value can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityRuleRemove"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AffinityRulesClearRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq AffinityRulesClearRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/affinityRulesClear"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AntiAffinityRuleAddRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
Topology string `url:"topology"`
|
||||
Policy string `url:"policy"`
|
||||
Mode string `url:"mode"`
|
||||
Key string `url:"key"`
|
||||
Value string `url:"value"`
|
||||
}
|
||||
|
||||
func (crq AntiAffinityRuleAddRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Topology == "" {
|
||||
return errors.New("validation-error: field Topology can not be empty")
|
||||
}
|
||||
|
||||
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Topology can be only compute or node")
|
||||
}
|
||||
|
||||
if crq.Policy == "" {
|
||||
return errors.New("validation-error: field Policy can not be empty")
|
||||
}
|
||||
|
||||
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
||||
}
|
||||
|
||||
if crq.Mode == "" {
|
||||
return errors.New("validation-error: field Mode can not be empty")
|
||||
}
|
||||
|
||||
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
||||
}
|
||||
|
||||
if crq.Key == "" {
|
||||
return errors.New("validation-error: field Key can not be empty")
|
||||
}
|
||||
|
||||
if crq.Value == "" {
|
||||
return errors.New("validation-error: field Value can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/antiAffinityRuleAdd"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AntiAffinityRuleRemoveRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
Topology string `url:"topology"`
|
||||
Policy string `url:"policy"`
|
||||
Mode string `url:"mode"`
|
||||
Key string `url:"key"`
|
||||
Value string `url:"value"`
|
||||
}
|
||||
|
||||
func (crq AntiAffinityRuleRemoveRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Topology == "" {
|
||||
return errors.New("validation-error: field Topology can not be empty")
|
||||
}
|
||||
|
||||
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Topology can be only compute or node")
|
||||
}
|
||||
|
||||
if crq.Policy == "" {
|
||||
return errors.New("validation-error: field Policy can not be empty")
|
||||
}
|
||||
|
||||
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
|
||||
}
|
||||
|
||||
if crq.Mode == "" {
|
||||
return errors.New("validation-error: field Mode can not be empty")
|
||||
}
|
||||
|
||||
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
|
||||
}
|
||||
|
||||
if crq.Key == "" {
|
||||
return errors.New("validation-error: field Key can not be empty")
|
||||
}
|
||||
|
||||
if crq.Value == "" {
|
||||
return errors.New("validation-error: field Value can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/antiAffinityRuleRemove"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AntiAffinityRulesClearRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq AntiAffinityRulesClearRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/antiAffinityRulesClear"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AttachGPURequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
VGPUID uint64 `url:"vgpuId"`
|
||||
}
|
||||
|
||||
func (crq AttachGPURequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.VGPUID == 0 {
|
||||
return errors.New("validation-error: field VGPUID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/compute/attachGpu"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AttachPciDeviceRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
DeviceID uint64 `url:"deviceId"`
|
||||
}
|
||||
|
||||
func (crq AttachPciDeviceRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DeviceID == 0 {
|
||||
return errors.New("validation-error: field DeviceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/attachPciDevice"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type AuditsRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq AuditsRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AuditList, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/audits"
|
||||
auditListRaw, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
auditList := AuditList{}
|
||||
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return auditList, nil
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CDEjectRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq CDEjectRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/cdEject"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CDInsertRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
CDROMID uint64 `url:"cdromId"`
|
||||
}
|
||||
|
||||
func (crq CDInsertRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
if crq.CDROMID == 0 {
|
||||
return errors.New("validation-error: field CDROMID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/cdInsert"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CloneRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
Name string `url:"name"`
|
||||
SnapshotTimestamp uint64 `url:"snapshotTimestamp"`
|
||||
SnapshotName string `url:"snapshotName"`
|
||||
}
|
||||
|
||||
func (crq CloneRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Clone(ctx context.Context, req CloneRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/compute/clone"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
type Compute struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *Compute {
|
||||
return &Compute{
|
||||
client,
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateTemplateRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
Name string `url:"name"`
|
||||
Async bool `url:"async"`
|
||||
}
|
||||
|
||||
func (crq CreateTemplateRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
req.Async = false
|
||||
|
||||
url := "/compute/createTemplate"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
req.Async = true
|
||||
|
||||
url := "/compute/createTemplate"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
DetachDisks bool `url:"detachDisks,omitempty"`
|
||||
}
|
||||
|
||||
func (crq DeleteRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/delete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DetachGPURequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
VGPUID int64 `url:"vgpuId,omitempty"`
|
||||
}
|
||||
|
||||
func (crq DetachGPURequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/detachGpu"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DetachPciDeviceRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
DeviceID uint64 `url:"deviceId"`
|
||||
}
|
||||
|
||||
func (crq DetachPciDeviceRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DeviceID == 0 {
|
||||
return errors.New("validation-error: field DeviceID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/detachPciDevice"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DisableRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq DisableRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Disable(ctx context.Context, req DisableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/disable"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskAddRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
DiskName string `url:"diskName"`
|
||||
Size uint64 `url:"size"`
|
||||
DiskType string `url:"diskType,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
Pool string `url:"pool,omitempty"`
|
||||
Description string `url:"desc,omitempty"`
|
||||
ImageID uint64 `url:"imageId,omitempty"`
|
||||
}
|
||||
|
||||
func (crq DiskAddRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.Size == 0 {
|
||||
return errors.New("validation-error: field Size can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskName == "" {
|
||||
return errors.New("validation-error: field DiskName can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/compute/diskAdd"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskAttachRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
}
|
||||
|
||||
func (crq DiskAttachRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskAttach"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskDelRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Permanently bool `url:"permanently"`
|
||||
}
|
||||
|
||||
func (crq DiskDelRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskDel"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskDetachRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
}
|
||||
|
||||
func (crq DiskDetachRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskDetach"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskQOSRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Limits string `url:"limits"`
|
||||
}
|
||||
|
||||
func (crq DiskQOSRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.Limits == "" {
|
||||
return errors.New("validation-error: field Limits can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskQos"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DiskResizeRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (crq DiskResizeRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID 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")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/diskResize"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type EnableRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq EnableRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Enable(ctx context.Context, req EnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/enable"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq GetRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*ComputeRecord, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/compute/get"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
compute := &ComputeRecord{}
|
||||
err = json.Unmarshal(res, compute)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return compute, nil
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetAuditsRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq GetAuditsRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest, options ...opts.DecortOpts) (AuditShortList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/compute/getAudits"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
auditsList := AuditShortList{}
|
||||
err = json.Unmarshal(res, &auditsList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return auditsList, nil
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetConsoleURLRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq GetConsoleURLRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/compute/getConsoleUrl"
|
||||
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
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetLogRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
Path string `url:"path"`
|
||||
}
|
||||
|
||||
func (crq GetLogRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if crq.Path == "" {
|
||||
return errors.New("validation-error: field Path can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) GetLog(ctx context.Context, req GetLogRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/compute/getLog"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
|
||||
func (c Compute) GetLogGet(ctx context.Context, req GetLogRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/compute/getLog"
|
||||
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.GET, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (c Compute) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ComputeList, error) {
|
||||
|
||||
url := "/compute/list"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
computeList := ComputeList{}
|
||||
|
||||
err = json.Unmarshal(res, &computeList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return computeList, nil
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListDeletedRequest struct {
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (ComputeList, error) {
|
||||
|
||||
url := "/compute/listDeleted"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
computeList := ComputeList{}
|
||||
|
||||
err = json.Unmarshal(res, &computeList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return computeList, nil
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListPCIDeviceRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq ListPCIDeviceRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest, options ...opts.DecortOpts) ([]interface{}, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/compute/listPciDevice"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pciDeviceList := []interface{}{}
|
||||
|
||||
err = json.Unmarshal(res, &pciDeviceList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pciDeviceList, nil
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListVGPURequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq ListVGPURequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest, options ...opts.DecortOpts) ([]interface{}, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/compute/listVgpu"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pciDeviceList := []interface{}{}
|
||||
|
||||
err = json.Unmarshal(res, &pciDeviceList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pciDeviceList, nil
|
||||
}
|
@ -0,0 +1,288 @@
|
||||
package compute
|
||||
|
||||
//ACL for compute
|
||||
type UserList struct {
|
||||
AccountACL ACLList `json:"accountACL"`
|
||||
ComputeACL ACLList `json:"computeACL"`
|
||||
RGACL ACLList `json:"rgACL"`
|
||||
}
|
||||
|
||||
type ACL struct {
|
||||
Explicit bool `json:"explicit"`
|
||||
GUID string `json:"guid"`
|
||||
Rigth string `json:"right"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
UserGroupId string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
type ACLList []ACL
|
||||
|
||||
type SnapshotUsage struct {
|
||||
Count uint64 `json:"count,omitempty"`
|
||||
Stored float64 `json:"stored"`
|
||||
Label string `json:"label,omitempty"`
|
||||
Timestamp uint64 `json:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
type SnapshotUsageList []SnapshotUsage
|
||||
|
||||
type Snapshot struct {
|
||||
Disks []uint64 `json:"disks"`
|
||||
GUID string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type SnapshotList []Snapshot
|
||||
|
||||
type PFW struct {
|
||||
ID uint64 `json:"id"`
|
||||
LocalIP string `json:"localIp"`
|
||||
LocalPort uint64 `json:"localPort"`
|
||||
Protocol string `json:"protocol"`
|
||||
PublicPortEnd uint64 `json:"publicPortEnd"`
|
||||
PublicPortStart uint64 `json:"publicPortStart"`
|
||||
VMID uint64 `json:"vmId"`
|
||||
}
|
||||
|
||||
type PFWList []PFW
|
||||
|
||||
type AffinityRelations struct {
|
||||
OtherNode []interface{} `json:"otherNode"`
|
||||
OtherNodeIndirect []interface{} `json:"otherNodeIndirect"`
|
||||
OtherNodeIndirectSoft []interface{} `json:"otherNodeIndirectSoft"`
|
||||
OtherNodeSoft []interface{} `json:"otherNodeSoft"`
|
||||
SameNode []interface{} `json:"sameNode"`
|
||||
SameNodeSoft []interface{} `json:"sameNodeSoft"`
|
||||
}
|
||||
|
||||
type NetAttach struct {
|
||||
ConnID uint64 `json:"connId"`
|
||||
ConnType string `json:"connType"`
|
||||
DefGW string `json:"defGw"`
|
||||
FlipGroupID uint64 `json:"flipgroupId"`
|
||||
GUID string `json:"guid"`
|
||||
IPAddress string `json:"ipAddress"`
|
||||
ListenSSH bool `json:"listenSsh"`
|
||||
MAC string `json:"mac"`
|
||||
Name string `json:"name"`
|
||||
NetID uint64 `json:"netId"`
|
||||
NetMask uint64 `json:"netMask"`
|
||||
NetType string `json:"netType"`
|
||||
PCISlot uint64 `json:"pciSlot"`
|
||||
QOS QOS `json:"qos"`
|
||||
Target string `json:"target"`
|
||||
Type string `json:"type"`
|
||||
VNFS []uint64 `json:"vnfs"`
|
||||
}
|
||||
|
||||
type Audit struct {
|
||||
Call string `json:"call"`
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
StatusCode uint64 `json:"statuscode"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
type AuditList []Audit
|
||||
|
||||
type AuditShort struct {
|
||||
Epoch float64 `json:"epoch"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type AuditShortList []AuditShort
|
||||
|
||||
type Rule struct {
|
||||
GUID string `json:"guid"`
|
||||
Key string `json:"key"`
|
||||
Mode string `json:"mode"`
|
||||
Policy string `json:"policy"`
|
||||
Topology string `json:"topology"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type RuleList []Rule
|
||||
|
||||
type ComputeRecord struct {
|
||||
ACL UserList `json:"ACL"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
AffinityLabel string `json:"affinityLabel"`
|
||||
AffinityRules RuleList `json:"affinityRules"`
|
||||
AffinityWeight uint64 `json:"affinityWeight"`
|
||||
AntiAffinityRules RuleList `json:"antiAffinityRules"`
|
||||
Architecture string `json:"arch"`
|
||||
BootOrder []string `json:"bootOrder"`
|
||||
BootDiskSize uint64 `json:"bootdiskSize"`
|
||||
CloneReference uint64 `json:"cloneReference"`
|
||||
Clones []uint64 `json:"clones"`
|
||||
ComputeCIID uint64 `json:"computeciId"`
|
||||
CPU uint64 `json:"cpus"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
CustomFields map[string]interface{} `json:"customFields"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Description string `json:"desc"`
|
||||
Devices interface{} `json:"devices"`
|
||||
Disks ComputeDiskList `json:"disks"`
|
||||
Driver string `json:"driver"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
ImageID uint64 `json:"imageId"`
|
||||
ImageName string `json:"imageName"`
|
||||
Intefaces IntefaceList `json:"interfaces"`
|
||||
LockStatus string `json:"lockStatus"`
|
||||
ManagerID uint64 `json:"managerId"`
|
||||
ManagerType string `json:"managerType"`
|
||||
MigrationJob uint64 `json:"migrationjob"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
NatableVinsID uint64 `json:"natableVinsId"`
|
||||
NatableVinsIP string `json:"natableVinsIp"`
|
||||
NatableVinsName string `json:"natableVinsName"`
|
||||
NatableVinsNetwork string `json:"natableVinsNetwork"`
|
||||
NatableVinsNetworkName string `json:"natableVinsNetworkName"`
|
||||
OSUsers OSUserList `json:"osUsers"`
|
||||
Pinned bool `json:"pinned"`
|
||||
RAM uint64 `json:"ram"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Registered bool `json:"registered"`
|
||||
ResName string `json:"resName"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
SnapSets SnapSetList `json:"snapSets"`
|
||||
StatelessSepID uint64 `json:"statelessSepId"`
|
||||
StatelessSepType string `json:"statelessSepType"`
|
||||
Status string `json:"status"`
|
||||
Tags map[string]string `json:"tags"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
Userdata interface{} `json:"userdata"`
|
||||
VGPUs []uint64 `json:"vgpus"`
|
||||
VirtualImageID uint64 `json:"virtualImageId"`
|
||||
VirtualImageName string `json:"virtualImageName"`
|
||||
}
|
||||
|
||||
type ComputeList []ComputeRecord
|
||||
|
||||
type OSUser struct {
|
||||
GUID string `json:"guid"`
|
||||
Login string `json:"login"`
|
||||
Password string `json:"password"`
|
||||
PubKey string `json:"pubkey"`
|
||||
}
|
||||
|
||||
type OSUserList []OSUser
|
||||
|
||||
type SnapSet struct {
|
||||
Disks []uint64 `json:"disks"`
|
||||
GUID string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type SnapSetList []SnapSet
|
||||
|
||||
type VNFInterface struct {
|
||||
ConnId uint64 `json:"connId"`
|
||||
ConnType string `json:"connType"`
|
||||
DefGW string `json:"defGw"`
|
||||
FlipGroupId uint64 `json:"flipgroupId"`
|
||||
GUID string `json:"guid"`
|
||||
IPAddress string `json:"ipAddress"`
|
||||
ListenSSH bool `json:"listenSsh"`
|
||||
MAC string `json:"mac"`
|
||||
Name string `json:"name"`
|
||||
NetId uint64 `json:"netId"`
|
||||
NetMask uint64 `json:"netMask"`
|
||||
NetType string `json:"netType"`
|
||||
PCISlot uint64 `json:"pciSlot"`
|
||||
QOS QOS `json:"qos"`
|
||||
Target string `json:"target"`
|
||||
Type string `json:"type"`
|
||||
VNFS []uint64 `json:"vnfs"`
|
||||
}
|
||||
|
||||
type QOS struct {
|
||||
ERate uint64 `json:"eRate"`
|
||||
GUID string `json:"guid"`
|
||||
InBurst uint64 `json:"inBurst"`
|
||||
InRate uint64 `json:"inRate"`
|
||||
}
|
||||
|
||||
type IntefaceList []VNFInterface
|
||||
|
||||
type ComputeDiskList []ComputeDisk
|
||||
|
||||
type ComputeDisk struct {
|
||||
Ckey string `json:"_ckey"`
|
||||
Acl map[string]interface{} `json:"acl"`
|
||||
AccountID int `json:"accountId"`
|
||||
Bootpartition uint64 `json:"bootPartition"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Description string `json:"desc"`
|
||||
DestructionTime uint64 `json:"destructionTime"`
|
||||
DiskPath string `json:"diskPath"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
ImageID uint64 `json:"imageId"`
|
||||
Images []uint64 `json:"images"`
|
||||
IOTune IOTune `json:"iotune"`
|
||||
IQN string `json:"iqn"`
|
||||
Login string `json:"login"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Order uint64 `json:"order"`
|
||||
Params string `json:"params"`
|
||||
ParentID uint64 `json:"parentId"`
|
||||
Passwd string `json:"passwd"`
|
||||
PciSlot uint64 `json:"pciSlot"`
|
||||
Pool string `json:"pool"`
|
||||
PurgeTime uint64 `json:"purgeTime"`
|
||||
RealityDeviceNumber uint64 `json:"realityDeviceNumber"`
|
||||
ResID string `json:"resId"`
|
||||
Role string `json:"role"`
|
||||
SepID int `json:"sepId"` // NOTE: absent from compute/get output
|
||||
SizeMax int `json:"sizeMax"`
|
||||
SizeUsed int `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space
|
||||
Snapshots SnapshotExtendList `json:"snapshots"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
VMID int `json:"vmid"`
|
||||
}
|
||||
|
||||
type SnapshotExtend struct {
|
||||
Guid string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
ResId string `json:"resId"`
|
||||
SnapSetGuid string `json:"snapSetGuid"`
|
||||
SnapSetTime uint64 `json:"snapSetTime"`
|
||||
TimeStamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type SnapshotExtendList []SnapshotExtend
|
||||
|
||||
type IOTune struct {
|
||||
ReadBytesSec int `json:"read_bytes_sec"`
|
||||
ReadBytesSecMax int `json:"read_bytes_sec_max"`
|
||||
ReadIopsSec int `json:"read_iops_sec"`
|
||||
ReadIopsSecMax int `json:"read_iops_sec_max"`
|
||||
SizeIopsSec int `json:"size_iops_sec"`
|
||||
TotalBytesSec int `json:"total_bytes_sec"`
|
||||
TotalBytesSecMax int `json:"total_bytes_sec_max"`
|
||||
TotalIopsSec int `json:"total_iops_sec"`
|
||||
TotalIopsSecMax int `json:"total_iops_sec_max"`
|
||||
WriteBytesSec int `json:"write_bytes_sec"`
|
||||
WriteBytesSecMax int `json:"write_bytes_sec_max"`
|
||||
WriteIopsSec int `json:"write_iops_sec"`
|
||||
WriteIopsSecMax int `json:"write_iops_sec_max"`
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type MoveToRGRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
RGID uint64 `url:"rgId"`
|
||||
Name string `url:"name,omitempty"`
|
||||
Autostart bool `url:"autostart,omitempty"`
|
||||
ForceStop bool `url:"forceStop,omitempty"`
|
||||
}
|
||||
|
||||
func (crq MoveToRGRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId 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")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) MoveToRG(ctx context.Context, req MoveToRGRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/moveToRg"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type NetAttachRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
NetType string `url:"netType"`
|
||||
NetID uint64 `url:"netId"`
|
||||
IPAddr string `url:"ipAddr,omitempty"`
|
||||
}
|
||||
|
||||
func (crq NetAttachRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
if crq.NetType == "" {
|
||||
return errors.New("validation-error: field NetType can not be empty")
|
||||
}
|
||||
validator := validators.StringInSlice(crq.NetType, []string{"EXTNET", "VINS"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field NetType can be only EXTNET or VINS")
|
||||
}
|
||||
|
||||
if crq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) NetAttach(ctx context.Context, req NetAttachRequest, options ...opts.DecortOpts) (*NetAttach, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/compute/netAttach"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
netAttach := &NetAttach{}
|
||||
err = json.Unmarshal(res, netAttach)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return netAttach, nil
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type NetDetachRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
IPAddr string `url:"ipAddr,omitempty"`
|
||||
MAC string `url:"mac,omitempty"`
|
||||
}
|
||||
|
||||
func (crq NetDetachRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) NetDetach(ctx context.Context, req NetDetachRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/netDetach"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type PauseRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
}
|
||||
|
||||
func (crq PauseRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) Pause(ctx context.Context, req PauseRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/pause"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type PFWAddRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
PublicPortStart uint64 `url:"publicPortStart"`
|
||||
PublicPortEnd uint64 `url:"publicPortEnd,omitempty"`
|
||||
LocalBasePort uint64 `url:"localBasePort"`
|
||||
Proto string `url:"proto"`
|
||||
}
|
||||
|
||||
func (crq PFWAddRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
if crq.PublicPortStart == 0 {
|
||||
return errors.New("validation-error: field PublicPortStart can not be empty or equal to 0")
|
||||
}
|
||||
if crq.LocalBasePort == 0 {
|
||||
return errors.New("validation-error: field LocalBasePort can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Proto == "" {
|
||||
return errors.New("validation-error: field Proto can not be empty")
|
||||
}
|
||||
validator := validators.StringInSlice(crq.Proto, []string{"tcp", "udp"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field Proto can be only tcp or udp")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) PFWAdd(ctx context.Context, req PFWAddRequest, options ...opts.DecortOpts) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/compute/pfwAdd"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type PFWDelRequest struct {
|
||||
ComputeId uint64 `url:"computeId"`
|
||||
PFWId uint64 `url:"ruleId,omitempty"`
|
||||
PublicPortStart uint64 `url:"publicPortStart,omitempty"`
|
||||
PublicPortEnd uint64 `url:"publicPortEnd,omitempty"`
|
||||
LocalBasePort uint64 `url:"localBasePort,omitempty"`
|
||||
Proto string `url:"proto,omitempty"`
|
||||
}
|
||||
|
||||
func (crq PFWDelRequest) Validate() error {
|
||||
if crq.ComputeId == 0 {
|
||||
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Compute) PFWDel(ctx context.Context, req PFWDelRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/compute/pfwDel"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := c.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue