Files
decort-golang-sdk/pkg/cloudapi/disks/replicate.go

98 lines
2.6 KiB
Go
Raw Normal View History

2024-04-16 14:26:06 +03:00
package disks
import (
"context"
2026-08-28 16:36:41 +03:00
"encoding/json"
2024-04-16 14:26:06 +03:00
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ReplicateRequest struct to create an empty disk in chosen SEP and pool combination.
type ReplicateRequest struct {
// Id of the disk to replicate. This disk will become master in replication
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Name of replica disk to create
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// ID of SEP to create slave disk
// Required: true
SepID uint64 `url:"sepId" json:"sepId" validate:"required"`
// Pool name to create slave disk in
// Required: true
PoolName string `url:"poolName" json:"poolName" validate:"required"`
2025-08-29 12:51:25 +03:00
// ID of the storage policy under the disk will be created
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
2024-04-16 14:26:06 +03:00
}
2026-08-28 16:36:41 +03:00
type wrapperReplicateRequest struct {
ReplicateRequest
AsyncMode bool `url:"async_mode" json:"async_mode"`
}
2025-08-29 12:51:25 +03:00
// Replicate create an empty disk in chosen SEP and pool combination.
2024-04-16 14:26:06 +03:00
// Starts replication between chosen disk and newly created disk
// Note: only TATLIN type SEP are supported for replications between
func (d Disks) Replicate(ctx context.Context, req ReplicateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicate"
2026-08-28 16:36:41 +03:00
wrappedReq := wrapperReplicateRequest{
ReplicateRequest: req,
AsyncMode: false,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, wrappedReq)
2024-04-16 14:26:06 +03:00
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}
2026-08-28 16:36:41 +03:00
// ReplicateAsync creates an empty disk in chosen SEP and pool combination in async mode.
// Starts replication between chosen disk and newly created disk
// Note: only TATLIN type SEP are supported for replications between
func (d Disks) ReplicateAsync(ctx context.Context, req ReplicateRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicate"
wrappedReq := wrapperReplicateRequest{
ReplicateRequest: req,
AsyncMode: true,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, wrappedReq)
if err != nil {
return "", err
}
var result string
if err := json.Unmarshal(res, &result); err != nil {
return "", err
}
return result, nil
}