From 7c787f6fcee184367a3fcda5f5ca514c6ef7be50 Mon Sep 17 00:00:00 2001 From: Tim Tkachev Date: Fri, 7 Jul 2023 12:40:03 +0300 Subject: [PATCH] v1.5.0-gamma2 --- pkg/cloudapi/account/filter.go | 2 +- pkg/cloudapi/account/list.go | 2 +- pkg/cloudapi/account/list_computes.go | 44 +- pkg/cloudapi/account/list_deleted.go | 12 + pkg/cloudapi/account/list_disks.go | 28 +- pkg/cloudapi/account/list_flipgroups.go | 38 +- pkg/cloudapi/account/list_rg.go | 32 +- pkg/cloudapi/account/list_vins.go | 28 +- pkg/cloudapi/account/models.go | 42 +- pkg/cloudapi/account/serialize.go | 2 +- pkg/cloudapi/account/sorting.go | 6 +- pkg/cloudapi/compute/list_deleted.go | 36 ++ pkg/cloudapi/compute/list_pci_device.go | 30 +- pkg/cloudapi/compute/list_vgpu.go | 32 +- pkg/cloudapi/compute/models.go | 18 + pkg/cloudapi/disks/list_deleted.go | 20 + pkg/cloudapi/disks/list_types.go | 14 +- pkg/cloudapi/disks/models.go | 8 + pkg/cloudapi/extnet/models.go | 5 +- pkg/cloudapi/image/filter.go | 10 +- pkg/cloudapi/image/filter_test.go | 139 ++++--- pkg/cloudapi/image/list.go | 52 ++- pkg/cloudapi/image/models.go | 8 +- pkg/cloudapi/image/serialize.go | 2 +- pkg/cloudapi/k8ci/list_deleted.go | 20 + pkg/cloudapi/k8s/filter.go | 10 +- pkg/cloudapi/k8s/filter_test.go | 186 ++++----- pkg/cloudapi/k8s/list.go | 36 +- pkg/cloudapi/k8s/list_deleted.go | 36 +- pkg/cloudapi/k8s/models.go | 8 +- pkg/cloudapi/k8s/serialize.go | 2 +- pkg/cloudapi/k8s/sorting.go | 24 +- pkg/cloudapi/k8s/worker_add.go | 5 +- pkg/cloudapi/k8s/workers_group_get_by_name.go | 4 +- pkg/cloudapi/lb/filter.go | 16 +- pkg/cloudapi/lb/filter_test.go | 173 ++++---- pkg/cloudapi/lb/list.go | 36 +- pkg/cloudapi/lb/list_deleted.go | 32 +- pkg/cloudapi/lb/models.go | 8 +- pkg/cloudapi/lb/serialize.go | 2 +- pkg/cloudapi/lb/sorting.go | 24 +- pkg/cloudapi/rg/list_computes.go | 44 +- pkg/cloudapi/rg/list_deleted.go | 28 ++ pkg/cloudapi/rg/list_lb.go | 40 +- pkg/cloudapi/rg/list_pfw.go | 4 +- pkg/cloudapi/rg/list_vins.go | 28 +- pkg/cloudapi/rg/models.go | 32 +- pkg/cloudapi/vins/list_deleted.go | 20 + pkg/cloudbroker/account/filter.go | 54 +-- pkg/cloudbroker/account/filter_test.go | 147 +++---- pkg/cloudbroker/account/list.go | 12 +- pkg/cloudbroker/account/list_computes.go | 44 +- pkg/cloudbroker/account/list_deleted.go | 22 +- pkg/cloudbroker/account/list_disks.go | 28 +- pkg/cloudbroker/account/list_flip_groups.go | 36 +- pkg/cloudbroker/account/list_rg.go | 32 +- pkg/cloudbroker/account/list_vins.go | 30 +- pkg/cloudbroker/account/models.go | 47 ++- pkg/cloudbroker/account/serialize.go | 20 - pkg/cloudbroker/account/sorting.go | 63 +-- pkg/cloudbroker/compute/disk_attach.go | 4 + pkg/cloudbroker/compute/disk_qos.go | 4 + pkg/cloudbroker/compute/filter.go | 22 +- pkg/cloudbroker/compute/filter_test.go | 391 +++++++++--------- pkg/cloudbroker/compute/list.go | 44 +- pkg/cloudbroker/compute/list_deleted.go | 40 +- pkg/cloudbroker/compute/list_pci_device.go | 28 +- pkg/cloudbroker/compute/list_vgpu.go | 66 +++ pkg/cloudbroker/compute/models.go | 28 +- pkg/cloudbroker/compute/resize.go | 6 +- pkg/cloudbroker/compute/serialize.go | 2 +- pkg/cloudbroker/compute/sorting.go | 40 +- pkg/cloudbroker/disks/filter.go | 26 +- pkg/cloudbroker/disks/filter_test.go | 263 ++++++------ pkg/cloudbroker/disks/list.go | 28 +- pkg/cloudbroker/disks/list_deleted.go | 26 +- pkg/cloudbroker/disks/list_types.go | 18 +- pkg/cloudbroker/disks/list_unattached.go | 28 +- pkg/cloudbroker/disks/models.go | 42 +- pkg/cloudbroker/disks/search.go | 4 +- pkg/cloudbroker/disks/serialize.go | 2 +- pkg/cloudbroker/disks/sorting.go | 24 +- pkg/cloudbroker/extnet/create.go | 8 +- pkg/cloudbroker/extnet/filter.go | 10 +- pkg/cloudbroker/extnet/filter_test.go | 148 +++---- pkg/cloudbroker/extnet/list.go | 30 +- pkg/cloudbroker/extnet/models.go | 13 +- pkg/cloudbroker/extnet/serialize.go | 2 +- pkg/cloudbroker/grid/filter.go | 10 +- pkg/cloudbroker/grid/filter_test.go | 169 ++++---- .../grid/get_resource_consumption.go | 40 ++ pkg/cloudbroker/grid/list.go | 12 +- pkg/cloudbroker/grid/list_emails.go | 20 +- .../grid/list_resource_consumption.go | 25 ++ pkg/cloudbroker/grid/models.go | 37 +- pkg/cloudbroker/grid/serialize.go | 2 +- pkg/cloudbroker/image/delete.go | 2 +- pkg/cloudbroker/image/filter.go | 8 +- pkg/cloudbroker/image/filter_test.go | 358 ++++++++-------- pkg/cloudbroker/image/list.go | 48 ++- pkg/cloudbroker/image/list_stacks.go | 16 +- pkg/cloudbroker/image/models.go | 102 +++-- pkg/cloudbroker/image/serialize.go | 2 +- pkg/cloudbroker/k8ci/create.go | 18 +- pkg/cloudbroker/k8ci/filter.go | 10 +- pkg/cloudbroker/k8ci/filter_test.go | 129 +++--- pkg/cloudbroker/k8ci/list.go | 28 +- pkg/cloudbroker/k8ci/list_deleted.go | 24 +- pkg/cloudbroker/k8ci/models.go | 8 +- pkg/cloudbroker/k8ci/serialize.go | 2 +- pkg/cloudbroker/k8ci/sorting.go | 8 +- 111 files changed, 2894 insertions(+), 1494 deletions(-) create mode 100644 pkg/cloudbroker/compute/list_vgpu.go create mode 100644 pkg/cloudbroker/grid/get_resource_consumption.go create mode 100644 pkg/cloudbroker/grid/list_resource_consumption.go diff --git a/pkg/cloudapi/account/filter.go b/pkg/cloudapi/account/filter.go index aa4d709..81bb1ef 100644 --- a/pkg/cloudapi/account/filter.go +++ b/pkg/cloudapi/account/filter.go @@ -62,7 +62,7 @@ func (la ListAccounts) FilterFunc(predicate func(ItemAccount) bool) ListAccounts // FindOne returns first found ItemAccount. // If none was found, returns an empty struct. func (la ListAccounts) FindOne() ItemAccount { - if la.EntryCount == 0 { + if len(la.Data) == 0 { return ItemAccount{} } diff --git a/pkg/cloudapi/account/list.go b/pkg/cloudapi/account/list.go index acaba37..82c02e7 100644 --- a/pkg/cloudapi/account/list.go +++ b/pkg/cloudapi/account/list.go @@ -14,7 +14,7 @@ type ListRequest struct { // Find by name // Required: false - Name string `urL:"name,omitempty" json:"name,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` // Find by access control list // Required: false diff --git a/pkg/cloudapi/account/list_computes.go b/pkg/cloudapi/account/list_computes.go index ed71792..79926f5 100644 --- a/pkg/cloudapi/account/list_computes.go +++ b/pkg/cloudapi/account/list_computes.go @@ -13,10 +13,50 @@ type ListComputesRequest struct { // ID an account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Find by compute id + // Required: false + ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by resource group name + // Required: false + RGName string `url:"rgName,omitempty" json:"rgName,omitempty"` + + // Find by resource group id + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by tech status + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + + // Find by ip address + // Required: false + IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"` + + // Find by external network name + // Required: false + ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"` + + // Find by external network id + // Required: false + ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListComputes gets list all compute instances under specified account, accessible by the user -func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) { +func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +78,5 @@ func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (Lis return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/account/list_deleted.go b/pkg/cloudapi/account/list_deleted.go index fd3e231..4819c8d 100644 --- a/pkg/cloudapi/account/list_deleted.go +++ b/pkg/cloudapi/account/list_deleted.go @@ -15,6 +15,18 @@ type ListDeletedRequest struct { // Page size // Required: false Size uint64 `url:"size,omitempty" json:"size,omitempty"` + + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by access control list + // Required: false + ACL string `url:"acl,omitempty" json:"acl,omitempty"` } // ListDeleted gets list all deleted accounts the user has access to diff --git a/pkg/cloudapi/account/list_disks.go b/pkg/cloudapi/account/list_disks.go index 63b059f..8bc3a47 100644 --- a/pkg/cloudapi/account/list_disks.go +++ b/pkg/cloudapi/account/list_disks.go @@ -13,10 +13,34 @@ type ListDisksRequest struct { // ID an account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Find by disk id + // Required: false + DiskID uint64 `url:"diskId,omitempty" json:"diskId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by max size disk + // Required: false + DiskMaxSize uint64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"` + + // Type of the disks + // Required: false + Type string `url:"type,omitempty" json:"type,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListDisks gets list all currently unattached disks under specified account -func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) { +func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (*ListDisks, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +62,5 @@ func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/account/list_flipgroups.go b/pkg/cloudapi/account/list_flipgroups.go index 4a634cc..6e523e9 100644 --- a/pkg/cloudapi/account/list_flipgroups.go +++ b/pkg/cloudapi/account/list_flipgroups.go @@ -10,13 +10,45 @@ import ( // Request struct for get list FLIPGroups type ListFLIPGroupsRequest struct { - // ID an account + // ID of the account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by vinsId + // Required: false + VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"` + + // Find by VINS name + // Required: false + VINSName string `url:"vinsName,omitempty" json:"vinsName,omitempty"` + + // Find by external network id + // Required: false + ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"` + + // Find by IP + // Required: false + ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"` + + // Find by flipGroup Id + // Required: false + FLIPGroupID uint64 `url:"flipGroupId,omitempty" json:"flipGroupId,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user -func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (ListFLIPGroups, error) { +func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (*ListFLIPGroups, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +70,5 @@ func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/account/list_rg.go b/pkg/cloudapi/account/list_rg.go index f3059d3..1d13fee 100644 --- a/pkg/cloudapi/account/list_rg.go +++ b/pkg/cloudapi/account/list_rg.go @@ -13,10 +13,38 @@ type ListRGRequest struct { // ID an account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` + + // Find by resource group id + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by vinsId + // Required: false + VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"` + + // Find by VM ID + // Required: false + VMID uint64 `url:"vmId,omitempty" json:"vmId,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` } // ListRG gets list all resource groups under specified account, accessible by the user -func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) { +func (a Account) ListRG(ctx context.Context, req ListRGRequest) (*ListRG, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +66,5 @@ func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/account/list_vins.go b/pkg/cloudapi/account/list_vins.go index 990aa99..1e3627f 100644 --- a/pkg/cloudapi/account/list_vins.go +++ b/pkg/cloudapi/account/list_vins.go @@ -13,10 +13,34 @@ type ListVINSRequest struct { // ID an account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Find by VINS ID + // Required: false + VINSID uint64 `url:"vins,omitempty" json:"vinsId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by resource group id + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by external network ip + // Required: false + ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListVINS gets list all ViNSes under specified account, accessible by the user -func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) { +func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +62,5 @@ func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, e return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/account/models.go b/pkg/cloudapi/account/models.go index 7a46633..b7bbb24 100644 --- a/pkg/cloudapi/account/models.go +++ b/pkg/cloudapi/account/models.go @@ -112,7 +112,7 @@ type DiskUsage struct { DiskSize float64 `json:"disksize"` // Disk size max - DiskSizeMax uint64 `json:"disksizemax"` + DiskSizeMax float64 `json:"disksizemax"` } // Information about resources @@ -299,7 +299,13 @@ type ItemCompute struct { } // List of computes -type ListComputes []ItemCompute +type ListComputes struct { + // Data + Data []ItemCompute `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about disk type ItemDisk struct { @@ -326,7 +332,13 @@ type ItemDisk struct { } // List of disks -type ListDisks []ItemDisk +type ListDisks struct { + // Data + Data []ItemDisk `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about VINS type ItemVINS struct { @@ -383,7 +395,13 @@ type ItemVINS struct { } // List of VINS -type ListVINS []ItemVINS +type ListVINS struct { + // Data + Data []ItemVINS `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main info about audit type ItemAudit struct { @@ -497,7 +515,13 @@ type ItemRG struct { } // List of Resource groups -type ListRG []ItemRG +type ListRG struct { + // Data + Data []ItemRG `json:"data"` + + // Enrtry count + EntryCount uint64 `json:"entryCount"` +} // Main information about template type ItemTemplate struct { @@ -602,4 +626,10 @@ type ItemFLIPGroup struct { } // List of FLIPGroups -type ListFLIPGroups []ItemFLIPGroup +type ListFLIPGroups struct { + // Data + Data []ItemFLIPGroup `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} diff --git a/pkg/cloudapi/account/serialize.go b/pkg/cloudapi/account/serialize.go index 5c45955..f71add8 100644 --- a/pkg/cloudapi/account/serialize.go +++ b/pkg/cloudapi/account/serialize.go @@ -12,7 +12,7 @@ import ( // - First argument -> prefix // - Second argument -> indent func (la ListAccounts) Serialize(params ...string) (serialization.Serialized, error) { - if la.EntryCount == 0 { + if len(la.Data) == 0 { return []byte{}, nil } diff --git a/pkg/cloudapi/account/sorting.go b/pkg/cloudapi/account/sorting.go index 7303f75..ce243df 100644 --- a/pkg/cloudapi/account/sorting.go +++ b/pkg/cloudapi/account/sorting.go @@ -6,7 +6,7 @@ import "sort" // // If inverse param is set to true, the order is reversed. func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts { - if la.EntryCount < 2 { + if len(la.Data) < 2 { return la } @@ -25,7 +25,7 @@ func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts { // // If inverse param is set to true, the order is reversed. func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts { - if la.EntryCount < 2 { + if len(la.Data) < 2 { return la } @@ -44,7 +44,7 @@ func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts { // // If inverse param is set to true, the order is reversed. func (la ListAccounts) SortByDeletedTime(inverse bool) ListAccounts { - if la.EntryCount < 2 { + if len(la.Data) < 2 { return la } diff --git a/pkg/cloudapi/compute/list_deleted.go b/pkg/cloudapi/compute/list_deleted.go index 8213504..2f0e3c2 100644 --- a/pkg/cloudapi/compute/list_deleted.go +++ b/pkg/cloudapi/compute/list_deleted.go @@ -8,6 +8,42 @@ import ( // Request struct for get deleted computes list type ListDeletedRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account ID + // Required: false + AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` + + // Find by resource group name + // Required: false + RGName string `url:"rgName,omitempty" json:"rgName,omitempty"` + + // Find by resource group ID + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by tech status + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + + // Find by IP address + // Required: false + IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"` + + // Find by external network name + // Required: false + ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"` + + // Find by external network ID + // Required: false + ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"` + // Page number // Required: false Page uint64 `url:"page,omitempty" json:"page,omitempty"` diff --git a/pkg/cloudapi/compute/list_pci_device.go b/pkg/cloudapi/compute/list_pci_device.go index b713a6d..c01df14 100644 --- a/pkg/cloudapi/compute/list_pci_device.go +++ b/pkg/cloudapi/compute/list_pci_device.go @@ -13,10 +13,34 @@ type ListPCIDeviceRequest struct { // Identifier compute // Required: true ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"` + + // Find by resource group ID + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by device id + // Required: false + DevID uint64 `url:"devId,omitempty" json:"devId,omitempty"` + + // Find by type + // Required: false + Type string `url:"type,omitempty" json:"type,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListPCIDevice gets list PCI device -func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([]interface{}, error) { +func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (*ListPCIDevices, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -31,12 +55,12 @@ func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([ return nil, err } - list := []interface{}{} + list := ListPCIDevices{} err = json.Unmarshal(res, &list) if err != nil { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/compute/list_vgpu.go b/pkg/cloudapi/compute/list_vgpu.go index b9a933e..7459377 100644 --- a/pkg/cloudapi/compute/list_vgpu.go +++ b/pkg/cloudapi/compute/list_vgpu.go @@ -13,10 +13,34 @@ type ListVGPURequest struct { // Identifier compute // Required: true ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"` + + // Find by GPU id + // Required: false + GPUID uint64 `url:"gpuId,omitempty" json:"gpuId,omitempty"` + + // Find by type + // Required: false + Type string `url:"type,omitempty" json:"type,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` + + // Include deleted computes. If using field 'status', then includedeleted will be ignored + // Required: false + IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"` } // ListVGPU gets list vGPU -func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface{}, error) { +func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) (*ListVGPUs, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -24,19 +48,19 @@ func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface } } - url := "/cloudapi/compute/listVgpu" + url := "/cloudapi/compute/listVGpu" res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { return nil, err } - list := []interface{}{} + list := ListVGPUs{} err = json.Unmarshal(res, &list) if err != nil { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/compute/models.go b/pkg/cloudapi/compute/models.go index 9088690..e77000a 100644 --- a/pkg/cloudapi/compute/models.go +++ b/pkg/cloudapi/compute/models.go @@ -915,3 +915,21 @@ type ListComputes struct { // Entry count EntryCount uint64 `json:"entryCount"` } + +// List VGPUs +type ListVGPUs struct { + // Data + Data []interface{} `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} + +// List PCI devices +type ListPCIDevices struct { + // Data + Data []interface{} `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} diff --git a/pkg/cloudapi/disks/list_deleted.go b/pkg/cloudapi/disks/list_deleted.go index fab8868..b3a5f29 100644 --- a/pkg/cloudapi/disks/list_deleted.go +++ b/pkg/cloudapi/disks/list_deleted.go @@ -8,6 +8,26 @@ import ( // Request struct for get list of deleted disks type ListDeletedRequest struct { + // Find by id + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account name + // Required: false + AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"` + + // Find by max size disk + // Required: false + DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"` + + // Find by shared, true or false + // Required: false + Shared bool `url:"shared,omitempty" json:"shared,omitempty"` + // ID of the account the disks belong to // Required: false AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` diff --git a/pkg/cloudapi/disks/list_types.go b/pkg/cloudapi/disks/list_types.go index ee91509..5c37b19 100644 --- a/pkg/cloudapi/disks/list_types.go +++ b/pkg/cloudapi/disks/list_types.go @@ -11,10 +11,18 @@ type ListTypesRequest struct { // Show detailed disk types by seps // Required: true Detailed bool `url:"detailed" json:"detailed" validate:"required"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListTypes gets list defined disk types -func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface{}, error) { +func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) (*ListTypes, error) { url := "/cloudapi/disks/listTypes" res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -22,12 +30,12 @@ func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface return nil, err } - list := make([]interface{}, 0) + list := ListTypes{} err = json.Unmarshal(res, &list) if err != nil { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/disks/models.go b/pkg/cloudapi/disks/models.go index 79f7d56..301f857 100644 --- a/pkg/cloudapi/disks/models.go +++ b/pkg/cloudapi/disks/models.go @@ -442,3 +442,11 @@ type RecordDisk struct { // Virtual machine ID VMID uint64 `json:"vmid"` } + +type ListTypes struct { + // Data + Data []interface{} `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} diff --git a/pkg/cloudapi/extnet/models.go b/pkg/cloudapi/extnet/models.go index 5059d46..308baae 100644 --- a/pkg/cloudapi/extnet/models.go +++ b/pkg/cloudapi/extnet/models.go @@ -139,11 +139,8 @@ type RecordExtNet struct { // Meta Meta []interface{} `json:"_meta"` - // CheckIPs - CheckIPs []string `json:"checkIPs"` - // CheckIps - CheckIps []string `json:"checkIps"` + CheckIPs []string `json:"checkIps"` // Default Default bool `json:"default"` diff --git a/pkg/cloudapi/image/filter.go b/pkg/cloudapi/image/filter.go index 7726491..4367ff7 100644 --- a/pkg/cloudapi/image/filter.go +++ b/pkg/cloudapi/image/filter.go @@ -40,21 +40,23 @@ func (li ListImages) FilterByBootType(bootType string) ListImages { func (li ListImages) FilterFunc(predicate func(ItemImage) bool) ListImages { var result ListImages - for _, item := range li { + for _, item := range li.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 ItemImage // If none was found, returns an empty struct. func (li ListImages) FindOne() ItemImage { - if len(li) == 0 { + if len(li.Data) == 0 { return ItemImage{} } - return li[0] + return li.Data[0] } diff --git a/pkg/cloudapi/image/filter_test.go b/pkg/cloudapi/image/filter_test.go index 0725368..180c735 100644 --- a/pkg/cloudapi/image/filter_test.go +++ b/pkg/cloudapi/image/filter_test.go @@ -3,66 +3,69 @@ package image import "testing" var images = ListImages{ - ItemImage{ - AccountID: 0, - Architecture: "X86_64", - BootType: "bios", - Bootable: true, - Description: "", - Drivers: []string{ - "KVM_X86", + Data: []ItemImage{ + { + AccountID: 0, + Architecture: "X86_64", + BootType: "bios", + Bootable: true, + Description: "", + Drivers: []string{ + "KVM_X86", + }, + HotResize: true, + ID: 9882, + LinkTo: 0, + Name: "u16", + Pool: "vmstor", + Size: 5, + Status: "CREATED", + Type: "linux", + Username: "", + Virtual: false, }, - HotResize: true, - ID: 9882, - LinkTo: 0, - Name: "u16", - Pool: "vmstor", - Size: 5, - Status: "CREATED", - Type: "linux", - Username: "", - Virtual: false, - }, - ItemImage{ - AccountID: 0, - Architecture: "X86_64", - BootType: "bois", - Bootable: true, - Description: "", - Drivers: []string{ - "KVM_X86", + { + AccountID: 0, + Architecture: "X86_64", + BootType: "bois", + Bootable: true, + Description: "", + Drivers: []string{ + "KVM_X86", + }, + HotResize: false, + ID: 9884, + LinkTo: 0, + Name: "alpine-virt-3.17", + Pool: "vmstor", + Size: 1, + Status: "CREATED", + Type: "linux", + Username: "", + Virtual: true, }, - HotResize: false, - ID: 9884, - LinkTo: 0, - Name: "alpine-virt-3.17", - Pool: "vmstor", - Size: 1, - Status: "CREATED", - Type: "linux", - Username: "", - Virtual: true, - }, - ItemImage{ - AccountID: 1, - Architecture: "X86_64", - BootType: "bios", - Bootable: true, - Description: "", - Drivers: []string{ - "KVM_X86", + { + AccountID: 1, + Architecture: "X86_64", + BootType: "bios", + Bootable: true, + Description: "", + Drivers: []string{ + "KVM_X86", + }, + HotResize: true, + ID: 9885, + LinkTo: 0, + Name: "test", + Pool: "vmstor", + Size: 4, + Status: "DESTROYED", + Type: "linux", + Username: "", + Virtual: false, }, - HotResize: true, - ID: 9885, - LinkTo: 0, - Name: "test", - Pool: "vmstor", - Size: 4, - Status: "DESTROYED", - Type: "linux", - Username: "", - Virtual: false, }, + EntryCount: 3, } func TestFilterByID(t *testing.T) { @@ -84,11 +87,11 @@ func TestFilterByName(t *testing.T) { func TestFilterByStatus(t *testing.T) { actual := images.FilterByStatus("CREATED") - if len(actual) != 2 { - t.Fatal("expected 2 found, actual: ", len(actual)) + if len(actual.Data) != 2 { + t.Fatal("expected 2 found, actual: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.Status != "CREATED" { t.Fatal("expected Status 'CREATED', found: ", item.Status) } @@ -98,11 +101,11 @@ func TestFilterByStatus(t *testing.T) { func TestFilterByBootType(t *testing.T) { actual := images.FilterByBootType("bios") - if len(actual) != 2 { - t.Fatal("expected 2 found, actual: ", len(actual)) + if len(actual.Data) != 2 { + t.Fatal("expected 2 found, actual: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.BootType != "bios" { t.Fatal("expected BootType 'bios', found: ", item.BootType) } @@ -110,15 +113,15 @@ func TestFilterByBootType(t *testing.T) { } func TestFilterFunc(t *testing.T) { - actual := images.FilterFunc(func(ii ItemImage) bool { - return ii.Virtual == true - }) + actual := images.FilterFunc(func(ii ItemImage) bool { + return ii.Virtual == true + }) - if len(actual) != 1 { - t.Fatal("expected 1 found, actual: ", len(actual)) + if len(actual.Data) != 1 { + t.Fatal("expected 1 found, actual: ", len(actual.Data)) } - if actual[0].Virtual != true { + if actual.Data[0].Virtual != true { t.Fatal("expected Virtual true, found false") } } diff --git a/pkg/cloudapi/image/list.go b/pkg/cloudapi/image/list.go index d5601c5..5533639 100644 --- a/pkg/cloudapi/image/list.go +++ b/pkg/cloudapi/image/list.go @@ -8,9 +8,53 @@ import ( // Request struct for get list available images type ListRequest struct { - // Optional account ID to include account images + // Find by storage endpoint provider ID // Required: false - AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` + SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"` + + // Find by id + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by ID + // 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 architecture + // Required: false + Architecture string `url:"architecture,omitempty" json:"architecture,omitempty"` + + // Find by type + // Required: false + TypeImage string `url:"typeImage,omitempty" json:"typeImage,omitempty"` + + // Find by image size + // Required: false + ImageSize uint64 `url:"imageSize,omitempty" json:"imageSize,omitempty"` + + // Find by SEP name + // Required: false + SEPName string `url:"sepName,omitempty" json:"sepName,omitempty"` + + // Find by pool + // Required: false + Pool string `url:"pool,omitempty" json:"pool,omitempty"` + + // Find by public True or False + // Required: false + Public bool `url:"public,omitempty" json:"public,omitempty"` + + // Find by hot resize True or False + // Required: false + HotResize bool `url:"hotResize,omitempty" json:"hotResize,omitempty"` + + // Find by bootable True or False + // Required: false + Bootable bool `url:"bootable,omitempty" json:"bootable,omitempty"` // Page number // Required: false @@ -22,7 +66,7 @@ type ListRequest struct { } // List gets list available images, optionally filtering by account ID -func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) { +func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) { url := "/cloudapi/image/list" res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -37,5 +81,5 @@ func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/image/models.go b/pkg/cloudapi/image/models.go index eac72f4..031f2dc 100644 --- a/pkg/cloudapi/image/models.go +++ b/pkg/cloudapi/image/models.go @@ -58,7 +58,13 @@ type ItemImage struct { } // List of information about images -type ListImages []ItemImage +type ListImages struct { + // Data + Data []ItemImage `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // History type History struct { diff --git a/pkg/cloudapi/image/serialize.go b/pkg/cloudapi/image/serialize.go index 2c6c081..3f1e17b 100644 --- a/pkg/cloudapi/image/serialize.go +++ b/pkg/cloudapi/image/serialize.go @@ -12,7 +12,7 @@ import ( // - First argument -> prefix // - Second argument -> indent func (li ListImages) Serialize(params ...string) (serialization.Serialized, error) { - if len(li) == 0 { + if len(li.Data) == 0 { return []byte{}, nil } diff --git a/pkg/cloudapi/k8ci/list_deleted.go b/pkg/cloudapi/k8ci/list_deleted.go index 42c10eb..8f49388 100644 --- a/pkg/cloudapi/k8ci/list_deleted.go +++ b/pkg/cloudapi/k8ci/list_deleted.go @@ -8,6 +8,26 @@ import ( // Request struct for get list information about deleted images type ListDeletedRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"k8cId,omitempty" json:"k8cId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by worker driver + // Required: false + WorkerDriver string `url:"workerDriver,omitempty" json:"workerDriver,omitempty"` + + // Find by master driver + // Required: false + MasterDriver string `url:"masterDriver,omitempty" json:"masterDriver,omitempty"` + + // Find by network plugin + // Required: false + NetworkPlugins string `url:"netPlugins,omitempty" json:"netPlugins,omitempty"` + // Page number // Required: false Page uint64 `url:"page,omitempty" json:"page,omitempty"` diff --git a/pkg/cloudapi/k8s/filter.go b/pkg/cloudapi/k8s/filter.go index 00c3d2d..0c64960 100644 --- a/pkg/cloudapi/k8s/filter.go +++ b/pkg/cloudapi/k8s/filter.go @@ -76,21 +76,23 @@ func (lkc ListK8SClusters) FilterByDeletedBy(deletedBy string) ListK8SClusters { func (lkc ListK8SClusters) FilterFunc(predicate func(ItemK8SCluster) bool) ListK8SClusters { var result ListK8SClusters - for _, item := range lkc { + for _, item := range lkc.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 ItemK8SCluster // If none was found, returns an empty struct. func (lkc ListK8SClusters) FindOne() ItemK8SCluster { - if len(lkc) == 0 { + if len(lkc.Data) == 0 { return ItemK8SCluster{} } - return lkc[0] + return lkc.Data[0] } diff --git a/pkg/cloudapi/k8s/filter_test.go b/pkg/cloudapi/k8s/filter_test.go index e7ced34..fa824b2 100644 --- a/pkg/cloudapi/k8s/filter_test.go +++ b/pkg/cloudapi/k8s/filter_test.go @@ -3,86 +3,88 @@ package k8s import "testing" var k8sItems = ListK8SClusters{ - ItemK8SCluster{ - AccountID: 1, - AccountName: "test_1", - ACL: []interface{}{}, - BServiceID: 1, - CIID: 1, - Config: nil, - CreatedBy: "test_user", - CreatedTime: 132454563, - DeletedBy: "", - DeletedTime: 0, - Description: "", - ExtNetID: 1, - GID: 0, - GUID: 1, - ID: 1, - LBID: 1, - Milestones: 999999, - Name: "k8s_1", - RGID: 1, - RGName: "rg_1", - Status: "ENABLED", - TechStatus: "STARTED", - UpdatedBy: "", - UpdatedTime: 0, - VINSID: 0, - }, - ItemK8SCluster{ - AccountID: 2, - AccountName: "test_2", - ACL: []interface{}{}, - BServiceID: 2, - CIID: 2, - Config: nil, - CreatedBy: "test_user", - CreatedTime: 132454638, - DeletedBy: "", - DeletedTime: 0, - Description: "", - ExtNetID: 2, - GID: 0, - GUID: 2, - ID: 2, - LBID: 2, - Milestones: 999999, - Name: "k8s_2", - RGID: 2, - RGName: "rg_2", - Status: "ENABLED", - TechStatus: "STARTED", - UpdatedBy: "", - UpdatedTime: 0, - VINSID: 0, - }, - ItemK8SCluster{ - AccountID: 3, - AccountName: "test_3", - ACL: []interface{}{}, - BServiceID: 3, - CIID: 3, - Config: nil, - CreatedBy: "test_user", - CreatedTime: 132454682, - DeletedBy: "", - DeletedTime: 0, - Description: "", - ExtNetID: 3, - GID: 0, - GUID: 3, - ID: 3, - LBID: 3, - Milestones: 999999, - Name: "k8s_3", - RGID: 3, - RGName: "rg_3", - Status: "DISABLED", - TechStatus: "STOPPED", - UpdatedBy: "", - UpdatedTime: 0, - VINSID: 0, + Data: []ItemK8SCluster{ + { + AccountID: 1, + AccountName: "test_1", + ACL: []interface{}{}, + BServiceID: 1, + CIID: 1, + Config: nil, + CreatedBy: "test_user", + CreatedTime: 132454563, + DeletedBy: "", + DeletedTime: 0, + Description: "", + ExtNetID: 1, + GID: 0, + GUID: 1, + ID: 1, + LBID: 1, + Milestones: 999999, + Name: "k8s_1", + RGID: 1, + RGName: "rg_1", + Status: "ENABLED", + TechStatus: "STARTED", + UpdatedBy: "", + UpdatedTime: 0, + VINSID: 0, + }, + { + AccountID: 2, + AccountName: "test_2", + ACL: []interface{}{}, + BServiceID: 2, + CIID: 2, + Config: nil, + CreatedBy: "test_user", + CreatedTime: 132454638, + DeletedBy: "", + DeletedTime: 0, + Description: "", + ExtNetID: 2, + GID: 0, + GUID: 2, + ID: 2, + LBID: 2, + Milestones: 999999, + Name: "k8s_2", + RGID: 2, + RGName: "rg_2", + Status: "ENABLED", + TechStatus: "STARTED", + UpdatedBy: "", + UpdatedTime: 0, + VINSID: 0, + }, + { + AccountID: 3, + AccountName: "test_3", + ACL: []interface{}{}, + BServiceID: 3, + CIID: 3, + Config: nil, + CreatedBy: "test_user", + CreatedTime: 132454682, + DeletedBy: "", + DeletedTime: 0, + Description: "", + ExtNetID: 3, + GID: 0, + GUID: 3, + ID: 3, + LBID: 3, + Milestones: 999999, + Name: "k8s_3", + RGID: 3, + RGName: "rg_3", + Status: "DISABLED", + TechStatus: "STOPPED", + UpdatedBy: "", + UpdatedTime: 0, + VINSID: 0, + }, }, } @@ -121,11 +123,11 @@ func TestFilterByRGID(t *testing.T) { func TestFilterByStatus(t *testing.T) { actual := k8sItems.FilterByStatus("ENABLED") - if len(actual) != 2 { - t.Fatal("expected 2 found, actual: ", len(actual)) + if len(actual.Data) != 2 { + t.Fatal("expected 2 found, actual: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.Status != "ENABLED" { t.Fatal("expected Status 'ENABLED', found: ", item.Status) } @@ -135,11 +137,11 @@ func TestFilterByStatus(t *testing.T) { func TestFilterByTechStatus(t *testing.T) { actual := k8sItems.FilterByTechStatus("STARTED") - if len(actual) != 2 { - t.Fatal("expected 2 found, actual: ", len(actual)) + if len(actual.Data) != 2 { + t.Fatal("expected 2 found, actual: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.TechStatus != "STARTED" { t.Fatal("expected TechStatus 'STARTED', found: ", item.TechStatus) } @@ -149,11 +151,11 @@ func TestFilterByTechStatus(t *testing.T) { func TestFilterByCreatedBy(t *testing.T) { actual := k8sItems.FilterByCreatedBy("test_user") - if len(actual) != 3 { - t.Fatal("expected 3 found, actual: ", len(actual)) + if len(actual.Data) != 3 { + t.Fatal("expected 3 found, actual: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.CreatedBy != "test_user" { t.Fatal("expected CreatedBy 'test_user', found: ", item.CreatedBy) } @@ -163,8 +165,8 @@ func TestFilterByCreatedBy(t *testing.T) { func TestFilterByDeletedBy(t *testing.T) { actual := k8sItems.FilterByDeletedBy("test_user") - if len(actual) != 0 { - t.Fatal("expected 0 found, actual: ", len(actual)) + if len(actual.Data) != 0 { + t.Fatal("expected 0 found, actual: ", len(actual.Data)) } } @@ -182,7 +184,7 @@ func TestFilterFunc(t *testing.T) { func TestSortByCreatedTime(t *testing.T) { actual := k8sItems.SortByCreatedTime(false) - if actual[0].CreatedTime != 132454563 || actual[2].CreatedTime != 132454682 { + if actual.Data[0].CreatedTime != 132454563 || actual.Data[2].CreatedTime != 132454682 { t.Fatal("expected ascending sort, seems to be inversed") } } diff --git a/pkg/cloudapi/k8s/list.go b/pkg/cloudapi/k8s/list.go index ea7689a..e24171d 100644 --- a/pkg/cloudapi/k8s/list.go +++ b/pkg/cloudapi/k8s/list.go @@ -8,6 +8,38 @@ import ( // Request struct for get list information K8S type ListRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by IP address + // Required: false + IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"` + + // Find by resource group ID + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by lbId + // Required: false + LBID uint64 `url:"lbId,omitempty" json:"lbId,omitempty"` + + // Find by basicServiceId + // Required: false + BasicServiceID uint64 `url:"basicServiceId,omitempty" json:"basicServiceId,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Find by techStatus + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + // Include deleted clusters in result // Required: false IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"` @@ -22,7 +54,7 @@ type ListRequest struct { } // List gets list all kubernetes clusters the user has access to -func (k8s K8S) List(ctx context.Context, req ListRequest) (ListK8SClusters, error) { +func (k8s K8S) List(ctx context.Context, req ListRequest) (*ListK8SClusters, error) { url := "/cloudapi/k8s/list" res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -37,5 +69,5 @@ func (k8s K8S) List(ctx context.Context, req ListRequest) (ListK8SClusters, erro return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/k8s/list_deleted.go b/pkg/cloudapi/k8s/list_deleted.go index 4914977..b37e8e9 100644 --- a/pkg/cloudapi/k8s/list_deleted.go +++ b/pkg/cloudapi/k8s/list_deleted.go @@ -8,6 +8,38 @@ import ( // Request struct for get list deleted kubernetes cluster type ListDeletedRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by IP address + // Required: false + IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"` + + // Find by resource group ID + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by lbId + // Required: false + LBID uint64 `url:"lbId,omitempty" json:"lbId,omitempty"` + + // Find by basicServiceId + // Required: false + BasicServiceID uint64 `url:"basicServiceId,omitempty" json:"basicServiceId,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Find by techStatus + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + // Page number // Required: false Page uint64 `url:"page,omitempty" json:"page,omitempty"` @@ -18,7 +50,7 @@ type ListDeletedRequest struct { } // ListDeleted gets all deleted kubernetes clusters the user has access to -func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8SClusters, error) { +func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8SClusters, error) { url := "/cloudapi/k8s/listDeleted" res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -33,5 +65,5 @@ func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8S return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/k8s/models.go b/pkg/cloudapi/k8s/models.go index 165ab3e..a4b6cd9 100644 --- a/pkg/cloudapi/k8s/models.go +++ b/pkg/cloudapi/k8s/models.go @@ -293,4 +293,10 @@ type RecordServiceAccount struct { } // List of kubernetes clusters -type ListK8SClusters []ItemK8SCluster +type ListK8SClusters struct { + // Data + Data []ItemK8SCluster `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} diff --git a/pkg/cloudapi/k8s/serialize.go b/pkg/cloudapi/k8s/serialize.go index 8f62cb4..eb0bf9b 100644 --- a/pkg/cloudapi/k8s/serialize.go +++ b/pkg/cloudapi/k8s/serialize.go @@ -12,7 +12,7 @@ import ( // - First argument -> prefix // - Second argument -> indent func (lkc ListK8SClusters) Serialize(params ...string) (serialization.Serialized, error) { - if len(lkc) == 0 { + if len(lkc.Data) == 0 { return []byte{}, nil } diff --git a/pkg/cloudapi/k8s/sorting.go b/pkg/cloudapi/k8s/sorting.go index b5259ec..9103137 100644 --- a/pkg/cloudapi/k8s/sorting.go +++ b/pkg/cloudapi/k8s/sorting.go @@ -6,16 +6,16 @@ import "sort" // // If inverse param is set to true, the order is reversed. func (lkc ListK8SClusters) SortByCreatedTime(inverse bool) ListK8SClusters { - if len(lkc) < 2 { + if len(lkc.Data) < 2 { return lkc } - sort.Slice(lkc, func(i, j int) bool { + sort.Slice(lkc.Data, func(i, j int) bool { if inverse { - return lkc[i].CreatedTime > lkc[j].CreatedTime + return lkc.Data[i].CreatedTime > lkc.Data[j].CreatedTime } - return lkc[i].CreatedTime < lkc[j].CreatedTime + return lkc.Data[i].CreatedTime < lkc.Data[j].CreatedTime }) return lkc @@ -25,16 +25,16 @@ func (lkc ListK8SClusters) SortByCreatedTime(inverse bool) ListK8SClusters { // // If inverse param is set to true, the order is reversed. func (lkc ListK8SClusters) SortByUpdatedTime(inverse bool) ListK8SClusters { - if len(lkc) < 2 { + if len(lkc.Data) < 2 { return lkc } - sort.Slice(lkc, func(i, j int) bool { + sort.Slice(lkc.Data, func(i, j int) bool { if inverse { - return lkc[i].UpdatedTime > lkc[j].UpdatedTime + return lkc.Data[i].UpdatedTime > lkc.Data[j].UpdatedTime } - return lkc[i].UpdatedTime < lkc[j].UpdatedTime + return lkc.Data[i].UpdatedTime < lkc.Data[j].UpdatedTime }) return lkc @@ -44,16 +44,16 @@ func (lkc ListK8SClusters) SortByUpdatedTime(inverse bool) ListK8SClusters { // // If inverse param is set to true, the order is reversed. func (lkc ListK8SClusters) SortByDeletedTime(inverse bool) ListK8SClusters { - if len(lkc) < 2 { + if len(lkc.Data) < 2 { return lkc } - sort.Slice(lkc, func(i, j int) bool { + sort.Slice(lkc.Data, func(i, j int) bool { if inverse { - return lkc[i].DeletedTime > lkc[j].DeletedTime + return lkc.Data[i].DeletedTime > lkc.Data[j].DeletedTime } - return lkc[i].DeletedTime < lkc[j].DeletedTime + return lkc.Data[i].DeletedTime < lkc.Data[j].DeletedTime }) return lkc diff --git a/pkg/cloudapi/k8s/worker_add.go b/pkg/cloudapi/k8s/worker_add.go index 94ef37a..812584e 100644 --- a/pkg/cloudapi/k8s/worker_add.go +++ b/pkg/cloudapi/k8s/worker_add.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "net/http" + "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" ) @@ -18,8 +19,8 @@ type WorkerAddRequest struct { WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"` // How many worker nodes to add - // Required: true - Num uint64 `url:"num" json:"num" validate:"required"` + // Required: false + Num uint64 `url:"num,omitempty" json:"num,omitempty"` } // WorkerAdd add worker nodes to a Kubernetes cluster diff --git a/pkg/cloudapi/k8s/workers_group_get_by_name.go b/pkg/cloudapi/k8s/workers_group_get_by_name.go index 2320d67..6ec0e5c 100644 --- a/pkg/cloudapi/k8s/workers_group_get_by_name.go +++ b/pkg/cloudapi/k8s/workers_group_get_by_name.go @@ -20,7 +20,7 @@ type WorkersGroupGetByNameRequest struct { } // WorkersGroupGetByName gets worker group metadata by name -func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*RecordK8SGroups, error) { +func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*ItemK8SGroup, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -35,7 +35,7 @@ func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByN return nil, err } - info := RecordK8SGroups{} + info := ItemK8SGroup{} err = json.Unmarshal(res, &info) if err != nil { diff --git a/pkg/cloudapi/lb/filter.go b/pkg/cloudapi/lb/filter.go index 6718f1f..c745b34 100644 --- a/pkg/cloudapi/lb/filter.go +++ b/pkg/cloudapi/lb/filter.go @@ -44,7 +44,7 @@ func (ll ListLB) FilterByImageID(imageID uint64) ListLB { } // FilterByK8SID returns ListLB used by specified K8S cluster. -func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListLB, error) { +func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListLB, error) { caller := k8s.New(decortClient) req := k8s.GetRequest{ @@ -60,28 +60,32 @@ func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient i return cluster.LBID == ill.ID } - return ll.FilterFunc(predicate), nil + result := ll.FilterFunc(predicate) + + return &result, nil } // FilterFunc allows filtering ListLB based on a user-specified predicate. func (ll ListLB) FilterFunc(predicate func(ItemLoadBalancer) bool) ListLB { var result ListLB - for _, item := range ll { + for _, item := range ll.Data { if predicate(item) { - result = append(result, item) + result.Data = append(result.Data, item) } } + result.EntryCount = uint64(len(ll.Data)) + return result } // FindOne returns first found ItemLoadBalancer // If none was found, returns an empty struct. func (ll ListLB) FindOne() ItemLoadBalancer { - if len(ll) == 0 { + if len(ll.Data) == 0 { return ItemLoadBalancer{} } - return ll[0] + return ll.Data[0] } diff --git a/pkg/cloudapi/lb/filter_test.go b/pkg/cloudapi/lb/filter_test.go index af9dbd2..38ce508 100644 --- a/pkg/cloudapi/lb/filter_test.go +++ b/pkg/cloudapi/lb/filter_test.go @@ -3,93 +3,96 @@ package lb import "testing" var lbs = ListLB{ - ItemLoadBalancer{ - DPAPIPassword: "0000", - RecordLB: RecordLB{ - HAMode: true, - ACL: []interface{}{}, - Backends: []ItemBackend{}, - CreatedBy: "test_user_1", - CreatedTime: 1636667448, - DeletedBy: "", - DeletedTime: 0, - Description: "", - DPAPIUser: "api_user", - ExtNetID: 2522, - Frontends: []ItemFrontend{}, - GID: 212, - GUID: 1, - ID: 1, - ImageID: 2121, - Milestones: 129000, - Name: "k8s-lb-test-1", - RGID: 25090, - RGName: "", - Status: "ENABLED", - TechStatus: "STARTED", - UpdatedBy: "", - UpdatedTime: 0, - VINSID: 101, + Data: []ItemLoadBalancer{ + { + DPAPIPassword: "0000", + RecordLB: RecordLB{ + HAMode: true, + ACL: []interface{}{}, + Backends: []ItemBackend{}, + CreatedBy: "test_user_1", + CreatedTime: 1636667448, + DeletedBy: "", + DeletedTime: 0, + Description: "", + DPAPIUser: "api_user", + ExtNetID: 2522, + Frontends: []ItemFrontend{}, + GID: 212, + GUID: 1, + ID: 1, + ImageID: 2121, + Milestones: 129000, + Name: "k8s-lb-test-1", + RGID: 25090, + RGName: "", + Status: "ENABLED", + TechStatus: "STARTED", + UpdatedBy: "", + UpdatedTime: 0, + VINSID: 101, + }, }, - }, - ItemLoadBalancer{ - DPAPIPassword: "0000", - RecordLB: RecordLB{ - HAMode: false, - ACL: []interface{}{}, - Backends: []ItemBackend{}, - CreatedBy: "test_user_2", - CreatedTime: 1636667506, - DeletedBy: "", - DeletedTime: 0, - Description: "", - DPAPIUser: "api_user_2", - ExtNetID: 2524, - Frontends: []ItemFrontend{}, - GID: 212, - GUID: 2, - ID: 2, - ImageID: 2129, - Milestones: 129013, - Name: "k8s-lb-test-2", - RGID: 25092, - RGName: "", - Status: "ENABLED", - TechStatus: "STOPPED", - UpdatedBy: "", - UpdatedTime: 0, - VINSID: 102, + { + DPAPIPassword: "0000", + RecordLB: RecordLB{ + HAMode: false, + ACL: []interface{}{}, + Backends: []ItemBackend{}, + CreatedBy: "test_user_2", + CreatedTime: 1636667506, + DeletedBy: "", + DeletedTime: 0, + Description: "", + DPAPIUser: "api_user_2", + ExtNetID: 2524, + Frontends: []ItemFrontend{}, + GID: 212, + GUID: 2, + ID: 2, + ImageID: 2129, + Milestones: 129013, + Name: "k8s-lb-test-2", + RGID: 25092, + RGName: "", + Status: "ENABLED", + TechStatus: "STOPPED", + UpdatedBy: "", + UpdatedTime: 0, + VINSID: 102, + }, }, - }, - ItemLoadBalancer{ - DPAPIPassword: "0000", - RecordLB: RecordLB{ - HAMode: true, - ACL: []interface{}{}, - Backends: []ItemBackend{}, - CreatedBy: "te2t_user_3", - CreatedTime: 1636667534, - DeletedBy: "", - DeletedTime: 0, - Description: "", - DPAPIUser: "api_user_3", - ExtNetID: 2536, - Frontends: []ItemFrontend{}, - GID: 212, - GUID: 3, - ID: 3, - ImageID: 2139, - Milestones: 129025, - Name: "k8s-lb-test-3", - RGID: 25106, - RGName: "", - Status: "DISABLED", - TechStatus: "STOPPED", - UpdatedBy: "", - UpdatedTime: 0, - VINSID: 118, + { + DPAPIPassword: "0000", + RecordLB: RecordLB{ + HAMode: true, + ACL: []interface{}{}, + Backends: []ItemBackend{}, + CreatedBy: "te2t_user_3", + CreatedTime: 1636667534, + DeletedBy: "", + DeletedTime: 0, + Description: "", + DPAPIUser: "api_user_3", + ExtNetID: 2536, + Frontends: []ItemFrontend{}, + GID: 212, + GUID: 3, + ID: 3, + ImageID: 2139, + Milestones: 129025, + Name: "k8s-lb-test-3", + RGID: 25106, + RGName: "", + Status: "DISABLED", + TechStatus: "STOPPED", + UpdatedBy: "", + UpdatedTime: 0, + VINSID: 118, + }, }, }, + EntryCount: 3, } func TestFilterByID(t *testing.T) { @@ -129,7 +132,7 @@ func TestFilterFunc(t *testing.T) { return rl.Status == "DISABLED" }) - for _, item := range actual { + for _, item := range actual.Data { if item.Status != "DISABLED" { t.Fatal("expected Status 'DISABLED', found: ", item.Status) } @@ -139,7 +142,7 @@ func TestFilterFunc(t *testing.T) { func TestSortByCreatedTime(t *testing.T) { actual := lbs.SortByCreatedTime(true) - if actual[0].CreatedTime != 1636667534 || actual[2].CreatedTime != 1636667448 { + if actual.Data[0].CreatedTime != 1636667534 || actual.Data[2].CreatedTime != 1636667448 { t.Fatal("expected descending order, found ascending") } } diff --git a/pkg/cloudapi/lb/list.go b/pkg/cloudapi/lb/list.go index 48f777b..efcdec5 100644 --- a/pkg/cloudapi/lb/list.go +++ b/pkg/cloudapi/lb/list.go @@ -8,6 +8,38 @@ import ( // Request struct for get list of load balancers type ListRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account ID + // Required: false + AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"` + + // Find by resource group ID + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by tech status + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Find by frontend Ip + // Required: false + FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"` + + // Find by backend Ip + // Required: false + BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"` + // Included deleted load balancers // Required: false IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"` @@ -22,7 +54,7 @@ type ListRequest struct { } // List gets list all load balancers -func (l LB) List(ctx context.Context, req ListRequest) (ListLB, error) { +func (l LB) List(ctx context.Context, req ListRequest) (*ListLB, error) { url := "/cloudapi/lb/list" res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -37,5 +69,5 @@ func (l LB) List(ctx context.Context, req ListRequest) (ListLB, error) { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/lb/list_deleted.go b/pkg/cloudapi/lb/list_deleted.go index 95dd6b0..37b3cc9 100644 --- a/pkg/cloudapi/lb/list_deleted.go +++ b/pkg/cloudapi/lb/list_deleted.go @@ -8,6 +8,34 @@ import ( // Request struct for get list of deleted load balancers type ListDeletedRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account ID + // Required: false + AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"` + + // Find by resource group ID + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by tech status + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + + // Find by frontend Ip + // Required: false + FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"` + + // Find by backend Ip + // Required: false + BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"` + // Page number // Required: false Page uint64 `url:"page,omitempty" json:"page,omitempty"` @@ -18,7 +46,7 @@ type ListDeletedRequest struct { } // ListDeleted gets list of deleted load balancers -func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, error) { +func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListLB, error) { url := "/cloudapi/lb/listDeleted" res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -33,5 +61,5 @@ func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, er return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/lb/models.go b/pkg/cloudapi/lb/models.go index 44eb31e..548dccf 100644 --- a/pkg/cloudapi/lb/models.go +++ b/pkg/cloudapi/lb/models.go @@ -90,7 +90,13 @@ type ItemLoadBalancer struct { } // List of load balancers -type ListLB []ItemLoadBalancer +type ListLB struct { + // Data + Data []ItemLoadBalancer `json:"data"` + + // EntryCount + EntryCount uint64 `json:"entryCount"` +} // Main information about backend type ItemBackend struct { diff --git a/pkg/cloudapi/lb/serialize.go b/pkg/cloudapi/lb/serialize.go index a4a8bee..bcf6606 100644 --- a/pkg/cloudapi/lb/serialize.go +++ b/pkg/cloudapi/lb/serialize.go @@ -12,7 +12,7 @@ import ( // - First argument -> prefix // - Second argument -> indent func (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) { - if len(ll) == 0 { + if len(ll.Data) == 0 { return []byte{}, nil } diff --git a/pkg/cloudapi/lb/sorting.go b/pkg/cloudapi/lb/sorting.go index 5ab873a..addadeb 100644 --- a/pkg/cloudapi/lb/sorting.go +++ b/pkg/cloudapi/lb/sorting.go @@ -6,16 +6,16 @@ import "sort" // // If inverse param is set to true, the order is reversed. func (ll ListLB) SortByCreatedTime(inverse bool) ListLB { - if len(ll) < 2 { + if len(ll.Data) < 2 { return ll } - sort.Slice(ll, func(i, j int) bool { + sort.Slice(ll.Data, func(i, j int) bool { if inverse { - return ll[i].CreatedTime > ll[j].CreatedTime + return ll.Data[i].CreatedTime > ll.Data[j].CreatedTime } - return ll[i].CreatedTime < ll[j].CreatedTime + return ll.Data[i].CreatedTime < ll.Data[j].CreatedTime }) return ll @@ -25,16 +25,16 @@ func (ll ListLB) SortByCreatedTime(inverse bool) ListLB { // // If inverse param is set to true, the order is reversed. func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB { - if len(ll) < 2 { + if len(ll.Data) < 2 { return ll } - sort.Slice(ll, func(i, j int) bool { + sort.Slice(ll.Data, func(i, j int) bool { if inverse { - return ll[i].UpdatedTime > ll[j].UpdatedTime + return ll.Data[i].UpdatedTime > ll.Data[j].UpdatedTime } - return ll[i].UpdatedTime < ll[j].UpdatedTime + return ll.Data[i].UpdatedTime < ll.Data[j].UpdatedTime }) return ll @@ -44,16 +44,16 @@ func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB { // // If inverse param is set to true, the order is reversed. func (ll ListLB) SortByDeletedTime(inverse bool) ListLB { - if len(ll) < 2 { + if len(ll.Data) < 2 { return ll } - sort.Slice(ll, func(i, j int) bool { + sort.Slice(ll.Data, func(i, j int) bool { if inverse { - return ll[i].DeletedTime > ll[j].DeletedTime + return ll.Data[i].DeletedTime > ll.Data[j].DeletedTime } - return ll[i].DeletedTime < ll[j].DeletedTime + return ll.Data[i].DeletedTime < ll.Data[j].DeletedTime }) return ll diff --git a/pkg/cloudapi/rg/list_computes.go b/pkg/cloudapi/rg/list_computes.go index 702a7a0..ceee176 100644 --- a/pkg/cloudapi/rg/list_computes.go +++ b/pkg/cloudapi/rg/list_computes.go @@ -14,13 +14,49 @@ type ListComputesRequest struct { // Required: true RGID uint64 `url:"rgId" json:"rgId" validate:"required"` - // Reason for action + // Find by compute id // Required: false - Reason string `url:"reason,omitempty" json:"reason,omitempty"` + ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // ID an account + // Required: false + AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` + + // Find by tech status + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Find by ip address + // Required: false + IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"` + + // Find by external network name + // Required: false + ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"` + + // Find by external network id + // Required: false + ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListComputes gets list of all compute instances under specified resource group, accessible by the user -func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) { +func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -42,5 +78,5 @@ func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComp return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/rg/list_deleted.go b/pkg/cloudapi/rg/list_deleted.go index f9625d0..49801f6 100644 --- a/pkg/cloudapi/rg/list_deleted.go +++ b/pkg/cloudapi/rg/list_deleted.go @@ -8,6 +8,34 @@ import ( // Request struct for get list deleted resource groups type ListDeletedRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account ID + // Required: false + AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` + + // Find by name account + // Required: false + AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"` + + // Find by created after time (unix timestamp) + // Required: false + CreatedAfter uint64 `url:"createdAfter,omitempty" json:"createdAfter,omitempty"` + + // Find by created before time (unix timestamp) + // Required: false + CreatedBefore uint64 `url:"createdBefore,omitempty" json:"createdBefore,omitempty"` + + // Find by status lock + // Required: false + LockStatus string `url:"lockStatus,omitempty" json:"lockStatus,omitempty"` + // Page number // Required: false Page uint64 `url:"page,omitempty" json:"page,omitempty"` diff --git a/pkg/cloudapi/rg/list_lb.go b/pkg/cloudapi/rg/list_lb.go index dcc3e34..3b58e44 100644 --- a/pkg/cloudapi/rg/list_lb.go +++ b/pkg/cloudapi/rg/list_lb.go @@ -13,10 +13,46 @@ type ListLBRequest struct { // Resource group ID // Required: true RGID uint64 `url:"rgId" json:"rgId" validate:"required"` + + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account ID + // Required: false + AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"` + + // Find by tech status + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Find by frontend Ip + // Required: false + FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"` + + // Find by backend Ip + // Required: false + BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListLB gets list all load balancers in the specified resource group, accessible by the user -func (r RG) ListLB(ctx context.Context, req ListLBRequest) (ListLB, error) { +func (r RG) ListLB(ctx context.Context, req ListLBRequest) (*ListLB, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +74,5 @@ func (r RG) ListLB(ctx context.Context, req ListLBRequest) (ListLB, error) { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/rg/list_pfw.go b/pkg/cloudapi/rg/list_pfw.go index 3b4afbb..dfc5c1c 100644 --- a/pkg/cloudapi/rg/list_pfw.go +++ b/pkg/cloudapi/rg/list_pfw.go @@ -16,7 +16,7 @@ type ListPFWRequest struct { } // ListPFW gets list port forward rules for the specified resource group -func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPortForwards, error) { +func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (*ListPortForwards, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +38,5 @@ func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPortForwards, return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/rg/list_vins.go b/pkg/cloudapi/rg/list_vins.go index fc7fe6c..6312b33 100644 --- a/pkg/cloudapi/rg/list_vins.go +++ b/pkg/cloudapi/rg/list_vins.go @@ -14,13 +14,33 @@ type ListVINSRequest struct { // Required: true RGID uint64 `url:"rgId" json:"rgId" validate:"required"` - // Reason for action + // Find by name // Required: false - Reason string `url:"reason,omitempty" json:"reason,omitempty"` + Name string `url:"name,omitempty" json:"name,omitempty"` + + // ID an account + // Required: false + AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` + + // Find by ip extnet address + // Required: false + ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"` + + // Find by vins id + // Required: false + VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListVINS gets list all ViNSes under specified resource group, accessible by the user -func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) { +func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -42,5 +62,5 @@ func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudapi/rg/models.go b/pkg/cloudapi/rg/models.go index 74eb40a..1b61953 100644 --- a/pkg/cloudapi/rg/models.go +++ b/pkg/cloudapi/rg/models.go @@ -449,7 +449,13 @@ type ItemCompute struct { } // List of computes -type ListComputes []ItemCompute +type ListComputes struct { + //Data + Data []ItemCompute `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about load balancer type RecordLoadBalancer struct { @@ -563,7 +569,13 @@ type ItemBackend struct { type ListBackends []ItemBackend // List of load balancers -type ListLB []ItemLoadBalancer +type ListLB struct { + // Data + Data []ItemLoadBalancer `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Server settings type RecordServerSettings struct { @@ -704,7 +716,13 @@ type ItemPortForward struct { } // List of port forwards -type ListPortForwards []ItemPortForward +type ListPortForwards struct { + //Data + Data []ItemPortForward `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about VINS type ItemVINS struct { @@ -761,7 +779,13 @@ type ItemVINS struct { } // List of VINSes -type ListVINS []ItemVINS +type ListVINS struct { + // Data + Data []ItemVINS `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about usage of resource type RecordResourceUsage struct { diff --git a/pkg/cloudapi/vins/list_deleted.go b/pkg/cloudapi/vins/list_deleted.go index cf86683..d7d77f4 100644 --- a/pkg/cloudapi/vins/list_deleted.go +++ b/pkg/cloudapi/vins/list_deleted.go @@ -8,6 +8,26 @@ import ( // Request struct for get list of deleted VINSes type ListDeletedRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account ID + // Required: false + AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` + + // Find by resource group id + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by external network IP + // Required: false + ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"` + // Page number // Required: false Page uint64 `url:"page,omitempty" json:"page,omitempty"` diff --git a/pkg/cloudbroker/account/filter.go b/pkg/cloudbroker/account/filter.go index bf1c60b..c402d33 100644 --- a/pkg/cloudbroker/account/filter.go +++ b/pkg/cloudbroker/account/filter.go @@ -1,34 +1,34 @@ package account -// FilterByID returns ListDeleted with specified ID. -func (ld ListDeleted) FilterByID(id uint64) ListDeleted { +// FilterByID returns ListAccounts with specified ID. +func (la ListAccounts) FilterByID(id uint64) ListAccounts { predicate := func(ia ItemAccount) bool { return ia.ID == id } - return ld.FilterFunc(predicate) + return la.FilterFunc(predicate) } -// FilterByName returns ListDeleted with specified Name. -func (ld ListDeleted) FilterByName(name string) ListDeleted { +// FilterByName returns ListAccounts with specified Name. +func (la ListAccounts) FilterByName(name string) ListAccounts { predicate := func(ia ItemAccount) bool { return ia.Name == name } - return ld.FilterFunc(predicate) + return la.FilterFunc(predicate) } -// FilterByStatus returns ListDeleted with specified Status. -func (ld ListDeleted) FilterByStatus(status string) ListDeleted { +// FilterByStatus returns ListAccounts with specified Status. +func (la ListAccounts) FilterByStatus(status string) ListAccounts { predicate := func(ia ItemAccount) bool { return ia.Status == status } - return ld.FilterFunc(predicate) + return la.FilterFunc(predicate) } -// FilterByUserGroupID returns ListDeleted with specified UserGroupID. -func (ld ListDeleted) FilterByUserGroupID(userGroupID string) ListDeleted { +// FilterByUserGroupID returns ListAccounts with specified UserGroupID. +func (la ListAccounts) FilterByUserGroupID(userGroupID string) ListAccounts { predicate := func(ia ItemAccount) bool { acl := ia.ACL @@ -41,46 +41,48 @@ func (ld ListDeleted) FilterByUserGroupID(userGroupID string) ListDeleted { return false } - return ld.FilterFunc(predicate) + return la.FilterFunc(predicate) } -// FilterByCompany returns ListDeleted with specified Company. -func (ld ListDeleted) FilterByCompany(company string) ListDeleted { +// FilterByCompany returns ListAccounts with specified Company. +func (la ListAccounts) FilterByCompany(company string) ListAccounts { predicate := func(ia ItemAccount) bool { return ia.Company == company } - return ld.FilterFunc(predicate) + return la.FilterFunc(predicate) } -// FilterByCreatedBy returns ListDeleted created by specified user. -func (ld ListDeleted) FilterByCreatedBy(createdBy string) ListDeleted { +// FilterByCreatedBy returns ListAccounts created by specified user. +func (la ListAccounts) FilterByCreatedBy(createdBy string) ListAccounts { predicate := func(ia ItemAccount) bool { return ia.CreatedBy == createdBy } - return ld.FilterFunc(predicate) + return la.FilterFunc(predicate) } -// FilterFunc allows filtering ListDeleted based on a user-specified predicate. -func (ld ListDeleted) FilterFunc(predicate func(ItemAccount) bool) ListDeleted { - var result ListDeleted +// FilterFunc allows filtering ListAccounts based on a user-specified predicate. +func (la ListAccounts) FilterFunc(predicate func(ItemAccount) bool) ListAccounts { + var result ListAccounts - for _, item := range ld { + for _, item := range la.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 ItemAccount. // If none was found, returns an empty struct. -func (ld ListDeleted) FindOne() ItemAccount { - if len(ld) == 0 { +func (la ListAccounts) FindOne() ItemAccount { + if len(la.Data) == 0 { return ItemAccount{} } - return ld[0] + return la.Data[0] } diff --git a/pkg/cloudbroker/account/filter_test.go b/pkg/cloudbroker/account/filter_test.go index f12ec4c..3b2458a 100644 --- a/pkg/cloudbroker/account/filter_test.go +++ b/pkg/cloudbroker/account/filter_test.go @@ -4,78 +4,81 @@ import ( "testing" ) -var accounts = ListDeleted{ - ItemAccount{ - Meta: []interface{}{}, - InfoAccount: InfoAccount{ - ACL: []ACL{ - { - Explicit: true, - GUID: "", - Right: "CXDRAU", - Status: "CONFIRMED", - Type: "U", - UserGroupID: "not_really_timofey_tkachev_1@decs3o", +var accounts = ListAccounts{ + Data: []ItemAccount{ + { + Meta: []interface{}{}, + InfoAccount: InfoAccount{ + ACL: []ACL{ + { + Explicit: true, + GUID: "", + Right: "CXDRAU", + Status: "CONFIRMED", + Type: "U", + UserGroupID: "not_really_timofey_tkachev_1@decs3o", + }, }, + CreatedTime: 1676878820, + DeletedTime: 0, + ID: 132847, + Name: "std_2", + Status: "CONFIRMED", + UpdatedTime: 1676645275, }, - CreatedTime: 1676878820, - DeletedTime: 0, - ID: 132847, - Name: "std_2", - Status: "CONFIRMED", - UpdatedTime: 1676645275, }, - }, - ItemAccount{ - Meta: []interface{}{}, - InfoAccount: InfoAccount{ - ACL: []ACL{ - { - Explicit: true, - GUID: "", - Right: "CXDRAU", - Status: "CONFIRMED", - Type: "U", - UserGroupID: "timofey_tkachev_1@decs3o", + { + Meta: []interface{}{}, + InfoAccount: InfoAccount{ + ACL: []ACL{ + { + Explicit: true, + GUID: "", + Right: "CXDRAU", + Status: "CONFIRMED", + Type: "U", + UserGroupID: "timofey_tkachev_1@decs3o", + }, }, + CreatedTime: 1676645275, + DeletedTime: 1677723401, + ID: 132846, + Name: "std", + Status: "DELETED", + UpdatedTime: 1676645275, }, - CreatedTime: 1676645275, - DeletedTime: 1677723401, - ID: 132846, - Name: "std", - Status: "DELETED", - UpdatedTime: 1676645275, }, - }, - ItemAccount{ - Meta: []interface{}{}, - InfoAccount: InfoAccount{ - ACL: []ACL{ - { - Explicit: true, - GUID: "", - Right: "CXDRAU", - Status: "CONFIRMED", - Type: "U", - UserGroupID: "timofey_tkachev_1@decs3o", - }, - { - Explicit: true, - GUID: "", - Right: "CXDRAU", - Status: "CONFIRMED", - Type: "U", - UserGroupID: "second_account@decs3o", + { + Meta: []interface{}{}, + InfoAccount: InfoAccount{ + ACL: []ACL{ + { + Explicit: true, + GUID: "", + Right: "CXDRAU", + Status: "CONFIRMED", + Type: "U", + UserGroupID: "timofey_tkachev_1@decs3o", + }, + { + Explicit: true, + GUID: "", + Right: "CXDRAU", + Status: "CONFIRMED", + Type: "U", + UserGroupID: "second_account@decs3o", + }, }, + CreatedTime: 1676883850, + DeletedTime: 1676883899, + ID: 132848, + Name: "std_broker", + Status: "DELETED", + UpdatedTime: 1676878820, }, - CreatedTime: 1676883850, - DeletedTime: 1676883899, - ID: 132848, - Name: "std_broker", - Status: "DELETED", - UpdatedTime: 1676878820, }, }, + EntryCount: 3, } func TestFilterByID(t *testing.T) { @@ -109,11 +112,11 @@ func TestFilterByName(t *testing.T) { func TestFilterByStatus(t *testing.T) { actual := accounts.FilterByStatus("DELETED") - if len(actual) != 2 { - t.Fatal("Expected 2 elements in slice, found: ", len(actual)) + if len(actual.Data) != 2 { + t.Fatal("Expected 2 elements in slice, found: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.Status != "DELETED" { t.Fatal("expected DELETED, found: ", item.Status) } @@ -125,7 +128,7 @@ func TestFilterFunc(t *testing.T) { return ia.DeletedTime == 0 }) - for _, item := range actual { + for _, item := range actual.Data { if item.DeletedTime != 0 { t.Fatal("Expected DeletedTime = 0, found: ", item.DeletedTime) } @@ -135,21 +138,21 @@ func TestFilterFunc(t *testing.T) { func TestSortingByCreatedTime(t *testing.T) { actual := accounts.SortByCreatedTime(false) - if actual[0].Name != "std" { - t.Fatal("Expected account std as earliest, found: ", actual[0].Name) + if actual.Data[0].Name != "std" { + t.Fatal("Expected account std as earliest, found: ", actual.Data[0].Name) } actual = accounts.SortByCreatedTime(true) - if actual[0].Name != "std_broker" { - t.Fatal("Expected account std_broker as latest, found: ", actual[0].Name) + if actual.Data[0].Name != "std_broker" { + t.Fatal("Expected account std_broker as latest, found: ", actual.Data[0].Name) } } func TestFilterEmpty(t *testing.T) { actual := accounts.FilterByID(0) - if len(actual) != 0 { - t.Fatal("Expected 0 found, actual: ", len(actual)) + if len(actual.Data) != 0 { + t.Fatal("Expected 0 found, actual: ", len(actual.Data)) } } diff --git a/pkg/cloudbroker/account/list.go b/pkg/cloudbroker/account/list.go index 136fd8b..e8e4918 100644 --- a/pkg/cloudbroker/account/list.go +++ b/pkg/cloudbroker/account/list.go @@ -10,27 +10,27 @@ import ( type ListRequest struct { // Find by ID // Required: false - ByID uint64 `url:"by_id" json:"by_id"` + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` // Find by name // Required: false - Name string `urL:"name" json:"name"` + Name string `url:"name,omitempty" json:"name,omitempty"` // Find by access control list // Required: false - ACL string `url:"acl" json:"acl"` + ACL string `url:"acl,omitempty" json:"acl,omitempty"` // Find by status // Required: false - Status string `url:"status" json:"status"` + Status string `url:"status,omitempty" json:"status,omitempty"` // Page number // Required: false - Page uint64 `url:"page" json:"page"` + Page uint64 `url:"page,omitempty" json:"page,omitempty"` // Page size // Required: false - Size uint64 `url:"size" json:"size"` + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // List gets list all accounts the user has access to diff --git a/pkg/cloudbroker/account/list_computes.go b/pkg/cloudbroker/account/list_computes.go index 1d914d5..f1ad745 100644 --- a/pkg/cloudbroker/account/list_computes.go +++ b/pkg/cloudbroker/account/list_computes.go @@ -13,10 +13,50 @@ type ListComputesRequest struct { // ID an account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Find by compute id + // Required: false + ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by resource group name + // Required: false + RGName string `url:"rgName,omitempty" json:"rgName,omitempty"` + + // Find by resource group id + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by tech status + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + + // Find by ip address + // Required: false + IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"` + + // Find by external network name + // Required: false + ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"` + + // Find by external network id + // Required: false + ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListComputes gets list all compute instances under specified account, accessible by the user -func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) { +func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +78,5 @@ func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (Lis return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/account/list_deleted.go b/pkg/cloudbroker/account/list_deleted.go index 5b65e59..25e3145 100644 --- a/pkg/cloudbroker/account/list_deleted.go +++ b/pkg/cloudbroker/account/list_deleted.go @@ -8,17 +8,29 @@ import ( // Request struct for get list deleted accounts type ListDeletedRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by access control list + // Required: false + ACL string `url:"acl,omitempty" json:"acl,omitempty"` + // Page number // Required: false - Page uint64 `url:"page" json:"page"` + Page uint64 `url:"page,omitempty" json:"page,omitempty"` // Page size // Required: false - Size uint64 `url:"size" json:"size"` + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListDeleted gets list all deleted accounts the user has access to -func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeleted, error) { +func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAccounts, error) { url := "/cloudbroker/account/listDeleted" res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -26,12 +38,12 @@ func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListD return nil, err } - list := ListDeleted{} + list := ListAccounts{} err = json.Unmarshal(res, &list) if err != nil { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/account/list_disks.go b/pkg/cloudbroker/account/list_disks.go index edd6715..d8db16a 100644 --- a/pkg/cloudbroker/account/list_disks.go +++ b/pkg/cloudbroker/account/list_disks.go @@ -13,10 +13,34 @@ type ListDisksRequest struct { // ID an account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Find by disk id + // Required: false + DiskID uint64 `url:"diskId,omitempty" json:"diskId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by max size disk + // Required: false + DiskMaxSize uint64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"` + + // Type of the disks + // Required: false + Type string `url:"type,omitempty" json:"type,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListDisks gets list all currently unattached disks under specified account -func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) { +func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (*ListDisks, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +62,5 @@ func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/account/list_flip_groups.go b/pkg/cloudbroker/account/list_flip_groups.go index e23ce19..5952350 100644 --- a/pkg/cloudbroker/account/list_flip_groups.go +++ b/pkg/cloudbroker/account/list_flip_groups.go @@ -13,10 +13,42 @@ type ListFLIPGroupsRequest struct { // ID an account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by vinsId + // Required: false + VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"` + + // Find by VINS name + // Required: false + VINSName string `url:"vinsName,omitempty" json:"vinsName,omitempty"` + + // Find by external network id + // Required: false + ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"` + + // Find by IP + // Required: false + ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"` + + // Find by flipGroup Id + // Required: false + FLIPGroupID uint64 `url:"flipGroupId,omitempty" json:"flipGroupId,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user -func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (ListFLIPGroups, error) { +func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (*ListFLIPGroups, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +70,5 @@ func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/account/list_rg.go b/pkg/cloudbroker/account/list_rg.go index 1da1377..d3f7d57 100644 --- a/pkg/cloudbroker/account/list_rg.go +++ b/pkg/cloudbroker/account/list_rg.go @@ -13,10 +13,38 @@ type ListRGRequest struct { // ID an account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` + + // Find by resource group id + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by vinsId + // Required: false + VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"` + + // Find by VM ID + // Required: false + VMID uint64 `url:"vmId,omitempty" json:"vmId,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` } // ListRG gets list all resource groups under specified account, accessible by the user -func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) { +func (a Account) ListRG(ctx context.Context, req ListRGRequest) (*ListRG, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +66,5 @@ func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/account/list_vins.go b/pkg/cloudbroker/account/list_vins.go index a35880a..02692fd 100644 --- a/pkg/cloudbroker/account/list_vins.go +++ b/pkg/cloudbroker/account/list_vins.go @@ -13,10 +13,34 @@ type ListVINSRequest struct { // ID an account // Required: true AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` + + // Find by VINS ID + // Required: false + VINSID uint64 `url:"vins,omitempty" json:"vinsId,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by resource group id + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by external network ip + // Required: false + ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListVINS gets list all ViNSes under specified account, accessible by the user -func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) { +func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -28,7 +52,7 @@ func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, e res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) if err != nil { - return ListVINS{}, err + return nil, err } list := ListVINS{} @@ -38,5 +62,5 @@ func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, e return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/account/models.go b/pkg/cloudbroker/account/models.go index 39382fd..2aef784 100644 --- a/pkg/cloudbroker/account/models.go +++ b/pkg/cloudbroker/account/models.go @@ -98,7 +98,7 @@ type ACL struct { // Resource limits type ResourceLimits struct { - // CuC + // CuC CuC float64 `json:"CU_C"` // CuD @@ -210,18 +210,23 @@ type ItemAccount struct { InfoAccount } -// List of accounts -type ListDeleted []ItemAccount - // List of accounts type ListAccounts struct { + // Data Data []ItemAccount `json:"data"` + // Entry count EntryCount uint64 `json:"entryCount"` } // List of computes -type ListComputes []ItemCompute +type ListComputes struct { + // Data + Data []ItemCompute `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about compute type ItemCompute struct { @@ -287,7 +292,13 @@ type ItemCompute struct { } // List of disks -type ListDisks []ItemDisk +type ListDisks struct { + // Data + Data []ItemDisk `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about disks type ItemDisk struct { @@ -314,7 +325,13 @@ type ItemDisk struct { } // List of FLIPGroups -type ListFLIPGroups []ItemFLIPGroup +type ListFLIPGroups struct { + // Data + Data []ItemFLIPGroup `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about FLIPGroup type ItemFLIPGroup struct { @@ -500,7 +517,13 @@ type ItemRG struct { } // List of resource groups -type ListRG []ItemRG +type ListRG struct { + // Data + Data []ItemRG `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about VINS type ItemVINS struct { @@ -557,4 +580,10 @@ type ItemVINS struct { } // List of VINSes -type ListVINS []ItemVINS +type ListVINS struct { + //Data + Data []ItemVINS `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} diff --git a/pkg/cloudbroker/account/serialize.go b/pkg/cloudbroker/account/serialize.go index d2bcfda..5c45955 100644 --- a/pkg/cloudbroker/account/serialize.go +++ b/pkg/cloudbroker/account/serialize.go @@ -6,26 +6,6 @@ import ( "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 (ld ListDeleted) Serialize(params ...string) (serialization.Serialized, error) { - if len(ld) == 0 { - return []byte{}, nil - } - - if len(params) > 1 { - prefix := params[0] - indent := params[1] - - return json.MarshalIndent(ld, prefix, indent) - } - - return json.Marshal(ld) -} - // 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: diff --git a/pkg/cloudbroker/account/sorting.go b/pkg/cloudbroker/account/sorting.go index 0f959c8..191bbe1 100644 --- a/pkg/cloudbroker/account/sorting.go +++ b/pkg/cloudbroker/account/sorting.go @@ -2,68 +2,11 @@ package account import "sort" -// SortByCreatedTime sorts ListDeleted by the CreatedTime field in ascending order. -// -// If inverse param is set to true, the order is reversed. -func (ld ListDeleted) SortByCreatedTime(inverse bool) ListDeleted { - if len(ld) < 2 { - return ld - } - - sort.Slice(ld, func(i, j int) bool { - if inverse { - return ld[i].CreatedTime > ld[j].CreatedTime - } - - return ld[i].CreatedTime < ld[j].CreatedTime - }) - - return ld -} - -// SortByUpdatedTime sorts ListDeleted by the UpdatedTime field in ascending order. -// -// If inverse param is set to true, the order is reversed. -func (ld ListDeleted) SortByUpdatedTime(inverse bool) ListDeleted { - if len(ld) < 2 { - return ld - } - - sort.Slice(ld, func(i, j int) bool { - if inverse { - return ld[i].UpdatedTime > ld[j].UpdatedTime - } - - return ld[i].UpdatedTime < ld[j].UpdatedTime - }) - - return ld -} - -// SortByDeletedTime sorts ListDeleted by the DeletedTime field in ascending order. -// -// If inverse param is set to true, the order is reversed. -func (ld ListDeleted) SortByDeletedTime(inverse bool) ListDeleted { - if len(ld) < 2 { - return ld - } - - sort.Slice(ld, func(i, j int) bool { - if inverse { - return ld[i].DeletedTime > ld[j].DeletedTime - } - - return ld[i].DeletedTime < ld[j].DeletedTime - }) - - return ld -} - // SortByCreatedTime sorts ListAccounts by the CreatedTime field in ascending order. // // If inverse param is set to true, the order is reversed. func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts { - if la.EntryCount < 2 { + if len(la.Data) < 2 { return la } @@ -82,7 +25,7 @@ func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts { // // If inverse param is set to true, the order is reversed. func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts { - if la.EntryCount < 2 { + if len(la.Data) < 2 { return la } @@ -101,7 +44,7 @@ func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts { // // If inverse param is set to true, the order is reversed. func (la ListAccounts) SortByDeletedTime(inverse bool) ListAccounts { - if la.EntryCount < 2 { + if len(la.Data) < 2 { return la } diff --git a/pkg/cloudbroker/compute/disk_attach.go b/pkg/cloudbroker/compute/disk_attach.go index de1339b..4acc8ae 100644 --- a/pkg/cloudbroker/compute/disk_attach.go +++ b/pkg/cloudbroker/compute/disk_attach.go @@ -18,6 +18,10 @@ type DiskAttachRequest struct { // Required: true DiskID uint64 `url:"diskId" json:"diskId" validate:"required"` + // Type of the disk B;D + // Required: false + DiskType string `url:"diskType,omitempty" json:"diskType,omitempty"` + // Reason for action // Required: false Reason string `url:"reason,omitempty" json:"reason,omitempty"` diff --git a/pkg/cloudbroker/compute/disk_qos.go b/pkg/cloudbroker/compute/disk_qos.go index cd083b6..8428413 100644 --- a/pkg/cloudbroker/compute/disk_qos.go +++ b/pkg/cloudbroker/compute/disk_qos.go @@ -21,6 +21,10 @@ type DiskQOSRequest struct { // Limit IO for a certain disk total and read/write options are not allowed to be combined // Required: true Limits string `url:"limits" json:"limits" validate:"required"` + + // Reason for action + // Required: false + Reason string `url:"reason,omitempty" json:"reason,omitempty"` } // DiskQOS change QOS of the disk diff --git a/pkg/cloudbroker/compute/filter.go b/pkg/cloudbroker/compute/filter.go index 2e5fa35..0de2d56 100644 --- a/pkg/cloudbroker/compute/filter.go +++ b/pkg/cloudbroker/compute/filter.go @@ -59,7 +59,7 @@ func (lc ListComputes) FilterByDiskID(diskID uint64) ListComputes { } // FilterByK8SID returns master and worker nodes (ListComputes) inside specified K8S cluster. -func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListComputes, error) { +func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListComputes, error) { caller := k8s.New(decortClient) req := k8s.GetRequest{ @@ -89,7 +89,9 @@ func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortCl return false } - return lc.FilterFunc(predicate), nil + result := lc.FilterFunc(predicate) + + return &result, nil } // K8SMasters is used to filter master nodes. Best used after FilterByK8SID function. @@ -121,7 +123,7 @@ func (lc ListComputes) FilterByK8SWorkers() ListComputes { } // FilterByLBID is used to filter ListComputes used by specified Load Balancer. -func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListComputes, error) { +func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (*ListComputes, error) { caller := lb.New(decortClient) req := lb.GetRequest{ @@ -137,28 +139,32 @@ func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClie return ic.ID == foundLB.PrimaryNode.ComputeID || ic.ID == foundLB.SecondaryNode.ComputeID } - return lc.FilterFunc(predicate), nil + result := lc.FilterFunc(predicate) + + return &result, nil } // FilterFunc allows filtering ListComputes based on a user-specified predicate. func (lc ListComputes) FilterFunc(predicate func(ItemCompute) bool) ListComputes { var result ListComputes - for _, item := range lc { + for _, item := range lc.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 ItemCompute // If none was found, returns an empty struct. func (lc ListComputes) FindOne() ItemCompute { - if len(lc) == 0 { + if len(lc.Data) == 0 { return ItemCompute{} } - return lc[0] + return lc.Data[0] } diff --git a/pkg/cloudbroker/compute/filter_test.go b/pkg/cloudbroker/compute/filter_test.go index 4c0df01..ce76bd3 100644 --- a/pkg/cloudbroker/compute/filter_test.go +++ b/pkg/cloudbroker/compute/filter_test.go @@ -1,247 +1,250 @@ package compute import ( - "testing" + "testing" ) var computes = ListComputes{ - ItemCompute{ - Disks: []InfoDisk{ - { - ID: 65191, - PCISlot: 6, - }, - }, - InfoCompute: InfoCompute{ - ACL: []interface{}{}, - AccountID: 132847, - AccountName: "std_2", - AffinityLabel: "", - AffinityRules: []ItemRule{ + Data: []ItemCompute{ + { + Disks: []InfoDisk{ { - GUID: "", - Key: "aff_key", - Mode: "ANY", - Policy: "RECOMMENDED", - Topology: "compute", - Value: "aff_val", + ID: 65191, + PCISlot: 6, }, }, - AffinityWeight: 0, - AntiAffinityRules: []ItemRule{ - { - GUID: "", - Key: "antiaff_key", - Mode: "ANY", - Policy: "RECOMMENDED", - Topology: "compute", - Value: "antiaff_val", + InfoCompute: InfoCompute{ + ACL: []interface{}{}, + AccountID: 132847, + AccountName: "std_2", + AffinityLabel: "", + AffinityRules: []ItemRule{ + { + GUID: "", + Key: "aff_key", + Mode: "ANY", + Policy: "RECOMMENDED", + Topology: "compute", + Value: "aff_val", + }, }, + AffinityWeight: 0, + AntiAffinityRules: []ItemRule{ + { + GUID: "", + Key: "antiaff_key", + Mode: "ANY", + Policy: "RECOMMENDED", + Topology: "compute", + Value: "antiaff_val", + }, + }, + Arch: "X86_64", + BootOrder: []string{ + "hd", "cdrom", + }, + BootDiskSize: 0, + CloneReference: 0, + Clones: []uint64{}, + ComputeCIID: 0, + CPUs: 4, + CreatedBy: "timofey_tkachev_1@decs3o", + CreatedTime: 1676975175, + CustomFields: map[string]interface{}{}, + DeletedBy: "", + DeletedTime: 0, + Description: "", + Devices: nil, + Driver: "KVM_X86", + GID: 212, + GUID: 48500, + ID: 48500, + ImageID: 9884, + Interfaces: ListInterfaces{}, + LockStatus: "UNLOCKED", + ManagerID: 0, + ManagerType: "", + MigrationJob: 0, + Milestones: 363500, + Name: "test", + Pinned: false, + RAM: 4096, + ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e", + Registered: true, + ResName: "compute-48500", + RGID: 79724, + RGName: "std_broker2", + SnapSets: ListSnapshots{}, + StatelessSEPID: 0, + StatelessSEPType: "", + Status: "ENABLED", + Tags: map[string]interface{}{}, + TechStatus: "STOPPED", + TotalDiskSize: 2, + UpdatedBy: "", + UpdatedTime: 1677058904, + UserManaged: true, + VGPUs: []uint64{}, + VINSConnected: 0, + VirtualImageID: 0, }, - Arch: "X86_64", - BootOrder: []string{ - "hd", "cdrom", - }, - BootDiskSize: 0, - CloneReference: 0, - Clones: []uint64{}, - ComputeCIID: 0, - CPUs: 4, - CreatedBy: "timofey_tkachev_1@decs3o", - CreatedTime: 1676975175, - CustomFields: map[string]interface{}{}, - DeletedBy: "", - DeletedTime: 0, - Description: "", - Devices: nil, - Driver: "KVM_X86", - GID: 212, - GUID: 48500, - ID: 48500, - ImageID: 9884, - Interfaces: ListInterfaces{}, - LockStatus: "UNLOCKED", - ManagerID: 0, - ManagerType: "", - MigrationJob: 0, - Milestones: 363500, - Name: "test", - Pinned: false, - RAM: 4096, - ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e", - Registered: true, - ResName: "compute-48500", - RGID: 79724, - RGName: "std_broker2", - SnapSets: ListSnapshots{}, - StatelessSEPID: 0, - StatelessSEPType: "", - Status: "ENABLED", - Tags: map[string]interface{}{}, - TechStatus: "STOPPED", - TotalDiskSize: 2, - UpdatedBy: "", - UpdatedTime: 1677058904, - UserManaged: true, - VGPUs: []uint64{}, - VINSConnected: 0, - VirtualImageID: 0, }, - }, - ItemCompute{ - Disks: []InfoDisk{ - { - ID: 65248, - PCISlot: 6, + { + Disks: []InfoDisk{ + { + ID: 65248, + PCISlot: 6, + }, }, - }, - InfoCompute: InfoCompute{ - ACL: []interface{}{}, - AccountID: 132848, - AccountName: "std_broker", - AffinityLabel: "", - AffinityRules: []ItemRule{}, - AffinityWeight: 0, - AntiAffinityRules: []ItemRule{}, - Arch: "X86_64", - BootOrder: []string{ - "hd", "cdrom", + InfoCompute: InfoCompute{ + ACL: []interface{}{}, + AccountID: 132848, + AccountName: "std_broker", + AffinityLabel: "", + AffinityRules: []ItemRule{}, + AffinityWeight: 0, + AntiAffinityRules: []ItemRule{}, + Arch: "X86_64", + BootOrder: []string{ + "hd", "cdrom", + }, + BootDiskSize: 0, + CloneReference: 0, + Clones: []uint64{}, + ComputeCIID: 0, + CPUs: 6, + CreatedBy: "timofey_tkachev_1@decs3o", + CreatedTime: 1677579436, + CustomFields: map[string]interface{}{}, + DeletedBy: "", + DeletedTime: 0, + Description: "", + Devices: nil, + Driver: "KVM_X86", + GID: 212, + GUID: 48556, + ID: 48556, + ImageID: 9884, + Interfaces: ListInterfaces{}, + LockStatus: "UNLOCKED", + ManagerID: 0, + ManagerType: "", + MigrationJob: 0, + Milestones: 363853, + Name: "compute_2", + Pinned: false, + RAM: 4096, + ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff", + Registered: true, + ResName: "compute-48556", + RGID: 79727, + RGName: "sdk_negative_fields_test", + SnapSets: ListSnapshots{}, + StatelessSEPID: 0, + StatelessSEPType: "", + Status: "ENABLED", + Tags: map[string]interface{}{}, + TechStatus: "STARTED", + TotalDiskSize: 1, + UpdatedBy: "", + UpdatedTime: 1677579436, + UserManaged: true, + VGPUs: []uint64{}, + VINSConnected: 0, + VirtualImageID: 0, }, - BootDiskSize: 0, - CloneReference: 0, - Clones: []uint64{}, - ComputeCIID: 0, - CPUs: 6, - CreatedBy: "timofey_tkachev_1@decs3o", - CreatedTime: 1677579436, - CustomFields: map[string]interface{}{}, - DeletedBy: "", - DeletedTime: 0, - Description: "", - Devices: nil, - Driver: "KVM_X86", - GID: 212, - GUID: 48556, - ID: 48556, - ImageID: 9884, - Interfaces: ListInterfaces{}, - LockStatus: "UNLOCKED", - ManagerID: 0, - ManagerType: "", - MigrationJob: 0, - Milestones: 363853, - Name: "compute_2", - Pinned: false, - RAM: 4096, - ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff", - Registered: true, - ResName: "compute-48556", - RGID: 79727, - RGName: "sdk_negative_fields_test", - SnapSets: ListSnapshots{}, - StatelessSEPID: 0, - StatelessSEPType: "", - Status: "ENABLED", - Tags: map[string]interface{}{}, - TechStatus: "STARTED", - TotalDiskSize: 1, - UpdatedBy: "", - UpdatedTime: 1677579436, - UserManaged: true, - VGPUs: []uint64{}, - VINSConnected: 0, - VirtualImageID: 0, }, }, + EntryCount: 2, } func TestFilterByID(t *testing.T) { - actual := computes.FilterByID(48500).FindOne() + actual := computes.FilterByID(48500).FindOne() - if actual.ID != 48500 { - t.Fatal("expected ID 48500, found: ", actual.ID) - } + if actual.ID != 48500 { + t.Fatal("expected ID 48500, found: ", actual.ID) + } - actualEmpty := computes.FilterByID(0) + actualEmpty := computes.FilterByID(0) - if len(actualEmpty) != 0 { - t.Fatal("expected empty, actual: ", len(actualEmpty)) - } + if len(actualEmpty.Data) != 0 { + t.Fatal("expected empty, actual: ", len(actualEmpty.Data)) + } } func TestFilterByName(t *testing.T) { - actual := computes.FilterByName("compute_2").FindOne() + actual := computes.FilterByName("compute_2").FindOne() - if actual.Name != "compute_2" { - t.Fatal("expected compute with name 'test', found: ", actual.Name) - } + if actual.Name != "compute_2" { + t.Fatal("expected compute with name 'test', found: ", actual.Name) + } } func TestFilterByStatus(t *testing.T) { - actual := computes.FilterByStatus("ENABLED") + actual := computes.FilterByStatus("ENABLED") - for _, item := range actual { - if item.Status != "ENABLED" { - t.Fatal("expected ENABLED status, found: ", item.Status) - } - } + for _, item := range actual.Data { + if item.Status != "ENABLED" { + t.Fatal("expected ENABLED status, found: ", item.Status) + } + } } func TestFilterByTechStatus(t *testing.T) { - actual := computes.FilterByTechStatus("STARTED").FindOne() + actual := computes.FilterByTechStatus("STARTED").FindOne() - if actual.ID != 48556 { - t.Fatal("expected 48556 with STARTED techStatus, found: ", actual.ID) - } + if actual.ID != 48556 { + t.Fatal("expected 48556 with STARTED techStatus, found: ", actual.ID) + } } func TestFilterByDiskID(t *testing.T) { - actual := computes.FilterByDiskID(65248).FindOne() + actual := computes.FilterByDiskID(65248).FindOne() - if actual.ID != 48556 { - t.Fatal("expected 48556 with DiskID 65248, found: ", actual.ID) - } + if actual.ID != 48556 { + t.Fatal("expected 48556 with DiskID 65248, found: ", actual.ID) + } } func TestFilterFunc(t *testing.T) { - actual := computes.FilterFunc(func(ic ItemCompute) bool { - return ic.Registered == true - }) - - if len(actual) != 2 { - t.Fatal("expected 2 elements found, actual: ", len(actual)) - } - - for _, item := range actual { - if item.Registered != true { - t.Fatal("expected Registered to be true, actual: ", item.Registered) - } - } + actual := computes.FilterFunc(func(ic ItemCompute) bool { + return ic.Registered == true + }) + + if len(actual.Data) != 2 { + t.Fatal("expected 2 elements found, actual: ", len(actual.Data)) + } + + for _, item := range actual.Data { + if item.Registered != true { + t.Fatal("expected Registered to be true, actual: ", item.Registered) + } + } } func TestSortingByCreatedTime(t *testing.T) { - actual := computes.SortByCreatedTime(false) + actual := computes.SortByCreatedTime(false) - if actual[0].Name != "test" { - t.Fatal("expected 'test', found: ", actual[0].Name) - } + if actual.Data[0].Name != "test" { + t.Fatal("expected 'test', found: ", actual.Data[0].Name) + } - actual = computes.SortByCreatedTime(true) - if actual[0].Name != "compute_2" { - t.Fatal("expected 'compute_2', found: ", actual[0].Name) - } + actual = computes.SortByCreatedTime(true) + if actual.Data[0].Name != "compute_2" { + t.Fatal("expected 'compute_2', found: ", actual.Data[0].Name) + } } func TestSortingByCPU(t *testing.T) { - actual := computes.SortByCPU(false) + actual := computes.SortByCPU(false) - if actual[0].CPUs != 4{ - t.Fatal("expected 4 CPU cores, found: ", actual[0].CPUs) - } + if actual.Data[0].CPUs != 4 { + t.Fatal("expected 4 CPU cores, found: ", actual.Data[0].CPUs) + } - actual = computes.SortByCPU(true) + actual = computes.SortByCPU(true) - if actual[0].CPUs != 6 { - t.Fatal("expected 6 CPU cores, found: ", actual[0].CPUs) - } + if actual.Data[0].CPUs != 6 { + t.Fatal("expected 6 CPU cores, found: ", actual.Data[0].CPUs) + } } diff --git a/pkg/cloudbroker/compute/list.go b/pkg/cloudbroker/compute/list.go index 22cb05a..3be186d 100644 --- a/pkg/cloudbroker/compute/list.go +++ b/pkg/cloudbroker/compute/list.go @@ -8,6 +8,46 @@ import ( // Request struct for get list available computes type ListRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account ID + // Required: false + AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` + + // Find by resource group name + // Required: false + RGName string `url:"rgName,omitempty" json:"rgName,omitempty"` + + // Find by resource group ID + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by tech status + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Find by IP address + // Required: false + IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"` + + // Find by external network name + // Required: false + ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"` + + // Find by external network ID + // Required: false + ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"` + // Include deleted computes // Required: false IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"` @@ -23,7 +63,7 @@ type ListRequest struct { // List gets list of the available computes. // Filtering based on status is possible -func (c Compute) List(ctx context.Context, req ListRequest) (ListComputes, error) { +func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, error) { url := "/cloudbroker/compute/list" res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -38,5 +78,5 @@ func (c Compute) List(ctx context.Context, req ListRequest) (ListComputes, error return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/compute/list_deleted.go b/pkg/cloudbroker/compute/list_deleted.go index 886b705..dac24da 100644 --- a/pkg/cloudbroker/compute/list_deleted.go +++ b/pkg/cloudbroker/compute/list_deleted.go @@ -8,6 +8,42 @@ import ( // Request struct for get deleted computes list type ListDeletedRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account ID + // Required: false + AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` + + // Find by resource group name + // Required: false + RGName string `url:"rgName,omitempty" json:"rgName,omitempty"` + + // Find by resource group ID + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by tech status + // Required: false + TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"` + + // Find by IP address + // Required: false + IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"` + + // Find by external network name + // Required: false + ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"` + + // Find by external network ID + // Required: false + ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"` + // Page number // Required: false Page uint64 `url:"page,omitempty" json:"page,omitempty"` @@ -18,7 +54,7 @@ type ListDeletedRequest struct { } // ListDeleted gets list all deleted computes -func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListComputes, error) { +func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListComputes, error) { url := "/cloudbroker/compute/listDeleted" res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -33,5 +69,5 @@ func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListC return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/compute/list_pci_device.go b/pkg/cloudbroker/compute/list_pci_device.go index 4cd5396..197cf78 100644 --- a/pkg/cloudbroker/compute/list_pci_device.go +++ b/pkg/cloudbroker/compute/list_pci_device.go @@ -13,10 +13,34 @@ type ListPCIDeviceRequest struct { // Identifier compute // Required: true ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"` + + // Find by resource group ID + // Required: false + RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` + + // Find by device id + // Required: false + DevID uint64 `url:"devId,omitempty" json:"devId,omitempty"` + + // Find by type + // Required: false + Type string `url:"type,omitempty" json:"type,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListPCIDevice gets list PCI device -func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (ListPCIDevices, error) { +func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (*ListPCIDevices, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -38,5 +62,5 @@ func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (L return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/compute/list_vgpu.go b/pkg/cloudbroker/compute/list_vgpu.go new file mode 100644 index 0000000..a57ea9f --- /dev/null +++ b/pkg/cloudbroker/compute/list_vgpu.go @@ -0,0 +1,66 @@ +package compute + +import ( + "context" + "encoding/json" + "net/http" + + "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" +) + +// Request struct for get list GPU for compute +type ListVGPURequest struct { + // ID of compute instance + // Required: true + ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"` + + // Find by GPU id + // Required: false + GPUID uint64 `url:"gpuId,omitempty" json:"gpuId,omitempty"` + + // Find by type + // Required: false + Type string `url:"type,omitempty" json:"type,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` + + // Include deleted computes. If using field 'status', then includedeleted will be ignored + // Required: false + IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"` +} + +// ListVGPU gets list GPU for compute +func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) (*ListVGPUs, error) { + err := validators.ValidateRequest(req) + if err != nil { + for _, validationError := range validators.GetErrors(err) { + return nil, validators.ValidationError(validationError) + } + } + + url := "/cloudbroker/compute/listVGpu" + + res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return nil, err + } + + list := ListVGPUs{} + + err = json.Unmarshal(res, &list) + if err != nil { + return nil, err + } + + return &list, nil +} diff --git a/pkg/cloudbroker/compute/models.go b/pkg/cloudbroker/compute/models.go index 2cb4098..91520b6 100644 --- a/pkg/cloudbroker/compute/models.go +++ b/pkg/cloudbroker/compute/models.go @@ -119,6 +119,9 @@ type RecordNetAttach struct { // Default GW DefGW string `json:"defGw"` + // Enabled + Enabled bool `json:"enabled"` + // FLIPGroup ID FLIPGroupID uint64 `json:"flipgroupId"` @@ -742,7 +745,13 @@ type InfoDisk struct { } // List computes -type ListComputes []ItemCompute +type ListComputes struct { + // Data + Data []ItemCompute `json:"data"` + + // Entru Count + EntryCount uint64 `json:"entrycount"` +} // Short information about audir type ItemAudit struct { @@ -796,4 +805,19 @@ type ItemPCIDevice struct { } // List PCI devices -type ListPCIDevices []ItemPCIDevice +type ListPCIDevices struct { + // Data + Data []ItemPCIDevice `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} + +// List VGPUs +type ListVGPUs struct { + // Data + Data []interface{} `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} diff --git a/pkg/cloudbroker/compute/resize.go b/pkg/cloudbroker/compute/resize.go index 4861d0b..5e88bc7 100644 --- a/pkg/cloudbroker/compute/resize.go +++ b/pkg/cloudbroker/compute/resize.go @@ -17,16 +17,16 @@ type ResizeRequest struct { // New CPU count. // Pass 0 if no change to CPU count is required // Required: false - Force bool `url:"force,omitempty" json:"force,omitempty"` + CPU uint64 `url:"cpu,omitempty" json:"cpu,omitempty"` // New RAM volume in MB. // Pass 0 if no change to RAM volume is required // Required: false - CPU uint64 `url:"cpu,omitempty" json:"cpu,omitempty"` + RAM uint64 `url:"ram,omitempty" json:"ram,omitempty"` // Force compute resize // Required: false - RAM uint64 `url:"ram,omitempty" json:"ram,omitempty"` + Force bool `url:"force,omitempty" json:"force,omitempty"` // Reason for action // Required: false diff --git a/pkg/cloudbroker/compute/serialize.go b/pkg/cloudbroker/compute/serialize.go index 31af2f2..b222130 100644 --- a/pkg/cloudbroker/compute/serialize.go +++ b/pkg/cloudbroker/compute/serialize.go @@ -12,7 +12,7 @@ import ( // - First argument -> prefix // - Second argument -> indent func (lc ListComputes) Serialize(params ...string) (serialization.Serialized, error) { - if len(lc) == 0 { + if len(lc.Data) == 0 { return []byte{}, nil } diff --git a/pkg/cloudbroker/compute/sorting.go b/pkg/cloudbroker/compute/sorting.go index a7ea27f..b244d55 100644 --- a/pkg/cloudbroker/compute/sorting.go +++ b/pkg/cloudbroker/compute/sorting.go @@ -6,16 +6,16 @@ import "sort" // // If inverse param is set to true, the order is reversed. func (lc ListComputes) SortByCPU(inverse bool) ListComputes { - if len(lc) < 2 { + if len(lc.Data) < 2 { return lc } - sort.Slice(lc, func(i, j int) bool { + sort.Slice(lc.Data, func(i, j int) bool { if inverse { - return lc[i].CPUs > lc[j].CPUs + return lc.Data[i].CPUs > lc.Data[j].CPUs } - return lc[i].CPUs < lc[j].CPUs + return lc.Data[i].CPUs < lc.Data[j].CPUs }) return lc @@ -25,16 +25,16 @@ func (lc ListComputes) SortByCPU(inverse bool) ListComputes { // // If inverse param is set to true, the order is reversed. func (lc ListComputes) SortByRAM(inverse bool) ListComputes { - if len(lc) < 2 { + if len(lc.Data) < 2 { return lc } - sort.Slice(lc, func(i, j int) bool { + sort.Slice(lc.Data, func(i, j int) bool { if inverse { - return lc[i].RAM > lc[j].RAM + return lc.Data[i].RAM > lc.Data[j].RAM } - return lc[i].RAM < lc[j].RAM + return lc.Data[i].RAM < lc.Data[j].RAM }) return lc @@ -44,16 +44,16 @@ func (lc ListComputes) SortByRAM(inverse bool) ListComputes { // // If inverse param is set to true, the order is reversed. func (lc ListComputes) SortByCreatedTime(inverse bool) ListComputes { - if len(lc) < 2 { + if len(lc.Data) < 2 { return lc } - sort.Slice(lc, func(i, j int) bool { + sort.Slice(lc.Data, func(i, j int) bool { if inverse { - return lc[i].CreatedTime > lc[j].CreatedTime + return lc.Data[i].CreatedTime > lc.Data[j].CreatedTime } - return lc[i].CreatedTime < lc[j].CreatedTime + return lc.Data[i].CreatedTime < lc.Data[j].CreatedTime }) return lc @@ -63,16 +63,16 @@ func (lc ListComputes) SortByCreatedTime(inverse bool) ListComputes { // // If inverse param is set to true, the order is reversed. func (lc ListComputes) SortByUpdatedTime(inverse bool) ListComputes { - if len(lc) < 2 { + if len(lc.Data) < 2 { return lc } - sort.Slice(lc, func(i, j int) bool { + sort.Slice(lc.Data, func(i, j int) bool { if inverse { - return lc[i].UpdatedTime > lc[j].UpdatedTime + return lc.Data[i].UpdatedTime > lc.Data[j].UpdatedTime } - return lc[i].UpdatedTime < lc[j].UpdatedTime + return lc.Data[i].UpdatedTime < lc.Data[j].UpdatedTime }) return lc @@ -82,16 +82,16 @@ func (lc ListComputes) SortByUpdatedTime(inverse bool) ListComputes { // // If inverse param is set to true, the order is reversed. func (lc ListComputes) SortByDeletedTime(inverse bool) ListComputes { - if len(lc) < 2 { + if len(lc.Data) < 2 { return lc } - sort.Slice(lc, func(i, j int) bool { + sort.Slice(lc.Data, func(i, j int) bool { if inverse { - return lc[i].DeletedTime > lc[j].DeletedTime + return lc.Data[i].DeletedTime > lc.Data[j].DeletedTime } - return lc[i].DeletedTime < lc[j].DeletedTime + return lc.Data[i].DeletedTime < lc.Data[j].DeletedTime }) return lc diff --git a/pkg/cloudbroker/disks/filter.go b/pkg/cloudbroker/disks/filter.go index 0067e52..b23c8ff 100644 --- a/pkg/cloudbroker/disks/filter.go +++ b/pkg/cloudbroker/disks/filter.go @@ -70,7 +70,7 @@ func (ld ListDisks) FilterByComputeID(computeID uint64) ListDisks { } // FilterByK8SID is used to filter ListDisks by specified K8S cluster. -func (ld ListDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListDisks, error) { +func (ld ListDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListDisks, error) { caller := k8s.New(decortClient) req := k8s.GetRequest{ @@ -85,20 +85,20 @@ func (ld ListDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClien var result ListDisks for _, masterCompute := range cluster.K8SGroups.Masters.DetailedInfo { - result = append(result, ld.FilterByComputeID(masterCompute.ID)...) + result.Data = append(result.Data, ld.FilterByComputeID(masterCompute.ID).Data...) } for _, workerGroup := range cluster.K8SGroups.Workers { for _, workerCompute := range workerGroup.DetailedInfo { - result = append(result, ld.FilterByComputeID(workerCompute.ID)...) + result.Data = append(result.Data, ld.FilterByComputeID(workerCompute.ID).Data...) } } - return result, nil + return &result, nil } // FilterByLBID is used to filter ListDisks used by computes inside specified Load Balancer. -func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListDisks, error) { +func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (*ListDisks, error) { caller := lb.New(decortClient) req := lb.GetRequest{ @@ -111,31 +111,33 @@ func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient } var result ListDisks - result = append(result, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID)...) - result = append(result, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID)...) + result.Data = append(result.Data, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID).Data...) + result.Data = append(result.Data, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID).Data...) - return result, nil + return &result, nil } // FilterFunc allows filtering ListDisks based on a user-specified predicate. func (ld ListDisks) FilterFunc(predicate func(ItemDisk) bool) ListDisks { var result ListDisks - for _, item := range ld { + for _, item := range ld.Data { if predicate(item) { - result = append(result, item) + result.Data = append(result.Data, item) } } + result.EntryCount = uint64(len(ld.Data)) + return result } // FindOne returns first found ItemDisk // If none was found, returns an empty struct. func (ld ListDisks) FindOne() ItemDisk { - if len(ld) == 0 { + if len(ld.Data) == 0 { return ItemDisk{} } - return ld[0] + return ld.Data[0] } diff --git a/pkg/cloudbroker/disks/filter_test.go b/pkg/cloudbroker/disks/filter_test.go index 21811b1..b84d636 100644 --- a/pkg/cloudbroker/disks/filter_test.go +++ b/pkg/cloudbroker/disks/filter_test.go @@ -3,131 +3,134 @@ package disks import "testing" var disks = ListDisks{ - ItemDisk{ - MachineID: 0, - MachineName: "", - RecordDisk: RecordDisk{ - DeviceName: "vda", - SEPType: "", - InfoDisk: InfoDisk{ - AccountID: 132847, - AccountName: "std_2", - ACL: map[string]interface{}{}, - BootPartition: 0, - Computes: map[string]string{ - "48500": "test", + Data: []ItemDisk{ + { + MachineID: 0, + MachineName: "", + RecordDisk: RecordDisk{ + DeviceName: "vda", + SEPType: "", + InfoDisk: InfoDisk{ + AccountID: 132847, + AccountName: "std_2", + ACL: map[string]interface{}{}, + BootPartition: 0, + Computes: map[string]string{ + "48500": "test", + }, + CreatedTime: 1676975177, + DeletedTime: 0, + Description: "", + DestructionTime: 0, + DiskPath: "", + GID: 212, + GUID: 65191, + ID: 65191, + ImageID: 9884, + Images: []uint64{}, + IOTune: IOTune{ + TotalIOPSSec: 2000, + }, + IQN: "", + Login: "", + Milestones: 363501, + Name: "bootdisk", + Order: 0, + Params: "", + ParentID: 0, + Password: "", + PCISlot: 6, + Pool: "vmstor", + PresentTo: []uint64{ + 27, + }, + PurgeAttempts: 0, + PurgeTime: 0, + RealityDeviceNumber: 0, + ReferenceID: "sample", + ResID: "sample", + ResName: "sample", + Role: "", + SEPID: 2504, + Shareable: false, + SizeMax: 2, + SizeUsed: 2, + Snapshots: []ItemSnapshot{}, + Status: "ASSIGNED", + TechStatus: "ALLOCATED", + Type: "B", + VMID: 48500, }, - CreatedTime: 1676975177, - DeletedTime: 0, - Description: "", - DestructionTime: 0, - DiskPath: "", - GID: 212, - GUID: 65191, - ID: 65191, - ImageID: 9884, - Images: []uint64{}, - IOTune: IOTune{ - TotalIOPSSec: 2000, - }, - IQN: "", - Login: "", - Milestones: 363501, - Name: "bootdisk", - Order: 0, - Params: "", - ParentID: 0, - Password: "", - PCISlot: 6, - Pool: "vmstor", - PresentTo: []uint64{ - 27, - }, - PurgeAttempts: 0, - PurgeTime: 0, - RealityDeviceNumber: 0, - ReferenceID: "sample", - ResID: "sample", - ResName: "sample", - Role: "", - SEPID: 2504, - Shareable: false, - SizeMax: 2, - SizeUsed: 2, - Snapshots: []ItemSnapshot{}, - Status: "ASSIGNED", - TechStatus: "ALLOCATED", - Type: "B", - VMID: 48500, }, }, - }, - ItemDisk{ - MachineID: 0, - MachineName: "", - RecordDisk: RecordDisk{ - DeviceName: "vda", - SEPType: "", - InfoDisk: InfoDisk{ - AccountID: 132852, - AccountName: "std", - ACL: map[string]interface{}{}, - BootPartition: 0, - Computes: map[string]string{ - "48502": "stdvm2", - }, - CreatedTime: 1676982606, - DeletedTime: 0, - Description: "", - DestructionTime: 0, - DiskPath: "", - GID: 212, - GUID: 65193, - ID: 65193, - ImageID: 9885, - Images: []uint64{}, - IOTune: IOTune{ - TotalIOPSSec: 2000, - }, - IQN: "", - Login: "", - Milestones: 363516, - Name: "bootdisk", - Order: 0, - Params: "", - ParentID: 0, - Password: "", - PCISlot: 6, - Pool: "vmstor", - PresentTo: []uint64{ - 27, - 27, + { + MachineID: 0, + MachineName: "", + RecordDisk: RecordDisk{ + DeviceName: "vda", + SEPType: "", + InfoDisk: InfoDisk{ + AccountID: 132852, + AccountName: "std", + ACL: map[string]interface{}{}, + BootPartition: 0, + Computes: map[string]string{ + "48502": "stdvm2", + }, + CreatedTime: 1676982606, + DeletedTime: 0, + Description: "", + DestructionTime: 0, + DiskPath: "", + GID: 212, + GUID: 65193, + ID: 65193, + ImageID: 9885, + Images: []uint64{}, + IOTune: IOTune{ + TotalIOPSSec: 2000, + }, + IQN: "", + Login: "", + Milestones: 363516, + Name: "bootdisk", + Order: 0, + Params: "", + ParentID: 0, + Password: "", + PCISlot: 6, + Pool: "vmstor", + PresentTo: []uint64{ + 27, + 27, + }, + PurgeAttempts: 0, + PurgeTime: 0, + RealityDeviceNumber: 0, + ReferenceID: "sample", + ResID: "sample", + ResName: "sample", + Role: "", + SEPID: 2504, + Shareable: false, + SizeMax: 4, + SizeUsed: 4, + Snapshots: []ItemSnapshot{}, + Status: "ASSIGNED", + TechStatus: "ALLOCATED", + Type: "B", + VMID: 48502, }, - PurgeAttempts: 0, - PurgeTime: 0, - RealityDeviceNumber: 0, - ReferenceID: "sample", - ResID: "sample", - ResName: "sample", - Role: "", - SEPID: 2504, - Shareable: false, - SizeMax: 4, - SizeUsed: 4, - Snapshots: []ItemSnapshot{}, - Status: "ASSIGNED", - TechStatus: "ALLOCATED", - Type: "B", - VMID: 48502, }, }, }, + EntryCount: 2, } func TestFilterByID(t *testing.T) { actual := disks.FilterByID(65193) - if len(actual) == 0 { + if len(actual.Data) == 0 { t.Fatal("No elements were found") } @@ -141,11 +144,11 @@ func TestFilterByID(t *testing.T) { func TestFilterByName(t *testing.T) { actual := disks.FilterByName("bootdisk") - if len(actual) != 2 { - t.Fatal("expected 2 elements, found: ", len(actual)) + if len(actual.Data) != 2 { + t.Fatal("expected 2 elements, found: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.Name != "bootdisk" { t.Fatal("expected 'bootdisk' name, found: ", item.Name) } @@ -155,11 +158,11 @@ func TestFilterByName(t *testing.T) { func TestFilterByStatus(t *testing.T) { actual := disks.FilterByStatus("ASSIGNED") - if len(actual) == 0 { + if len(actual.Data) == 0 { t.Fatal("No elements were found") } - for _, item := range actual { + for _, item := range actual.Data { if item.Status != "ASSIGNED" { t.Fatal("expected 'ASSIGNED' status, found: ", item.Status) } @@ -169,11 +172,11 @@ func TestFilterByStatus(t *testing.T) { func TestFilterByTechStatus(t *testing.T) { actual := disks.FilterByTechStatus("ALLOCATED") - if len(actual) == 0 { + if len(actual.Data) == 0 { t.Fatal("No elements were found") } - for _, item := range actual { + for _, item := range actual.Data { if item.TechStatus != "ALLOCATED" { t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus) } @@ -183,12 +186,12 @@ func TestFilterByTechStatus(t *testing.T) { func TestFilterByImageID(t *testing.T) { actual := disks.FilterByImageID(9885) - if len(actual) == 0 { + if len(actual.Data) == 0 { t.Fatal("No elements were found") } - if actual[0].ImageID != 9885 { - t.Fatal("expected 9885 ImageID, found: ", actual[0].ImageID) + if actual.Data[0].ImageID != 9885 { + t.Fatal("expected 9885 ImageID, found: ", actual.Data[0].ImageID) } } @@ -197,25 +200,25 @@ func TestFilterFunc(t *testing.T) { return len(id.PresentTo) == 2 }) - if len(actual) == 0 { + if len(actual.Data) == 0 { t.Fatal("No elements were found") } - if len(actual[0].PresentTo) != 2 { - t.Fatal("expected 2 elements in PresentTo, found: ", len(actual[0].PresentTo)) + if len(actual.Data[0].PresentTo) != 2 { + t.Fatal("expected 2 elements in PresentTo, found: ", len(actual.Data[0].PresentTo)) } } func TestSortByCreatedTime(t *testing.T) { actual := disks.SortByCreatedTime(false) - if actual[0].ID != 65191 { - t.Fatal("expected ID 65191, found: ", actual[0].ID) + if actual.Data[0].ID != 65191 { + t.Fatal("expected ID 65191, found: ", actual.Data[0].ID) } actual = disks.SortByCreatedTime(true) - if actual[0].ID != 65193 { - t.Fatal("expected ID 65193, found: ", actual[0].ID) + if actual.Data[0].ID != 65193 { + t.Fatal("expected ID 65193, found: ", actual.Data[0].ID) } } diff --git a/pkg/cloudbroker/disks/list.go b/pkg/cloudbroker/disks/list.go index 11cb0e7..fcbadec 100644 --- a/pkg/cloudbroker/disks/list.go +++ b/pkg/cloudbroker/disks/list.go @@ -8,6 +8,30 @@ import ( // Request struct for get list/list_deleted of disks type ListRequest struct { + // Find by id + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account name + // Required: false + AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"` + + // Find by max size disk + // Required: false + DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Find by shared, true or false + // Required: false + Shared bool `url:"shared,omitempty" json:"shared,omitempty"` + // ID of the account the disks belong to // Required: false AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` @@ -26,7 +50,7 @@ type ListRequest struct { } // List gets list the created disks belonging to an account -func (d Disks) List(ctx context.Context, req ListRequest) (ListDisks, error) { +func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) { url := "/cloudbroker/disks/list" res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -41,5 +65,5 @@ func (d Disks) List(ctx context.Context, req ListRequest) (ListDisks, error) { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/disks/list_deleted.go b/pkg/cloudbroker/disks/list_deleted.go index b723cf8..78d099c 100644 --- a/pkg/cloudbroker/disks/list_deleted.go +++ b/pkg/cloudbroker/disks/list_deleted.go @@ -8,6 +8,26 @@ import ( // Request struct for get list deleted disks type ListDeletedRequest struct { + // Find by id + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by account name + // Required: false + AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"` + + // Find by max size disk + // Required: false + DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"` + + // Find by shared, true or false + // Required: false + Shared bool `url:"shared,omitempty" json:"shared,omitempty"` + // ID of the account the disks belong to // Required: false AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` @@ -26,7 +46,7 @@ type ListDeletedRequest struct { } // ListDeleted gets list the deleted disks based on filter -func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeletedDisks, error) { +func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListDisks, error) { url := "/cloudbroker/disks/listDeleted" res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -34,12 +54,12 @@ func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDel return nil, err } - list := ListDeletedDisks{} + list := ListDisks{} err = json.Unmarshal(res, &list) if err != nil { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/disks/list_types.go b/pkg/cloudbroker/disks/list_types.go index 61c9bce..e591cc3 100644 --- a/pkg/cloudbroker/disks/list_types.go +++ b/pkg/cloudbroker/disks/list_types.go @@ -11,12 +11,20 @@ import ( // Request struct for get list types of disks type ListTypesRequest struct { // Show detailed disk types by seps - // Required: true - Detailed bool `url:"detailed" json:"detailed" validate:"required"` + // Required: false + Detailed bool `url:"detailed" json:"detailed"` + + // Page number + // Required: false + Page uint64 `url:"page,omitempty" json:"page,omitempty"` + + // Page size + // Required: false + Size uint64 `url:"size,omitempty" json:"size,omitempty"` } // ListTypes gets list defined disk types -func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface{}, error) { +func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) (*ListTypes, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -31,13 +39,13 @@ func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface return nil, err } - list := make([]interface{}, 0) + list := ListTypes{} err = json.Unmarshal(res, &list) if err != nil { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/disks/list_unattached.go b/pkg/cloudbroker/disks/list_unattached.go index e24d015..3aa7e63 100644 --- a/pkg/cloudbroker/disks/list_unattached.go +++ b/pkg/cloudbroker/disks/list_unattached.go @@ -8,6 +8,30 @@ import ( // Request struct for get list unattached disk type ListUnattachedRequest struct { + // Find by id + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by account name + // Required: false + AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"` + + // Find by max size disk + // Required: false + DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + + // Find by shared, true or false + // Required: false + Shared bool `url:"shared,omitempty" json:"shared,omitempty"` + + // Type of the disks + // Required: false + Type string `url:"type,omitempty" json:"type,omitempty"` + // ID of the account // Required: false AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` @@ -22,7 +46,7 @@ type ListUnattachedRequest struct { } // ListUnattached gets list of unattached disks -func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (ListUnattachedDisks, error) { +func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (*ListUnattachedDisks, error) { url := "/cloudbroker/disks/listUnattached" res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -37,5 +61,5 @@ func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (L return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/disks/models.go b/pkg/cloudbroker/disks/models.go index a7e5618..d114412 100644 --- a/pkg/cloudbroker/disks/models.go +++ b/pkg/cloudbroker/disks/models.go @@ -199,28 +199,16 @@ type ItemDisk struct { } // List disks -type ListDisks []ItemDisk +type ListDisks struct { + // Data + Data []ItemDisk `json:"data"` -// Main information about deleted disk -type ItemDeletedDisk struct { - // Machine ID - MachineID uint64 `json:"machineId"` - - // Machine name - MachineName string `json:"machineName"` - - // Detailed information about disk - RecordDisk - - // Updated by - UpdatedBy uint64 `json:"updatedBy"` - - // Updated time - UpdatedTime uint64 `json:"updatedTime"` + // Entry count + EntryCount uint64 `json:"entryCount"` } -// List deleted disks -type ListDeletedDisks []ItemDeletedDisk +// ListSearchDisks +type SearchListDisks []ItemDisk // Main information about unattached disk type ItemUnattachedDisk struct { @@ -241,7 +229,13 @@ type ItemUnattachedDisk struct { } // List unattached disks -type ListUnattachedDisks []ItemUnattachedDisk +type ListUnattachedDisks struct { + // Data + Data []ItemUnattachedDisk `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Main information about snapshot type ItemSnapshot struct { @@ -269,3 +263,11 @@ type ItemSnapshot struct { // List snapshots type ListSnapshots []ItemSnapshot + +type ListTypes struct { + // Data + Data []interface{} `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} diff --git a/pkg/cloudbroker/disks/search.go b/pkg/cloudbroker/disks/search.go index 12c68ee..8f062e2 100644 --- a/pkg/cloudbroker/disks/search.go +++ b/pkg/cloudbroker/disks/search.go @@ -29,7 +29,7 @@ type SearchRequest struct { } // Search search disks -func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error) { +func (d Disks) Search(ctx context.Context, req SearchRequest) (SearchListDisks, error) { url := "/cloudbroker/disks/search" res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -37,7 +37,7 @@ func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error) return nil, err } - list := ListDisks{} + list := SearchListDisks{} err = json.Unmarshal(res, &list) if err != nil { diff --git a/pkg/cloudbroker/disks/serialize.go b/pkg/cloudbroker/disks/serialize.go index 2de9476..1128394 100644 --- a/pkg/cloudbroker/disks/serialize.go +++ b/pkg/cloudbroker/disks/serialize.go @@ -12,7 +12,7 @@ import ( // - First argument -> prefix // - Second argument -> indent func (ld ListDisks) Serialize(params ...string) (serialization.Serialized, error) { - if len(ld) == 0 { + if len(ld.Data) == 0 { return []byte{}, nil } diff --git a/pkg/cloudbroker/disks/sorting.go b/pkg/cloudbroker/disks/sorting.go index 56891f9..7a973b8 100644 --- a/pkg/cloudbroker/disks/sorting.go +++ b/pkg/cloudbroker/disks/sorting.go @@ -6,16 +6,16 @@ import "sort" // // If inverse param is set to true, the order is reversed. func (ld ListDisks) SortByCreatedTime(inverse bool) ListDisks { - if len(ld) < 2 { + if len(ld.Data) < 2 { return ld } - sort.Slice(ld, func(i, j int) bool { + sort.Slice(ld.Data, func(i, j int) bool { if inverse { - return ld[i].CreatedTime > ld[j].CreatedTime + return ld.Data[i].CreatedTime > ld.Data[j].CreatedTime } - return ld[i].CreatedTime < ld[j].CreatedTime + return ld.Data[i].CreatedTime < ld.Data[j].CreatedTime }) return ld @@ -25,16 +25,16 @@ func (ld ListDisks) SortByCreatedTime(inverse bool) ListDisks { // // If inverse param is set to true, the order is reversed. func (ld ListDisks) SortByDestructionTime(inverse bool) ListDisks { - if len(ld) < 2 { + if len(ld.Data) < 2 { return ld } - sort.Slice(ld, func(i, j int) bool { + sort.Slice(ld.Data, func(i, j int) bool { if inverse { - return ld[i].DestructionTime > ld[j].DestructionTime + return ld.Data[i].DestructionTime > ld.Data[j].DestructionTime } - return ld[i].DestructionTime < ld[j].DestructionTime + return ld.Data[i].DestructionTime < ld.Data[j].DestructionTime }) return ld @@ -44,16 +44,16 @@ func (ld ListDisks) SortByDestructionTime(inverse bool) ListDisks { // // If inverse param is set to true, the order is reversed. func (ld ListDisks) SortByDeletedTime(inverse bool) ListDisks { - if len(ld) < 2 { + if len(ld.Data) < 2 { return ld } - sort.Slice(ld, func(i, j int) bool { + sort.Slice(ld.Data, func(i, j int) bool { if inverse { - return ld[i].DeletedTime > ld[j].DeletedTime + return ld.Data[i].DeletedTime > ld.Data[j].DeletedTime } - return ld[i].DeletedTime < ld[j].DeletedTime + return ld.Data[i].DeletedTime < ld.Data[j].DeletedTime }) return ld diff --git a/pkg/cloudbroker/extnet/create.go b/pkg/cloudbroker/extnet/create.go index d595714..48fd109 100644 --- a/pkg/cloudbroker/extnet/create.go +++ b/pkg/cloudbroker/extnet/create.go @@ -23,14 +23,14 @@ type CreateRequest struct { // Required: true IPCIDR string `url:"ipcidr" json:"ipcidr" validate:"required"` - // External network gateway IP address - // Required: true - Gateway string `url:"gateway" json:"gateway" validate:"required"` - // VLAN ID // Required: true VLANID uint64 `url:"vlanId" json:"vlanId" validate:"required"` + // External network gateway IP address + // Required: false + Gateway string `url:"gateway,omitempty" json:"gateway,omitempty"` + // List of DNS addresses // Required: false DNS []string `url:"dns,omitempty" json:"dns,omitempty"` diff --git a/pkg/cloudbroker/extnet/filter.go b/pkg/cloudbroker/extnet/filter.go index 56f13a3..5b21c55 100644 --- a/pkg/cloudbroker/extnet/filter.go +++ b/pkg/cloudbroker/extnet/filter.go @@ -31,21 +31,23 @@ func (lenet ListExtNet) FilterByStatus(status string) ListExtNet { func (lenet ListExtNet) FilterFunc(predicate func(ItemExtNet) bool) ListExtNet { var result ListExtNet - for _, item := range lenet { + for _, item := range lenet.Data { if predicate(item) { - result = append(result, item) + result.Data = append(result.Data, item) } } + result.EntryCount = uint64(len(lenet.Data)) + return result } // FindOne returns first found ItemExtNet // If none was found, returns an empty struct. func (lenet ListExtNet) FindOne() ItemExtNet { - if len(lenet) == 0 { + if len(lenet.Data) == 0 { return ItemExtNet{} } - return lenet[0] + return lenet.Data[0] } diff --git a/pkg/cloudbroker/extnet/filter_test.go b/pkg/cloudbroker/extnet/filter_test.go index 5da2e34..e92a0b3 100644 --- a/pkg/cloudbroker/extnet/filter_test.go +++ b/pkg/cloudbroker/extnet/filter_test.go @@ -3,74 +3,76 @@ package extnet import "testing" var extnets = ListExtNet{ - ItemExtNet{ - CKey: "", - Meta: []interface{}{}, - CheckIPs: []string{}, - Default: false, - DefaultQOS: QOS{}, - Description: "", - FreeIPs: 0, - GID: 212, - GUID: 3, - ID: 3, - IPCIDR: "176.118.164.0/24", - Milestones: 1355466, - Name: "176.118.164.0/24", - NetworkID: 0, - OVSBridge: "", - PreReservationsNum: 0, - PriVNFDevID: 0, - SharedWith: []interface{}{}, - Status: "ENABLED", - VLANID: 0, - VNFs: VNFs{}, - }, - ItemExtNet{ - CKey: "", - Meta: []interface{}{}, - CheckIPs: []string{}, - Default: false, - DefaultQOS: QOS{}, - Description: "", - FreeIPs: 0, - GID: 212, - GUID: 10, - ID: 10, - IPCIDR: "45.134.255.0/24", - Milestones: 2135543, - Name: "45.134.255.0/24", - NetworkID: 0, - OVSBridge: "", - PreReservationsNum: 0, - PriVNFDevID: 0, - SharedWith: []interface{}{}, - Status: "ENABLED", - VLANID: 0, - VNFs: VNFs{}, - }, - ItemExtNet{ - CKey: "", - Meta: []interface{}{}, - CheckIPs: []string{}, - Default: false, - DefaultQOS: QOS{}, - Description: "", - FreeIPs: 0, - GID: 212, - GUID: 13, - ID: 13, - IPCIDR: "88.218.249.0/24", - Milestones: 1232134, - Name: "88.218.249.0/24", - NetworkID: 0, - OVSBridge: "", - PreReservationsNum: 0, - PriVNFDevID: 0, - SharedWith: []interface{}{}, - Status: "DISABLED", - VLANID: 0, - VNFs: VNFs{}, + Data: []ItemExtNet{ + { + CKey: "", + Meta: []interface{}{}, + CheckIPs: []string{}, + Default: false, + DefaultQOS: QOS{}, + Description: "", + FreeIPs: 0, + GID: 212, + GUID: 3, + ID: 3, + IPCIDR: "176.118.164.0/24", + Milestones: 1355466, + Name: "176.118.164.0/24", + NetworkID: 0, + OVSBridge: "", + PreReservationsNum: 0, + PriVNFDevID: 0, + SharedWith: []interface{}{}, + Status: "ENABLED", + VLANID: 0, + VNFs: VNFs{}, + }, + { + CKey: "", + Meta: []interface{}{}, + CheckIPs: []string{}, + Default: false, + DefaultQOS: QOS{}, + Description: "", + FreeIPs: 0, + GID: 212, + GUID: 10, + ID: 10, + IPCIDR: "45.134.255.0/24", + Milestones: 2135543, + Name: "45.134.255.0/24", + NetworkID: 0, + OVSBridge: "", + PreReservationsNum: 0, + PriVNFDevID: 0, + SharedWith: []interface{}{}, + Status: "ENABLED", + VLANID: 0, + VNFs: VNFs{}, + }, + { + CKey: "", + Meta: []interface{}{}, + CheckIPs: []string{}, + Default: false, + DefaultQOS: QOS{}, + Description: "", + FreeIPs: 0, + GID: 212, + GUID: 13, + ID: 13, + IPCIDR: "88.218.249.0/24", + Milestones: 1232134, + Name: "88.218.249.0/24", + NetworkID: 0, + OVSBridge: "", + PreReservationsNum: 0, + PriVNFDevID: 0, + SharedWith: []interface{}{}, + Status: "DISABLED", + VLANID: 0, + VNFs: VNFs{}, + }, }, } @@ -94,11 +96,11 @@ func TestFilterByName(t *testing.T) { func TestFilterByStatus(t *testing.T) { actual := extnets.FilterByStatus("ENABLED") - if len(actual) != 2 { - t.Fatal("expected 2 found, actual: ", len(actual)) + if len(actual.Data) != 2 { + t.Fatal("expected 2 found, actual: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.Status != "ENABLED" { t.Fatal("expected Status 'ENABLED', found: ", item.Status) } @@ -110,7 +112,7 @@ func TestFilterFunc(t *testing.T) { return ien.IPCIDR == ien.Name }) - if len(actual) != 3 { - t.Fatal("expected 3 elements, found: ", len(actual)) + if len(actual.Data) != 3 { + t.Fatal("expected 3 elements, found: ", len(actual.Data)) } } diff --git a/pkg/cloudbroker/extnet/list.go b/pkg/cloudbroker/extnet/list.go index 63e6278..4bd64c4 100644 --- a/pkg/cloudbroker/extnet/list.go +++ b/pkg/cloudbroker/extnet/list.go @@ -8,10 +8,34 @@ import ( // Request struct for get list external network type ListRequest struct { - // Filter by account ID + // Find by account ID // Required: false AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by network ip address + // Required: false + Network string `url:"network,omitempty" json:"network,omitempty"` + + // Find by vlan ID + // Required: false + VLANID uint64 `url:"vlanId,omitempty" json:"vlanId,omitempty"` + + // Find by vnfDevices ID + // Required: false + VNFDevID uint64 `url:"vnfDevId,omitempty" json:"vnfDevId,omitempty"` + + // Find by status + // Required: false + Status string `url:"status,omitempty" json:"status,omitempty"` + // Page number // Required: false Page uint64 `url:"page,omitempty" json:"page,omitempty"` @@ -22,7 +46,7 @@ type ListRequest struct { } // List gets list all available external networks -func (e ExtNet) List(ctx context.Context, req ListRequest) (ListExtNet, error) { +func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNet, error) { url := "/cloudbroker/extnet/list" res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -37,5 +61,5 @@ func (e ExtNet) List(ctx context.Context, req ListRequest) (ListExtNet, error) { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/extnet/models.go b/pkg/cloudbroker/extnet/models.go index 0ad4aae..203216b 100644 --- a/pkg/cloudbroker/extnet/models.go +++ b/pkg/cloudbroker/extnet/models.go @@ -117,18 +117,21 @@ type ItemExtNet struct { } // List external networks -type ListExtNet []ItemExtNet +type ListExtNet struct { + // Data + Data []ItemExtNet `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Detailed information about external network type RecordExtNet struct { // Main information about external network ItemExtNet - // CheckIPs - CheckIPs []string `json:"checkIPs"` - // CheckIps - CheckIps []string `json:"checkIps"` + CheckIPs []string `json:"checkIps"` // List DNS DNS []string `json:"dns"` diff --git a/pkg/cloudbroker/extnet/serialize.go b/pkg/cloudbroker/extnet/serialize.go index a80dd53..762d114 100644 --- a/pkg/cloudbroker/extnet/serialize.go +++ b/pkg/cloudbroker/extnet/serialize.go @@ -12,7 +12,7 @@ import ( // - First argument -> prefix // - Second argument -> indent func (lenet ListExtNet) Serialize(params ...string) (serialization.Serialized, error) { - if len(lenet) == 0 { + if len(lenet.Data) == 0 { return []byte{}, nil } diff --git a/pkg/cloudbroker/grid/filter.go b/pkg/cloudbroker/grid/filter.go index de17d12..cbea1b8 100644 --- a/pkg/cloudbroker/grid/filter.go +++ b/pkg/cloudbroker/grid/filter.go @@ -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] } diff --git a/pkg/cloudbroker/grid/filter_test.go b/pkg/cloudbroker/grid/filter_test.go index b1f3c53..2cf82ad 100644 --- a/pkg/cloudbroker/grid/filter_test.go +++ b/pkg/cloudbroker/grid/filter_test.go @@ -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) { diff --git a/pkg/cloudbroker/grid/get_resource_consumption.go b/pkg/cloudbroker/grid/get_resource_consumption.go new file mode 100644 index 0000000..afd6c40 --- /dev/null +++ b/pkg/cloudbroker/grid/get_resource_consumption.go @@ -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 +} diff --git a/pkg/cloudbroker/grid/list.go b/pkg/cloudbroker/grid/list.go index a30bdbb..1c3101d 100644 --- a/pkg/cloudbroker/grid/list.go +++ b/pkg/cloudbroker/grid/list.go @@ -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 } diff --git a/pkg/cloudbroker/grid/list_emails.go b/pkg/cloudbroker/grid/list_emails.go index 8f59ad2..71a9151 100644 --- a/pkg/cloudbroker/grid/list_emails.go +++ b/pkg/cloudbroker/grid/list_emails.go @@ -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 } diff --git a/pkg/cloudbroker/grid/list_resource_consumption.go b/pkg/cloudbroker/grid/list_resource_consumption.go new file mode 100644 index 0000000..0891f19 --- /dev/null +++ b/pkg/cloudbroker/grid/list_resource_consumption.go @@ -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 +} diff --git a/pkg/cloudbroker/grid/models.go b/pkg/cloudbroker/grid/models.go index f70526d..688a329 100644 --- a/pkg/cloudbroker/grid/models.go +++ b/pkg/cloudbroker/grid/models.go @@ -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"` +} diff --git a/pkg/cloudbroker/grid/serialize.go b/pkg/cloudbroker/grid/serialize.go index 5210435..b6423f3 100644 --- a/pkg/cloudbroker/grid/serialize.go +++ b/pkg/cloudbroker/grid/serialize.go @@ -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 } diff --git a/pkg/cloudbroker/image/delete.go b/pkg/cloudbroker/image/delete.go index fdc3c90..8463c22 100644 --- a/pkg/cloudbroker/image/delete.go +++ b/pkg/cloudbroker/image/delete.go @@ -16,7 +16,7 @@ type DeleteRequest struct { // Reason for action // Required: true - Reason string `url:"reason" json:"reason" validate:"required"` + Reason string `url:"reason,omitempty" json:"reason,omitempty"` // Whether to completely delete the image // Required: false diff --git a/pkg/cloudbroker/image/filter.go b/pkg/cloudbroker/image/filter.go index 55b3f40..44295e5 100644 --- a/pkg/cloudbroker/image/filter.go +++ b/pkg/cloudbroker/image/filter.go @@ -49,9 +49,9 @@ func (li ListImages) FilterByBootType(bootType string) ListImages { func (li ListImages) FilterFunc(predicate func(RecordImage) bool) ListImages { var result ListImages - for _, item := range li { + for _, item := range li.Data { if predicate(item) { - result = append(result, item) + result.Data = append(result.Data, item) } } @@ -61,9 +61,9 @@ func (li ListImages) FilterFunc(predicate func(RecordImage) bool) ListImages { // FindOne returns first found RecordImage // If none was found, returns an empty struct. func (li ListImages) FindOne() RecordImage { - if len(li) == 0 { + if len(li.Data) == 0 { return RecordImage{} } - return li[0] + return li.Data[0] } diff --git a/pkg/cloudbroker/image/filter_test.go b/pkg/cloudbroker/image/filter_test.go index 64c9e50..8c91556 100644 --- a/pkg/cloudbroker/image/filter_test.go +++ b/pkg/cloudbroker/image/filter_test.go @@ -3,155 +3,157 @@ package image import "testing" var images = ListImages{ - RecordImage{ - UNCPath: "", - CKey: "", - Meta: []interface{}{ - "osismodel", - "cloudbroker", - "image", - 1, + Data: []RecordImage{ + { + UNCPath: "", + CKey: "", + Meta: []interface{}{ + "osismodel", + "cloudbroker", + "image", + 1, + }, + AccountID: 0, + ACL: []ACL{}, + Architecture: "X86_64", + BootType: "bios", + Bootable: true, + ComputeCIID: 0, + DeletedTime: 0, + Description: "", + Drivers: []string{ + "KVM_X86", + }, + Enabled: true, + GID: 212, + GUID: 9882, + History: []History{}, + HotResize: true, + ID: 9882, + LastModified: 0, + LinkTo: 0, + Milestones: 363491, + Name: "u16", + Password: "", + Pool: "vmstor", + PresentTo: []uint64{}, + ProviderName: "", + PurgeAttempts: 0, + ReferenceID: "sample_reference_id_u16", + ResID: "b321318-3214as-324-213-fdas", + ResName: "templates/image_9882", + RescueCD: false, + SEPID: 2504, + SharedWith: []uint64{}, + Size: 5, + Status: "CREATED", + TechStatus: "ALLOCATED", + Type: "linux", + URL: "http://sample_url:8000/u16", + Username: "", + Version: "", + Virtual: false, }, - AccountID: 0, - ACL: []ACL{}, - Architecture: "X86_64", - BootType: "bios", - Bootable: true, - ComputeCIID: 0, - DeletedTime: 0, - Description: "", - Drivers: []string{ - "KVM_X86", + { + UNCPath: "", + CKey: "", + Meta: []interface{}{ + "osismodel", + "cloudbroker", + "image", + 1, + }, + AccountID: 0, + ACL: []ACL{}, + Architecture: "X86_64", + BootType: "bois", + Bootable: true, + ComputeCIID: 0, + DeletedTime: 0, + Description: "", + Drivers: []string{ + "KVM_X86", + }, + Enabled: false, + GID: 212, + GUID: 9884, + History: []History{}, + HotResize: false, + ID: 9884, + LastModified: 0, + LinkTo: 0, + Milestones: 363499, + Name: "alpine-virt-3.17", + Password: "", + Pool: "vmstor", + PresentTo: []uint64{}, + ProviderName: "", + PurgeAttempts: 0, + ReferenceID: "sample_reference_id_alpine", + ResID: "31d1d410-74f1-4e09-866b-046a5a8433c3", + ResName: "templates/image_9884", + RescueCD: false, + SEPID: 2504, + SharedWith: []uint64{}, + Size: 1, + Status: "CREATED", + TechStatus: "ALLOCATED", + Type: "linux", + URL: "http://sample_url:8000/alpine-virt-3", + Username: "", + Version: "", + Virtual: true, }, - Enabled: true, - GID: 212, - GUID: 9882, - History: []History{}, - HotResize: true, - ID: 9882, - LastModified: 0, - LinkTo: 0, - Milestones: 363491, - Name: "u16", - Password: "", - Pool: "vmstor", - PresentTo: []uint64{}, - ProviderName: "", - PurgeAttempts: 0, - ReferenceID: "sample_reference_id_u16", - ResID: "b321318-3214as-324-213-fdas", - ResName: "templates/image_9882", - RescueCD: false, - SEPID: 2504, - SharedWith: []uint64{}, - Size: 5, - Status: "CREATED", - TechStatus: "ALLOCATED", - Type: "linux", - URL: "http://sample_url:8000/u16", - Username: "", - Version: "", - Virtual: false, - }, - RecordImage{ - UNCPath: "", - CKey: "", - Meta: []interface{}{ - "osismodel", - "cloudbroker", - "image", - 1, - }, - AccountID: 0, - ACL: []ACL{}, - Architecture: "X86_64", - BootType: "bois", - Bootable: true, - ComputeCIID: 0, - DeletedTime: 0, - Description: "", - Drivers: []string{ - "KVM_X86", - }, - Enabled: false, - GID: 212, - GUID: 9884, - History: []History{}, - HotResize: false, - ID: 9884, - LastModified: 0, - LinkTo: 0, - Milestones: 363499, - Name: "alpine-virt-3.17", - Password: "", - Pool: "vmstor", - PresentTo: []uint64{}, - ProviderName: "", - PurgeAttempts: 0, - ReferenceID: "sample_reference_id_alpine", - ResID: "31d1d410-74f1-4e09-866b-046a5a8433c3", - ResName: "templates/image_9884", - RescueCD: false, - SEPID: 2504, - SharedWith: []uint64{}, - Size: 1, - Status: "CREATED", - TechStatus: "ALLOCATED", - Type: "linux", - URL: "http://sample_url:8000/alpine-virt-3", - Username: "", - Version: "", - Virtual: true, - }, - RecordImage{ - UNCPath: "", - CKey: "", - Meta: []interface{}{ - "osismodel", - "cloudbroker", - "image", - 1, - }, - AccountID: 1, - ACL: []ACL{}, - Architecture: "X86_64", - BootType: "bios", - Bootable: true, - ComputeCIID: 0, - DeletedTime: 0, - Description: "", - Drivers: []string{ - "KVM_X86", + { + UNCPath: "", + CKey: "", + Meta: []interface{}{ + "osismodel", + "cloudbroker", + "image", + 1, + }, + AccountID: 1, + ACL: []ACL{}, + Architecture: "X86_64", + BootType: "bios", + Bootable: true, + ComputeCIID: 0, + DeletedTime: 0, + Description: "", + Drivers: []string{ + "KVM_X86", + }, + Enabled: true, + GID: 212, + GUID: 9885, + History: []History{}, + HotResize: true, + ID: 9885, + LastModified: 0, + LinkTo: 0, + Milestones: 363513, + Name: "test", + Password: "", + Pool: "vmstor", + PresentTo: []uint64{}, + ProviderName: "", + PurgeAttempts: 0, + ReferenceID: "sample_reference_id_test", + ResID: "1f53b815-1ac9-4a4b-af98-a0a3b69a34bb", + ResName: "templates/image_9885", + RescueCD: false, + SEPID: 2505, + SharedWith: []uint64{}, + Size: 4, + Status: "DESTROYED", + TechStatus: "ALLOCATED", + Type: "linux", + URL: "http://sample_url:8000/test", + Username: "", + Version: "", + Virtual: false, }, - Enabled: true, - GID: 212, - GUID: 9885, - History: []History{}, - HotResize: true, - ID: 9885, - LastModified: 0, - LinkTo: 0, - Milestones: 363513, - Name: "test", - Password: "", - Pool: "vmstor", - PresentTo: []uint64{}, - ProviderName: "", - PurgeAttempts: 0, - ReferenceID: "sample_reference_id_test", - ResID: "1f53b815-1ac9-4a4b-af98-a0a3b69a34bb", - ResName: "templates/image_9885", - RescueCD: false, - SEPID: 2505, - SharedWith: []uint64{}, - Size: 4, - Status: "DESTROYED", - TechStatus: "ALLOCATED", - Type: "linux", - URL: "http://sample_url:8000/test", - Username: "", - Version: "", - Virtual: false, }, } @@ -159,56 +161,56 @@ func TestFilterByID(t *testing.T) { actual := images.FilterByID(9885).FindOne() if actual.ID != 9885 { - t.Fatal("expected ID 9885, found: ", actual.ID) + t.Fatal("expected ID 9885, found: ", actual.ID) } } func TestFilterByName(t *testing.T) { - actual := images.FilterByName("u16").FindOne() + actual := images.FilterByName("u16").FindOne() - if actual.Name != "u16" { - t.Fatal("expected Name 'u16', found: ", actual.Name) - } + if actual.Name != "u16" { + t.Fatal("expected Name 'u16', found: ", actual.Name) + } } func TestFilterByStatus(t *testing.T) { - actual := images.FilterByStatus("CREATED") + actual := images.FilterByStatus("CREATED") - if len(actual) != 2 { - t.Fatal("expected 2 found, actual: ", len(actual)) - } + if len(actual.Data) != 2 { + t.Fatal("expected 2 found, actual: ", len(actual.Data)) + } - for _, item := range actual { - if item.Status != "CREATED" { - t.Fatal("expected Status 'CREATED', found: ", item.Status) - } - } + for _, item := range actual.Data { + if item.Status != "CREATED" { + t.Fatal("expected Status 'CREATED', found: ", item.Status) + } + } } func TestFilterByBootType(t *testing.T) { - actual := images.FilterByBootType("bios") + actual := images.FilterByBootType("bios") - if len(actual) != 2 { - t.Fatal("expected 2 found, actual: ", len(actual)) - } + if len(actual.Data) != 2 { + t.Fatal("expected 2 found, actual: ", len(actual.Data)) + } - for _, item := range actual { - if item.BootType != "bios" { - t.Fatal("expected BootType 'bios', found: ", item.BootType) - } - } + for _, item := range actual.Data { + if item.BootType != "bios" { + t.Fatal("expected BootType 'bios', found: ", item.BootType) + } + } } func TestFilterFunc(t *testing.T) { - actual := images.FilterFunc(func(ri RecordImage) bool { - return ri.Virtual == true - }) + actual := images.FilterFunc(func(ri RecordImage) bool { + return ri.Virtual == true + }) - if len(actual) != 1 { - t.Fatal("expected 1 found, actual: ", len(actual)) - } + if len(actual.Data) != 1 { + t.Fatal("expected 1 found, actual: ", len(actual.Data)) + } - if actual[0].Virtual != true { - t.Fatal("expected Virtual true, found false") - } + if actual.Data[0].Virtual != true { + t.Fatal("expected Virtual true, found false") + } } diff --git a/pkg/cloudbroker/image/list.go b/pkg/cloudbroker/image/list.go index 39a30c7..69aeadf 100644 --- a/pkg/cloudbroker/image/list.go +++ b/pkg/cloudbroker/image/list.go @@ -12,9 +12,49 @@ type ListRequest struct { // Required: false SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"` - // Filter images by account ID availability + // Find by ID // Required: false - SharedWith uint64 `url:"sharedWith,omitempty" json:"sharedWith,omitempty"` + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // 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 architecture + // Required: false + Architecture string `url:"architecture,omitempty" json:"architecture,omitempty"` + + // Find by type + // Required: false + TypeImage string `url:"typeImage,omitempty" json:"typeImage,omitempty"` + + // Find by image size + // Required: false + ImageSize uint64 `url:"imageSize,omitempty" json:"imageSize,omitempty"` + + // Find by SEP name + // Required: false + SEPName string `url:"sepName,omitempty" json:"sepName,omitempty"` + + // Find by pool + // Required: false + Pool string `url:"pool,omitempty" json:"pool,omitempty"` + + // Find by public True or False + // Required: false + Public bool `url:"public,omitempty" json:"public,omitempty"` + + // Find by hot resize True or False + // Required: false + HotResize bool `url:"hotResize,omitempty" json:"hotResize,omitempty"` + + // Find by bootable True or False + // Required: false + Bootable bool `url:"bootable,omitempty" json:"bootable,omitempty"` // Page number // Required: false @@ -26,7 +66,7 @@ type ListRequest struct { } // List gets list of information about images -func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) { +func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) { url := "/cloudbroker/image/list" res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -41,5 +81,5 @@ func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/image/list_stacks.go b/pkg/cloudbroker/image/list_stacks.go index f40180e..7808f3e 100644 --- a/pkg/cloudbroker/image/list_stacks.go +++ b/pkg/cloudbroker/image/list_stacks.go @@ -21,10 +21,22 @@ type ListStacksRequest struct { // Page size // Required: false Size uint64 `url:"size,omitempty" json:"size,omitempty"` + + // Find by name + // 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 type + // Required: false + Type string `url:"type,omitempty" json:"type,omitempty"` } // ListStacks gets list stack by image ID -func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (ListStacks, error) { +func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (*ListStacks, error) { err := validators.ValidateRequest(req) if err != nil { for _, validationError := range validators.GetErrors(err) { @@ -46,5 +58,5 @@ func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (ListStack return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/image/models.go b/pkg/cloudbroker/image/models.go index 11df2cd..87a28db 100644 --- a/pkg/cloudbroker/image/models.go +++ b/pkg/cloudbroker/image/models.go @@ -127,7 +127,13 @@ type RecordImage struct { } // List images -type ListImages []RecordImage +type ListImages struct { + // Data + Data []RecordImage `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Access Control List type ACL struct { @@ -156,7 +162,7 @@ type ListACL []ACL // History information type History struct { // GUID - GUID string `json:"guid"` + GUID uint64 `json:"guid"` // ID ID uint64 `json:"id"` @@ -169,61 +175,75 @@ type History struct { type ListHistory []History // List stacks -type ListStacks []struct { - // CKey - CKey string `json:"_ckey"` +type ListStacks struct { + Data []struct { + // CKey + CKey string `json:"_ckey"` - // Meta - Meta []interface{} `json:"_meta"` + // Meta + Meta []interface{} `json:"_meta"` - // API URL - APIURL string `json:"apiUrl"` + // API URL + APIURL string `json:"apiUrl"` - // API key - APIKey string `json:"apikey"` + // API key + APIKey string `json:"apikey"` - // App ID - AppID string `json:"appId"` + // App ID + AppID string `json:"appId"` - // Description - Description string `json:"desc"` + // CPU allocation ratio + CPUAllocationRatio float64 `json:"cpu_allocation_ratio"` - // Drivers - Drivers []string `json:"drivers"` + // Description + Description string `json:"desc"` - // Eco - Eco interface{} `json:"eco"` + // Descr + Descr string `json:"descr"` - // Error - Error uint64 `json:"error"` + // Drivers + Drivers []string `json:"drivers"` - // Grid ID - GID uint64 `json:"gid"` + // Eco + Eco interface{} `json:"eco"` - // GID - GUID uint64 `json:"guid"` + // Error + Error uint64 `json:"error"` - // ID - ID uint64 `json:"id"` + // Grid ID + GID uint64 `json:"gid"` - // List image IDs - Images []uint64 `json:"images"` + // GID + GUID uint64 `json:"guid"` - // Login - Login string `json:"login"` + // ID + ID uint64 `json:"id"` - // Name - Name string `json:"name"` + // List image IDs + Images []uint64 `json:"images"` - // Password - Password string `json:"passwd"` + // Login + Login string `json:"login"` - // Reference ID - ReferenceID string `json:"referenceId"` + // Mem allocation ratio + // Required: false + MemAllocationRatio float64 `json:"mem_allocation_ratio"` - // Status - Status string `json:"status"` + // Name + Name string `json:"name"` - // Type - Type string `json:"type"` + // Password + Password string `json:"passwd"` + + // Reference ID + ReferenceID string `json:"referenceId"` + + // Status + Status string `json:"status"` + + // Type + Type string `json:"type"` + } `json:"data"` + + EntryCount uint64 `json:"entryCount"` } diff --git a/pkg/cloudbroker/image/serialize.go b/pkg/cloudbroker/image/serialize.go index 3b962b4..8f53fe8 100644 --- a/pkg/cloudbroker/image/serialize.go +++ b/pkg/cloudbroker/image/serialize.go @@ -12,7 +12,7 @@ import ( // - First argument -> prefix // - Second argument -> indent func (li ListImages) Serialize(params ...string) (serialization.Serialized, error) { - if len(li) == 0 { + if len(li.Data) == 0 { return []byte{}, nil } diff --git a/pkg/cloudbroker/k8ci/create.go b/pkg/cloudbroker/k8ci/create.go index bcbab08..4cec30a 100644 --- a/pkg/cloudbroker/k8ci/create.go +++ b/pkg/cloudbroker/k8ci/create.go @@ -34,11 +34,6 @@ type CreateRequest struct { // Required: true MasterDriver string `url:"masterDriver" json:"masterDriver" validate:"driver"` - // Network plugins - // Values of slice must be flannel, weawenet or calico - //Required: true - NetworkPlugins []string `url:"networkPlugins" json:"networkPlugins" validate:"required,networkPlugins"` - // Image ID for worker K8S node // Required: true WorkerImageID uint64 `url:"workerImageId" json:"workerImageId" validate:"required"` @@ -51,10 +46,6 @@ type CreateRequest struct { // Required: true WorkerDriver string `url:"workerDriver" json:"workerDriver" validate:"driver"` - // Image ID for load balancer node - // Required: true - LBImageID uint64 `url:"lbImageId" json:"lbImageId" validate:"required"` - // List of account IDs, which have access to this item. // If empty, any account has access // Required: false @@ -62,11 +53,16 @@ type CreateRequest struct { // Policy limit on maximum number of master nodes // Required: true - MaxMasterCount uint64 `url:"maxMasterCount" json:"maxMasterCount"` + MaxMasterCount uint64 `url:"maxMasterCount" json:"maxMasterCount" validate:"required"` // Policy limit on maximum number of worker nodes // Required: true - MaxWorkerCount uint64 `url:"maxWorkerCount" json:"maxWorkerCount"` + MaxWorkerCount uint64 `url:"maxWorkerCount" json:"maxWorkerCount" validate:"required"` + + // Network plugins + // Values of slice must be flannel, weawenet or calico + //Required: true + NetworkPlugins []string `url:"networkPlugins" json:"networkPlugins" validate:"required,networkPlugins"` } // Create creates a new K8CI instance diff --git a/pkg/cloudbroker/k8ci/filter.go b/pkg/cloudbroker/k8ci/filter.go index 9fd58cb..7cc2a35 100644 --- a/pkg/cloudbroker/k8ci/filter.go +++ b/pkg/cloudbroker/k8ci/filter.go @@ -58,21 +58,23 @@ func (lkc ListK8CI) FilterByMasterImageID(masterImageID uint64) ListK8CI { func (lkc ListK8CI) FilterFunc(predicate func(ItemK8CI) bool) ListK8CI { var result ListK8CI - for _, item := range lkc { + for _, item := range lkc.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 ItemK8CI // If none was found, returns an empty struct. func (lkc ListK8CI) FindOne() ItemK8CI { - if len(lkc) == 0 { + if len(lkc.Data) == 0 { return ItemK8CI{} } - return lkc[0] + return lkc.Data[0] } diff --git a/pkg/cloudbroker/k8ci/filter_test.go b/pkg/cloudbroker/k8ci/filter_test.go index 8afbd47..64f1d7a 100644 --- a/pkg/cloudbroker/k8ci/filter_test.go +++ b/pkg/cloudbroker/k8ci/filter_test.go @@ -3,66 +3,69 @@ package k8ci import "testing" var k8ciItems = ListK8CI{ - ItemK8CI{ - CreatedTime: 123902139, - RecordK8CI: RecordK8CI{ - Description: "", - GID: 0, - GUID: 1, - ID: 1, - LBImageID: 5, - MasterDriver: "KVM_X86", - MasterImageID: 120, - MaxMasterCount: 2, - MaxWorkerCount: 3, - Name: "purple_snake", - SharedWith: []interface{}{}, - Status: "ENABLED", - Version: "1", - WorkerDriver: "KVM_X86", - WorkerImageID: 120, + Data: []ItemK8CI{ + { + CreatedTime: 123902139, + RecordK8CI: RecordK8CI{ + Description: "", + GID: 0, + GUID: 1, + ID: 1, + LBImageID: 5, + MasterDriver: "KVM_X86", + MasterImageID: 120, + MaxMasterCount: 2, + MaxWorkerCount: 3, + Name: "purple_snake", + SharedWith: []interface{}{}, + Status: "ENABLED", + Version: "1", + WorkerDriver: "KVM_X86", + WorkerImageID: 120, + }, }, - }, - ItemK8CI{ - CreatedTime: 123902232, - RecordK8CI: RecordK8CI{ - Description: "", - GID: 0, - GUID: 2, - ID: 2, - LBImageID: 10, - MasterDriver: "KVM_X86", - MasterImageID: 121, - MaxMasterCount: 3, - MaxWorkerCount: 5, - Name: "green_giant", - SharedWith: []interface{}{}, - Status: "DISABLED", - Version: "2", - WorkerDriver: "KVM_X86", - WorkerImageID: 121, + { + CreatedTime: 123902232, + RecordK8CI: RecordK8CI{ + Description: "", + GID: 0, + GUID: 2, + ID: 2, + LBImageID: 10, + MasterDriver: "KVM_X86", + MasterImageID: 121, + MaxMasterCount: 3, + MaxWorkerCount: 5, + Name: "green_giant", + SharedWith: []interface{}{}, + Status: "DISABLED", + Version: "2", + WorkerDriver: "KVM_X86", + WorkerImageID: 121, + }, }, - }, - ItemK8CI{ - CreatedTime: 123902335, - RecordK8CI: RecordK8CI{ - Description: "", - GID: 0, - GUID: 3, - ID: 3, - LBImageID: 12, - MasterDriver: "KVM_X86", - MasterImageID: 98, - MaxMasterCount: 5, - MaxWorkerCount: 9, - Name: "magenta_cloud", - SharedWith: []interface{}{}, - Status: "ENABLED", - Version: "3", - WorkerDriver: "KVM_X86", - WorkerImageID: 98, + { + CreatedTime: 123902335, + RecordK8CI: RecordK8CI{ + Description: "", + GID: 0, + GUID: 3, + ID: 3, + LBImageID: 12, + MasterDriver: "KVM_X86", + MasterImageID: 98, + MaxMasterCount: 5, + MaxWorkerCount: 9, + Name: "magenta_cloud", + SharedWith: []interface{}{}, + Status: "ENABLED", + Version: "3", + WorkerDriver: "KVM_X86", + WorkerImageID: 98, + }, }, }, + EntryCount: 3, } func TestFilterByID(t *testing.T) { @@ -84,11 +87,11 @@ func TestFilterByName(t *testing.T) { func TestFilterByStatus(t *testing.T) { actual := k8ciItems.FilterByStatus("ENABLED") - if len(actual) != 2 { - t.Fatal("expected 2 found, actual: ", len(actual)) + if len(actual.Data) != 2 { + t.Fatal("expected 2 found, actual: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.Status != "ENABLED" { t.Fatal("expected Status 'ENABLED', found: ", item.Status) } @@ -124,11 +127,11 @@ func TestFilterFunc(t *testing.T) { return ikc.CreatedTime > 123902139 }) - if len(actual) != 2 { - t.Fatal("expected 2 found, actual: ", len(actual)) + if len(actual.Data) != 2 { + t.Fatal("expected 2 found, actual: ", len(actual.Data)) } - for _, item := range actual { + for _, item := range actual.Data { if item.CreatedTime < 123902139 { t.Fatal("expected CreatedTime greater than 123902139, found: ", item.CreatedTime) } @@ -138,7 +141,7 @@ func TestFilterFunc(t *testing.T) { func TestSortingByCreatedTime(t *testing.T) { actual := k8ciItems.SortByCreatedTime(true) - if actual[0].CreatedTime != 123902335 && actual[2].CreatedTime != 123902139 { + if actual.Data[0].CreatedTime != 123902335 && actual.Data[2].CreatedTime != 123902139 { t.Fatal("expected inverse sort, found normal") } } diff --git a/pkg/cloudbroker/k8ci/list.go b/pkg/cloudbroker/k8ci/list.go index c696ffc..09cb4dd 100644 --- a/pkg/cloudbroker/k8ci/list.go +++ b/pkg/cloudbroker/k8ci/list.go @@ -8,6 +8,30 @@ import ( // Request struct for get list information about images type ListRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // 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 worker driver + // Required: false + WorkerDriver string `url:"workerDriver,omitempty" json:"workerDriver,omitempty"` + + // Find by master driver + // Required: false + MasterDriver string `url:"masterDriver,omitempty" json:"masterDriver,omitempty"` + + // Find by network plugin + // Required: false + NetworkPlugins string `url:"netPlugins,omitempty" json:"masterDrnetPluginsiver,omitempty"` + // List disabled items as well // Required: false IncludeDisabled bool `url:"includeDisabled,omitempty" json:"includeDisabled,omitempty"` @@ -22,7 +46,7 @@ type ListRequest struct { } // List gets list all k8ci catalog items available to the current user -func (k K8CI) List(ctx context.Context, req ListRequest) (ListK8CI, error) { +func (k K8CI) List(ctx context.Context, req ListRequest) (*ListK8CI, error) { url := "/cloudbroker/k8ci/list" res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -37,5 +61,5 @@ func (k K8CI) List(ctx context.Context, req ListRequest) (ListK8CI, error) { return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/k8ci/list_deleted.go b/pkg/cloudbroker/k8ci/list_deleted.go index b7075bc..83ffda8 100644 --- a/pkg/cloudbroker/k8ci/list_deleted.go +++ b/pkg/cloudbroker/k8ci/list_deleted.go @@ -8,6 +8,26 @@ import ( // Request struct for get list information about deleted images type ListDeletedRequest struct { + // Find by ID + // Required: false + ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` + + // Find by name + // Required: false + Name string `url:"name,omitempty" json:"name,omitempty"` + + // Find by worker driver + // Required: false + WorkerDriver string `url:"workerDriver,omitempty" json:"workerDriver,omitempty"` + + // Find by master driver + // Required: false + MasterDriver string `url:"masterDriver,omitempty" json:"masterDriver,omitempty"` + + // Find by network plugin + // Required: false + NetworkPlugins string `url:"netPlugins,omitempty" json:"masterDrnetPluginsiver,omitempty"` + // Page number // Required: false Page uint64 `url:"page,omitempty" json:"page,omitempty"` @@ -18,7 +38,7 @@ type ListDeletedRequest struct { } // ListDeleted gets list all deleted k8ci catalog items available to the current user -func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8CI, error) { +func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8CI, error) { url := "/cloudbroker/k8ci/listDeleted" res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req) @@ -33,5 +53,5 @@ func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8CI return nil, err } - return list, nil + return &list, nil } diff --git a/pkg/cloudbroker/k8ci/models.go b/pkg/cloudbroker/k8ci/models.go index 9fb36a5..0b131cd 100644 --- a/pkg/cloudbroker/k8ci/models.go +++ b/pkg/cloudbroker/k8ci/models.go @@ -9,7 +9,13 @@ type ItemK8CI struct { } // List K8CI -type ListK8CI []ItemK8CI +type ListK8CI struct { + //Data + Data []ItemK8CI `json:"data"` + + // Entry count + EntryCount uint64 `json:"entryCount"` +} // Detailed information about K8CI type RecordK8CI struct { diff --git a/pkg/cloudbroker/k8ci/serialize.go b/pkg/cloudbroker/k8ci/serialize.go index 01fadfa..6fd1bbf 100644 --- a/pkg/cloudbroker/k8ci/serialize.go +++ b/pkg/cloudbroker/k8ci/serialize.go @@ -12,7 +12,7 @@ import ( // - First argument -> prefix // - Second argument -> indent func (lkc ListK8CI) Serialize(params ...string) (serialization.Serialized, error) { - if len(lkc) == 0 { + if len(lkc.Data) == 0 { return []byte{}, nil } diff --git a/pkg/cloudbroker/k8ci/sorting.go b/pkg/cloudbroker/k8ci/sorting.go index db8b328..865c239 100644 --- a/pkg/cloudbroker/k8ci/sorting.go +++ b/pkg/cloudbroker/k8ci/sorting.go @@ -6,16 +6,16 @@ import "sort" // // If inverse param is set to true, the order is reversed. func (lkc ListK8CI) SortByCreatedTime(inverse bool) ListK8CI { - if len(lkc) < 2 { + if len(lkc.Data) < 2 { return lkc } - sort.Slice(lkc, func(i, j int) bool { + sort.Slice(lkc.Data, func(i, j int) bool { if inverse { - return lkc[i].CreatedTime > lkc[j].CreatedTime + return lkc.Data[i].CreatedTime > lkc.Data[j].CreatedTime } - return lkc[i].CreatedTime < lkc[j].CreatedTime + return lkc.Data[i].CreatedTime < lkc.Data[j].CreatedTime }) return lkc