This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -6,12 +6,18 @@ import (
"net/http"
)
// Request struct for check all computes with current affinity label can start
type AffinityGroupCheckStartRequest struct {
RGID uint64 `url:"rgId"`
// ID of the resource group
// Required: true
RGID uint64 `url:"rgId"`
// Affinity group label
// Required: true
AffinityLabel string `url:"affinityLabel"`
}
func (crq AffinityGroupCheckStartRequest) Validate() error {
func (crq AffinityGroupCheckStartRequest) validate() error {
if crq.RGID == 0 {
return errors.New("validation-error: field RGID can not be empty or equal to 0")
}
@@ -22,8 +28,9 @@ func (crq AffinityGroupCheckStartRequest) Validate() error {
return nil
}
// AffinityGroupCheckStart check all computes with current affinity label can start
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return "", err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for clear affinity label for compute
type AffinityLabelRemoveRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq AffinityLabelRemoveRequest) Validate() error {
func (crq AffinityLabelRemoveRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq AffinityLabelRemoveRequest) Validate() error {
return nil
}
// AffinityLabelRemove clear affinity label for compute
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for set affinity label for compute
type AffinityLabelSetRequest struct {
ComputeID uint64 `url:"computeId"`
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Affinity group label
// Required: true
AffinityLabel string `url:"affinityLabel"`
}
func (crq AffinityLabelSetRequest) Validate() error {
func (crq AffinityLabelSetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -23,8 +29,9 @@ func (crq AffinityLabelSetRequest) Validate() error {
return nil
}
// AffinityLabelSet set affinity label for compute
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,12 +7,14 @@ import (
"net/http"
)
// Request struct for get dict of computes
type AffinityRelationsRequest struct {
ComputeID uint64 `url:"computeId"`
AffinityLabel string `url:"affinityLabel"`
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq AffinityRelationsRequest) Validate() error {
func (crq AffinityRelationsRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -20,8 +22,9 @@ func (crq AffinityRelationsRequest) Validate() error {
return nil
}
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*AffinityRelations, error) {
err := req.Validate()
// AffinityRelations gets dict of computes divided by affinity and anti affinity rules
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*RecordAffinityRelations, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -33,12 +36,12 @@ func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsReq
return nil, err
}
relations := &AffinityRelations{}
info := RecordAffinityRelations{}
err = json.Unmarshal(res, relations)
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return relations, nil
return &info, nil
}

View File

@@ -9,50 +9,68 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for add affinity rule
type AffinityRuleAddRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value"`
}
func (crq AffinityRuleAddRequest) Validate() error {
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")
}
@@ -60,8 +78,9 @@ func (crq AffinityRuleAddRequest) Validate() error {
return nil
}
// AffinityRuleAdd add affinity rule
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -9,50 +9,68 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for remove affinity rule
type AffinityRuleRemoveRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value"`
}
func (crq AffinityRuleRemoveRequest) Validate() error {
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")
}
@@ -60,8 +78,9 @@ func (crq AffinityRuleRemoveRequest) Validate() error {
return nil
}
// AffinityRuleRemove remove affinity rule
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for clear affinity rules
type AffinityRulesClearRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq AffinityRulesClearRequest) Validate() error {
func (crq AffinityRulesClearRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq AffinityRulesClearRequest) Validate() error {
return nil
}
// AffinityRulesClear clear affinity rules
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -9,50 +9,68 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for add anti affinity rule
type AntiAffinityRuleAddRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value"`
}
func (crq AntiAffinityRuleAddRequest) Validate() error {
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")
}
@@ -60,8 +78,9 @@ func (crq AntiAffinityRuleAddRequest) Validate() error {
return nil
}
// AntiAffinityRuleAdd add anti affinity rule
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -9,50 +9,68 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for remove anti affinity rule
type AntiAffinityRuleRemoveRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Topology string `url:"topology"`
Policy string `url:"policy"`
Mode string `url:"mode"`
Key string `url:"key"`
Value string `url:"value"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value"`
}
func (crq AntiAffinityRuleRemoveRequest) Validate() error {
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")
}
@@ -60,8 +78,9 @@ func (crq AntiAffinityRuleRemoveRequest) Validate() error {
return nil
}
// AntiAffinityRuleRemove remove anti affinity rule
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for clear anti affinity rules
type AntiAffinityRulesClearRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq AntiAffinityRulesClearRequest) Validate() error {
func (crq AntiAffinityRulesClearRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq AntiAffinityRulesClearRequest) Validate() error {
return nil
}
// AntiAffinityRulesClear clear anti affinity rules
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,16 +7,21 @@ import (
"strconv"
)
// Request struct for attach GPU for compute
type AttachGPURequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
VGPUID uint64 `url:"vgpuId"`
// Identifier vGPU
// Required: true
VGPUID uint64 `url:"vgpuId"`
}
func (crq AttachGPURequest) Validate() error {
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")
}
@@ -24,8 +29,9 @@ func (crq AttachGPURequest) Validate() error {
return nil
}
// AttachGPU attach GPU for compute, returns vgpu id on success
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -7,16 +7,21 @@ import (
"strconv"
)
type AttachPciDeviceRequest struct {
// Request struct for atttach PCI device
type AttachPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
DeviceID uint64 `url:"deviceId"`
// PCI device ID
// Required: true
DeviceID uint64 `url:"deviceId"`
}
func (crq AttachPciDeviceRequest) Validate() error {
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")
}
@@ -24,8 +29,9 @@ func (crq AttachPciDeviceRequest) Validate() error {
return nil
}
func (c Compute) AttachPciDevice(ctx context.Context, req AttachPciDeviceRequest) (bool, error) {
err := req.Validate()
// AttachPCIDevice attach PCI device
func (c Compute) AttachPCIDevice(ctx context.Context, req AttachPCIDeviceRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get audit records
type AuditsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq AuditsRequest) Validate() error {
func (crq AuditsRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("field ComputeID can not be empty or equal to 0")
}
@@ -19,21 +22,26 @@ func (crq AuditsRequest) Validate() error {
return nil
}
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (AuditList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/compute/audits"
auditListRaw, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
// Audits gets audit records for the specified compute object
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate()
if err != nil {
return nil, err
}
auditList := AuditList{}
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
url := "/cloudapi/compute/audits"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
return auditList, nil
list := ListAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for eject CD image
type CDEjectRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq CDEjectRequest) Validate() error {
func (crq CDEjectRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq CDEjectRequest) Validate() error {
return nil
}
// CDEject eject CD image to compute's CD-ROM
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for insert new CD image
type CDInsertRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
CDROMID uint64 `url:"cdromId"`
// ID of CD-ROM image
// Required: true
CDROMID uint64 `url:"cdromId"`
}
func (crq CDInsertRequest) Validate() error {
func (crq CDInsertRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -23,8 +29,9 @@ func (crq CDInsertRequest) Validate() error {
return nil
}
// CDInsert insert new CD image to compute's CD-ROM
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,14 +7,26 @@ import (
"strconv"
)
// Request struct for clone compute instance
type CloneRequest struct {
ComputeID uint64 `url:"computeId"`
Name string `url:"name"`
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Name of the clone
// Required: true
Name string `url:"name"`
// Timestamp of the parent's snapshot to create clone from
// Required: false
SnapshotTimestamp uint64 `url:"snapshotTimestamp"`
SnapshotName string `url:"snapshotName"`
// Name of the parent's snapshot to create clone from
// Required: false
SnapshotName string `url:"snapshotName"`
}
func (crq CloneRequest) Validate() error {
func (crq CloneRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -25,8 +37,9 @@ func (crq CloneRequest) Validate() error {
return nil
}
// Clone clones compute instance
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}
@@ -42,5 +55,6 @@ func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -1,13 +1,16 @@
// API Actor for managing Compute. This actor is a final API for endusers to manage Compute
package compute
import (
"github.com/rudecs/decort-sdk/interfaces"
)
// Structure for creating request to compute
type Compute struct {
client interfaces.Caller
}
// Builder for compute endpoints
func New(client interfaces.Caller) *Compute {
return &Compute{
client,

View File

@@ -8,17 +8,27 @@ import (
"strings"
)
// Request struct for create template
type CreateTemplateRequest struct {
// ID of the compute to create template from
// Required: true
ComputeID uint64 `url:"computeId"`
Name string `url:"name"`
Async bool `url:"async"`
// Name to assign to the template being created
// Required: true
Name string `url:"name"`
// Async API call
// For async call use CreateTemplateAsync
// For sync call use CreateTemplate
// Required: true
async bool `url:"async"`
}
func (crq CreateTemplateRequest) Validate() error {
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")
}
@@ -26,13 +36,14 @@ func (crq CreateTemplateRequest) Validate() error {
return nil
}
// CreateTemplate create template from compute instance
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}
req.Async = false
req.async = false
url := "/cloudapi/compute/createTemplate"
@@ -49,13 +60,14 @@ func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest)
return result, nil
}
// CreateTemplateAsync create template from compute instance
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return "", err
}
req.Async = true
req.async = true
url := "/cloudapi/compute/createTemplate"

View File

@@ -7,13 +7,22 @@ import (
"strconv"
)
// Request struct for delete compute
type DeleteRequest struct {
ComputeID uint64 `url:"computeId"`
Permanently bool `url:"permanently,omitempty"`
DetachDisks bool `url:"detachDisks,omitempty"`
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Delete permanently
// Required: false
Permanently bool `url:"permanently,omitempty"`
// Set True if you want to detach data disks (if any) from the compute before its deletion
// Required: false
DetachDisks bool `url:"detachDisks,omitempty"`
}
func (crq DeleteRequest) Validate() error {
func (crq DeleteRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -21,8 +30,9 @@ func (crq DeleteRequest) Validate() error {
return nil
}
// Delete deletes compute
func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -38,5 +48,6 @@ func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for detach vgpu for compute
type DetachGPURequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
VGPUID int64 `url:"vgpuId,omitempty"`
// Identifier virtual GPU
// Required: false
VGPUID int64 `url:"vgpuId,omitempty"`
}
func (crq DetachGPURequest) Validate() error {
func (crq DetachGPURequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -20,8 +26,10 @@ func (crq DetachGPURequest) Validate() error {
return nil
}
// DetachGPU detach vgpu for compute.
// If param vgpuid is equivalent -1, then detach all vgpu for compute
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,16 +7,21 @@ import (
"strconv"
)
type DetachPciDeviceRequest struct {
// Request struct for detach PCI device
type DetachPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
DeviceID uint64 `url:"deviceId"`
// Pci device ID
// Required: true
DeviceID uint64 `url:"deviceId"`
}
func (crq DetachPciDeviceRequest) Validate() error {
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")
}
@@ -24,8 +29,9 @@ func (crq DetachPciDeviceRequest) Validate() error {
return nil
}
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPciDeviceRequest) (bool, error) {
err := req.Validate()
// DetachPCIDevice detach PCI device
func (c Compute) DetachPCIDevice(ctx context.Context, req DetachPCIDeviceRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for disable compute
type DisableRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq DisableRequest) Validate() error {
func (crq DisableRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq DisableRequest) Validate() error {
return nil
}
// Disable disables compute
func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,26 +7,53 @@ import (
"strconv"
)
// Request struct for create and attach disk to compute
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"`
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Name for disk
// Required: true
DiskName string `url:"diskName"`
// Disk size in GB
// Required: true
Size uint64 `url:"size"`
// Type of the disk
// Should be one of:
// - D
// - B
// Required: false
DiskType string `url:"diskType,omitempty"`
// Storage endpoint provider ID
// By default the same with boot disk
// Required: false
SepID uint64 `url:"sepId,omitempty"`
// Pool name
// By default will be chosen automatically
// Required: false
Pool string `url:"pool,omitempty"`
// Optional description
// Required: false
Description string `url:"desc,omitempty"`
ImageID uint64 `url:"imageId,omitempty"`
// Specify image id for create disk from template
// Required: false
ImageID uint64 `url:"imageId,omitempty"`
}
func (crq DiskAddRequest) Validate() error {
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")
}
@@ -34,8 +61,9 @@ func (crq DiskAddRequest) Validate() error {
return nil
}
// DiskAdd creates new disk and attach to compute
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -7,16 +7,21 @@ import (
"strconv"
)
// Request struct for attach disk to compute
type DiskAttachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
DiskID uint64 `url:"diskId"`
// ID of the disk to attach
// Required: true
DiskID uint64 `url:"diskId"`
}
func (crq DiskAttachRequest) Validate() error {
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")
}
@@ -24,8 +29,9 @@ func (crq DiskAttachRequest) Validate() error {
return nil
}
// DiskAttach attach disk to compute
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,17 +7,25 @@ import (
"strconv"
)
// Request struct for detach and delete disk from compute
type DiskDelRequest struct {
ComputeID uint64 `url:"computeId"`
DiskID uint64 `url:"diskId"`
Permanently bool `url:"permanently"`
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of disk instance
// Required: true
DiskID uint64 `url:"diskId"`
// False if disk is to be deleted to recycle bin
// Required: true
Permanently bool `url:"permanently"`
}
func (crq DiskDelRequest) Validate() error {
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")
}
@@ -25,8 +33,9 @@ func (crq DiskDelRequest) Validate() error {
return nil
}
// DiskDel delete disk and detach from compute
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,16 +7,21 @@ import (
"strconv"
)
// Request struct for detach disk from compute
type DiskDetachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
DiskID uint64 `url:"diskId"`
// ID of the disk to detach
// Required: true
DiskID uint64 `url:"diskId"`
}
func (crq DiskDetachRequest) Validate() error {
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")
}
@@ -24,8 +29,9 @@ func (crq DiskDetachRequest) Validate() error {
return nil
}
// DiskDetach detach disk from compute
func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,21 +7,28 @@ import (
"strconv"
)
// Request struct for change QoS of the disk
type DiskQOSRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
DiskID uint64 `url:"diskId"`
Limits string `url:"limits"`
// ID of the disk to apply limits
// Required: true
DiskID uint64 `url:"diskId"`
// Limit IO for a certain disk total and read/write options are not allowed to be combined
// Required: true
Limits string `url:"limits"`
}
func (crq DiskQOSRequest) Validate() error {
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")
}
@@ -29,8 +36,9 @@ func (crq DiskQOSRequest) Validate() error {
return nil
}
// DiskQOS change QoS of the disk
func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,21 +7,28 @@ import (
"strconv"
)
// Request struct for change disk size
type DiskResizeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
DiskID uint64 `url:"diskId"`
Size uint64 `url:"size"`
// ID of the disk to resize
// Required: true
DiskID uint64 `url:"diskId"`
// New disk size
// Required: true
Size uint64 `url:"size"`
}
func (crq DiskResizeRequest) Validate() error {
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")
}
@@ -29,8 +36,9 @@ func (crq DiskResizeRequest) Validate() error {
return nil
}
// DiskResize change disk size
func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for enable compute
type EnableRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq EnableRequest) Validate() error {
func (crq EnableRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq EnableRequest) Validate() error {
return nil
}
// Enable enables compute
func (c Compute) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request for get information about compute
type GetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq GetRequest) Validate() error {
func (crq GetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq GetRequest) Validate() error {
return nil
}
func (c Compute) Get(ctx context.Context, req GetRequest) (*ComputeRecord, error) {
err := req.Validate()
// Get Gets information about compute
func (c Compute) Get(ctx context.Context, req GetRequest) (*RecordCompute, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -32,11 +36,12 @@ func (c Compute) Get(ctx context.Context, req GetRequest) (*ComputeRecord, error
return nil, err
}
compute := &ComputeRecord{}
err = json.Unmarshal(res, compute)
info := RecordCompute{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return compute, nil
return &info, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get compute audits
type GetAuditsRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq GetAuditsRequest) Validate() error {
func (crq GetAuditsRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq GetAuditsRequest) Validate() error {
return nil
}
func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest) (AuditShortList, error) {
err := req.Validate()
// GetAudits gets compute audits
func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest) (ListShortAudits, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -32,11 +36,12 @@ func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest) (AuditShor
return nil, err
}
auditsList := AuditShortList{}
err = json.Unmarshal(res, &auditsList)
list := ListShortAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return auditsList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strings"
)
// Request struct for get console URL
type GetConsoleURLRequest struct {
// ID of compute instance to get console for
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq GetConsoleURLRequest) Validate() error {
func (crq GetConsoleURLRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq GetConsoleURLRequest) Validate() error {
return nil
}
// GetConsoleURL gets computes console URL
func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest) (string, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return "", err
}

View File

@@ -6,16 +6,21 @@ import (
"net/http"
)
// Request struct for get compute logs
type GetLogRequest struct {
// ID of compute instance to get log for
// Required: true
ComputeID uint64 `url:"computeId"`
Path string `url:"path"`
// Path to log file
// Required: true
Path string `url:"path"`
}
func (crq GetLogRequest) Validate() error {
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")
}
@@ -23,8 +28,9 @@ func (crq GetLogRequest) Validate() error {
return nil
}
// GetLog gets compute's log file by path
func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return "", err
}
@@ -39,16 +45,15 @@ func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error)
return string(res), nil
}
// GetLogGet gets compute's log file by path
func (c Compute) GetLogGet(ctx context.Context, req GetLogRequest) (string, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return "", err
}
url := "/compute/getLog"
prefix := "/cloudapi"
url := "/cloudapi//compute/getLog"
url = prefix + url
res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return "", err

View File

@@ -6,14 +6,24 @@ import (
"net/http"
)
// Request struct for get list available computes
type ListRequest struct {
IncludeDeleted bool `url:"includedeleted,omitempty"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
// Include deleted computes
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (c Compute) List(ctx context.Context, req ListRequest) (ComputeList, error) {
// List gets list of the available computes.
// Filtering based on status is possible
func (c Compute) List(ctx context.Context, req ListRequest) (ListComputes, error) {
url := "/cloudapi/compute/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -21,12 +31,12 @@ func (c Compute) List(ctx context.Context, req ListRequest) (ComputeList, error)
return nil, err
}
computeList := ComputeList{}
list := ListComputes{}
err = json.Unmarshal(res, &computeList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return computeList, nil
return list, nil
}

View File

@@ -6,13 +6,19 @@ import (
"net/http"
)
// Request struct for get deleted computes list
type ListDeletedRequest struct {
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ComputeList, error) {
// ListDeleted gets list all deleted computes
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListComputes, error) {
url := "/cloudapi/compute/listDeleted"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -20,12 +26,12 @@ func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (Compu
return nil, err
}
computeList := ComputeList{}
list := ListComputes{}
err = json.Unmarshal(res, &computeList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return computeList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list PCI devices
type ListPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq ListPCIDeviceRequest) Validate() error {
func (crq ListPCIDeviceRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq ListPCIDeviceRequest) Validate() error {
return nil
}
// ListPCIDevice gets list PCI device
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([]interface{}, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return nil, err
}
@@ -32,12 +36,12 @@ func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([
return nil, err
}
pciDeviceList := []interface{}{}
list := []interface{}{}
err = json.Unmarshal(res, &pciDeviceList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return pciDeviceList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list vGPU
type ListVGPURequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq ListVGPURequest) Validate() error {
func (crq ListVGPURequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq ListVGPURequest) Validate() error {
return nil
}
// ListVGPU gets list vGPU
func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface{}, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return nil, err
}
@@ -32,12 +36,12 @@ func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface
return nil, err
}
pciDeviceList := []interface{}{}
list := []interface{}{}
err = json.Unmarshal(res, &pciDeviceList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return pciDeviceList, nil
return list, nil
}

File diff suppressed because it is too large Load Diff

View File

@@ -7,15 +7,33 @@ import (
"strconv"
)
// Request struct for move compute new resource group
type MoveToRGRequest struct {
// ID of the compute instance to move
// Required: true
ComputeID uint64 `url:"computeId"`
RGID uint64 `url:"rgId"`
Name string `url:"name,omitempty"`
Autostart bool `url:"autostart,omitempty"`
ForceStop bool `url:"forceStop,omitempty"`
// ID of the target resource group
// Required: true
RGID uint64 `url:"rgId"`
// New name for the compute upon successful move,
// if name change required.
// Pass empty string if no name change necessary
// Required: false
Name string `url:"name,omitempty"`
// Should the compute be restarted upon successful move
// Required: false
Autostart bool `url:"autostart,omitempty"`
// By default moving compute in a running state is not allowed.
// Set this flag to True to force stop running compute instance prior to move.
// Required: false
ForceStop bool `url:"forceStop,omitempty"`
}
func (crq MoveToRGRequest) Validate() error {
func (crq MoveToRGRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -26,8 +44,9 @@ func (crq MoveToRGRequest) Validate() error {
return nil
}
// MoveToRG moves compute instance to new resource group
func (c Compute) MoveToRG(ctx context.Context, req MoveToRGRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -43,5 +62,6 @@ func (c Compute) MoveToRG(ctx context.Context, req MoveToRGRequest) (bool, error
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -9,14 +9,30 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for attach network
type NetAttachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
NetType string `url:"netType"`
NetID uint64 `url:"netId"`
IPAddr string `url:"ipAddr,omitempty"`
// Network type
// 'EXTNET' for connect to external network directly
// and 'VINS' for connect to ViNS
// Required: true
NetType string `url:"netType"`
// Network ID for connect to
// For EXTNET - external network ID
// For VINS - VINS ID
// Required: true
NetID uint64 `url:"netId"`
// Directly required IP address for new network interface
// Required: true
IPAddr string `url:"ipAddr,omitempty"`
}
func (crq NetAttachRequest) Validate() error {
func (crq NetAttachRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -27,7 +43,6 @@ func (crq NetAttachRequest) Validate() error {
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")
}
@@ -35,8 +50,9 @@ func (crq NetAttachRequest) Validate() error {
return nil
}
func (c Compute) NetAttach(ctx context.Context, req NetAttachRequest) (*NetAttach, error) {
err := req.Validate()
// NetAttach attach network to compute and gets info about network
func (c Compute) NetAttach(ctx context.Context, req NetAttachRequest) (*RecordNetAttach, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -48,11 +64,12 @@ func (c Compute) NetAttach(ctx context.Context, req NetAttachRequest) (*NetAttac
return nil, err
}
netAttach := &NetAttach{}
err = json.Unmarshal(res, netAttach)
info := RecordNetAttach{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return netAttach, nil
return &info, nil
}

View File

@@ -7,13 +7,22 @@ import (
"strconv"
)
// Request struct for detach networ to compute
type NetDetachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
IPAddr string `url:"ipAddr,omitempty"`
MAC string `url:"mac,omitempty"`
// IP of the network interface
// Required: false
IPAddr string `url:"ipAddr,omitempty"`
// MAC of the network interface
// Required: false
MAC string `url:"mac,omitempty"`
}
func (crq NetDetachRequest) Validate() error {
func (crq NetDetachRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -21,8 +30,9 @@ func (crq NetDetachRequest) Validate() error {
return nil
}
// NetDetach detach network to compute
func (c Compute) NetDetach(ctx context.Context, req NetDetachRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -38,5 +48,6 @@ func (c Compute) NetDetach(ctx context.Context, req NetDetachRequest) (bool, err
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for pause compute
type PauseRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq PauseRequest) Validate() error {
func (crq PauseRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq PauseRequest) Validate() error {
return nil
}
// Pause pause compute
func (c Compute) Pause(ctx context.Context, req PauseRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -36,5 +40,6 @@ func (c Compute) Pause(ctx context.Context, req PauseRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -9,15 +9,31 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for add port forward rule
type PFWAddRequest struct {
ComputeID uint64 `url:"computeId"`
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// External start port number for the rule
// Required: true
PublicPortStart uint64 `url:"publicPortStart"`
PublicPortEnd uint64 `url:"publicPortEnd,omitempty"`
LocalBasePort uint64 `url:"localBasePort"`
Proto string `url:"proto"`
// End port number (inclusive) for the ranged rule
// Required: false
PublicPortEnd uint64 `url:"publicPortEnd,omitempty"`
// Internal base port number
// Required: true
LocalBasePort uint64 `url:"localBasePort"`
// Network protocol
// either "tcp" or "udp"
// Required: true
Proto string `url:"proto"`
}
func (crq PFWAddRequest) Validate() error {
func (crq PFWAddRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -38,8 +54,9 @@ func (crq PFWAddRequest) Validate() error {
return nil
}
// PFWAdd add port forward rule
func (c Compute) PFWAdd(ctx context.Context, req PFWAddRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -7,16 +7,35 @@ import (
"strconv"
)
// Request struct for delete port forward rule
type PFWDelRequest struct {
ComputeID uint64 `url:"computeId"`
PFWID uint64 `url:"ruleId,omitempty"`
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the rule to delete. If specified, all other arguments will be ignored
// Required: false
PFWID uint64 `url:"ruleId,omitempty"`
// External start port number for the rule
// Required: false
PublicPortStart uint64 `url:"publicPortStart,omitempty"`
PublicPortEnd uint64 `url:"publicPortEnd,omitempty"`
LocalBasePort uint64 `url:"localBasePort,omitempty"`
Proto string `url:"proto,omitempty"`
// End port number (inclusive) for the ranged rule
// Required: false
PublicPortEnd uint64 `url:"publicPortEnd,omitempty"`
// Internal base port number
// Required: false
LocalBasePort uint64 `url:"localBasePort,omitempty"`
// Network protocol
// either "tcp" or "udp"
// Required: false
Proto string `url:"proto,omitempty"`
}
func (crq PFWDelRequest) Validate() error {
func (crq PFWDelRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -24,8 +43,9 @@ func (crq PFWDelRequest) Validate() error {
return nil
}
// PFWDel delete port forward rule
func (c Compute) PFWDel(ctx context.Context, req PFWDelRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list port forwards
type PFWListRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq PFWListRequest) Validate() error {
func (crq PFWListRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq PFWListRequest) Validate() error {
return nil
}
func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (PFWList, error) {
err := req.Validate()
// PFWList gets compute port forwards list
func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (ListPFWs, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -32,12 +36,12 @@ func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (PFWList, erro
return nil, err
}
pfwList := PFWList{}
list := ListPFWs{}
err = json.Unmarshal(res, &pfwList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return pfwList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for pin comptute to stack
type PinToStackRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq PinToStackRequest) Validate() error {
func (crq PinToStackRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq PinToStackRequest) Validate() error {
return nil
}
// PinToStack pin compute to current stack
func (c Compute) PinToStack(ctx context.Context, req PinToStackRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}
@@ -36,5 +40,6 @@ func (c Compute) PinToStack(ctx context.Context, req PinToStackRequest) (uint64,
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for force stop and start compute
type PowerCycleRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq PowerCycleRequest) Validate() error {
func (crq PowerCycleRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq PowerCycleRequest) Validate() error {
return nil
}
// PowerCycle makes force stop and start compute
func (c Compute) PowerCycle(ctx context.Context, req PowerCycleRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -36,5 +40,6 @@ func (c Compute) PowerCycle(ctx context.Context, req PowerCycleRequest) (bool, e
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for reboot compute
type RebootRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq RebootRequest) Validate() error {
func (crq RebootRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq RebootRequest) Validate() error {
return nil
}
// Reboot reboot compute
func (c Compute) Reboot(ctx context.Context, req RebootRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -36,5 +40,6 @@ func (c Compute) Reboot(ctx context.Context, req RebootRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,16 +7,35 @@ import (
"strconv"
)
// Request struct for redeploy
type RedeployRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
ImageID uint64 `url:"imageId,omitempty"`
DiskSize uint64 `url:"diskSize,omitempty"`
// ID of the new OS image, if image change is required
// Required: false
ImageID uint64 `url:"imageId,omitempty"`
// new size for the boot disk in GB, if boot disk size change is required
// Required: false
DiskSize uint64 `url:"diskSize,omitempty"`
// How to handle data disks connected to this compute instance,
// KEEP, DETACH, DESTROY
// Required: false
DataDisks string `url:"dataDisks,omitempty"`
AutoStart bool `url:"autoStart,omitempty"`
ForceStop bool `url:"forceStop,omitempty"`
// Should the compute be restarted upon successful redeploy
// Required: false
AutoStart bool `url:"autoStart,omitempty"`
// Set this flag to True to force stop running compute instance and redeploy next
// Required: false
ForceStop bool `url:"forceStop,omitempty"`
}
func (crq RedeployRequest) Validate() error {
func (crq RedeployRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -24,8 +43,9 @@ func (crq RedeployRequest) Validate() error {
return nil
}
// Redeploy redeploy compute
func (c Compute) Redeploy(ctx context.Context, req RedeployRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -41,5 +61,6 @@ func (c Compute) Redeploy(ctx context.Context, req RedeployRequest) (bool, error
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for reset compute
type ResetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq ResetRequest) Validate() error {
func (crq ResetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq ResetRequest) Validate() error {
return nil
}
// Reset reset compute
func (c Compute) Reset(ctx context.Context, req ResetRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -36,5 +40,6 @@ func (c Compute) Reset(ctx context.Context, req ResetRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,14 +7,28 @@ import (
"strconv"
)
// Request struct for resize compute
type ResizeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Force bool `url:"force,omitempty"`
CPU uint64 `url:"cpu,omitempty"`
RAM uint64 `url:"ram,omitempty"`
// New CPU count.
// Pass 0 if no change to CPU count is required
// Required: false
Force bool `url:"force,omitempty"`
// New RAM volume in MB.
// Pass 0 if no change to RAM volume is required
// Required: false
CPU uint64 `url:"cpu,omitempty"`
// Force compute resize
// Required: false
RAM uint64 `url:"ram,omitempty"`
}
func (crq ResizeRequest) Validate() error {
func (crq ResizeRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -22,8 +36,9 @@ func (crq ResizeRequest) Validate() error {
return nil
}
// Resize resize compute instance
func (c Compute) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -39,5 +54,6 @@ func (c Compute) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -6,11 +6,14 @@ import (
"net/http"
)
// Request struct for restore compute
type RestoreRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq RestoreRequest) Validate() error {
func (crq RestoreRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -18,8 +21,9 @@ func (crq RestoreRequest) Validate() error {
return nil
}
// Restore restore compute from recycle bin
func (c Compute) Restore(ctx context.Context, req RestoreRequest) (string, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return "", err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for resume compute
type ResumeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq ResumeRequest) Validate() error {
func (crq ResumeRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq ResumeRequest) Validate() error {
return nil
}
// Resume resume Compute from paused state
func (c Compute) Resume(ctx context.Context, req ResumeRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -36,5 +40,6 @@ func (c Compute) Resume(ctx context.Context, req ResumeRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,12 +7,19 @@ import (
"strings"
)
// Request struct for create snapshot
type SnapshotCreateRequest struct {
// ID of the compute instance to create snapshot for
// Required: true
ComputeID uint64 `url:"computeId"`
Label string `url:"label"`
// Text label for snapshot.
// Must be unique among this compute snapshots
// Required: true
Label string `url:"label"`
}
func (crq SnapshotCreateRequest) Validate() error {
func (crq SnapshotCreateRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -23,8 +30,9 @@ func (crq SnapshotCreateRequest) Validate() error {
return nil
}
// SnapshotCreate create compute snapshot
func (c Compute) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (string, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return "", err
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for delete snapshot
type SnapshotDeleteRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Label string `url:"label"`
// Text label of snapshot to delete
// Required: true
Label string `url:"label"`
}
func (crq SnapshotDeleteRequest) Validate() error {
func (crq SnapshotDeleteRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -23,8 +29,9 @@ func (crq SnapshotDeleteRequest) Validate() error {
return nil
}
// SnapshotDelete delete specified compute snapshot
func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list snapshots
type SnapshotListRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq SnapshotListRequest) Validate() error {
func (crq SnapshotListRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq SnapshotListRequest) Validate() error {
return nil
}
func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (SnapshotList, error) {
err := req.Validate()
// SnapshotList gets list compute snapshots
func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapShots, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -32,12 +36,12 @@ func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (Sna
return nil, err
}
snapshotList := SnapshotList{}
list := ListSnapShots{}
err = json.Unmarshal(res, &snapshotList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return snapshotList, nil
return list, nil
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for rollback
type SnapshotRollbackRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Label string `url:"label"`
// Text label of snapshot to rollback
// Required: true
Label string `url:"label"`
}
func (crq SnapshotRollbackRequest) Validate() error {
func (crq SnapshotRollbackRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -23,8 +29,9 @@ func (crq SnapshotRollbackRequest) Validate() error {
return nil
}
// SnapshotRollback rollback specified compute snapshot
func (c Compute) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,12 +7,19 @@ import (
"net/http"
)
// Request struct for get compute snapshot real size on storage
type SnapshotUsageRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Label string `url:"label,omitempty"`
// Specify to show usage exact for this snapshot.
// Leave empty for get usage for all compute snapshots
// Required: false
Label string `url:"label,omitempty"`
}
func (crq SnapshotUsageRequest) Validate() error {
func (crq SnapshotUsageRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -20,8 +27,11 @@ func (crq SnapshotUsageRequest) Validate() error {
return nil
}
func (c Compute) SnapshotUsage(ctx context.Context, req SnapshotUsageRequest) (SnapshotUsageList, error) {
err := req.Validate()
// SnapshotUsage Get compute snapshot real size on storage.
// Always returns list of json objects, and first json object contains summary about all related
// snapshots.
func (c Compute) SnapshotUsage(ctx context.Context, req SnapshotUsageRequest) (ListUsageSnapshots, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -33,12 +43,12 @@ func (c Compute) SnapshotUsage(ctx context.Context, req SnapshotUsageRequest) (S
return nil, err
}
snapshotUsage := SnapshotUsageList{}
list := ListUsageSnapshots{}
err = json.Unmarshal(res, &snapshotUsage)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return snapshotUsage, nil
return list, nil
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for start compute
type StartRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of CD-ROM live image to boot
// Required: false
AltBootID uint64 `url:"altBootId,omitempty"`
}
func (crq StartRequest) Validate() error {
func (crq StartRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -20,8 +26,9 @@ func (crq StartRequest) Validate() error {
return nil
}
// Start starts compute
func (c Compute) Start(ctx context.Context, req StartRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -37,5 +44,6 @@ func (c Compute) Start(ctx context.Context, req StartRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for stop compute
type StopRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Force bool `url:"force,omitempty"`
// Force stop compute
// Required: false
Force bool `url:"force,omitempty"`
}
func (crq StopRequest) Validate() error {
func (crq StopRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -20,8 +26,9 @@ func (crq StopRequest) Validate() error {
return nil
}
// Stop stops compute
func (c Compute) Stop(ctx context.Context, req StopRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -37,5 +44,6 @@ func (c Compute) Stop(ctx context.Context, req StopRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,20 +7,28 @@ import (
"strconv"
)
// Request struct for add tag to compute
type TagAddRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Key string `url:"key"`
Value string `url:"value"`
// Tag key
// Required: true
Key string `url:"key"`
// Tag value
// Required: true
Value string `url:"value"`
}
func (crq TagAddRequest) Validate() error {
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")
}
@@ -28,8 +36,9 @@ func (crq TagAddRequest) Validate() error {
return nil
}
// TagAdd add tag to compute tags dict
func (c Compute) TagAdd(ctx context.Context, req TagAddRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -45,5 +54,6 @@ func (c Compute) TagAdd(ctx context.Context, req TagAddRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,12 +7,18 @@ import (
"strconv"
)
// Request struct for remove tag from compute
type TagRemoveRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Key string `url:"key"`
// Tag key
// Required: true
Key string `url:"key"`
}
func (crq TagRemoveRequest) Validate() error {
func (crq TagRemoveRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -23,8 +29,9 @@ func (crq TagRemoveRequest) Validate() error {
return nil
}
// TagRemove removes tag from compute tags dict
func (c Compute) TagRemove(ctx context.Context, req TagRemoveRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -40,5 +47,6 @@ func (c Compute) TagRemove(ctx context.Context, req TagRemoveRequest) (bool, err
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for unpin from stack
type UnpinFromStackRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq UnpinFromStackRequest) Validate() error {
func (crq UnpinFromStackRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (crq UnpinFromStackRequest) Validate() error {
return nil
}
// UnpinFromStack unpin compute from current stack
func (c Compute) UnpinFromStack(ctx context.Context, req UnpinFromStackRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -36,5 +40,6 @@ func (c Compute) UnpinFromStack(ctx context.Context, req UnpinFromStackRequest)
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,13 +7,22 @@ import (
"strconv"
)
// Request struct for update compute
type UpdateRequest struct {
ComputeID uint64 `url:"computeId"`
Name string `url:"name,omitempty"`
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId"`
// New name
// Required: false
Name string `url:"name,omitempty"`
// New description
// Required: false
Description string `url:"desc,omitempty"`
}
func (crq UpdateRequest) Validate() error {
func (crq UpdateRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -21,8 +30,9 @@ func (crq UpdateRequest) Validate() error {
return nil
}
// Update updates some properties of the compute
func (c Compute) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -38,5 +48,6 @@ func (c Compute) Update(ctx context.Context, req UpdateRequest) (bool, error) {
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -9,21 +9,32 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for grant access to compute
type UserGrantRequest struct {
ComputeID uint64 `url:"computeId"`
Username string `url:"userName"`
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Name of the user to add
// Required: true
Username string `url:"userName"`
// Access type
// Should be one of:
// - 'R' for Read only
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype"`
}
func (crq UserGrantRequest) Validate() error {
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")
}
@@ -35,8 +46,9 @@ func (crq UserGrantRequest) Validate() error {
return nil
}
// UserGrant grant user access to the compute
func (c Compute) UserGrant(ctx context.Context, req UserGrantRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -52,5 +64,6 @@ func (c Compute) UserGrant(ctx context.Context, req UserGrantRequest) (bool, err
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list users for compute
type UserListRequest struct {
ComputeID uint64 `url:"computeId "`
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq UserListRequest) Validate() error {
func (crq UserListRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
@@ -19,7 +22,12 @@ func (crq UserListRequest) Validate() error {
return nil
}
func (c Compute) UserList(ctx context.Context, req UserListRequest) (*UserList, error) {
// UserList gets users list for compute
func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudapi/compute/userList"
@@ -28,12 +36,12 @@ func (c Compute) UserList(ctx context.Context, req UserListRequest) (*UserList,
return nil, err
}
userList := &UserList{}
list := RecordACL{}
err = json.Unmarshal(res, userList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return userList, nil
return &list, nil
}

View File

@@ -7,16 +7,21 @@ import (
"strconv"
)
// Request struct for revoke user access
type UserRevokeRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
Username string `url:"userName"`
// Name of the user to remove
// Required: true
Username string `url:"userName"`
}
func (crq UserRevokeRequest) Validate() error {
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")
}
@@ -24,8 +29,9 @@ func (crq UserRevokeRequest) Validate() error {
return nil
}
// UserRevoke revokes user access to the compute
func (c Compute) UserRevoke(ctx context.Context, req UserRevokeRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -41,5 +47,6 @@ func (c Compute) UserRevoke(ctx context.Context, req UserRevokeRequest) (bool, e
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -9,21 +9,32 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for update user access
type UserUpdateRequest struct {
ComputeID uint64 `url:"computeId"`
Username string `url:"userName"`
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Name of the user to update
// Required: true
Username string `url:"userName"`
// Access type
// Should be one of:
// - 'R' for Read only
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype"`
}
func (crq UserUpdateRequest) Validate() error {
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")
}
@@ -35,8 +46,9 @@ func (crq UserUpdateRequest) Validate() error {
return nil
}
// UserUpdate updates user access to the compute
func (c Compute) UserUpdate(ctx context.Context, req UserUpdateRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -52,5 +64,6 @@ func (c Compute) UserUpdate(ctx context.Context, req UserUpdateRequest) (bool, e
if err != nil {
return false, err
}
return result, nil
}