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.
68 lines
1.6 KiB
68 lines
1.6 KiB
package compute
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
// Request struct for move compute new resource group
|
|
type MoveToRGRequest struct {
|
|
// ID of the compute instance to move
|
|
// Required: true
|
|
ComputeID uint64 `url:"computeId"`
|
|
|
|
// ID of the target resource group
|
|
// Required: true
|
|
RGID uint64 `url:"rgId"`
|
|
|
|
// New name for the compute upon successful move,
|
|
// if name change required.
|
|
// Pass empty string if no name change necessary
|
|
// Required: false
|
|
Name string `url:"name,omitempty"`
|
|
|
|
// Should the compute be restarted upon successful move
|
|
// Required: false
|
|
Autostart bool `url:"autostart,omitempty"`
|
|
|
|
// 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
|
|
ForceStop bool `url:"forceStop,omitempty"`
|
|
}
|
|
|
|
func (crq MoveToRGRequest) validate() error {
|
|
if crq.ComputeID == 0 {
|
|
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
|
}
|
|
if crq.RGID == 0 {
|
|
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// MoveToRG moves compute instance to new resource group
|
|
func (c Compute) MoveToRG(ctx context.Context, req MoveToRGRequest) (bool, error) {
|
|
err := req.validate()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
return result, nil
|
|
}
|