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.

44 lines
1.1 KiB

4 months ago
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/models"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/requests"
)
// Get return information about specified VM
func (vm VM) Get(ctx context.Context, req requests.GetVMRequest) (*models.RecordVMResponse, error) {
res, err := vm.GetRaw(ctx, req)
if err != nil {
return nil, err
}
item := models.RecordVMResponse{}
err = json.Unmarshal(res, &item)
if err != nil {
return nil, err
}
return &item, nil
}
// GetRaw return information about specified VMas an array of bytes
func (vm VM) GetRaw(ctx context.Context, req requests.GetVMRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := constants.APIv0 + "/vm/" + fmt.Sprint(req.VmID)
res, err := vm.client.ApiCall(ctx, http.MethodGet, url, req)
return res, err
}