v9.0.0
This commit is contained in:
36
pkg/cloudbroker/k8ci/access_add.go
Normal file
36
pkg/cloudbroker/k8ci/access_add.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AccessAddRequest struct for adding permission to access to account for a k8ci
|
||||
type AccessAddRequest struct {
|
||||
// ID of the K8 catalog item to add access for
|
||||
// Required: true
|
||||
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
|
||||
|
||||
// Account ID to add to the sharedWith access list
|
||||
// Required: true
|
||||
AccountId uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// Add accountId to sharedWith access list for k8ci.
|
||||
func (k K8CI) AccessAdd(ctx context.Context, req AccessAddRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/accessAdd"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
36
pkg/cloudbroker/k8ci/access_remove.go
Normal file
36
pkg/cloudbroker/k8ci/access_remove.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AccessRemoveRequest struct for removing permission to access to account for a k8ci
|
||||
type AccessRemoveRequest struct {
|
||||
// ID of the K8 catalog item to remove access for
|
||||
// Required: true
|
||||
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
|
||||
|
||||
// Account ID to be removed from the sharedWith access list
|
||||
// Required: true
|
||||
AccountId uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// Remove accountId from sharedWith access list for k8ci.
|
||||
func (k K8CI) AccessRemove(ctx context.Context, req AccessRemoveRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/accessRemove"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
86
pkg/cloudbroker/k8ci/create.go
Normal file
86
pkg/cloudbroker/k8ci/create.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create K8CI instance
|
||||
type CreateRequest struct {
|
||||
// Name of catalog item
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Version tag
|
||||
// Required: true
|
||||
Version string `url:"version" json:"version" validate:"required"`
|
||||
|
||||
// Optional description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// Image ID for master K8S node
|
||||
// Required: true
|
||||
MasterImageID uint64 `url:"masterImageId" json:"masterImageId" validate:"required"`
|
||||
|
||||
// Compute driver
|
||||
// Should be one of:
|
||||
// - KVM_X86
|
||||
// - etc
|
||||
// Required: true
|
||||
MasterDriver string `url:"masterDriver" json:"masterDriver" validate:"driver"`
|
||||
|
||||
// Image ID for worker K8S node
|
||||
// Required: true
|
||||
WorkerImageID uint64 `url:"workerImageId" json:"workerImageId" validate:"required"`
|
||||
|
||||
// Compute driver
|
||||
// Should be one of
|
||||
// - KVM_X86
|
||||
// - etc
|
||||
// Required: true
|
||||
WorkerDriver string `url:"workerDriver" json:"workerDriver" validate:"driver"`
|
||||
|
||||
// List of account IDs, which have access to this item.
|
||||
// If empty, any account has access
|
||||
// Required: false
|
||||
SharedWith []uint64 `url:"sharedWith,omitempty" json:"sharedWith,omitempty"`
|
||||
|
||||
// Policy limit on maximum number of master nodes
|
||||
// Required: true
|
||||
MaxMasterCount uint64 `url:"maxMasterCount" json:"maxMasterCount" validate:"required"`
|
||||
|
||||
// Policy limit on maximum number of worker nodes
|
||||
// Required: true
|
||||
MaxWorkerCount uint64 `url:"maxWorkerCount" json:"maxWorkerCount" validate:"required"`
|
||||
|
||||
// Network plugins
|
||||
// Values of slice must be flannel, weavenet or calico
|
||||
//Required: true
|
||||
NetworkPlugins []string `url:"networkPlugins" json:"networkPlugins" validate:"required,networkPlugins"`
|
||||
}
|
||||
|
||||
// Create creates a new K8CI instance
|
||||
func (k K8CI) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/create"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/k8ci/delete.go
Normal file
42
pkg/cloudbroker/k8ci/delete.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteRequest struct to delete K8CI
|
||||
type DeleteRequest struct {
|
||||
// K8CI ID
|
||||
// Required: true
|
||||
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
|
||||
|
||||
// Delete permanently or not
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently" json:"permanently"`
|
||||
}
|
||||
|
||||
// Delete deletes K8CI by ID
|
||||
func (k K8CI) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/delete"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudbroker/k8ci/disable.go
Normal file
38
pkg/cloudbroker/k8ci/disable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DisableRequest struct to disable K8CI
|
||||
type DisableRequest struct {
|
||||
// K8CI ID
|
||||
// Required: true
|
||||
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables K8CI
|
||||
func (k K8CI) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/disable"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudbroker/k8ci/enable.go
Normal file
38
pkg/cloudbroker/k8ci/enable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// EnableRequest struct to enable K8CI
|
||||
type EnableRequest struct {
|
||||
// K8CI ID
|
||||
// Required: true
|
||||
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
|
||||
}
|
||||
|
||||
// Enable enables K8CI
|
||||
func (k K8CI) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/enable"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
80
pkg/cloudbroker/k8ci/filter.go
Normal file
80
pkg/cloudbroker/k8ci/filter.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package k8ci
|
||||
|
||||
// FilterByID returns ListK8CI with specified ID.
|
||||
func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.RecordK8CIList.ID == id
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListK8CI with specified Name.
|
||||
func (lkc ListK8CI) FilterByName(name string) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.RecordK8CIList.Name == name
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListK8CI with specified Status.
|
||||
func (lkc ListK8CI) FilterByStatus(status string) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.Status == status
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByWorkerImageID returns ListK8CI with specified WorkerImageID.
|
||||
func (lkc ListK8CI) FilterByWorkerImageID(workerImageID uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.WorkerImageID == workerImageID
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByLBImageID returns ListK8CI with specified LBImageID.
|
||||
func (lkc ListK8CI) FilterByLBImageID(lbImageID uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.LBImageID == lbImageID
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByMasterImageID returns ListK8CI with specified MasterImageID.
|
||||
func (lkc ListK8CI) FilterByMasterImageID(masterImageID uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.MasterImageID == masterImageID
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListK8CI based on a user-specified predicate.
|
||||
func (lkc ListK8CI) FilterFunc(predicate func(ItemK8CI) bool) ListK8CI {
|
||||
var result ListK8CI
|
||||
|
||||
for _, item := range lkc.Data {
|
||||
if predicate(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.Data) == 0 {
|
||||
return ItemK8CI{}
|
||||
}
|
||||
|
||||
return lkc.Data[0]
|
||||
}
|
||||
147
pkg/cloudbroker/k8ci/filter_test.go
Normal file
147
pkg/cloudbroker/k8ci/filter_test.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package k8ci
|
||||
|
||||
import "testing"
|
||||
|
||||
var k8ciItems = ListK8CI{
|
||||
Data: []ItemK8CI{
|
||||
{
|
||||
CreatedTime: 123902139,
|
||||
RecordK8CIList: RecordK8CIList{
|
||||
Description: "",
|
||||
GID: 0,
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
LBImageID: 5,
|
||||
MasterDriver: "KVM_X86",
|
||||
MasterImageID: 120,
|
||||
MaxMasterCount: 2,
|
||||
MaxWorkerCount: 3,
|
||||
Name: "purple_snake",
|
||||
SharedWith: []uint64{},
|
||||
Status: "ENABLED",
|
||||
Version: "1",
|
||||
WorkerDriver: "KVM_X86",
|
||||
WorkerImageID: 120,
|
||||
},
|
||||
},
|
||||
{
|
||||
CreatedTime: 123902232,
|
||||
RecordK8CIList: RecordK8CIList{
|
||||
Description: "",
|
||||
GID: 0,
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
LBImageID: 10,
|
||||
MasterDriver: "KVM_X86",
|
||||
MasterImageID: 121,
|
||||
MaxMasterCount: 3,
|
||||
MaxWorkerCount: 5,
|
||||
Name: "green_giant",
|
||||
SharedWith: []uint64{},
|
||||
Status: "DISABLED",
|
||||
Version: "2",
|
||||
WorkerDriver: "KVM_X86",
|
||||
WorkerImageID: 121,
|
||||
},
|
||||
},
|
||||
{
|
||||
CreatedTime: 123902335,
|
||||
RecordK8CIList: RecordK8CIList{
|
||||
Description: "",
|
||||
GID: 0,
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
LBImageID: 12,
|
||||
MasterDriver: "KVM_X86",
|
||||
MasterImageID: 98,
|
||||
MaxMasterCount: 5,
|
||||
MaxWorkerCount: 9,
|
||||
Name: "magenta_cloud",
|
||||
SharedWith: []uint64{},
|
||||
Status: "ENABLED",
|
||||
Version: "3",
|
||||
WorkerDriver: "KVM_X86",
|
||||
WorkerImageID: 98,
|
||||
},
|
||||
},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := k8ciItems.FilterByID(2).FindOne()
|
||||
|
||||
if actual.ID != 2 {
|
||||
t.Fatal("expected ID 2, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := k8ciItems.FilterByName("magenta_cloud").FindOne()
|
||||
|
||||
if actual.Name != "magenta_cloud" {
|
||||
t.Fatal("expected Name 'magenta_cloud', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := k8ciItems.FilterByStatus("ENABLED")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByWorkerImageID(t *testing.T) {
|
||||
actual := k8ciItems.FilterByWorkerImageID(98).FindOne()
|
||||
|
||||
if actual.WorkerImageID != 98 {
|
||||
t.Fatal("expected WorkerImageID 98, found: ", actual.WorkerImageID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByLBImageID(t *testing.T) {
|
||||
actual := k8ciItems.FilterByLBImageID(10).FindOne()
|
||||
|
||||
if actual.LBImageID != 10 {
|
||||
t.Fatal("expected LBImageID 10, found: ", actual.LBImageID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByMasterImageID(t *testing.T) {
|
||||
actual := k8ciItems.FilterByMasterImageID(120).FindOne()
|
||||
|
||||
if actual.MasterImageID != 120 {
|
||||
t.Fatal("expected MasterImageID 120, found: ", actual.MasterImageID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := k8ciItems.FilterFunc(func(ikc ItemK8CI) bool {
|
||||
return ikc.CreatedTime > 123902139
|
||||
})
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.CreatedTime < 123902139 {
|
||||
t.Fatal("expected CreatedTime greater than 123902139, found: ", item.CreatedTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortingByCreatedTime(t *testing.T) {
|
||||
actual := k8ciItems.SortByCreatedTime(true)
|
||||
|
||||
if actual.Data[0].CreatedTime != 123902335 && actual.Data[2].CreatedTime != 123902139 {
|
||||
t.Fatal("expected inverse sort, found normal")
|
||||
}
|
||||
}
|
||||
46
pkg/cloudbroker/k8ci/get.go
Normal file
46
pkg/cloudbroker/k8ci/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get information about K8CI
|
||||
type GetRequest struct {
|
||||
// ID of the K8 catalog item to get
|
||||
// Required: true
|
||||
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets details of the specified K8 catalog item as a RecordK8CI struct
|
||||
func (k K8CI) Get(ctx context.Context, req GetRequest) (*RecordK8CI, error) {
|
||||
res, err := k.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
item := RecordK8CI{}
|
||||
|
||||
err = json.Unmarshal(res, &item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// GetRaw gets details of the specified K8 catalog item as an array of bytes
|
||||
func (k K8CI) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/get"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
10
pkg/cloudbroker/k8ci/ids.go
Normal file
10
pkg/cloudbroker/k8ci/ids.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package k8ci
|
||||
|
||||
// IDs gets array of K8CIIDs from ListK8CI struct
|
||||
func (lk8ci ListK8CI) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lk8ci.Data))
|
||||
for _, i := range lk8ci.Data {
|
||||
res = append(res, i.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
18
pkg/cloudbroker/k8ci/k8ci.go
Normal file
18
pkg/cloudbroker/k8ci/k8ci.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// API to manage K8CI instances
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to K8CI
|
||||
type K8CI struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for K8CI endpoints
|
||||
func New(client interfaces.Caller) *K8CI {
|
||||
return &K8CI{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
84
pkg/cloudbroker/k8ci/list.go
Normal file
84
pkg/cloudbroker/k8ci/list.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to 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"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of all k8ci catalog items available to the current user as a ListK8CI struct
|
||||
func (k K8CI) List(ctx context.Context, req ListRequest) (*ListK8CI, error) {
|
||||
|
||||
res, err := k.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListK8CI{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of all k8ci catalog items available to the current user as an array of bytes
|
||||
func (k K8CI) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/list"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
69
pkg/cloudbroker/k8ci/list_deleted.go
Normal file
69
pkg/cloudbroker/k8ci/list_deleted.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get list information about deleted k8ci items
|
||||
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"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListDeleted gets list all deleted k8ci catalog items available to the current user
|
||||
func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8CI, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/listDeleted"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListK8CI{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
120
pkg/cloudbroker/k8ci/models.go
Normal file
120
pkg/cloudbroker/k8ci/models.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package k8ci
|
||||
|
||||
// Main information about K8CI in List
|
||||
type ItemK8CI struct {
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
// Detailed information about K8CI
|
||||
RecordK8CIList
|
||||
}
|
||||
|
||||
// List K8CI
|
||||
type ListK8CI struct {
|
||||
//Data
|
||||
Data []ItemK8CI `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Detailed information about K8CI in List
|
||||
type RecordK8CIList struct {
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Load balancer image ID
|
||||
LBImageID uint64 `json:"lbImageId"`
|
||||
|
||||
// Master driver
|
||||
MasterDriver string `json:"masterDriver"`
|
||||
|
||||
// Master image ID
|
||||
MasterImageID uint64 `json:"masterImageId"`
|
||||
|
||||
// Max master count
|
||||
MaxMasterCount uint64 `json:"maxMasterCount"`
|
||||
|
||||
// Max worker count
|
||||
MaxWorkerCount uint64 `json:"maxWorkerCount"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Shared with
|
||||
SharedWith []uint64 `json:"sharedWith"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Version
|
||||
Version string `json:"version"`
|
||||
|
||||
// Worker driver
|
||||
WorkerDriver string `json:"workerDriver"`
|
||||
|
||||
// Worker image ID
|
||||
WorkerImageID uint64 `json:"workerImageId"`
|
||||
}
|
||||
|
||||
// Detailed information about K8CI
|
||||
type RecordK8CI struct {
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Load balancer image ID
|
||||
LBImageID uint64 `json:"lbImageId"`
|
||||
|
||||
// Master driver
|
||||
MasterDriver string `json:"masterDriver"`
|
||||
|
||||
// Master image ID
|
||||
MasterImageID uint64 `json:"masterImageId"`
|
||||
|
||||
// Max master count
|
||||
MaxMasterCount uint64 `json:"maxMasterCount"`
|
||||
|
||||
// Max worker count
|
||||
MaxWorkerCount uint64 `json:"maxWorkerCount"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
//NetworkPlugins
|
||||
NetworkPlugins []string `json:"networkPlugins"`
|
||||
|
||||
// Shared with
|
||||
SharedWith []uint64 `json:"sharedWith"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Version
|
||||
Version string `json:"version"`
|
||||
|
||||
// Worker driver
|
||||
WorkerDriver string `json:"workerDriver"`
|
||||
|
||||
// Worker image ID
|
||||
WorkerImageID uint64 `json:"workerImageId"`
|
||||
}
|
||||
38
pkg/cloudbroker/k8ci/restore.go
Normal file
38
pkg/cloudbroker/k8ci/restore.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// RestoreRequest struct to restore K8CI
|
||||
type RestoreRequest struct {
|
||||
// K8CI ID
|
||||
// Required: true
|
||||
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
|
||||
}
|
||||
|
||||
// Restore restores K8CI
|
||||
func (k K8CI) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8ci/restore"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/cloudbroker/k8ci/serialize.go
Normal file
43
pkg/cloudbroker/k8ci/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package k8ci
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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 (lkc ListK8CI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lkc.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lkc, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lkc)
|
||||
}
|
||||
|
||||
// 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 (ikc ItemK8CI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ikc, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ikc)
|
||||
}
|
||||
22
pkg/cloudbroker/k8ci/sorting.go
Normal file
22
pkg/cloudbroker/k8ci/sorting.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package k8ci
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedTime sorts ListK8CI by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lkc ListK8CI) SortByCreatedTime(inverse bool) ListK8CI {
|
||||
if len(lkc.Data) < 2 {
|
||||
return lkc
|
||||
}
|
||||
|
||||
sort.Slice(lkc.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lkc.Data[i].CreatedTime > lkc.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return lkc.Data[i].CreatedTime < lkc.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return lkc
|
||||
}
|
||||
Reference in New Issue
Block a user