This commit is contained in:
2024-05-31 13:35:39 +03:00
parent e7c968797b
commit 3393934456
65 changed files with 905 additions and 393 deletions

View File

@@ -0,0 +1,41 @@
package disks
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
"strconv"
)
// DepresentRequest struct to depresent disk from node
type DepresentRequest struct {
// ID of the disk to depresent
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// ID of the node to depresent disk from
// Required: true
NodeID uint64 `url:"nodeId" json:"nodeId" validate:"required"`
}
// Depresent depresents disk from node
func (d Disks) Depresent(ctx context.Context, req DepresentRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/disks/depresent"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -57,7 +57,7 @@ type FromPlatformDiskRequest struct {
// List of types of compute suitable for image
// Example: [ "KVM_X86" ]
// Required: false
Drivers []string `url:"drivers" json:"drivers" validate:"min=1,max=2,imageDrivers"`
Drivers []string `url:"drivers,omitempty" json:"drivers,omitempty"`
// Does this machine supports hot resize
// Required: false

View File

@@ -32,7 +32,7 @@ type ListRequest struct {
// Find by shared, true or false
// Required: false
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
Shared interface{} `url:"shared,omitempty" json:"shared,omitempty" validate:"omitempty,isBool"`
// ID of the account the disks belong to
// Required: false

View File

@@ -28,7 +28,7 @@ type ListDeletedRequest struct {
// Find by shared, true or false
// Required: false
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
Shared interface{} `url:"shared,omitempty" json:"shared,omitempty" validate:"omitempty,isBool"`
// ID of the account the disks belong to
// Required: false

View File

@@ -138,7 +138,7 @@ type InfoDisk struct {
ReferenceID string `json:"referenceId"`
// Replication
Replication interface{} `json:"replication"`
Replication ItemReplication `json:"replication"`
// Resource ID
ResID string `json:"resId"`
@@ -177,6 +177,26 @@ type InfoDisk struct {
VMID uint64 `json:"vmid"`
}
type ItemReplication struct {
// DiskID
DiskID uint64 `json:"diskId"`
// PoolID
PoolID string `json:"poolId"`
// Role
Role string `json:"role"`
// SelfVolumeID
SelfVolumeID string `json:"selfVolumeId"`
// StorageID
StorageID string `json:"storageId"`
// VolumeID
VolumeID string `json:"volumeId"`
}
// Detailed indormation about disk
type RecordDisk struct {
// Device name

View File

@@ -0,0 +1,41 @@
package disks
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
"strconv"
)
// PresentRequest struct to present disk to node
type PresentRequest struct {
// ID of the disk to present
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// ID of the node to present disk to
// Required: true
NodeID uint64 `url:"nodeId" json:"nodeId" validate:"required"`
}
// Present presents disk to node
func (d Disks) Present(ctx context.Context, req PresentRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/disks/present"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -15,23 +15,18 @@ type ReplicationStatusRequest struct {
}
// ReplicationStatus get replication status
func (d Disks) ReplicationStatus(ctx context.Context, req ReplicationStatusRequest) (interface{}, error) {
func (d Disks) ReplicationStatus(ctx context.Context, req ReplicationStatusRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/disks/replicationStatus"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
return "", err
}
// result, err := strconv.ParseBool(string(res))
// if err != nil {
// return nil, err
// }
return res, nil
return string(res), nil
}