v1.16.7
v1.16.7
This commit is contained in:
78
pkg/cloudbroker/disks/replication_promote.go
Normal file
78
pkg/cloudbroker/disks/replication_promote.go
Normal file
@@ -0,0 +1,78 @@
|
||||
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 := "/cloudbroker/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 := "/cloudbroker/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
|
||||
}
|
||||
Reference in New Issue
Block a user