git test
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
package zone
|
||||
|
||||
// FilterByID returns ListZones with specified ID.
|
||||
func (list ListZones) FilterByID(id uint64) ListZones {
|
||||
predicate := func(izone ItemZone) bool {
|
||||
return izone.ID == id
|
||||
}
|
||||
|
||||
return list.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListZones with specified Name.
|
||||
func (list ListZones) FilterByName(name string) ListZones {
|
||||
predicate := func(izone ItemZone) bool {
|
||||
return izone.Name == name
|
||||
}
|
||||
|
||||
return list.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListZones with specified Status.
|
||||
func (list ListZones) FilterByStatus(status string) ListZones {
|
||||
predicate := func(izone ItemZone) bool {
|
||||
return izone.Status == status
|
||||
}
|
||||
|
||||
return list.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListZones based on a user-specified predicate.
|
||||
func (list ListZones) FilterFunc(predicate func(ItemZone) bool) ListZones {
|
||||
var result ListZones
|
||||
|
||||
for _, item := range list.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemZone
|
||||
// If none was found, returns an empty struct.
|
||||
func (list ListZones) FindOne() ItemZone {
|
||||
if list.EntryCount == 0 {
|
||||
return ItemZone{}
|
||||
}
|
||||
|
||||
return list.Data[0]
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package zone
|
||||
|
||||
import "testing"
|
||||
|
||||
var zones = ListZones{
|
||||
Data: []ItemZone{
|
||||
|
||||
{
|
||||
ID: 2,
|
||||
GUID: 0,
|
||||
GID: 0,
|
||||
Name: "System Config",
|
||||
Description: "",
|
||||
Deletable: true,
|
||||
Status: "LOCKED",
|
||||
CreatedTime: 1640995200, // 2022-01-01
|
||||
UpdatedTime: 1640995200,
|
||||
NodeIDs: nil,
|
||||
},
|
||||
{
|
||||
ID: 5,
|
||||
GUID: 5500,
|
||||
GID: 6600,
|
||||
Name: "ssss Nodes",
|
||||
Description: " infrastructure",
|
||||
Deletable: true,
|
||||
Status: "DISABLED",
|
||||
CreatedTime: 1577836800, // 2020-01-01
|
||||
UpdatedTime: 1580515200, // 2020-02-01
|
||||
NodeIDs: []uint64{777, 888, 999},
|
||||
},
|
||||
{
|
||||
ID: 10,
|
||||
GUID: 5500,
|
||||
GID: 6600,
|
||||
Name: "node",
|
||||
Description: "infrastructure",
|
||||
Deletable: true,
|
||||
Status: "DISABLED",
|
||||
CreatedTime: 1577836800,
|
||||
UpdatedTime: 1580515200,
|
||||
NodeIDs: []uint64{777, 888, 999},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := zones.FilterByID(10).FindOne()
|
||||
|
||||
if actual.ID != 10 {
|
||||
t.Fatal("expected ID 10, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
name := "node"
|
||||
actual := zones.FilterByName(name).FindOne()
|
||||
|
||||
if actual.Name != name {
|
||||
t.Fatal("expected ", name, " found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := zones.FilterByStatus("DISABLED")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "DISABLED" {
|
||||
t.Fatal("expected Status 'DISABLED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := zones.FilterFunc(func(ien ItemZone) bool {
|
||||
return ien.Deletable == true
|
||||
})
|
||||
|
||||
if len(actual.Data) != 3 {
|
||||
t.Fatal("expected 3 elements, found: ", len(actual.Data))
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package zone
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get detailed information about zone
|
||||
type GetRequest struct {
|
||||
// ID of zone
|
||||
// Required: true
|
||||
ID uint64 `url:"id" json:"id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets detailed information about zone struct
|
||||
func (e Zone) Get(ctx context.Context, req GetRequest) (*RecordZone, error) {
|
||||
res, err := e.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordZone{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets detailed information about zone as an array of bytes
|
||||
func (e Zone) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/zone/get"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package zone
|
||||
|
||||
// IDs gets array of IDs from ListZones struct
|
||||
func (le ListZones) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(le.Data))
|
||||
for _, e := range le.Data {
|
||||
res = append(res, e.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package zone
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of zones
|
||||
type ListRequest struct {
|
||||
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by Grid ID
|
||||
// Required: false
|
||||
GID uint64 `url:"gid,omitempty" json:"gid,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by deletable
|
||||
// Required: false
|
||||
Deletable bool `url:"deletable,omitempty" json:"deletable,omitempty"`
|
||||
|
||||
// Find by node ID
|
||||
// Required: false
|
||||
NodeID uint64 `url:"nodeId,omitempty" json:"nodeId,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of all zones as a ListZones struct
|
||||
func (e Zone) List(ctx context.Context, req ListRequest) (*ListZones, error) {
|
||||
|
||||
res, err := e.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListZones{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of all available zones as an array of bytes
|
||||
func (e Zone) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/zone/list"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package zone
|
||||
@@ -1,186 +0,0 @@
|
||||
package zone
|
||||
|
||||
// CPU alignment profile
|
||||
type CpuAlignmentProfile struct {
|
||||
// Profile name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Vendor
|
||||
Vendor string `json:"vendor"`
|
||||
|
||||
// Model
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
type ListZones struct {
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
|
||||
// Data
|
||||
Data []ItemZone `json:"data"`
|
||||
}
|
||||
|
||||
// Detailed information about the zone record
|
||||
type RecordZone struct {
|
||||
// If true, all nodes belonging to the given zone will be marked for autostart
|
||||
AutoStart bool `json:"autostart"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// GID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// List of associated account IDs
|
||||
AccountIDs []uint64 `json:"accountIds"`
|
||||
|
||||
// List of associated bservice IDs
|
||||
BserviceIDs []uint64 `json:"bserviceIds"`
|
||||
|
||||
// List of associated compute IDs
|
||||
ComputeIDs []uint64 `json:"computeIds"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// Deletable flag
|
||||
Deletable bool `json:"deletable"`
|
||||
|
||||
// List of associated ExtNet IDs
|
||||
ExtnetIDs []uint64 `json:"extnetIds"`
|
||||
|
||||
// List of associated K8s IDs
|
||||
K8SIDs []uint64 `json:"k8sIds"`
|
||||
|
||||
// List of associated LB IDs
|
||||
LBIDs []uint64 `json:"lbsIds"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Created timestamp
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Updated timestamp
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// List of associated Node IDs
|
||||
NodeIDs []uint64 `json:"nodeIds"`
|
||||
|
||||
// List of associated VINS IDs
|
||||
VinsIDs []uint64 `json:"vinsIds"`
|
||||
|
||||
// DRS
|
||||
DRS bool `json:"drs"`
|
||||
|
||||
// DRS UID
|
||||
DRSUID string `json:"drs_uid"`
|
||||
|
||||
// App ID
|
||||
AppID string `json:"app_id"`
|
||||
|
||||
// Decort URL
|
||||
DecortURL string `json:"decort_url"`
|
||||
|
||||
// DRS Name
|
||||
DRSName string `json:"drs_name"`
|
||||
|
||||
// SSO URL
|
||||
SSOURL string `json:"sso_url"`
|
||||
|
||||
// SSO type
|
||||
SSOType string `json:"sso_type"`
|
||||
|
||||
// Ping address
|
||||
PingAddr string `json:"ping_addr"`
|
||||
|
||||
// Broadcast address
|
||||
BroadcastAddr string `json:"broadcast_addr"`
|
||||
|
||||
// Skip ssl verify
|
||||
SSLSkipVerify bool `json:"ssl_skip_verify"`
|
||||
|
||||
// Domain
|
||||
Domain string `json:"domain"`
|
||||
|
||||
// CPU alignment profiles
|
||||
CpuAlignmentProfiles []CpuAlignmentProfile `json:"cpu_alignment_profiles"`
|
||||
}
|
||||
|
||||
// A zone item from a list
|
||||
type ItemZone struct {
|
||||
// App ID
|
||||
AppID string `json:"app_id"`
|
||||
|
||||
// If true, all nodes belonging to the given zone will be marked for autostart
|
||||
AutoStart bool `json:"autostart"`
|
||||
|
||||
// Created timestamp
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Decort URL
|
||||
DecortURL string `json:"decort_url"`
|
||||
|
||||
// Deletable flag
|
||||
Deletable bool `json:"deletable"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// DRS
|
||||
DRS bool `json:"drs"`
|
||||
|
||||
// DRS Name
|
||||
DRSName string `json:"drs_name"`
|
||||
|
||||
// DRS UID
|
||||
DRSUID string `json:"drs_uid"`
|
||||
|
||||
// GID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// List of associated Node IDs
|
||||
NodeIDs []uint64 `json:"nodeIds"`
|
||||
|
||||
// SSO URL
|
||||
SSOURL string `json:"sso_url"`
|
||||
|
||||
// SSO type
|
||||
SSOType string `json:"sso_type"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Updated timestamp
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// Ping address
|
||||
PingAddr string `json:"ping_addr"`
|
||||
|
||||
// Broadcast address
|
||||
BroadcastAddr string `json:"broadcast_addr"`
|
||||
|
||||
// Skip ssl verify
|
||||
SSLSkipVerify bool `json:"ssl_skip_verify"`
|
||||
|
||||
// Domain
|
||||
Domain string `json:"domain"`
|
||||
|
||||
// CPU alignment profiles
|
||||
CpuAlignmentProfiles []CpuAlignmentProfile `json:"cpu_alignment_profiles"`
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package zone
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (list ListZones) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if list.EntryCount == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(list, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(list)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (item RecordZone) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(item, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(item)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
// API Actor for use zones
|
||||
package zone
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to zone
|
||||
type Zone struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for zone endpoints
|
||||
func New(client interfaces.Caller) *Zone {
|
||||
return &Zone{
|
||||
client,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user