2023-04-28 11:46:58 +03:00
|
|
|
package compute
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"net/http"
|
|
|
|
|
"strconv"
|
2026-06-05 17:14:39 +03:00
|
|
|
|
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
2023-04-28 11:46:58 +03:00
|
|
|
)
|
|
|
|
|
|
2023-10-25 17:37:18 +03:00
|
|
|
// ChangeLinkStateRequest struct for changing link state
|
2023-04-28 11:46:58 +03:00
|
|
|
type ChangeLinkStateRequest struct {
|
|
|
|
|
// Compute ID
|
|
|
|
|
// Required: true
|
|
|
|
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
|
|
|
|
|
|
|
|
|
// Interface name or MAC address
|
|
|
|
|
// Required: true
|
|
|
|
|
Interface string `url:"interface" json:"interface" validate:"required"`
|
|
|
|
|
|
|
|
|
|
// Interface state
|
|
|
|
|
// Must be either "on" or "off"
|
|
|
|
|
// Required: true
|
|
|
|
|
State string `url:"state" json:"state" validate:"required,interfaceState"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-05 17:14:39 +03:00
|
|
|
type wrapperChangeLinkStateRequest struct {
|
|
|
|
|
ChangeLinkStateRequest
|
|
|
|
|
|
|
|
|
|
AsyncMode bool `url:"asyncMode"`
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 11:46:58 +03:00
|
|
|
// ChangeLinkState changes the status link virtual of compute
|
|
|
|
|
func (c Compute) ChangeLinkState(ctx context.Context, req ChangeLinkStateRequest) (bool, error) {
|
|
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
2023-10-25 17:37:18 +03:00
|
|
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
2023-04-28 11:46:58 +03:00
|
|
|
}
|
|
|
|
|
|
2026-06-05 17:14:39 +03:00
|
|
|
reqWrapped := wrapperChangeLinkStateRequest{
|
|
|
|
|
ChangeLinkStateRequest: req,
|
|
|
|
|
AsyncMode: false,
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 11:46:58 +03:00
|
|
|
url := "/cloudbroker/compute/changeLinkState"
|
|
|
|
|
|
2026-06-05 17:14:39 +03:00
|
|
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
2023-04-28 11:46:58 +03:00
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := strconv.ParseBool(string(res))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
}
|
2026-06-05 17:14:39 +03:00
|
|
|
|
2023-04-28 11:46:58 +03:00
|
|
|
return result, nil
|
|
|
|
|
}
|
2026-06-05 17:14:39 +03:00
|
|
|
|
|
|
|
|
// ChangeLinkStateAsync changes the status link virtual of compute with AsyncMode
|
|
|
|
|
func (c Compute) ChangeLinkStateAsync(ctx context.Context, req ChangeLinkStateRequest) (string, error) {
|
|
|
|
|
err := validators.ValidateRequest(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reqWrapped := wrapperChangeLinkStateRequest{
|
|
|
|
|
ChangeLinkStateRequest: req,
|
|
|
|
|
AsyncMode: true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url := "/cloudbroker/compute/changeLinkState"
|
|
|
|
|
|
|
|
|
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string(res), nil
|
|
|
|
|
}
|