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.
51 lines
1.3 KiB
51 lines
1.3 KiB
package vm
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/constants"
|
|
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/validators"
|
|
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/common"
|
|
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/models"
|
|
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/requests"
|
|
)
|
|
|
|
// PowerOff Power off vm
|
|
func (vm VM) PowerOff(ctx context.Context, req requests.PowerOffRequest) (*models.DisableInfoResponse, error) {
|
|
|
|
res, err := vm.PowerOffRaw(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
list := models.DisableInfoResponse{}
|
|
|
|
err = json.Unmarshal(res, &list)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &list, nil
|
|
}
|
|
|
|
// PowerOffRaw Power off vm with response as an array of bytes
|
|
func (vm VM) PowerOffRaw(ctx context.Context, req requests.PowerOffRequest) ([]byte, error) {
|
|
realReq := common.PowerVMRequest{
|
|
VmID: req.VmID,
|
|
Command: common.PowerOff,
|
|
Graceful: req.Graceful,
|
|
Force: req.Force,
|
|
}
|
|
|
|
if err := validators.ValidateRequest(realReq); err != nil {
|
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := constants.APIv0 + "/vm/" + fmt.Sprint(req.VmID) + "/task"
|
|
|
|
res, err := vm.client.ApiCall(ctx, http.MethodPost, url, realReq)
|
|
return res, err
|
|
}
|