This commit is contained in:
2025-04-09 11:21:07 +03:00
parent 3f21a89e80
commit 8a101c6fcb
115 changed files with 2342 additions and 429 deletions

View File

@@ -13,6 +13,10 @@ type DisableEnableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Reason of disabling
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// Disable disables an account

View File

@@ -62,6 +62,9 @@ type ItemAccount struct {
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// ID
ID uint64 `json:"id"`
@@ -197,6 +200,9 @@ type RecordAccount struct {
// Created time
CreatedTime uint64 `json:"createdTime"`
// Description
Description string `json:"desc"`
// Deactivation time
DeactivationTime float64 `json:"deactivationTime"`
@@ -512,6 +518,9 @@ type ItemRG struct {
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Resource group ID
RGID uint64 `json:"id"`

View File

@@ -14,6 +14,10 @@ type UpdateRequest struct {
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Description
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
// Name of the account
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`

View File

@@ -12,7 +12,7 @@ import (
type GetRequest struct {
// Audit GUID
// Required: true
AuditGuid string `url:"auditGuid" json:"auditGuid" validate:"required"`
AuditGuid string `url:"audit_guid" json:"audit_guid" validate:"required"`
}
// Get gets information about audit as a RecordAudit struct

View File

@@ -71,6 +71,10 @@ type GroupAddRequest struct {
// Meta data for working group computes, format YAML "user_data": 1111
// Required: false
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
//Chipset "i440fx" or "Q35
//Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"chipset"`
}
// GetRAM returns RAM field values

View File

@@ -22,6 +22,12 @@ type GroupResizeRequest struct {
// Required: true
Count int64 `url:"count" json:"count" validate:"required"`
//Chipset for new computes, either i440fx or Q35 (i440fx by default)
//Available values : i440fx, Q35
//Default value : i440fx
//Required: true
Chipset string `url:"chipset" json:"chipset" validate:"required,chipset"`
// Either delta or absolute value of computes
// Should be one of:
// - ABSOLUTE

View File

@@ -295,6 +295,9 @@ type ItemGroupCompute struct {
// List of information about OS Users
OSUsers ListOSUsers `json:"osUsers"`
//Chipset
Chipset string `json:"chipset"`
}
// List of Group Computes

View File

@@ -12,23 +12,23 @@ import (
type ChangeIPRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
// Network type
// 'EXTNET' for connect to external network directly
// 'VINS' for connect to ViNS
// Required: true
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
NetType string `url:"net_type" json:"net_type" validate:"computeNetType"`
// Network ID for connect to
// For EXTNET - external network ID
// For VINS - VINS ID
// Required: true
NetID uint64 `url:"netId" json:"netId" validate:"required"`
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
// IP address to which we will change the existing one, it must be from the same subnet
// Required: true
IPAddr string `url:"ipAddr" json:"ipAddr" validate:"required"`
IPAddr string `url:"ip_addr" json:"ip_addr" validate:"required"`
}
// ChangeIP change reserved IP for compute instance

View File

@@ -0,0 +1,46 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ChangeMACRequest struct to change MAC for network
type ChangeMACRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
// Current mac address
// Required: true
СurrentMAC string `url:"current_mac_address" json:"current_mac_address" validate:"required"`
// the MAC address to which we will change the existing one
// Required: true
NewMAC string `url:"new_mac_address" json:"new_mac_address" validate:"required"`
}
// ChangeMAC change MAC for compute instance
func (c Compute) ChangeMAC(ctx context.Context, req ChangeMACRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/changeMac"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -48,8 +48,7 @@ var computes = ListComputes{
Devices: nil,
Disks: []InfoDisk{
{
ID: 65191,
PCISlot: 6,
ID: 65191,
},
},
Driver: "KVM_X86",
@@ -64,7 +63,7 @@ var computes = ListComputes{
MigrationJob: 0,
Milestones: 363500,
Name: "test",
Pinned: false,
PinnedToStack: true,
RAM: 4096,
ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e",
Registered: true,
@@ -111,8 +110,7 @@ var computes = ListComputes{
Devices: nil,
Disks: []InfoDisk{
{
ID: 65248,
PCISlot: 6,
ID: 65248,
},
},
Driver: "KVM_X86",
@@ -127,10 +125,10 @@ var computes = ListComputes{
MigrationJob: 0,
Milestones: 363853,
Name: "compute_2",
Pinned: false,
RAM: 4096,
ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff",
Registered: true,
PinnedToStack: true,
ResName: "compute-48556",
RGID: 79727,
RGName: "sdk_negative_fields_test",

View File

@@ -308,6 +308,9 @@ type RecordCompute struct {
// Boot order
BootOrder []string `json:"bootOrder"`
// Boot type
BootType string `json:"bootType"`
// Boot disk size
BootDiskSize uint64 `json:"bootdiskSize"`
@@ -368,6 +371,9 @@ type RecordCompute struct {
// HPBacked
HPBacked bool `json:"hpBacked"`
// Hot resize
HotResize bool `json:"hotResize"`
// ID
ID uint64 `json:"id"`
@@ -380,6 +386,9 @@ type RecordCompute struct {
// List interfaces
Interfaces ListInterfaces `json:"interfaces"`
// Loader type
LoaderType string `json:"loaderType"`
// Lock status
LockStatus string `json:"lockStatus"`
@@ -401,6 +410,9 @@ type RecordCompute struct {
// NeedReboot
NeedReboot bool `json:"needReboot"`
// Network interface naming
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
// Numa Affinity
NumaAffinity string `json:"numaAffinity"`
@@ -425,8 +437,8 @@ type RecordCompute struct {
// List OS Users
OSUsers ListOSUser `json:"osUsers"`
// Pinned or not
Pinned bool `json:"pinned"`
// Pinned to stack
PinnedToStack bool `json:"pinnedToStack"`
// PreferredCPU
PreferredCPU []int64 `json:"preferredCpu"`
@@ -712,13 +724,13 @@ type ItemComputeDisk struct {
Passwd string `json:"passwd"`
// PCI slot
PCISlot int64 `json:"pciSlot"`
PCISlot int64 `json:"pci_slot"`
// Pool
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
PresentTo map[string]uint64 `json:"presentTo"`
// Purge time
PurgeTime uint64 `json:"purgeTime"`
@@ -741,6 +753,9 @@ type ItemComputeDisk struct {
// Shareable
Shareable bool `json:"shareable"`
// Size available
SizeAvailable uint64 `json:"sizeAvailable"`
// Size max
SizeMax uint64 `json:"sizeMax"`
@@ -759,6 +774,9 @@ type ItemComputeDisk struct {
// Type
Type string `json:"type"`
// Updated by
UpdatedBy uint64 `json:"updatedBy"`
// Virtual machine ID
VMID uint64 `json:"vmid"`
}
@@ -884,6 +902,9 @@ type ItemCompute struct {
// Boot order
BootOrder []string `json:"bootOrder"`
// Boot type
BootType string `json:"bootType"`
// Boot disk size
BootDiskSize uint64 `json:"bootdiskSize"`
@@ -941,6 +962,9 @@ type ItemCompute struct {
// GUID
GUID uint64 `json:"guid"`
// Hot resize
HotResize bool `json:"hotResize"`
// HPBacked
HPBacked bool `json:"hpBacked"`
@@ -953,6 +977,9 @@ type ItemCompute struct {
// List interfaces
Interfaces ListInterfaces `json:"interfaces"`
// Loader type
LoaderType string `json:"loaderType"`
// Lock status
LockStatus string `json:"lockStatus"`
@@ -974,14 +1001,17 @@ type ItemCompute struct {
// NeedReboot
NeedReboot bool `json:"needReboot"`
// network interface naming
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
// Numa Affinity
NumaAffinity string `json:"numaAffinity"`
//NumaNodeId
NumaNodeId int64 `json:"numaNodeId"`
// Pinned or not
Pinned bool `json:"pinned"`
// Pinned to stack
PinnedToStack bool `json:"pinnedToStack"`
// PreferredCPU
PreferredCPU []int64 `json:"preferredCpu"`
@@ -1054,12 +1084,6 @@ type ListInfoDisks []InfoDisk
type InfoDisk struct {
// ID
ID uint64 `json:"id"`
// PCISlot
PCISlot int64 `json:"pciSlot"`
// Bus number
BusNumber uint64 `json:"bus_number"`
}
// List information about computes

View File

@@ -32,6 +32,10 @@ type NetAttachRequest struct {
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// MAC address
// Required: false
MACAddr string `url:"mac_addr,omitempty" json:"mac_addr,omitempty"`
// Used only for DPDK type, must be 1-9216
// Required: false
MTU uint64 `url:"mtu,omitempty" json:"mtu,omitempty" validate:"omitempty,mtu"`

View File

@@ -52,6 +52,22 @@ type UpdateRequest struct {
// Recommended isolated CPUs. Field is ignored if compute.cpupin=False or compute.pinned=False
// Required: false
PreferredCPU []int64 `url:"preferredCpu,omitempty" json:"preferredCpu,omitempty" validate:"omitempty,preferredCPU"`
// VM type linux, windows or unknown
// Required: false
LoaderType string `url:"loaderType,omitempty" json:"loaderType,omitempty" validate:"omitempty,loaderType"`
// Boot type of image bios or uefi
// Required: false
BootType string `url:"bootType,omitempty" json:"bootType,omitempty" validate:"omitempty,imageBootType"`
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming.
// Required: false
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
// Does this machine supports hot resize
// Required: false
HotResize bool `url:"hotResize,omitempty" json:"hotResize,omitempty"`
}
// Update updates some properties of the compute

View File

@@ -3,8 +3,9 @@ package disks
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CreateRequest struct to create disk
@@ -13,10 +14,6 @@ type CreateRequest struct {
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// ID of the grid (platform)
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// Name of disk
// Required: true
Name string `url:"name" json:"name" validate:"required"`
@@ -29,17 +26,6 @@ type CreateRequest struct {
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Type of disk
// - B=Boot
// - D=Data
// - T=Temp
// Required: true
Type string `url:"type" json:"type" validate:"diskType"`
// Size in GB default is 0
// Required: false
SSDSize uint64 `url:"ssdSize,omitempty" json:"ssdSize,omitempty"`
// Max IOPS disk can perform defaults to 2000
// Required: false
IOPS uint64 `url:"iops,omitempty" json:"iops,omitempty"`

View File

@@ -35,9 +35,9 @@ var disks = ListDisks{
ParentID: 0,
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
},
//PresentTo: []uint64{
// 27,
//},
PurgeTime: 0,
ResID: "sample",
ResName: "sample",
@@ -78,10 +78,10 @@ var disks = ListDisks{
ParentID: 0,
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
27,
},
//PresentTo: []uint64{
// 27,
// 27,
//},
PurgeTime: 0,
ResID: "sample",
ResName: "sample",
@@ -211,9 +211,9 @@ var searchDisks = ListSearchDisks{
ParentID: 0,
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
},
//PresentTo: []uint64{
// 27,
//},
PurgeTime: 0,
ResID: "sample",
ResName: "sample",
@@ -254,10 +254,10 @@ var searchDisks = ListSearchDisks{
ParentID: 0,
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
27,
},
//PresentTo: []uint64{
// 27,
// 27,
//},
PurgeTime: 0,
ResID: "sample",
ResName: "sample",
@@ -393,7 +393,7 @@ var unattachedDisks = ListDisksUnattached{
Password: "",
PCISlot: -1,
Pool: "data05",
PresentTo: []uint64{},
PresentTo: map[string]uint64{},
PurgeAttempts: 0,
PurgeTime: 0,
RealityDeviceNumber: 0,
@@ -445,10 +445,10 @@ var unattachedDisks = ListDisksUnattached{
Password: "",
PCISlot: -1,
Pool: "data05",
PresentTo: []uint64{
27,
27,
},
//PresentTo: []uint64{
// 27,
// 27,
//},
PurgeAttempts: 0,
PurgeTime: 0,
RealityDeviceNumber: 0,

View File

@@ -14,9 +14,15 @@ type ItemDisk struct {
// Computes
Computes map[string]string `json:"computes"`
//Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
@@ -50,6 +56,9 @@ type ItemDisk struct {
// Machine name
MachineName string `json:"machineName"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
@@ -69,7 +78,7 @@ type ItemDisk struct {
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
PresentTo map[string]uint64 `json:"presentTo"`
// Purge time
PurgeTime uint64 `json:"purgeTime"`
@@ -95,6 +104,9 @@ type ItemDisk struct {
// SepID
SepID uint64 `json:"sepId"`
// Size available
SizeAvailable uint64 `json:"sizeAvailable"`
// Size max
SizeMax uint64 `json:"sizeMax"`
@@ -115,6 +127,12 @@ type ItemDisk struct {
// Virtual machine ID
VMID uint64 `json:"vmid"`
// Update time
UpdatedTime uint64 `json:"updatedTime"`
// Updated by
UpdatedBy string `json:"updatedBy"`
}
type ItemDiskUnattached struct {
@@ -200,7 +218,7 @@ type ItemDiskUnattached struct {
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
PresentTo map[string]uint64 `json:"presentTo"`
// Purge attempts
PurgeAttempts uint64 `json:"purgeAttempts"`
@@ -354,9 +372,15 @@ type RecordDisk struct {
// Computes
Computes map[string]string `json:"computes"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
@@ -384,6 +408,15 @@ type RecordDisk struct {
// IOTune
IOTune IOTune `json:"iotune"`
// Machine ID
MachineID uint64 `json:"machineId"`
// Machine name
MachineName string `json:"machineName"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
@@ -403,7 +436,7 @@ type RecordDisk struct {
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
PresentTo map[string]uint64 `json:"presentTo"`
// Purge time
PurgeTime uint64 `json:"purgeTime"`
@@ -429,6 +462,9 @@ type RecordDisk struct {
// Shareable
Shareable bool `json:"shareable"`
// Size available
SizeAvailable uint64 `json:"sizeAvailable"`
// Size max
SizeMax uint64 `json:"sizeMax"`
@@ -449,6 +485,12 @@ type RecordDisk struct {
// Virtual machine ID
VMID uint64 `json:"vmid"`
// Update time
UpdatedTime uint64 `json:"updatedTime"`
// Updated by
UpdatedBy string `json:"updatedBy"`
}
type ItemReplication struct {

View File

@@ -49,6 +49,10 @@ type ListRequest struct {
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
//openVswitch bridge name
//Required: false
OVSBridge string `url:"ovsBridge,omitempty" json:"ovsBridge,omitempty"`
}
// List gets list of all available external networks as a ListExtNets struct

View File

@@ -202,6 +202,9 @@ type RecordExtNet struct {
// Network ID
NetworkID uint64 `json:"networkId"`
// NTP
NTP []string `json:"ntp"`
// OVS Bridge
OVSBridge string `json:"ovsBridge"`

View File

@@ -162,7 +162,7 @@ type RecordImage struct {
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
PresentTo map[string]uint64 `json:"presentTo"`
// ProviderName
ProviderName string `json:"provider_name"`
@@ -185,6 +185,9 @@ type RecordImage struct {
// Size
Size uint64 `json:"size"`
// snapshot ID
SnapshotID string `json:"snapshotId"`
// Status
Status string `json:"status"`

View File

@@ -89,6 +89,9 @@ type RecordK8S struct {
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Only external network
ExtnetOnly bool `json:"extnetOnly"`

View File

@@ -31,6 +31,10 @@ type Interface struct {
// Used only to DPDK net type
// Required: false
MTU uint64 `url:"mtu,omitempty" json:"mtu,omitempty" validate:"omitempty,mtu"`
// MAC address to assign to this VM when connecting to the specified network
// Required: false
MAC string `url:"mac,omitempty" json:"mac,omitempty" validate:"omitempty"`
}
// DataDisk detailed struct for DataDisks field in CreateRequest and CreateBlankRequest

View File

@@ -72,6 +72,22 @@ type CreateBlankRequest struct {
// Recommended isolated CPUs. Field is ignored if compute.cpupin=False or compute.pinned=False
// Required: false
PreferredCPU []int64 `url:"preferredCpu,omitempty" json:"preferredCpu,omitempty" validate:"omitempty,preferredCPU"`
// VM type linux, windows or unknown
// Required: false
LoaderType string `url:"loaderType,omitempty" json:"loaderType,omitempty" validate:"omitempty,loaderType"`
// Boot type of image bios or uefi
// Required: false
BootType string `url:"bootType,omitempty" json:"bootType,omitempty" validate:"omitempty,imageBootType"`
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming.
// Required: false
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
// Does this machine supports hot resize
// Required: false
HotResize bool `url:"hotResize,omitempty" json:"hotResize,omitempty"`
}
// GetRAM returns RAM field values

View File

@@ -71,10 +71,6 @@ type CreateRequest struct {
// External IP address
// Required: false
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
// Register computes in registration system
// Required: false
RegisterComputes bool `url:"registerComputes,omitempty" json:"registerComputes,omitempty"`
}
// Create creates resource group

View File

@@ -42,10 +42,6 @@ type UpdateRequest struct {
// Required: false
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
// Register computes in registration system
// Required: false
RegisterComputes bool `url:"registerComputes,omitempty" json:"registerComputes,omitempty"`
// List of strings with pools i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`

8
pkg/cloudapi/sep.go Normal file
View File

@@ -0,0 +1,8 @@
package cloudapi
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/sep"
// Accessing the SEP method group
func (cb *CloudAPI) SEP() *sep.SEP {
return sep.New(cb.client)
}

View File

@@ -0,0 +1,83 @@
package sep
// FilterBySEPID returns ListAvailableSEP with the specified SEPID.
func (sl ListAvailableSEP) FilterBySEPID(sepID uint64) ListAvailableSEP {
predicate := func(sd SEPData) bool {
return sd.SEPID == sepID
}
return sl.FilterFunc(predicate)
}
// FilterBySEPName returns ListAvailableSEP with the specified SEPName.
func (sl ListAvailableSEP) FilterBySEPName(SEPName string) ListAvailableSEP {
predicate := func(sd SEPData) bool {
return sd.SEPName == SEPName
}
return sl.FilterFunc(predicate)
}
// FilterBySEPType returns ListAvailableSEP with the specified SEPType.
func (sl ListAvailableSEP) FilterBySEPType(SEPType string) ListAvailableSEP {
predicate := func(sd SEPData) bool {
return sd.SEPType == SEPType
}
return sl.FilterFunc(predicate)
}
// FilterByPoolType returns ListAvailableSEP where at least one pool has the specified type.
func (sl ListAvailableSEP) FilterByPoolType(poolType string) ListAvailableSEP {
predicate := func(sd SEPData) bool {
for _, pool := range sd.Pools {
for _, pt := range pool.Types {
if pt == poolType {
return true
}
}
}
return false
}
return sl.FilterFunc(predicate)
}
// FilterBySystemPool returns ListAvailableSEP where at least one pool is a system pool.
func (sl ListAvailableSEP) FilterBySystemPool(isSystem bool) ListAvailableSEP {
predicate := func(sd SEPData) bool {
for _, pool := range sd.Pools {
if pool.System == isSystem {
return true
}
}
return false
}
return sl.FilterFunc(predicate)
}
// FilterFunc allows filtering ListAvailableSEP based on a user-defined predicate.
func (sl ListAvailableSEP) FilterFunc(predicate func(SEPData) bool) ListAvailableSEP {
var result ListAvailableSEP
for _, item := range sl.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns the first found SEPData.
// If nothing is found, returns an empty struct.
func (sl ListAvailableSEP) FindOne() SEPData {
if len(sl.Data) == 0 {
return SEPData{}
}
return sl.Data[0]
}

View File

@@ -0,0 +1,134 @@
package sep
import (
"testing"
)
var seps = ListAvailableSEP{
EntryCount: 3,
Data: []SEPData{
{
SEPID: 1,
SEPName: "sep_1",
SEPType: "TATLIN",
Pools: []Pool{
{
Name: "pool_1",
Types: []string{"DES"},
System: false,
},
},
},
{
SEPID: 2,
SEPName: "sep_2",
SEPType: "SHARED",
Pools: []Pool{
{
Name: "pool_2",
Types: []string{"DES"},
System: true,
},
},
},
{
SEPID: 3,
SEPName: "sep_3",
SEPType: "DES",
Pools: []Pool{
{
Name: "pool_3",
Types: []string{"DES"},
System: false,
},
},
},
},
}
func TestFilterBySEPID(t *testing.T) {
actual := seps.FilterBySEPID(1).FindOne()
if actual.SEPID != 1 {
t.Fatal("expected SEPID 1, found: ", actual.SEPID)
}
}
func TestFilterBySEPName(t *testing.T) {
actual := seps.FilterBySEPName("sep_2").FindOne()
if actual.SEPName != "sep_2" {
t.Fatal("expected SEPName 'sep_2', found: ", actual.SEPName)
}
}
func TestFilterBySEPType(t *testing.T) {
actual := seps.FilterBySEPType("TATLIN").FindOne()
if actual.SEPType != "TATLIN" {
t.Fatal("expected SEPType 'TATLIN', found: ", actual.SEPType)
}
}
func TestFilterByPoolType(t *testing.T) {
actual := seps.FilterByPoolType("DES")
if len(actual.Data) != 3 {
t.Fatal("expected 3 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
found := false
for _, pool := range item.Pools {
for _, poolType := range pool.Types {
if poolType == "DES" {
found = true
break
}
}
if found {
break
}
}
if !found {
t.Fatal("expected Pool type 'DES', not found in SEP: ", item.SEPID)
}
}
}
func TestFilterBySystemPool(t *testing.T) {
actual := seps.FilterBySystemPool(true)
if len(actual.Data) != 1 {
t.Fatal("expected 1 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
found := false
for _, pool := range item.Pools {
if pool.System {
found = true
break
}
}
if !found {
t.Fatal("expected System pool, not found in SEP: ", item.SEPID)
}
}
}
func TestFilterFunc(t *testing.T) {
actual := seps.FilterFunc(func(sd SEPData) bool {
return len(sd.Pools) > 0
})
if len(actual.Data) != 3 {
t.Fatal("expected 3 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if len(item.Pools) == 0 {
t.Fatal("expected Pools to contain at least 1 element, found: ", len(item.Pools))
}
}
}

10
pkg/cloudapi/sep/ids.go Normal file
View File

@@ -0,0 +1,10 @@
package sep
// IDs gets array of SEPIDs from ListSEP struct
func (ls ListAvailableSEP) IDs() []uint64 {
res := make([]uint64, 0, len(ls.Data))
for _, s := range ls.Data {
res = append(res, s.SEPID)
}
return res
}

View File

@@ -0,0 +1,52 @@
package sep
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListAvailableSEPAndPoolsRequest struct to get dict with entry count and list of dict with SEPs and pools details accessible by the Account and RG
type ListAvailableSEPAndPoolsRequest struct {
// Account ID
// Required: true
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
// RG ID
// Required: false
RGID uint64 `url:"rg_id,omitempty" json:"rg_id,omitempty"`
}
// ListAvailableSEPAndPools get dict with entry count and list of dict with SEPs and pools details accessible by the Account and RG
func (s SEP) ListAvailableSEPAndPools(ctx context.Context, req ListAvailableSEPAndPoolsRequest) (*ListAvailableSEP, error) {
res, err := s.ListAvailableSEPAndPoolsRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListAvailableSEP{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list as an array of bytes
func (s SEP) ListAvailableSEPAndPoolsRaw(ctx context.Context, req ListAvailableSEPAndPoolsRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/sep/listAvailableSepAndPools"
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,34 @@
package sep
type Pool struct {
// Pool name
Name string `json:"name"`
// Pool types
Types []string `json:"types"`
// System
System bool `json:"system"`
}
type SEPData struct {
// SEP ID
SEPID uint64 `json:"sepId"`
// SEP name
SEPName string `json:"sepName"`
// Sep type
SEPType string `json:"sepType"`
// Pools
Pools []Pool `json:"pools"`
}
type ListAvailableSEP struct {
// Entry count
EntryCount uint64 `json:"entryCount"`
// Data
Data []SEPData `json:"data"`
}

18
pkg/cloudapi/sep/sep.go Normal file
View File

@@ -0,0 +1,18 @@
// Operator actions for handling interventions on a storage endpoint provider
package sep
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
)
// Structure for creating request to storage endpoint provider
type SEP struct {
client interfaces.Caller
}
// Builder for SEP endpoints
func New(client interfaces.Caller) *SEP {
return &SEP{
client: client,
}
}

View File

@@ -0,0 +1,43 @@
package sep
import (
"encoding/json"
"repository.basistech.ru/BASIS/decort-golang-sdk/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 (lsep ListAvailableSEP) Serialize(params ...string) (serialization.Serialized, error) {
if len(lsep.Data) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(lsep, prefix, indent)
}
return json.Marshal(lsep)
}
// 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 (rsep SEPData) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(rsep, prefix, indent)
}
return json.Marshal(rsep)
}

View File

@@ -28,6 +28,10 @@ type GetAuditRequest struct {
// Required: false
MinStatusCode uint64 `url:"minStatusCode,omitempty" json:"minStatusCode,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"`

View File

@@ -18,6 +18,10 @@ type ListRequest struct {
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`