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.

49 lines
1.3 KiB

package vm
import (
"context"
"encoding/json"
"fmt"
"net/http"
"repository.basistech.ru/BASIS/dynamix-standard-go-sdk/internal/constants"
"repository.basistech.ru/BASIS/dynamix-standard-go-sdk/internal/validators"
"repository.basistech.ru/BASIS/dynamix-standard-go-sdk/pkg/vm/common"
"repository.basistech.ru/BASIS/dynamix-standard-go-sdk/pkg/vm/models"
"repository.basistech.ru/BASIS/dynamix-standard-go-sdk/pkg/vm/requests"
)
// Enable vm
func (vm VM) PowerOn(ctx context.Context, req requests.PowerOnRequest) (*models.EnableInfoResponse, error) {
res, err := vm.PowerOnRaw(ctx, req)
if err != nil {
return nil, err
}
list := models.EnableInfoResponse{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// Enable vm with response as an array of bytes
func (vm VM) PowerOnRaw(ctx context.Context, req requests.PowerOnRequest) ([]byte, error) {
realReq := common.PowerVMRequest{
VmID: req.VmID,
Command: common.PowerOn,
}
if err := validators.ValidateRequest(realReq); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := constants.APIv0 + "/vm/" + fmt.Sprint(req) + "/task"
res, err := vm.client.ApiCall(ctx, http.MethodPost, url, realReq)
return res, err
}