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

71 lines
2.0 KiB
Go
Raw Normal View History

2022-12-22 17:56:47 +03:00
package compute
import (
"context"
"net/http"
"strconv"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-12-22 17:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// RedeployRequest struct for redeploy
2022-12-22 17:56:47 +03:00
type RedeployRequest struct {
// ID of compute instance
// Required: true
2023-03-24 17:09:30 +03:00
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
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"`
2022-12-22 17:56:47 +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"`
2025-08-29 12:51:25 +03:00
// Storage policy id of compute. The rules of the specified storage policy will be used.
// Required: true
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
// 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
// Should be one of:
// - KEEP
// - DETACH
// - DESTROY
// Required: false
2023-03-24 17:09:30 +03:00
DataDisks string `url:"dataDisks,omitempty" json:"dataDisks,omitempty" validate:"omitempty,computeDataDisks"`
2022-12-22 17:56:47 +03:00
// Should the compute be restarted upon successful redeploy
// 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-12-22 17:56:47 +03:00
}
2023-10-25 17:37:18 +03:00
// Redeploy redeploys compute
2022-12-22 17:56:47 +03:00
func (c Compute) Redeploy(ctx context.Context, req RedeployRequest) (bool, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-12-22 17:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return false, validators.ValidationErrors(validators.GetErrors(err))
2022-12-22 17:56:47 +03:00
}
url := "/cloudbroker/compute/redeploy"
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
}
return result, nil
}