78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package stpolicy
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// CalendarRequest struct for replication schedule calendar
|
|
type CalendarRequest struct {
|
|
// Weekly schedule
|
|
// Required: true
|
|
Weekly []string `url:"weekly" json:"weekly" validate:"required"`
|
|
}
|
|
|
|
// SchedulesRequest struct for replication profile schedule
|
|
type SchedulesRequest struct {
|
|
// Type of the schedule
|
|
// Required: true
|
|
Type string `url:"type" json:"type" validate:"required"`
|
|
|
|
// Name of the schedule
|
|
// Required: false
|
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
|
|
// Min interval
|
|
// Required: false
|
|
MINInterval uint64 `url:"min_interval,omitempty" json:"min_interval,omitempty"`
|
|
|
|
// Calendar of the schedule
|
|
// Required: false
|
|
Calendar []CalendarRequest `url:"calendar,omitempty" json:"calendar,omitempty" validate:"omitempty,dive"`
|
|
}
|
|
|
|
// CreateReplicationProfileRequest struct to create replication profile
|
|
type CreateReplicationProfileRequest struct {
|
|
// Name of the replication profile
|
|
// Required: true
|
|
Name string `url:"name" json:"name" validate:"required"`
|
|
|
|
// Replication type
|
|
// Required: true
|
|
ReplicationType string `url:"replication_type" json:"replication_type" validate:"required"`
|
|
|
|
// Max copy rate
|
|
// Required: false
|
|
MAXCopyRate uint64 `url:"max_copy_rate,omitempty" json:"max_copy_rate,omitempty"`
|
|
|
|
// List of schedules
|
|
// Required: false
|
|
Schedules []SchedulesRequest `url:"schedules,omitempty" json:"schedules,omitempty" validate:"omitempty,dive"`
|
|
}
|
|
|
|
// CreateReplicationProfile creates a new replication profile
|
|
func (sp StPolicy) CreateReplicationProfile(ctx context.Context, req CreateReplicationProfileRequest) (uint64, error) {
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudbroker/storage_policy/create_replication_profile"
|
|
|
|
res, err := sp.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return result, nil
|
|
}
|