Files
decort-golang-sdk/pkg/cloudapi/disks/replication_promote.go
dayterr 8cde0e9371 v1.16.7
v1.16.7
2026-10-09 16:23:35 +03:00

79 lines
1.9 KiB
Go

package disks
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ReplicationPromoteRequest to promote the primary side of an asynchronous replication pair
type ReplicationPromoteRequest struct {
// Disk ID
// Required: true
DiskID uint64 `url:"disk_id" json:"disk_id" validate:"required"`
}
type wrapperReplicationPromoteRequest struct {
ReplicationPromoteRequest
AsyncMode bool `url:"async_mode" json:"async_mode"`
}
// ReplicationPromote promotes the primary side of an asynchronous replication pair
func (d Disks) ReplicationPromote(ctx context.Context, req ReplicationPromoteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replication_promote"
aReq := wrapperReplicationPromoteRequest{
ReplicationPromoteRequest: req,
AsyncMode: false,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
// ReplicationPromoteAsync promotes the primary side of an asynchronous replication pair in async mode
func (d Disks) ReplicationPromoteAsync(ctx context.Context, req ReplicationPromoteRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replication_promote"
aReq := wrapperReplicationPromoteRequest{
ReplicationPromoteRequest: req,
AsyncMode: true,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
if err != nil {
return "", err
}
var resp string
err = json.Unmarshal(res, &resp)
if err != nil {
return "", err
}
return resp, nil
}