v1.3.0
This commit is contained in:
@@ -2,7 +2,6 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,15 +12,15 @@ import (
|
||||
type CreateRequest struct {
|
||||
// ID of the account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// ID of the grid (platform)
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid"`
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// Name of disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Description of disk
|
||||
// Required: false
|
||||
@@ -36,7 +35,7 @@ type CreateRequest struct {
|
||||
// - D=Data
|
||||
// - T=Temp
|
||||
// Required: true
|
||||
Type string `url:"type" json:"type"`
|
||||
Type string `url:"type" json:"type" validate:"diskType"`
|
||||
|
||||
// Size in GB default is 0
|
||||
// Required: false
|
||||
@@ -55,29 +54,13 @@ type CreateRequest struct {
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
}
|
||||
|
||||
func (drq CreateRequest) validate() error {
|
||||
if drq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.GID == 0 {
|
||||
return errors.New("validation-error: field GID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
validType := validators.StringInSlice(drq.Type, []string{"B", "D", "T"})
|
||||
if !validType {
|
||||
return errors.New("validation-error: field Type must be set as B, D or T")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates a disk
|
||||
func (d Disks) Create(ctx context.Context, req CreateRequest) (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/disks/create"
|
||||
|
||||
@@ -2,16 +2,17 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request for delete disk
|
||||
type DeleteRequest struct {
|
||||
// ID of disk to delete
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Detach disk from machine first
|
||||
// Required: false
|
||||
@@ -26,19 +27,13 @@ type DeleteRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (d DeleteRequest) validate() error {
|
||||
if d.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes disk by ID
|
||||
func (d Disks) 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/disks/delete"
|
||||
|
||||
@@ -2,42 +2,34 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for multiple disks
|
||||
type DisksDeleteRequest struct {
|
||||
// List of disk ids to delete
|
||||
// Required: true
|
||||
DisksIDs []uint64 `url:"diskIds" json:"diskIds"`
|
||||
DisksIDs []uint64 `url:"diskIds" json:"diskIds" validate:"required"`
|
||||
|
||||
// Reason for deleting the disks
|
||||
// Required: true
|
||||
Reason string `url:"reason" json:"reason"`
|
||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
||||
|
||||
// Whether to completely delete the disks, works only with non attached disks
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (drq DisksDeleteRequest) validate() error {
|
||||
if len(drq.DisksIDs) == 0 {
|
||||
return errors.New("validation-error: field DisksIDs must include one or more disks ids")
|
||||
}
|
||||
if drq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteDisks deletes multiple disks permanently
|
||||
func (d Disks) DeleteDisks(ctx context.Context, req DisksDeleteRequest) (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/disks/deleteDisks"
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||
)
|
||||
|
||||
// FilterByID returns ListDisks with specified ID.
|
||||
func (ld ListDisks) FilterByID(id uint64) ListDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
@@ -36,6 +45,69 @@ func (ld ListDisks) FilterByTechStatus(techStatus string) ListDisks {
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByComputeID is used to filter ListDisks attached to specified compute.
|
||||
func (ld ListDisks) FilterByComputeID(computeID uint64) ListDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
for k := range idisk.Computes {
|
||||
if k == strconv.FormatUint(computeID, 10) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByK8SID is used to filter ListDisks by specified K8S cluster.
|
||||
func (ld ListDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListDisks, error) {
|
||||
caller := k8s.New(decortClient)
|
||||
|
||||
req := k8s.GetRequest{
|
||||
K8SID: k8sID,
|
||||
}
|
||||
|
||||
cluster, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result ListDisks
|
||||
|
||||
for _, masterCompute := range cluster.K8SGroups.Masters.DetailedInfo {
|
||||
result = append(result, ld.FilterByComputeID(masterCompute.ID)...)
|
||||
}
|
||||
|
||||
for _, workerGroup := range cluster.K8SGroups.Workers {
|
||||
for _, workerCompute := range workerGroup.DetailedInfo {
|
||||
result = append(result, ld.FilterByComputeID(workerCompute.ID)...)
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FilterByLBID is used to filter ListDisks used by computes inside specified Load Balancer.
|
||||
func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListDisks, error) {
|
||||
caller := lb.New(decortClient)
|
||||
|
||||
req := lb.GetRequest{
|
||||
LBID: lbID,
|
||||
}
|
||||
|
||||
foundLB, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result ListDisks
|
||||
result = append(result, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID)...)
|
||||
result = append(result, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID)...)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListDisks based on a user-specified predicate.
|
||||
func (ld ListDisks) FilterFunc(predicate func(ItemDisk) bool) ListDisks {
|
||||
var result ListDisks
|
||||
|
||||
@@ -3,31 +3,26 @@ package disks
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get information about disk
|
||||
type GetRequest struct {
|
||||
// ID of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
}
|
||||
|
||||
func (drq GetRequest) validate() error {
|
||||
if drq.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"`
|
||||
}
|
||||
|
||||
// Get gets disk details
|
||||
// Notice: the devicename field is the name as it is passed to the kernel (kname in linux) for unattached disks this field has no relevant value
|
||||
func (d Disks) Get(ctx context.Context, req GetRequest) (*RecordDisk, 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/disks/get"
|
||||
|
||||
@@ -2,16 +2,17 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for limit IO
|
||||
type LimitIORequest struct {
|
||||
// ID of the disk to limit
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Alias for total_iops_sec for backwards compatibility
|
||||
// Required: false
|
||||
@@ -70,21 +71,15 @@ type LimitIORequest struct {
|
||||
SizeIOPSSec uint64 `url:"size_iops_sec,omitempty" json:"size_iops_sec,omitempty"`
|
||||
}
|
||||
|
||||
func (drq LimitIORequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LimitIO limit IO for a certain disk
|
||||
// total and read/write options are not allowed to be combined
|
||||
// see http://libvirt.org/formatdomain.html#elementsDisks iotune section for more details
|
||||
func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (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/disks/limitIO"
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
type ListTypesRequest struct {
|
||||
// Show detailed disk types by seps
|
||||
// Required: false
|
||||
Detailed bool `url:"detailed" json:"detailed"`
|
||||
Detailed bool `url:"detailed,omitempty" json:"detailed,omitempty"`
|
||||
}
|
||||
|
||||
// ListTypes gets list defined disk types
|
||||
|
||||
@@ -2,38 +2,30 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for rename disk
|
||||
type RenameRequest struct {
|
||||
// ID of the disk to rename
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// New name of disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
}
|
||||
|
||||
func (drq RenameRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
}
|
||||
|
||||
// Rename rename disk
|
||||
func (d Disks) Rename(ctx context.Context, req RenameRequest) (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/disks/rename"
|
||||
|
||||
@@ -2,31 +2,21 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for resize disk
|
||||
type ResizeRequest struct {
|
||||
// ID of the disk to resize
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// New size of the disk in GB
|
||||
// Required: true
|
||||
Size uint64 `url:"size" json:"size"`
|
||||
}
|
||||
|
||||
func (drq ResizeRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.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"`
|
||||
}
|
||||
|
||||
// Resize resize disk
|
||||
@@ -34,9 +24,11 @@ func (drq ResizeRequest) validate() error {
|
||||
// in that case please stop and start your machine after changing the disk size, for your changes to be reflected.
|
||||
// This method will not be used for disks, assigned to computes. Only unassigned disks and disks, assigned with "old" virtual machines.
|
||||
func (d Disks) 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/disks/resize"
|
||||
@@ -59,9 +51,11 @@ func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
// in that case please stop and start your machine after changing the disk size, for your changes to be reflected.
|
||||
// This method will not be used for disks, assigned to "old" virtual machines. Only unassigned disks and disks, assigned with computes.
|
||||
func (d Disks) Resize2(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/disks/resize2"
|
||||
|
||||
@@ -2,38 +2,30 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restore a deleted unattached disk
|
||||
type RestoreRequest struct {
|
||||
// ID of the disk to restore
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Reason for restoring the disk
|
||||
// Required: true
|
||||
Reason string `url:"reason" json:"reason"`
|
||||
}
|
||||
|
||||
func (drq RestoreRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
||||
}
|
||||
|
||||
// Restore restore a deleted unattached disk from recycle bin
|
||||
func (d Disks) Restore(ctx context.Context, req RestoreRequest) (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/disks/restore"
|
||||
|
||||
@@ -2,31 +2,26 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for share data disk
|
||||
type ShareRequest struct {
|
||||
// ID of the disk to share
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
}
|
||||
|
||||
func (drq ShareRequest) validate() error {
|
||||
if drq.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"`
|
||||
}
|
||||
|
||||
// Share shares data disk
|
||||
func (d Disks) Share(ctx context.Context, req ShareRequest) (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/disks/share"
|
||||
|
||||
@@ -2,39 +2,30 @@ package disks
|
||||
|
||||
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 disk to delete
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Label of the snapshot to delete
|
||||
// Required: false
|
||||
Label string `url:"label" json:"label"`
|
||||
}
|
||||
|
||||
func (drq SnapshotDeleteRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if drq.Label == "" {
|
||||
return errors.New("validation-error: field Label can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
// Required: true
|
||||
Label string `url:"label" json:"label" validate:"required"`
|
||||
}
|
||||
|
||||
// SnapshotDelete deletes a snapshot
|
||||
func (d Disks) 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/disks/snapshotDelete"
|
||||
|
||||
@@ -2,42 +2,34 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for rollback snapshot
|
||||
type SnapshotRollbackRequest struct {
|
||||
// ID of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Label of the snapshot to rollback
|
||||
// Required: true
|
||||
Label string `url:"label" json:"label"`
|
||||
// Required: false
|
||||
Label string `url:"label,omitempty" json:"label,omitempty"`
|
||||
|
||||
// Timestamp of the snapshot to rollback
|
||||
// Required: true
|
||||
TimeStamp uint64 `url:"timestamp" json:"timestamp"`
|
||||
}
|
||||
|
||||
func (drq SnapshotRollbackRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.Label == "" && drq.TimeStamp == 0 {
|
||||
return errors.New("validation-error: field Label or field TimeStamp can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
// Required: false
|
||||
TimeStamp uint64 `url:"timestamp,omitempty" json:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
// SnapshotRollback rollback an individual disk snapshot
|
||||
func (d Disks) 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/disks/snapshotRollback"
|
||||
|
||||
@@ -2,31 +2,26 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for unshare data disk
|
||||
type UnshareRequest struct {
|
||||
// ID of the disk to unshare
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
}
|
||||
|
||||
func (drq UnshareRequest) validate() error {
|
||||
if drq.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"`
|
||||
}
|
||||
|
||||
// Unshare unshares data disk
|
||||
func (d Disks) Unshare(ctx context.Context, req UnshareRequest) (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/disks/unshare"
|
||||
|
||||
Reference in New Issue
Block a user