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.

46 lines
1.2 KiB

package vm
import (
"context"
"encoding/json"
"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"
)
// List gets a list of all vms the user has access to a ListAccounts struct
func (vm VM) List(ctx context.Context, req requests.ListVMRequest) (*models.ListVMResponse, error) {
res, err := vm.ListRaw(ctx, req)
if err != nil {
return nil, err
}
if req.FolderSubtree == nil {
req.FolderSubtree = true
}
list := models.ListVMResponse{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets a list of all vms the user has access to as an array of bytes
func (vm VM) ListRaw(ctx context.Context, req requests.ListVMRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := constants.APIv0 + "/vm"
res, err := vm.client.ApiCall(ctx, http.MethodGet, url, req)
return res, err
}