v1.5.0-gamma2
This commit is contained in:
@@ -31,21 +31,23 @@ func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids {
|
||||
func (lg ListGrids) FilterFunc(predicate func(RecordGrid) bool) ListGrids {
|
||||
var result ListGrids
|
||||
|
||||
for _, item := range lg {
|
||||
for _, item := range lg.Data {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found RecordGrid.
|
||||
// If none was found, returns an empty struct.
|
||||
func (lg ListGrids) FindOne() RecordGrid {
|
||||
if len(lg) == 0 {
|
||||
if len(lg.Data) == 0 {
|
||||
return RecordGrid{}
|
||||
}
|
||||
|
||||
return lg[0]
|
||||
return lg.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,96 +3,99 @@ package grid
|
||||
import "testing"
|
||||
|
||||
var grids = ListGrids{
|
||||
{
|
||||
Resources: Resources{
|
||||
Current: RecordResource{
|
||||
CPU: 84,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 79500,
|
||||
RAM: 0,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
},
|
||||
Reserved: RecordResource{
|
||||
CPU: 123,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 0,
|
||||
RAM: 152600,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
Data: []RecordGrid{
|
||||
{
|
||||
Resources: Resources{
|
||||
Current: RecordResource{
|
||||
CPU: 84,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 79500,
|
||||
RAM: 0,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
},
|
||||
Reserved: RecordResource{
|
||||
CPU: 123,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 0,
|
||||
RAM: 152600,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
},
|
||||
},
|
||||
Flag: "",
|
||||
GID: 212,
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
LocationCode: "alfa",
|
||||
Name: "alfa",
|
||||
},
|
||||
Flag: "",
|
||||
GID: 212,
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
LocationCode: "alfa",
|
||||
Name: "alfa",
|
||||
},
|
||||
{
|
||||
Resources: Resources{
|
||||
Current: RecordResource{
|
||||
CPU: 84,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 79500,
|
||||
RAM: 0,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
},
|
||||
Reserved: RecordResource{
|
||||
CPU: 123,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 0,
|
||||
RAM: 152600,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
{
|
||||
Resources: Resources{
|
||||
Current: RecordResource{
|
||||
CPU: 84,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 79500,
|
||||
RAM: 0,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
},
|
||||
Reserved: RecordResource{
|
||||
CPU: 123,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 0,
|
||||
RAM: 152600,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
},
|
||||
},
|
||||
Flag: "",
|
||||
GID: 666,
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
LocationCode: "beta",
|
||||
Name: "beta",
|
||||
},
|
||||
Flag: "",
|
||||
GID: 666,
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
LocationCode: "beta",
|
||||
Name: "beta",
|
||||
},
|
||||
{
|
||||
Resources: Resources{
|
||||
Current: RecordResource{
|
||||
CPU: 84,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 79500,
|
||||
RAM: 0,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
},
|
||||
Reserved: RecordResource{
|
||||
CPU: 123,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 0,
|
||||
RAM: 152600,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
{
|
||||
Resources: Resources{
|
||||
Current: RecordResource{
|
||||
CPU: 84,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 79500,
|
||||
RAM: 0,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
},
|
||||
Reserved: RecordResource{
|
||||
CPU: 123,
|
||||
DiskSize: 976,
|
||||
DiskSizeMax: 1200,
|
||||
ExtIPs: 132,
|
||||
ExtTraffic: 0,
|
||||
GPU: 0,
|
||||
RAM: 152600,
|
||||
SEPs: map[string]map[string]DiskUsage{},
|
||||
},
|
||||
},
|
||||
Flag: "",
|
||||
GID: 777,
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
LocationCode: "gamma",
|
||||
Name: "gamma",
|
||||
},
|
||||
Flag: "",
|
||||
GID: 777,
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
LocationCode: "gamma",
|
||||
Name: "gamma",
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
|
||||
40
pkg/cloudbroker/grid/get_resource_consumption.go
Normal file
40
pkg/cloudbroker/grid/get_resource_consumption.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetResourceConsumptionRequest struct {
|
||||
// ID of the grid
|
||||
// Required: true
|
||||
GridID uint64 `url:"gridId" json:"gridId" validate:"required"`
|
||||
}
|
||||
|
||||
func (g Grid) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResourcesConsumption, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/grid/getResourceConsumption"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := RecordResourcesConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
@@ -8,6 +8,14 @@ import (
|
||||
|
||||
// Request struct for get list locations
|
||||
type ListRequest struct {
|
||||
// Find by id grid
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name grid
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -18,7 +26,7 @@ type ListRequest struct {
|
||||
}
|
||||
|
||||
// List gets list all locations
|
||||
func (g Grid) List(ctx context.Context, req ListRequest) (ListGrids, error) {
|
||||
func (g Grid) List(ctx context.Context, req ListRequest) (*ListGrids, error) {
|
||||
url := "/cloudbroker/grid/list"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -33,5 +41,5 @@ func (g Grid) List(ctx context.Context, req ListRequest) (ListGrids, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -6,21 +6,33 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for getting list of email addresses of users
|
||||
type ListEmailsRequest struct {
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListEmails returns list of email addresses of users
|
||||
func (g Grid) ListEmails(ctx context.Context) ([]string, error) {
|
||||
func (g Grid) ListEmails(ctx context.Context, req ListEmailsRequest) (*ListEmails, error) {
|
||||
|
||||
url := "/cloudbroker/grid/listEmails"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]string, 0)
|
||||
list := ListEmails{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
25
pkg/cloudbroker/grid/list_resource_consumption.go
Normal file
25
pkg/cloudbroker/grid/list_resource_consumption.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (g Grid) ListResourceConsumption(ctx context.Context) (*ListResourceConsumption, error) {
|
||||
url := "/cloudbroker/grid/listResourceConsumption"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := ListResourceConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
@@ -9,6 +9,26 @@ type Resources struct {
|
||||
Reserved RecordResource `json:"Reserved"`
|
||||
}
|
||||
|
||||
// Resource consumption information
|
||||
type RecordResourcesConsumption struct {
|
||||
// Current resources
|
||||
Consumed RecordResource `json:"Consumed"`
|
||||
|
||||
// Reserved resources
|
||||
Reserved RecordResource `json:"Reserved"`
|
||||
|
||||
// GID
|
||||
GID uint64 `json:"gid"`
|
||||
}
|
||||
|
||||
type ListResourceConsumption struct {
|
||||
// Data
|
||||
Data []RecordResourcesConsumption `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Resource details
|
||||
type RecordResource struct {
|
||||
// Number of CPU
|
||||
@@ -70,4 +90,19 @@ type RecordGrid struct {
|
||||
}
|
||||
|
||||
// List Grids
|
||||
type ListGrids []RecordGrid
|
||||
type ListGrids struct {
|
||||
//Data
|
||||
Data []RecordGrid `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// List emails
|
||||
type ListEmails struct {
|
||||
//Data
|
||||
Data []string `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lg ListGrids) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lg) == 0 {
|
||||
if len(lg.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user