You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.7 KiB
62 lines
1.7 KiB
package compute
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// Request struct for redeploy
|
|
type RedeployRequest struct {
|
|
// ID of compute instance
|
|
// Required: true
|
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
|
|
|
// ID of the new OS image, if image change is required
|
|
// Required: false
|
|
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
|
|
|
|
// new size for the boot disk in GB, if boot disk size change is required
|
|
// Required: false
|
|
DiskSize uint64 `url:"diskSize,omitempty" json:"diskSize,omitempty"`
|
|
|
|
// How to handle data disks connected to this compute instance,
|
|
// KEEP, DETACH, DESTROY
|
|
// Required: false
|
|
DataDisks string `url:"dataDisks,omitempty" json:"dataDisks,omitempty"`
|
|
|
|
// Should the compute be restarted upon successful redeploy
|
|
// Required: false
|
|
AutoStart bool `url:"autoStart,omitempty" json:"autoStart,omitempty"`
|
|
|
|
// Set this flag to True to force stop running compute instance and redeploy next
|
|
// Required: false
|
|
ForceStop bool `url:"forceStop,omitempty" json:"forceStop,omitempty"`
|
|
}
|
|
|
|
// Redeploy redeploy compute
|
|
func (c Compute) Redeploy(ctx context.Context, req RedeployRequest) (bool, error) {
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
for _, validationError := range validators.GetErrors(err) {
|
|
return false, validators.ValidationError(validationError)
|
|
}
|
|
}
|
|
|
|
url := "/cloudapi/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
|
|
}
|