Files
decort-golang-sdk/pkg/cloudapi/compute/move_to_rg.go

58 lines
1.6 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package compute
import (
"context"
"net/http"
"strconv"
2023-03-17 12:54:34 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// MoveToRGRequest struct to move compute to new resource group
2022-10-03 16:56:47 +03:00
type MoveToRGRequest struct {
2022-12-22 17:56:47 +03:00
// ID of the compute instance to move
// Required: true
2023-03-17 12:54:34 +03:00
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
2022-12-22 17:56:47 +03:00
// ID of the target resource group
// Required: true
2023-03-17 12:54:34 +03:00
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
2022-12-22 17:56:47 +03:00
// New name for the compute upon successful move,
// if name change required.
// Pass empty string if no name change necessary
// Required: false
2023-03-01 19:05:53 +03:00
Name string `url:"name,omitempty" json:"name,omitempty"`
2022-12-22 17:56:47 +03:00
// Should the compute be restarted upon successful move
// Required: false
2023-03-01 19:05:53 +03:00
Autostart bool `url:"autostart,omitempty" json:"autostart,omitempty"`
2022-12-22 17:56:47 +03:00
// By default moving compute in a running state is not allowed.
// Set this flag to True to force stop running compute instance prior to move.
// Required: false
2023-03-01 19:05:53 +03:00
ForceStop bool `url:"forceStop,omitempty" json:"forceStop,omitempty"`
2022-10-03 16:56:47 +03:00
}
2022-12-22 17:56:47 +03:00
// MoveToRG moves compute instance to new resource group
2022-10-03 16:56:47 +03:00
func (c Compute) MoveToRG(ctx context.Context, req MoveToRGRequest) (bool, error) {
2023-03-17 12:54:34 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return false, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/compute/moveToRg"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
2022-12-22 17:56:47 +03:00
2022-10-03 16:56:47 +03:00
return result, nil
}