update go.mod and imports

This commit is contained in:
2023-03-17 12:54:34 +03:00
parent f3a1a4c83f
commit 437841c8dd
268 changed files with 4019 additions and 2045 deletions

View File

@@ -2,37 +2,29 @@ package compute
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for check all computes with current affinity label can start
type AffinityGroupCheckStartRequest struct {
// ID of the resource group
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Affinity group label
// Required: true
AffinityLabel string `url:"affinityLabel" json:"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
AffinityLabel string `url:"affinityLabel" json:"affinityLabel" validate:"required"`
}
// 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 := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityGroupCheckStart"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for clear affinity label for compute
type AffinityLabelRemoveRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// AffinityLabelRemove clear affinity label for compute
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityLabelRemove"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for set affinity label for compute
type AffinityLabelSetRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Affinity group label
// Required: true
AffinityLabel string `url:"affinityLabel" json:"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
AffinityLabel string `url:"affinityLabel" json:"affinityLabel" validate:"required"`
}
// AffinityLabelSet set affinity label for compute
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityLabelSet"

View File

@@ -3,30 +3,25 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get dict of computes
type AffinityRelationsRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
}
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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// 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()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityRelations"

View File

@@ -2,29 +2,28 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for add affinity rule
type AffinityRuleAddRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology" json:"topology"`
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy" json:"policy"`
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
@@ -32,57 +31,24 @@ type AffinityRuleAddRequest struct {
// - EN
// - ANY
// Required: true
Mode string `url:"mode" json:"mode"`
Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key" json:"key"`
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value" json:"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
Value string `url:"value" json:"value" validate:"required"`
}
// AffinityRuleAdd add affinity rule
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityRuleAdd"

View File

@@ -2,29 +2,28 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for remove affinity rule
type AffinityRuleRemoveRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology" json:"topology"`
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy" json:"policy"`
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
@@ -32,57 +31,24 @@ type AffinityRuleRemoveRequest struct {
// - EN
// - ANY
// Required: true
Mode string `url:"mode" json:"mode"`
Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key" json:"key"`
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value" json:"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
Value string `url:"value" json:"value" validate:"required"`
}
// AffinityRuleRemove remove affinity rule
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityRuleRemove"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for clear affinity rules
type AffinityRulesClearRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// AffinityRulesClear clear affinity rules
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityRulesClear"

View File

@@ -2,29 +2,28 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for add anti affinity rule
type AntiAffinityRuleAddRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology" json:"topology"`
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy" json:"policy"`
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
@@ -32,57 +31,24 @@ type AntiAffinityRuleAddRequest struct {
// - EN
// - ANY
// Required: true
Mode string `url:"mode" json:"mode"`
Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key" json:"key"`
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value" json:"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
Value string `url:"value" json:"value" validate:"required"`
}
// AntiAffinityRuleAdd add anti affinity rule
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/antiAffinityRuleAdd"

View File

@@ -2,29 +2,28 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for remove anti affinity rule
type AntiAffinityRuleRemoveRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology" json:"topology"`
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy" json:"policy"`
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
@@ -32,57 +31,24 @@ type AntiAffinityRuleRemoveRequest struct {
// - EN
// - ANY
// Required: true
Mode string `url:"mode" json:"mode"`
Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key" json:"key"`
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value" json:"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
Value string `url:"value" json:"value" validate:"required"`
}
// AntiAffinityRuleRemove remove anti affinity rule
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/antiAffinityRuleRemove"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for clear anti affinity rules
type AntiAffinityRulesClearRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// AntiAffinityRulesClear clear anti affinity rules
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/antiAffinityRulesClear"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for attach GPU for compute
type AttachGPURequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Identifier vGPU
// Required: true
VGPUID uint64 `url:"vgpuId" json:"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
VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
}
// 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 := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/attachGpu"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for atttach PCI device
type AttachPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// PCI device ID
// Required: true
DeviceID uint64 `url:"deviceId" json:"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
DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
}
// AttachPCIDevice attach PCI device
func (c Compute) AttachPCIDevice(ctx context.Context, req AttachPCIDeviceRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/attachPciDevice"

View File

@@ -3,30 +3,25 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get audit records
type AuditsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Audits gets audit records for the specified compute object
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/audits"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for eject CD image
type CDEjectRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// CDEject eject CD image to compute's CD-ROM
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/cdEject"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for insert new CD image
type CDInsertRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of CD-ROM image
// Required: true
CDROMID uint64 `url:"cdromId" json:"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
CDROMID uint64 `url:"cdromId" json:"cdromId" validate:"required"`
}
// 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 := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/cdInsert"

View File

@@ -2,46 +2,38 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for clone compute instance
type CloneRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name of the clone
// Required: true
Name string `url:"name" json:"name"`
Name string `url:"name" json:"name" validate:"required"`
// Timestamp of the parent's snapshot to create clone from
// Required: false
SnapshotTimestamp uint64 `url:"snapshotTimestamp" json:"snapshotTimestamp"`
SnapshotTimestamp uint64 `url:"snapshotTimestamp,omitempty" json:"snapshotTimestamp,omitempty"`
// Name of the parent's snapshot to create clone from
// Required: false
SnapshotName string `url:"snapshotName" json:"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
SnapshotName string `url:"snapshotName,omitempty" json:"snapshotName,omitempty"`
}
// Clone clones compute instance
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/clone"

View File

@@ -2,7 +2,7 @@
package compute
import (
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
)
// Structure for creating request to compute

View File

@@ -2,21 +2,22 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for create template
type CreateTemplateRequest struct {
// ID of the compute to create template from
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name to assign to the template being created
// Required: true
Name string `url:"name" json:"name"`
Name string `url:"name" json:"name" validate:"required"`
// Async API call
// For async call use CreateTemplateAsync
@@ -25,22 +26,13 @@ type CreateTemplateRequest struct {
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
}
// CreateTemplate create template from compute instance
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
req.async = false
@@ -62,9 +54,11 @@ func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest)
// CreateTemplateAsync create template from compute instance
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
req.async = true

View File

@@ -2,16 +2,17 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete compute
type DeleteRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Delete permanently
// Required: false
@@ -22,19 +23,13 @@ type DeleteRequest struct {
DetachDisks bool `url:"detachDisks,omitempty" json:"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
}
// Delete deletes compute
func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/delete"

View File

@@ -2,36 +2,31 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for detach vgpu for compute
type DetachGPURequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Identifier virtual GPU
// Required: false
VGPUID int64 `url:"vgpuId,omitempty" json:"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
}
// 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 := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/detachGpu"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for detach PCI device
type DetachPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Pci device ID
// Required: true
DeviceID uint64 `url:"deviceId" json:"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
DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
}
// DetachPCIDevice detach PCI device
func (c Compute) DetachPCIDevice(ctx context.Context, req DetachPCIDeviceRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/detachPciDevice"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for disable compute
type DisableRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Disable disables compute
func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/disable"

View File

@@ -2,31 +2,32 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for create and attach disk to compute
type DiskAddRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name for disk
// Required: true
DiskName string `url:"diskName" json:"diskName"`
DiskName string `url:"diskName" json:"diskName" validate:"required"`
// Disk size in GB
// Required: true
Size uint64 `url:"size" json:"size"`
Size uint64 `url:"size" json:"size" validate:"required"`
// Type of the disk
// Should be one of:
// - D
// - B
// Required: false
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty"`
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
// Storage endpoint provider ID
// By default the same with boot disk
@@ -47,25 +48,13 @@ type DiskAddRequest struct {
ImageID uint64 `url:"imageId,omitempty" json:"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
}
// DiskAdd creates new disk and attach to compute
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskAdd"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for attach disk to compute
type DiskAttachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to attach
// Required: true
DiskID uint64 `url:"diskId" json:"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
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// DiskAttach attach disk to compute
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskAttach"

View File

@@ -2,42 +2,34 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for detach and delete disk from compute
type DiskDelRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of disk instance
// Required: true
DiskID uint64 `url:"diskId" json:"diskId"`
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// False if disk is to be deleted to recycle bin
// Required: true
Permanently bool `url:"permanently" json:"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
Permanently bool `url:"permanently" json:"permanently" validate:"required"`
}
// DiskDel delete disk and detach from compute
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskDel"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for detach disk from compute
type DiskDetachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to detach
// Required: true
DiskID uint64 `url:"diskId" json:"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
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// DiskDetach detach disk from compute
func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskDetach"

View File

@@ -2,45 +2,34 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for change QoS of the disk
type DiskQOSRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to apply limits
// Required: true
DiskID uint64 `url:"diskId" json:"diskId"`
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Limit IO for a certain disk total and read/write options are not allowed to be combined
// Required: true
Limits string `url:"limits" json:"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
Limits string `url:"limits" json:"limits" validate:"required"`
}
// DiskQOS change QoS of the disk
func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskQos"

View File

@@ -2,45 +2,34 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for change disk size
type DiskResizeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to resize
// Required: true
DiskID uint64 `url:"diskId" json:"diskId"`
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// New disk size
// Required: true
Size uint64 `url:"size" json:"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
Size uint64 `url:"size" json:"size" validate:"required"`
}
// DiskResize change disk size
func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskResize"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for enable compute
type EnableRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Enable enables compute
func (c Compute) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/enable"

View File

@@ -3,30 +3,25 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request for get information about compute
type GetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Get Gets information about compute
func (c Compute) Get(ctx context.Context, req GetRequest) (*RecordCompute, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/get"

View File

@@ -3,30 +3,25 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get compute audits
type GetAuditsRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// GetAudits gets compute audits
func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest) (ListShortAudits, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/getAudits"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get console URL
type GetConsoleURLRequest struct {
// ID of compute instance to get console for
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// GetConsoleURL gets computes console URL
func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/getConsoleUrl"

View File

@@ -2,37 +2,29 @@ package compute
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get compute logs
type GetLogRequest struct {
// ID of compute instance to get log for
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Path to log file
// Required: true
Path string `url:"path" json:"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
Path string `url:"path" json:"path" validate:"required"`
}
// GetLog gets compute's log file by path
func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/getLog"
@@ -47,9 +39,11 @@ func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error)
// GetLogGet gets compute's log file by path
func (c Compute) GetLogGet(ctx context.Context, req GetLogRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi//compute/getLog"

View File

@@ -3,30 +3,25 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list PCI devices
type ListPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// ListPCIDevice gets list PCI device
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([]interface{}, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/listPciDevice"

View File

@@ -3,30 +3,25 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list vGPU
type ListVGPURequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// ListVGPU gets list vGPU
func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface{}, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/listVgpu"

View File

@@ -2,20 +2,21 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for move compute new resource group
type MoveToRGRequest struct {
// ID of the compute instance to move
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the target resource group
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// New name for the compute upon successful move,
// if name change required.
@@ -33,22 +34,13 @@ type MoveToRGRequest struct {
ForceStop bool `url:"forceStop,omitempty" json:"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
}
// MoveToRG moves compute instance to new resource group
func (c Compute) MoveToRG(ctx context.Context, req MoveToRGRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/moveToRg"

View File

@@ -3,58 +3,41 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for attach network
type NetAttachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Network type
// 'EXTNET' for connect to external network directly
// and 'VINS' for connect to ViNS
// Required: true
NetType string `url:"netType" json:"netType"`
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
// Network ID for connect to
// For EXTNET - external network ID
// For VINS - VINS ID
// Required: true
NetID uint64 `url:"netId" json:"netId"`
NetID uint64 `url:"netId" json:"netId" validate:"required"`
// Directly required IP address for new network interface
// Required: true
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"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
}
// NetAttach attach network to compute and gets info about network
func (c Compute) NetAttach(ctx context.Context, req NetAttachRequest) (*RecordNetAttach, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/netAttach"

View File

@@ -2,16 +2,17 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for detach networ to compute
type NetDetachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// IP of the network interface
// Required: false
@@ -22,19 +23,13 @@ type NetDetachRequest struct {
MAC string `url:"mac,omitempty" json:"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
}
// NetDetach detach network to compute
func (c Compute) NetDetach(ctx context.Context, req NetDetachRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/netDetach"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for pause compute
type PauseRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Pause pause compute
func (c Compute) Pause(ctx context.Context, req PauseRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/pause"

View File

@@ -2,22 +2,21 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for add port forward rule
type PFWAddRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// External start port number for the rule
// Required: true
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart"`
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
// End port number (inclusive) for the ranged rule
// Required: false
@@ -25,40 +24,21 @@ type PFWAddRequest struct {
// Internal base port number
// Required: true
LocalBasePort uint64 `url:"localBasePort" json:"localBasePort"`
LocalBasePort uint64 `url:"localBasePort" json:"localBasePort" validate:"required"`
// Network protocol
// either "tcp" or "udp"
// Required: true
Proto string `url:"proto" json:"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
Proto string `url:"proto" json:"proto" validate:"computeProto"`
}
// PFWAdd add port forward rule
func (c Compute) PFWAdd(ctx context.Context, req PFWAddRequest) (uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/pfwAdd"

View File

@@ -2,16 +2,17 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete port forward rule
type PFWDelRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the rule to delete. If specified, all other arguments will be ignored
// Required: false
@@ -35,19 +36,13 @@ type PFWDelRequest struct {
Proto string `url:"proto,omitempty" json:"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
}
// PFWDel delete port forward rule
func (c Compute) PFWDel(ctx context.Context, req PFWDelRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/pfwDel"

View File

@@ -3,30 +3,25 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list port forwards
type PFWListRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// PFWList gets compute port forwards list
func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (ListPFWs, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/pfwList"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for pin comptute to stack
type PinToStackRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// PinToStack pin compute to current stack
func (c Compute) PinToStack(ctx context.Context, req PinToStackRequest) (uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/pinToStack"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for force stop and start compute
type PowerCycleRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// PowerCycle makes force stop and start compute
func (c Compute) PowerCycle(ctx context.Context, req PowerCycleRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/powerCycle"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for reboot compute
type RebootRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Reboot reboot compute
func (c Compute) Reboot(ctx context.Context, req RebootRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/reboot"

View File

@@ -2,16 +2,17 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for redeploy
type RedeployRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the new OS image, if image change is required
// Required: false
@@ -35,19 +36,13 @@ type RedeployRequest struct {
ForceStop bool `url:"forceStop,omitempty" json:"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
}
// Redeploy redeploy compute
func (c Compute) Redeploy(ctx context.Context, req RedeployRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/redeploy"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for reset compute
type ResetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Reset reset compute
func (c Compute) Reset(ctx context.Context, req ResetRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/reset"

View File

@@ -2,16 +2,17 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for resize compute
type ResizeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// New CPU count.
// Pass 0 if no change to CPU count is required
@@ -28,19 +29,13 @@ type ResizeRequest struct {
RAM uint64 `url:"ram,omitempty" json:"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
}
// Resize resize compute instance
func (c Compute) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/resize"

View File

@@ -2,30 +2,25 @@ package compute
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for restore compute
type RestoreRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Restore restore compute from recycle bin
func (c Compute) Restore(ctx context.Context, req RestoreRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/restore"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for resume compute
type ResumeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Resume resume Compute from paused state
func (c Compute) Resume(ctx context.Context, req ResumeRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/resume"

View File

@@ -3,7 +3,7 @@ package compute
import (
"encoding/json"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.

View File

@@ -2,39 +2,31 @@ package compute
import (
"context"
"errors"
"net/http"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for create snapshot
type SnapshotCreateRequest struct {
// ID of the compute instance to create snapshot for
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Text label for snapshot.
// Must be unique among this compute snapshots
// Required: true
Label string `url:"label" json:"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
Label string `url:"label" json:"label" validate:"required"`
}
// SnapshotCreate create compute snapshot
func (c Compute) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/snapshotCreate"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete snapshot
type SnapshotDeleteRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Text label of snapshot to delete
// Required: true
Label string `url:"label" json:"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
Label string `url:"label" json:"label" validate:"required"`
}
// SnapshotDelete delete specified compute snapshot
func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/snapshotDelete"

View File

@@ -3,30 +3,25 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list snapshots
type SnapshotListRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// SnapshotList gets list compute snapshots
func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapShots, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/snapshotList"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for rollback
type SnapshotRollbackRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Text label of snapshot to rollback
// Required: true
Label string `url:"label" json:"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
Label string `url:"label" json:"label" validate:"required"`
}
// SnapshotRollback rollback specified compute snapshot
func (c Compute) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/snapshotRollback"

View File

@@ -3,15 +3,16 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get compute snapshot real size on storage
type SnapshotUsageRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Specify to show usage exact for this snapshot.
// Leave empty for get usage for all compute snapshots
@@ -19,21 +20,15 @@ type SnapshotUsageRequest struct {
Label string `url:"label,omitempty" json:"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
}
// 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()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/snapshotUsage"

View File

@@ -2,35 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for start compute
type StartRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of CD-ROM live image to boot
// Required: false
AltBootID uint64 `url:"altBootId,omitempty" json:"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
}
// Start starts compute
func (c Compute) Start(ctx context.Context, req StartRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/start"

View File

@@ -2,35 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for stop compute
type StopRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Force stop compute
// Required: false
Force bool `url:"force,omitempty" json:"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
}
// Stop stops compute
func (c Compute) Stop(ctx context.Context, req StopRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/stop"

View File

@@ -2,45 +2,34 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for add tag to compute
type TagAddRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Tag key
// Required: true
Key string `url:"key" json:"key"`
Key string `url:"key" json:"key" validate:"required"`
// Tag value
// Required: true
Value string `url:"value" json:"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
Value string `url:"value" json:"value" validate:"required"`
}
// TagAdd add tag to compute tags dict
func (c Compute) TagAdd(ctx context.Context, req TagAddRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/tagAdd"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for remove tag from compute
type TagRemoveRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Tag key
// Required: true
Key string `url:"key" json:"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
Key string `url:"key" json:"key" validate:"required"`
}
// TagRemove removes tag from compute tags dict
func (c Compute) TagRemove(ctx context.Context, req TagRemoveRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/tagRemove"

View File

@@ -2,31 +2,26 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for unpin from stack
type UnpinFromStackRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// UnpinFromStack unpin compute from current stack
func (c Compute) UnpinFromStack(ctx context.Context, req UnpinFromStackRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/unpinFromStack"

View File

@@ -2,16 +2,17 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update compute
type UpdateRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// New name
// Required: false
@@ -22,19 +23,13 @@ type UpdateRequest struct {
Description string `url:"desc,omitempty" json:"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
}
// Update updates some properties of the compute
func (c Compute) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/update"

View File

@@ -2,22 +2,21 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for grant access to compute
type UserGrantRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name of the user to add
// Required: true
Username string `url:"userName" json:"userName"`
Username string `url:"userName" json:"userName" validate:"required"`
// Access type
// Should be one of:
@@ -25,32 +24,16 @@ type UserGrantRequest struct {
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype" json:"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
AccessType string `url:"accesstype" json:"accesstype" validate:"accountAccessType"`
}
// UserGrant grant user access to the compute
func (c Compute) UserGrant(ctx context.Context, req UserGrantRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/userGrant"

View File

@@ -3,30 +3,25 @@ package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list users for compute
type UserListRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"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
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// UserList gets users list for compute
func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/userList"

View File

@@ -2,38 +2,30 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for revoke user access
type UserRevokeRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name of the user to remove
// Required: true
Username string `url:"userName" json:"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
Username string `url:"userName" json:"userName" validate:"required"`
}
// UserRevoke revokes user access to the compute
func (c Compute) UserRevoke(ctx context.Context, req UserRevokeRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/userRevoke"

View File

@@ -2,22 +2,21 @@ package compute
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update user access
type UserUpdateRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name of the user to update
// Required: true
Username string `url:"userName" json:"userName"`
Username string `url:"userName" json:"userName" validate:"required"`
// Access type
// Should be one of:
@@ -25,32 +24,16 @@ type UserUpdateRequest struct {
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype" json:"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
AccessType string `url:"accesstype" json:"accesstype" validate:"accountAccessType"`
}
// UserUpdate updates user access to the compute
func (c Compute) UserUpdate(ctx context.Context, req UserUpdateRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/userUpdate"