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

101 lines
2.7 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
// RedeployRequest struct to redeploy
2022-10-03 16:56:47 +03:00
type RedeployRequest struct {
2022-12-22 17:56:47 +03:00
// ID of compute instance
// 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
2025-08-29 12:51:25 +03:00
// Storage policy id of compute. The rules of the specified storage policy will be used.
2026-05-29 17:47:13 +03:00
// Required: false
2025-12-08 16:16:35 +03:00
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
2025-08-29 12:51:25 +03:00
2022-12-22 17:56:47 +03:00
// ID of the new OS image, if image change is required
// Required: false
2023-03-01 19:05:53 +03:00
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
2025-12-08 16:16:35 +03:00
2025-09-11 15:56:44 +03:00
// The OS version that will be installed on the virtual machine
// Required: false
OSVersion string `url:"os_version,omitempty" json:"os_version,omitempty"`
2022-12-22 17:56:47 +03:00
// new size for the boot disk in GB, if boot disk size change is required
// Required: false
2023-03-01 19:05:53 +03:00
DiskSize uint64 `url:"diskSize,omitempty" json:"diskSize,omitempty"`
2022-12-22 17:56:47 +03:00
// How to handle data disks connected to this compute instance,
// KEEP, DETACH, DESTROY
// Required: false
2023-03-01 19:05:53 +03:00
DataDisks string `url:"dataDisks,omitempty" json:"dataDisks,omitempty"`
2022-12-22 17:56:47 +03:00
2023-10-25 17:37:18 +03:00
// Should compute be restarted upon successful redeploy
2022-12-22 17:56:47 +03:00
// 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
// Set this flag to True to force stop running compute instance and redeploy next
// 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
}
2026-06-05 17:14:39 +03:00
type wrapperRedeployRequest struct {
RedeployRequest
AsyncMode bool `url:"asyncMode"`
}
2023-10-25 17:37:18 +03:00
// Redeploy redeploys compute
2022-10-03 16:56:47 +03:00
func (c Compute) Redeploy(ctx context.Context, req RedeployRequest) (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
}
2026-06-05 17:14:39 +03:00
reqWrapped := wrapperRedeployRequest{
RedeployRequest: req,
AsyncMode: false,
}
2022-10-03 16:56:47 +03:00
url := "/cloudapi/compute/redeploy"
2026-06-05 17:14:39 +03:00
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
2022-10-03 16:56:47 +03:00
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
}
2026-06-05 17:14:39 +03:00
// RedeployAsync redeploys compute with AsyncMode
func (c Compute) RedeployAsync(ctx context.Context, req RedeployRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperRedeployRequest{
RedeployRequest: req,
AsyncMode: true,
}
url := "/cloudapi/compute/redeploy"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
return string(res), nil
}