Files
dynamix-golang-sdk/pkg/cloudbroker/compute/anti_affinity_rule_add.go
T

111 lines
2.8 KiB
Go
Raw Normal View History

2025-09-23 14:34:24 +03:00
package compute
import (
"context"
2026-09-18 16:56:47 +03:00
"encoding/json"
2025-09-23 14:34:24 +03:00
"net/http"
"strconv"
2026-08-21 18:12:55 +04:00
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators"
2025-09-23 14:34:24 +03:00
)
// AntiAffinityRuleAddRequest struct to add anti affinity rule
type AntiAffinityRuleAddRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
2025-12-23 17:49:46 +03:00
// Required: true
Value string `url:"value" json:"value" validate:"required"`
2026-09-18 16:56:47 +03:00
// Migrate compute according to the rule
// Default: false
// Required: false
Migrate bool `url:"migrate" json:"migrate"`
}
type wrapperAntiAffinityRuleAddRequest struct {
AntiAffinityRuleAddRequest
AsyncMode bool `url:"async_mode"`
2025-09-23 14:34:24 +03:00
}
// AntiAffinityRuleAdd adds anti affinity rule
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/antiAffinityRuleAdd"
2026-09-18 16:56:47 +03:00
aReq := wrapperAntiAffinityRuleAddRequest{
AntiAffinityRuleAddRequest: req,
AsyncMode: false,
}
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, aReq)
2025-09-23 14:34:24 +03:00
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
2026-09-18 16:56:47 +03:00
// AsyncAntiAffinityRuleAdd add anti affinity rule in async mode
func (c Compute) AsyncAntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/antiAffinityRuleAdd"
aReq := wrapperAntiAffinityRuleAddRequest{
AntiAffinityRuleAddRequest: req,
AsyncMode: true,
}
res, err := c.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
}