This commit is contained in:
asteam
2024-10-01 11:15:36 +03:00
commit a25a3c2e5c
81 changed files with 5143 additions and 0 deletions

42
pkg/respool/list.go Normal file
View File

@@ -0,0 +1,42 @@
package respool
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/respool/models"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/respool/requests"
)
// List gets a list of all resource pools
func (rp ResourcePool) List(ctx context.Context, req requests.ListResPoolRequest) (*models.ListResPoolResponse, error) {
res, err := rp.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := models.ListResPoolResponse{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets a list of all resource pools as an array of bytes
func (rp ResourcePool) ListRaw(ctx context.Context, req requests.ListResPoolRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := constants.APIv0 + "/resource_pool"
res, err := rp.client.ApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,38 @@
package models
import "time"
type ListResPoolResponse struct {
List ListResPool `json:"resource_pool_list"`
RequestID string `json:"request_id"`
}
type ListResPool struct {
Total int `json:"total"`
Page int `json:"page"`
PerPage int `json:"per_page"`
IsApproximateTotal bool `json:"is_approximate_total"`
Items []ItemResPool `json:"items"`
HasMore bool `json:"has_more"`
}
type ItemResPool struct {
RAMLimitMb int `json:"ram_limit_mb"`
DiskLimitMb int `json:"disk_limit_mb"`
ClusterID int `json:"cluster_id"`
ExternalUUID string `json:"external_uuid"`
ResourcePoolID int `json:"resource_pool_id"`
Lock bool `json:"lock"`
Deleted time.Time `json:"deleted"`
Name string `json:"name"`
PrimaryExternalStorageID int `json:"primary_external_storage_id"`
ExternalResourceID any `json:"external_resource_id"`
CPULimit int `json:"cpu_limit"`
NodeCount int `json:"node_count"`
Created time.Time `json:"created"`
CPUUsed int `json:"cpu_used"`
RAMUsedMb int `json:"ram_used_mb"`
DiskUsedMb int `json:"disk_used_mb"`
ClusterName string `json:"cluster_name"`
ExternalStorageIds []int `json:"external_storage_ids"`
}

View File

@@ -0,0 +1,70 @@
package requests
import "time"
// ListResPoolRequest represents the request for retrieving a list of resource pools.
type ListResPoolRequest struct {
// Resource pool name. Searching by partial matching. Ignored if NameExact is provided.
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Exact resource pool name.
// Required: false
NameExact string `url:"name_exact,omitempty" json:"name_exact,omitempty"`
// Cluster ID.
// Required: false
ClusterID int `url:"cluster_id,omitempty" json:"cluster_id,omitempty"`
// Cluster name.
// Required: false
ClusterName string `url:"cluster_name,omitempty" json:"cluster_name,omitempty"`
// Filter resource pools by lock status.
// Required: false
Lock interface{} `url:"lock,omitempty" json:"lock,omitempty" validate:"omitempty,is_bool"`
// List of resource pool IDs to exclude from listing.
// Required: false
ExcludeIDs []int `url:"exclude_ids,omitempty" json:"exclude_ids,omitempty"`
// External resource ID where the resource pool is located.
// Required: false
ExternalResourceID int `url:"external_resource_id,omitempty" json:"external_resource_id,omitempty"`
// Include external resource pools for filtering or not. Default: false.
// Required: false
IncludeExternal bool `url:"include_external,omitempty" json:"include_external,omitempty"`
// Template for filtering by any text field.
// Required: false
FilterText string `url:"filter_text,omitempty" json:"filter_text,omitempty"`
// List of columns that will be used by FilterText.
// Required: false
FilterColumns string `url:"filter_columns,omitempty" json:"filter_columns,omitempty"`
// Filter entities created before this date.
// Required: false
CreatedBefore time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
// Filter entities created after this date.
// Required: false
CreatedAfter time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
// Field name or list of field names used for sorting. Ascending sort is default. For descending sort, use "-" before the name.
// Required: false
Sort []string `url:"sort,omitempty" json:"sort,omitempty"`
// Visibility options: "visible" - Only active resource pools, "deleted" - Only removed resource pools, "all" - All resource pools.
// Required: false
Visibility string `url:"visibility,omitempty" json:"visibility,omitempty" validate:"omitempty,visibility"`
// Number of the returning page.
// Required: false
Page int `url:"page,omitempty" json:"page,omitempty"`
// Number of items on the page.
// Required: false
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
}

View File

@@ -0,0 +1,17 @@
package respool
import (
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/interfaces"
)
// Structure for creating request to resource pools
type ResourcePool struct {
client interfaces.Caller
}
// Builder for file share endpoints
func New(client interfaces.Caller) *ResourcePool {
return &ResourcePool{
client,
}
}