v1.0.0
This commit is contained in:
15
pkg/extstorage/extstorage.go
Normal file
15
pkg/extstorage/extstorage.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package extstorage
|
||||
|
||||
import "repository.basistech.ru/BASIS/dynamix-standart-go-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to external storage
|
||||
type ExtStorage struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for external storage endpoints
|
||||
func New(client interfaces.Caller) *ExtStorage {
|
||||
return &ExtStorage{
|
||||
client,
|
||||
}
|
||||
}
|
||||
42
pkg/extstorage/list.go
Normal file
42
pkg/extstorage/list.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package extstorage
|
||||
|
||||
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/extstorage/models"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/extstorage/requests"
|
||||
)
|
||||
|
||||
// List gets a list of all storages.
|
||||
func (e ExtStorage) List(ctx context.Context, req requests.ListExtStorageRequest) (*models.ListExtStorageResponse, error) {
|
||||
|
||||
res, err := e.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := models.ListExtStorageResponse{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets a list of all storages as an array of bytes
|
||||
func (e ExtStorage) ListRaw(ctx context.Context, req requests.ListExtStorageRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := constants.APIv0 + "/external_storage"
|
||||
|
||||
res, err := e.client.ApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
45
pkg/extstorage/models/model_list.go
Normal file
45
pkg/extstorage/models/model_list.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type ListExtStorageResponse struct {
|
||||
List ListExtStorage `json:"external_storage_list"`
|
||||
RequestID string `json:"request_id"`
|
||||
}
|
||||
|
||||
type ListExtStorage struct {
|
||||
Total int `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PerPage int `json:"per_page"`
|
||||
IsApproximateTotal bool `json:"is_approximate_total"`
|
||||
Items []ItemStorage `json:"items"`
|
||||
HasMore bool `json:"has_more"`
|
||||
}
|
||||
|
||||
type ItemStorage struct {
|
||||
ClusterName string `json:"cluster_name"`
|
||||
ExternalStorageID int `json:"external_storage_id"`
|
||||
Path string `json:"path"`
|
||||
ClusterID int `json:"cluster_id"`
|
||||
MaxDisksNum int `json:"max_disks_num"`
|
||||
StorageType string `json:"storage_type"`
|
||||
CacheStatus string `json:"cache_status"`
|
||||
Username string `json:"username"`
|
||||
Server string `json:"server"`
|
||||
CacheSizeMb int `json:"cache_size_mb"`
|
||||
UsedMb int `json:"used_mb"`
|
||||
StoragePath string `json:"storage_path"`
|
||||
CachePath string `json:"cache_path"`
|
||||
Status string `json:"status"`
|
||||
Deleted time.Time `json:"deleted"`
|
||||
Description string `json:"description"`
|
||||
CacheEnabled bool `json:"cache_enabled"`
|
||||
Iqn string `json:"iqn"`
|
||||
Created time.Time `json:"created"`
|
||||
Modified time.Time `json:"modified"`
|
||||
MountPoint string `json:"mount_point"`
|
||||
Name string `json:"name"`
|
||||
TotalMb int `json:"total_mb"`
|
||||
VMHomeDirSizeGb int `json:"vm_home_dir_size_gb"`
|
||||
VMCount int `json:"vm_count"`
|
||||
}
|
||||
65
pkg/extstorage/requests/request_list.go
Normal file
65
pkg/extstorage/requests/request_list.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package requests
|
||||
|
||||
import "time"
|
||||
|
||||
type ListExtStorageRequest struct {
|
||||
// Storage description
|
||||
// Required: false
|
||||
Description int `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// Name of the storage
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Storage path
|
||||
// Required: false
|
||||
Path string `url:"path,omitempty" json:"path,omitempty"`
|
||||
|
||||
// Storage server
|
||||
// Required: false
|
||||
Server string `url:"server,omitempty" json:"server,omitempty"`
|
||||
|
||||
// Status of storage
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty" validate:"omitempty,extstorage_status"`
|
||||
|
||||
// Type of storage
|
||||
// Required: false
|
||||
StorageType string `url:"storage_type,omitempty" json:"storage_type,omitempty" validate:"omitempty,extstorage_type"`
|
||||
|
||||
// Cluster ID
|
||||
// Required: false
|
||||
ClusterID string `url:"cluster_id,omitempty" json:"cluster_id,omitempty"`
|
||||
|
||||
// Cluster name
|
||||
// Required: false
|
||||
ClusterName string `url:"cluster_name,omitempty" json:"cluster_name,omitempty"`
|
||||
|
||||
// List only unused external storages
|
||||
// Required: false
|
||||
OnlyUnused interface{} `url:"only_unused,omitempty" json:"only_unused,omitempty" validate:"omitempty,is_bool"`
|
||||
|
||||
// List columns which will be used by filter_text
|
||||
// Required: false
|
||||
FilterText 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"`
|
||||
|
||||
// List of columns for sorting.
|
||||
// Required: false
|
||||
// Sort []string `url:"sort,omitempty" json:"sort,omitempty"`
|
||||
|
||||
// Number of the page to return.
|
||||
// Required: false
|
||||
Page int `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Number of items to return per page.
|
||||
// Required: false
|
||||
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user