Refactoring

This commit is contained in:
stSolo
2022-08-11 16:39:39 +03:00
parent 9563097dcb
commit 39a6f9a1ce
300 changed files with 64 additions and 58 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,53 @@
package compute
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type PFWListRequest struct {
ComputeId uint64 `url:"computeId"`
}
func (crq PFWListRequest) 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) PFWList(ctx context.Context, req PFWListRequest, options ...opts.DecortOpts) (PFWList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/compute/pfwList"
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
}
pfwList := PFWList{}
err = json.Unmarshal(res, &pfwList)
if err != nil {
return nil, err
}
return pfwList, nil
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type PinToStackRequest struct {
ComputeId uint64 `url:"computeId"`
}
func (crq PinToStackRequest) 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) PinToStack(ctx context.Context, req PinToStackRequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/compute/pinToStack"
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
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type PowerCycleRequest struct {
ComputeId uint64 `url:"computeId"`
}
func (crq PowerCycleRequest) 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) PowerCycle(ctx context.Context, req PowerCycleRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/powerCycle"
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
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RebootRequest struct {
ComputeId uint64 `url:"computeId"`
}
func (crq RebootRequest) 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) Reboot(ctx context.Context, req RebootRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/reboot"
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
}

View File

@@ -0,0 +1,55 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RedeployRequest struct {
ComputeId uint64 `url:"computeId"`
ImageId uint64 `url:"imageId,omitempty"`
DiskSize uint64 `url:"diskSize,omitempty"`
DataDisks string `url:"dataDisks,omitempty"`
AutoStart bool `url:"autoStart,omitempty"`
ForceStop bool `url:"forceStop,omitempty"`
}
func (crq RedeployRequest) 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) Redeploy(ctx context.Context, req RedeployRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/redeploy"
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
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ResetRequest struct {
ComputeId uint64 `url:"computeId"`
}
func (crq ResetRequest) 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) Reset(ctx context.Context, req ResetRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/reset"
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
}

View File

@@ -0,0 +1,53 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ResizeRequest struct {
ComputeId uint64 `url:"computeId"`
Force bool `url:"force,omitempty"`
CPU uint64 `url:"cpu,omitempty"`
RAM uint64 `url:"ram,omitempty"`
}
func (crq ResizeRequest) 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) Resize(ctx context.Context, req ResizeRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/resize"
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
}

View File

@@ -0,0 +1,45 @@
package compute
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RestoreRequest struct {
ComputeId uint64 `url:"computeId"`
}
func (crq RestoreRequest) 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) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/compute/restore"
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
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ResumeRequest struct {
ComputeId uint64 `url:"computeId"`
}
func (crq ResumeRequest) 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) Resume(ctx context.Context, req ResumeRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/resume"
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
}

View File

@@ -0,0 +1,52 @@
package compute
import (
"context"
"errors"
"strings"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotCreateRequest struct {
ComputeId uint64 `url:"computeId"`
Label string `url:"label"`
}
func (crq SnapshotCreateRequest) Validate() error {
if crq.ComputeId == 0 {
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
}
if crq.Label == "" {
return errors.New("validation-error: field Label can not be empty")
}
return nil
}
func (c Compute) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/compute/snapshotCreate"
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
}

View File

@@ -0,0 +1,55 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotDeleteRequest struct {
ComputeId uint64 `url:"computeId"`
Label string `url:"label"`
}
func (crq SnapshotDeleteRequest) Validate() error {
if crq.ComputeId == 0 {
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
}
if crq.Label == "" {
return errors.New("validation-error: field Label can not be empty")
}
return nil
}
func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/snapshotDelete"
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
}

View File

@@ -0,0 +1,53 @@
package compute
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotListRequest struct {
ComputeId uint64 `url:"computeId"`
}
func (crq SnapshotListRequest) 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) SnapshotList(ctx context.Context, req SnapshotListRequest, options ...opts.DecortOpts) (SnapshotList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/compute/snapshotList"
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
}
snapshotList := SnapshotList{}
err = json.Unmarshal(res, &snapshotList)
if err != nil {
return nil, err
}
return snapshotList, nil
}

View File

@@ -0,0 +1,55 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotRollbackRequest struct {
ComputeId uint64 `url:"computeId"`
Label string `url:"label"`
}
func (crq SnapshotRollbackRequest) Validate() error {
if crq.ComputeId == 0 {
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
}
if crq.Label == "" {
return errors.New("validation-error: field Label can not be empty")
}
return nil
}
func (c Compute) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/snapshotRollback"
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
}

View File

@@ -0,0 +1,54 @@
package compute
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotUsageRequest struct {
ComputeId uint64 `url:"computeId"`
Label string `url:"label,omitempty"`
}
func (crq SnapshotUsageRequest) 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) SnapshotUsage(ctx context.Context, req SnapshotUsageRequest, options ...opts.DecortOpts) (SnapshotUsageList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/compute/snapshotUsage"
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
}
snapshotUsage := SnapshotUsageList{}
err = json.Unmarshal(res, &snapshotUsage)
if err != nil {
return nil, err
}
return snapshotUsage, nil
}

View File

@@ -0,0 +1,51 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type StartRequest struct {
ComputeId uint64 `url:"computeId"`
AltBootId uint64 `url:"altBootId,omitempty"`
}
func (crq StartRequest) 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) Start(ctx context.Context, req StartRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/start"
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
}

View File

@@ -0,0 +1,51 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type StopRequest struct {
ComputeId uint64 `url:"computeId"`
Force bool `url:"force,omitempty"`
}
func (crq StopRequest) 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) Stop(ctx context.Context, req StopRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/stop"
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
}

View File

@@ -0,0 +1,59 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type TagAddRequest struct {
ComputeId uint64 `url:"computeId"`
Key string `url:"key"`
Value string `url:"value"`
}
func (crq TagAddRequest) Validate() error {
if crq.ComputeId == 0 {
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
}
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) TagAdd(ctx context.Context, req TagAddRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/tagAdd"
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
}

View File

@@ -0,0 +1,54 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type TagRemoveRequest struct {
ComputeId uint64 `url:"computeId"`
Key string `url:"key"`
}
func (crq TagRemoveRequest) Validate() error {
if crq.ComputeId == 0 {
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
return nil
}
func (c Compute) TagRemove(ctx context.Context, req TagRemoveRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/tagRemove"
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
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type UnpinFromStackRequest struct {
ComputeId uint64 `url:"computeId"`
}
func (crq UnpinFromStackRequest) 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) UnpinFromStack(ctx context.Context, req UnpinFromStackRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/unpinFromStack"
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
}

View File

@@ -0,0 +1,52 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type UpdateRequest struct {
ComputeId uint64 `url:"computeId"`
Name string `url:"name,omitempty"`
Description string `url:"desc,omitempty"`
}
func (crq UpdateRequest) 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) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/update"
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
}

View File

@@ -0,0 +1,65 @@
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 UserGrantRequest struct {
ComputeId uint64 `url:"computeId"`
Username string `url:"userName"`
AccessType string `url:"accesstype"`
}
func (crq UserGrantRequest) Validate() error {
if crq.ComputeId == 0 {
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
}
if crq.Username == "" {
return errors.New("validation-error: field Username can not be empty")
}
if crq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
validator := validators.StringInSlice(crq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !validator {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
}
func (c Compute) UserGrant(ctx context.Context, req UserGrantRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/userGrant"
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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type UserListRequest struct {
ComputeId uint64 `url:"computeId "`
}
func (crq UserListRequest) 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) UserList(ctx context.Context, req UserListRequest, options ...opts.DecortOpts) (*UserList, error) {
url := "/compute/userList"
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
}
userList := &UserList{}
err = json.Unmarshal(res, userList)
if err != nil {
return nil, err
}
return userList, nil
}

View File

@@ -0,0 +1,55 @@
package compute
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type UserRevokeRequest struct {
ComputeId uint64 `url:"computeId"`
Username string `url:"userName"`
}
func (crq UserRevokeRequest) Validate() error {
if crq.ComputeId == 0 {
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
}
if crq.Username == "" {
return errors.New("validation-error: field Username can not be empty")
}
return nil
}
func (c Compute) UserRevoke(ctx context.Context, req UserRevokeRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/userRevoke"
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
}

View File

@@ -0,0 +1,65 @@
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 UserUpdateRequest struct {
ComputeId uint64 `url:"computeId"`
Username string `url:"userName"`
AccessType string `url:"accesstype"`
}
func (crq UserUpdateRequest) Validate() error {
if crq.ComputeId == 0 {
return errors.New("validation-error: field ComputeId can not be empty or equal to 0")
}
if crq.Username == "" {
return errors.New("validation-error: field Username can not be empty")
}
if crq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
validator := validators.StringInSlice(crq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !validator {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
}
func (c Compute) UserUpdate(ctx context.Context, req UserUpdateRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/compute/userUpdate"
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
}