git test
This commit is contained in:
43
pkg/cloudbroker/sep/access_grant.go
Normal file
43
pkg/cloudbroker/sep/access_grant.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// AccessGrantRequest struct to grant access to SEP
|
||||
type AccessGrantRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Account ID to grant access to the specified SEP. If 0,
|
||||
// the SEP will be available for all accounts with no exceptions
|
||||
// Required: true
|
||||
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
|
||||
}
|
||||
|
||||
// AccessGrant grants access to SEP
|
||||
func (s SEP) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/accessGrant"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
50
pkg/cloudbroker/sep/access_grant_to_pool.go
Normal file
50
pkg/cloudbroker/sep/access_grant_to_pool.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// AccessGrantToPoolRequest struct to grant access to pool SEP
|
||||
type AccessGrantToPoolRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Pool name
|
||||
// Required: true
|
||||
PoolName string `url:"pool_name" json:"pool_name" validate:"required"`
|
||||
|
||||
// Account ID to grant access to the specified pool SEP
|
||||
// Required: false
|
||||
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
|
||||
|
||||
// Resource group to grant access to the specified pool SEP
|
||||
// Required: false
|
||||
RGID uint64 `url:"resgroup_id,omitempty" json:"resgroup_id,omitempty"`
|
||||
}
|
||||
|
||||
// AccessGrantToPool grants access to pool SEP
|
||||
func (s SEP) AccessGrantToPool(ctx context.Context, req AccessGrantToPoolRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/accessGrantToPool"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
42
pkg/cloudbroker/sep/access_revoke.go
Normal file
42
pkg/cloudbroker/sep/access_revoke.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// AccessRevokeRequest struct to revoke access to SEP
|
||||
type AccessRevokeRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Account ID to revoke access to the specified SEP
|
||||
// Required: true
|
||||
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
|
||||
}
|
||||
|
||||
// AccessRevoke revokes access to SEP
|
||||
func (s SEP) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/accessRevoke"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
50
pkg/cloudbroker/sep/access_revoke_to_pool.go
Normal file
50
pkg/cloudbroker/sep/access_revoke_to_pool.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// AccessRevokeToPoolRequest struct to revoke access to pool SEP
|
||||
type AccessRevokeToPoolRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Pool name
|
||||
// Required: true
|
||||
PoolName string `url:"pool_name" json:"pool_name" validate:"required"`
|
||||
|
||||
// Account ID to grant access to the specified pool SEP
|
||||
// Required: false
|
||||
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
|
||||
|
||||
// Resource group ID to grant access to the specified pool SEP
|
||||
// Required: false
|
||||
RGID uint64 `url:"resgroup_id,omitempty" json:"resgroup_id,omitempty"`
|
||||
}
|
||||
|
||||
// AccessRevokeToPool revokes access to pool SEP
|
||||
func (s SEP) AccessRevokeToPool(ctx context.Context, req AccessRevokeToPoolRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/accessRevokeToPool"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
42
pkg/cloudbroker/sep/add_consumer_nodes.go
Normal file
42
pkg/cloudbroker/sep/add_consumer_nodes.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// AddConsumerNodesRequest struct to add consumer nodes
|
||||
type AddConsumerNodesRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// List of nodes IDs
|
||||
// Required: true
|
||||
ConsumerNIDs []uint64 `url:"consumer_nids" json:"consumer_nids" validate:"min=1"`
|
||||
}
|
||||
|
||||
// AddConsumerNodes adds consumer nodes to SEP parameters
|
||||
func (s SEP) AddConsumerNodes(ctx context.Context, req AddConsumerNodesRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/addConsumerNodes"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
80
pkg/cloudbroker/sep/add_pool.go
Normal file
80
pkg/cloudbroker/sep/add_pool.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// AddPoolRequest struct to add pool to storage endpoint (SEP)
|
||||
type AddPoolRequest struct {
|
||||
// ID of SEP to add new pool
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Pool structure which contains fields such as "name", "usage_limit", "types", "system", "accessAccountIds", "accessResGroupIds". Added fields for other pool types: Des, Ovs - "uris" list of "ip, port".
|
||||
// Dorado, Tatlin - "vdisk_discard". Hitachi - "id", "snapshotable", "snapshot_pool_id", "minLdevId", "maxLdevId", "clone_technology", "vdisk_discard". Shared - "description", "wwns", "allocate_type", "stripes", "metadata_size", "metadatatalun", "vdisk_discard" Local - "description", "node_consumer", "block_disk".
|
||||
// Required: true
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
}
|
||||
|
||||
type wrapperAddPoolRequest struct {
|
||||
AddPoolRequest
|
||||
AsyncMode bool `url:"asyncMode"`
|
||||
}
|
||||
|
||||
// AddPool adds pool to SEP in sync mode.
|
||||
// It returns result of operation and error.
|
||||
func (s SEP) AddPool(ctx context.Context, req AddPoolRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperAddPoolRequest{
|
||||
AddPoolRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/addPool"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// AddPoolAsync adds pool to SEP in async mode.
|
||||
// It returns guid of task and error.
|
||||
func (s SEP) AddPoolAsync(ctx context.Context, req AddPoolRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperAddPoolRequest{
|
||||
AddPoolRequest: req,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/addPool"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/sep/add_provider_nodes.go
Normal file
42
pkg/cloudbroker/sep/add_provider_nodes.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// AddProviderNodesRequest struct to add provider nodes
|
||||
type AddProviderNodesRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// List of node IDs
|
||||
// Required: true
|
||||
ProviderNIDs []uint64 `url:"provider_nids" json:"provider_nids" validate:"min=1"`
|
||||
}
|
||||
|
||||
// AddProviderNodes adds provider nodes to SEP parameters
|
||||
func (s SEP) AddProviderNodes(ctx context.Context, req AddProviderNodesRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/addProviderNodes"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
58
pkg/cloudbroker/sep/config_field_edit.go
Normal file
58
pkg/cloudbroker/sep/config_field_edit.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// ConfigFieldEditRequest struct to edit config fields
|
||||
type ConfigFieldEditRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Field name
|
||||
// Required: true
|
||||
FieldName string `url:"field_name" json:"field_name" validate:"required"`
|
||||
|
||||
// Field value
|
||||
// Required: true
|
||||
FieldValue string `url:"field_value" json:"field_value" validate:"required"`
|
||||
|
||||
// Field type
|
||||
// Should be one of:
|
||||
// - int
|
||||
// - str
|
||||
// - bool
|
||||
// - list
|
||||
// - dict
|
||||
// Required: true
|
||||
FieldType string `url:"field_type" json:"field_type" validate:"sepFieldType"`
|
||||
}
|
||||
|
||||
// ConfigFieldEdit edits SEP config field value
|
||||
func (s SEP) ConfigFieldEdit(ctx context.Context, req ConfigFieldEditRequest) (*RecordConfigFieldEdit, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/configFieldEdit"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordConfigFieldEdit{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
42
pkg/cloudbroker/sep/config_insert.go
Normal file
42
pkg/cloudbroker/sep/config_insert.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// ConfigInsertRequest struct to insert config
|
||||
type ConfigInsertRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Storage provider config
|
||||
// Required: true
|
||||
Config string `url:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigInsert inserts config to SEP
|
||||
func (s SEP) ConfigInsert(ctx context.Context, req ConfigInsertRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/configInsert"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
42
pkg/cloudbroker/sep/config_validate.go
Normal file
42
pkg/cloudbroker/sep/config_validate.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// ConfigValidateRequest struct to validate config
|
||||
type ConfigValidateRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Storage provider config
|
||||
// Required: true
|
||||
Config string `url:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigValidate verifies config for the SEP
|
||||
func (s SEP) ConfigValidate(ctx context.Context, req ConfigValidateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/configValidate"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
40
pkg/cloudbroker/sep/consumption.go
Normal file
40
pkg/cloudbroker/sep/consumption.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// ConsumptionRequest struct to get consumption info
|
||||
type ConsumptionRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: false
|
||||
SEPID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
|
||||
}
|
||||
|
||||
// Consumption gets SEP consumption info
|
||||
func (s SEP) Consumption(ctx context.Context, req ConsumptionRequest) (*ListConsumption, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/consumption"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := ListConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
58
pkg/cloudbroker/sep/create.go
Normal file
58
pkg/cloudbroker/sep/create.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create SEP object
|
||||
type CreateRequest struct {
|
||||
// Grid ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// SEP name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Type of storage
|
||||
// Required: true
|
||||
SEPType string `url:"sep_type" json:"sep_type" validate:"required,sepType"`
|
||||
|
||||
// SEP config
|
||||
// Required: true
|
||||
Config string `url:"config" json:"config" validate:"required"`
|
||||
|
||||
// Description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// Enable SEP after creation
|
||||
// Required: false
|
||||
Enable bool `url:"enable,omitempty" json:"enable,omitempty"`
|
||||
}
|
||||
|
||||
// Create creates SEP object
|
||||
func (s SEP) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/create"
|
||||
|
||||
res, err := s.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/sep/decommission.go
Normal file
42
pkg/cloudbroker/sep/decommission.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// DecommissionRequest struct for decommission
|
||||
type DecommissionRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Clear disks and images physically
|
||||
// Required: false
|
||||
ClearPhisically bool `url:"clear_physically,omitempty" json:"clear_physically,omitempty"`
|
||||
}
|
||||
|
||||
// Decommission unlink everything that exists from SEP
|
||||
func (s SEP) Decommission(ctx context.Context, req DecommissionRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/decommission"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
49
pkg/cloudbroker/sep/del_consumer_nodes.go
Normal file
49
pkg/cloudbroker/sep/del_consumer_nodes.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// DelConsumerNodesRequest struct to exclude consumer nodes
|
||||
type DelConsumerNodesRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// List of consumer node IDs
|
||||
// Required: true
|
||||
ConsumerNIDs []uint64 `url:"consumer_nids" json:"consumer_nids" validate:"min=1"`
|
||||
|
||||
// The force flag must be set to true only if the node will never come back online
|
||||
// Default: false
|
||||
// Required: false
|
||||
Force bool `url:"force" json:"force"`
|
||||
}
|
||||
|
||||
// DelConsumerNodes excludes consumer nodes from SEP parameters
|
||||
func (s SEP) DelConsumerNodes(ctx context.Context, req DelConsumerNodesRequest) (interface{}, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/delConsumerNodes"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result interface{}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/sep/del_pool.go
Normal file
42
pkg/cloudbroker/sep/del_pool.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// DelPoolRequest struct to delete pool from storage endpoint (SEP)
|
||||
type DelPoolRequest struct {
|
||||
// ID of SEP to delete pool
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Name of pool to delete
|
||||
// Required: true
|
||||
PoolName string `url:"pool_name" json:"pool_name" validate:"required"`
|
||||
}
|
||||
|
||||
// DelPool deletes pool from SEP
|
||||
func (s SEP) DelPool(ctx context.Context, req DelPoolRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/delPool"
|
||||
|
||||
res, err := s.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/sep/delete.go
Normal file
38
pkg/cloudbroker/sep/delete.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteRequest struct to delete SEP
|
||||
type DeleteRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Delete deletes SEP by ID
|
||||
func (s SEP) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/delete"
|
||||
|
||||
res, err := s.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/sep/disable.go
Normal file
38
pkg/cloudbroker/sep/disable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// DisableRequest struct to disable SEP
|
||||
type DisableRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables SEP by ID
|
||||
func (s SEP) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/disable"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
44
pkg/cloudbroker/sep/disk_list.go
Normal file
44
pkg/cloudbroker/sep/disk_list.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// DiskListRequest struct to get list of disk IDs
|
||||
type DiskListRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Pool name
|
||||
// Required: false
|
||||
PoolName string `url:"pool_name,omitempty" json:"pool_name,omitempty"`
|
||||
}
|
||||
|
||||
// DiskList gets list of disk IDs, who use this SEP and pool (if provided)
|
||||
func (s SEP) DiskList(ctx context.Context, req DiskListRequest) ([]uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/diskList"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]uint64, 0)
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
38
pkg/cloudbroker/sep/enable.go
Normal file
38
pkg/cloudbroker/sep/enable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// EnableRequest struct to enable SEP
|
||||
type EnableRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Enable enables SEP by ID
|
||||
func (s SEP) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/enable"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
153
pkg/cloudbroker/sep/filter.go
Normal file
153
pkg/cloudbroker/sep/filter.go
Normal file
@@ -0,0 +1,153 @@
|
||||
package sep
|
||||
|
||||
// FilterByID returns ListSEP with specified ID.
|
||||
func (lsep ListSEP) FilterByID(id uint64) ListSEP {
|
||||
predicate := func(rsep RecordSEP) bool {
|
||||
return rsep.ID == id
|
||||
}
|
||||
|
||||
return lsep.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListSEP with specified Name.
|
||||
func (lsep ListSEP) FilterByName(name string) ListSEP {
|
||||
predicate := func(rsep RecordSEP) bool {
|
||||
return rsep.Name == name
|
||||
}
|
||||
|
||||
return lsep.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByObjStatus returns ListSEP with specified ObjStatus.
|
||||
func (lsep ListSEP) FilterByObjStatus(objStatus string) ListSEP {
|
||||
predicate := func(rsep RecordSEP) bool {
|
||||
return rsep.ObjStatus == objStatus
|
||||
}
|
||||
|
||||
return lsep.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByTechStatus returns ListSEP with specified TechStatus.
|
||||
func (lsep ListSEP) FilterByTechStatus(techStatus string) ListSEP {
|
||||
predicate := func(rsep RecordSEP) bool {
|
||||
return rsep.TechStatus == techStatus
|
||||
}
|
||||
|
||||
return lsep.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByType returns ListSEP with specified Type.
|
||||
func (lsep ListSEP) FilterByType(sepType string) ListSEP {
|
||||
predicate := func(rsep RecordSEP) bool {
|
||||
return rsep.Type == sepType
|
||||
}
|
||||
|
||||
return lsep.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListSEP based on user-specified predicate.
|
||||
func (lsep ListSEP) FilterFunc(predicate func(RecordSEP) bool) ListSEP {
|
||||
var result ListSEP
|
||||
|
||||
for _, item := range lsep.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found RecordSEP
|
||||
// If none was found, returns an empty struct.
|
||||
func (lsep ListSEP) FindOne() RecordSEP {
|
||||
if len(lsep.Data) == 0 {
|
||||
return RecordSEP{}
|
||||
}
|
||||
|
||||
return lsep.Data[0]
|
||||
}
|
||||
|
||||
// FilterBySEPID returns ListAvailableSEP with the specified SEPID.
|
||||
func (sl ListAvailableSEP) FilterBySEPID(sepID uint64) ListAvailableSEP {
|
||||
predicate := func(sd SEPData) bool {
|
||||
return sd.SEPID == sepID
|
||||
}
|
||||
|
||||
return sl.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterBySEPName returns ListAvailableSEP with the specified SEPName.
|
||||
func (sl ListAvailableSEP) FilterBySEPName(SEPName string) ListAvailableSEP {
|
||||
predicate := func(sd SEPData) bool {
|
||||
return sd.SEPName == SEPName
|
||||
}
|
||||
|
||||
return sl.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterBySEPType returns ListAvailableSEP with the specified SEPType.
|
||||
func (sl ListAvailableSEP) FilterBySEPType(SEPType string) ListAvailableSEP {
|
||||
predicate := func(sd SEPData) bool {
|
||||
return sd.SEPType == SEPType
|
||||
}
|
||||
|
||||
return sl.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByPoolType returns ListAvailableSEP where at least one pool has the specified type.
|
||||
func (sl ListAvailableSEP) FilterByPoolType(poolType string) ListAvailableSEP {
|
||||
predicate := func(sd SEPData) bool {
|
||||
for _, pool := range sd.Pools {
|
||||
for _, pt := range pool.Types {
|
||||
if pt == poolType {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return sl.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterBySystemPool returns ListAvailableSEP where at least one pool is a system pool.
|
||||
func (sl ListAvailableSEP) FilterBySystemPool(isSystem bool) ListAvailableSEP {
|
||||
predicate := func(sd SEPData) bool {
|
||||
for _, pool := range sd.Pools {
|
||||
if pool.System == isSystem {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return sl.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListAvailableSEP based on a user-defined predicate.
|
||||
func (sl ListAvailableSEP) FilterFunc(predicate func(SEPData) bool) ListAvailableSEP {
|
||||
var result ListAvailableSEP
|
||||
|
||||
for _, item := range sl.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns the first found SEPData.
|
||||
// If nothing is found, returns an empty struct.
|
||||
func (sl ListAvailableSEP) FindOne() SEPData {
|
||||
if len(sl.Data) == 0 {
|
||||
return SEPData{}
|
||||
}
|
||||
|
||||
return sl.Data[0]
|
||||
}
|
||||
282
pkg/cloudbroker/sep/filter_test.go
Normal file
282
pkg/cloudbroker/sep/filter_test.go
Normal file
@@ -0,0 +1,282 @@
|
||||
package sep
|
||||
|
||||
import "testing"
|
||||
|
||||
var seps = ListSEP{
|
||||
Data: []RecordSEP{
|
||||
{
|
||||
|
||||
Config: map[string]interface{}{
|
||||
"API_IPs": []string{
|
||||
"10.212.3.61",
|
||||
"10.212.3.62",
|
||||
"10.212.3.63",
|
||||
},
|
||||
},
|
||||
ConsumedBy: []uint64{
|
||||
27,
|
||||
},
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
Milestones: 278329,
|
||||
Name: "sep_1",
|
||||
ObjStatus: "CREATED",
|
||||
ProvidedBy: []uint64{
|
||||
24,
|
||||
35,
|
||||
29,
|
||||
},
|
||||
SharedWith: []uint64{},
|
||||
TechStatus: "ENABLED",
|
||||
Type: "DES",
|
||||
},
|
||||
{
|
||||
|
||||
Config: map[string]interface{}{
|
||||
"API_IPs": []string{
|
||||
"10.212.3.64",
|
||||
"10.212.3.65",
|
||||
"10.212.3.66",
|
||||
},
|
||||
},
|
||||
ConsumedBy: []uint64{
|
||||
32,
|
||||
26,
|
||||
},
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
Milestones: 278337,
|
||||
Name: "sep_2",
|
||||
ObjStatus: "CREATED",
|
||||
ProvidedBy: []uint64{
|
||||
36,
|
||||
42,
|
||||
35,
|
||||
},
|
||||
SharedWith: []uint64{},
|
||||
TechStatus: "ENABLED",
|
||||
Type: "DES",
|
||||
},
|
||||
{
|
||||
|
||||
Config: map[string]interface{}{
|
||||
"API_IPs": []string{
|
||||
"10.212.3.67",
|
||||
"10.212.3.68",
|
||||
"10.212.3.69",
|
||||
},
|
||||
},
|
||||
ConsumedBy: []uint64{
|
||||
38,
|
||||
28,
|
||||
},
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
Milestones: 278345,
|
||||
Name: "sep_3",
|
||||
ObjStatus: "DESTROYED",
|
||||
ProvidedBy: []uint64{
|
||||
49,
|
||||
48,
|
||||
41,
|
||||
},
|
||||
SharedWith: []uint64{},
|
||||
TechStatus: "DISABLED",
|
||||
Type: "DES",
|
||||
},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := seps.FilterByID(1).FindOne()
|
||||
|
||||
if actual.ID != 1 {
|
||||
t.Fatal("expected ID 1, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := seps.FilterByName("sep_2").FindOne()
|
||||
|
||||
if actual.Name != "sep_2" {
|
||||
t.Fatal("expected Name 'sep_2', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByObjStatus(t *testing.T) {
|
||||
actual := seps.FilterByObjStatus("CREATED")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.ObjStatus != "CREATED" {
|
||||
t.Fatal("expected ObjStatus 'CREATED', found: ", item.ObjStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByTechStatus(t *testing.T) {
|
||||
actual := seps.FilterByTechStatus("ENABLED")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.TechStatus != "ENABLED" {
|
||||
t.Fatal("expected TechStatus 'ENABLED', found: ", item.TechStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByType(t *testing.T) {
|
||||
actual := seps.FilterByType("DES")
|
||||
|
||||
if len(actual.Data) != 3 {
|
||||
t.Fatal("expected 3 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Type != "DES" {
|
||||
t.Fatal("expected Type 'DES', found: ", item.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := seps.FilterFunc(func(rs RecordSEP) bool {
|
||||
return len(rs.ConsumedBy) > 1
|
||||
})
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if len(item.ConsumedBy) <= 1 {
|
||||
t.Fatal("expected ConsumedBy to contain more than 1 element, found: ", len(item.ConsumedBy))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var availableSeps = ListAvailableSEP{
|
||||
EntryCount: 3,
|
||||
Data: []SEPData{
|
||||
{
|
||||
SEPID: 1,
|
||||
SEPName: "sep_1",
|
||||
SEPType: "TATLIN",
|
||||
Pools: []Pool{
|
||||
{
|
||||
Name: "pool_1",
|
||||
Types: []string{"DES"},
|
||||
System: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
SEPID: 2,
|
||||
SEPName: "sep_2",
|
||||
SEPType: "SHARED",
|
||||
Pools: []Pool{
|
||||
{
|
||||
Name: "pool_2",
|
||||
Types: []string{"DES"},
|
||||
System: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
SEPID: 3,
|
||||
SEPName: "sep_3",
|
||||
SEPType: "DES",
|
||||
Pools: []Pool{
|
||||
{
|
||||
Name: "pool_3",
|
||||
Types: []string{"DES"},
|
||||
System: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterBySEPID(t *testing.T) {
|
||||
actual := availableSeps.FilterBySEPID(1).FindOne()
|
||||
|
||||
if actual.SEPID != 1 {
|
||||
t.Fatal("expected SEPID 1, found: ", actual.SEPID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterBySEPName(t *testing.T) {
|
||||
actual := availableSeps.FilterBySEPName("sep_2").FindOne()
|
||||
|
||||
if actual.SEPName != "sep_2" {
|
||||
t.Fatal("expected SEPName 'sep_2', found: ", actual.SEPName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterBySEPType(t *testing.T) {
|
||||
actual := availableSeps.FilterBySEPType("TATLIN").FindOne()
|
||||
|
||||
if actual.SEPType != "TATLIN" {
|
||||
t.Fatal("expected SEPType 'TATLIN', found: ", actual.SEPType)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByPoolType(t *testing.T) {
|
||||
actual := availableSeps.FilterByPoolType("DES")
|
||||
|
||||
if len(actual.Data) != 3 {
|
||||
t.Fatal("expected 3 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
found := false
|
||||
for _, pool := range item.Pools {
|
||||
for _, poolType := range pool.Types {
|
||||
if poolType == "DES" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("expected Pool type 'DES', not found in SEP: ", item.SEPID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterBySystemPool(t *testing.T) {
|
||||
actual := availableSeps.FilterBySystemPool(true)
|
||||
|
||||
if len(actual.Data) != 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
found := false
|
||||
for _, pool := range item.Pools {
|
||||
if pool.System {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("expected System pool, not found in SEP: ", item.SEPID)
|
||||
}
|
||||
}
|
||||
}
|
||||
46
pkg/cloudbroker/sep/get.go
Normal file
46
pkg/cloudbroker/sep/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get SEP parameters
|
||||
type GetRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets SEP parameters as a RecordSEP struct
|
||||
func (s SEP) Get(ctx context.Context, req GetRequest) (*RecordSEP, error) {
|
||||
res, err := s.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordSEP{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets SEP parameters as an array of bytes
|
||||
func (s SEP) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/get"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
40
pkg/cloudbroker/sep/get_config.go
Normal file
40
pkg/cloudbroker/sep/get_config.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// GetConfigRequest struct to get SEP config
|
||||
type GetConfigRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
}
|
||||
|
||||
// GetConfig gets SEP config
|
||||
func (s SEP) GetConfig(ctx context.Context, req GetConfigRequest) (*SEPConfig, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/getConfig"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := SEPConfig{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
44
pkg/cloudbroker/sep/get_pool.go
Normal file
44
pkg/cloudbroker/sep/get_pool.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// GetPoolRequest struct to get SEP pool config by name
|
||||
type GetPoolRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Pool name
|
||||
// Required: true
|
||||
PoolName string `url:"pool_name" json:"pool_name" validate:"required"`
|
||||
}
|
||||
|
||||
// GetPool gets SEP pool config by name
|
||||
func (s SEP) GetPool(ctx context.Context, req GetPoolRequest) (*RecordPool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/getPool"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordPool{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
36
pkg/cloudbroker/sep/get_template.go
Normal file
36
pkg/cloudbroker/sep/get_template.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// GetTemplateRequest struct to get template of SEP
|
||||
type GetTemplateRequest struct {
|
||||
// Type of SEP
|
||||
// Required: true
|
||||
SepType string `url:"sep_type" json:"sep_type" validate:"required,sepType"`
|
||||
|
||||
// Language of template
|
||||
// Required: true
|
||||
Language string `url:"lang" json:"lang" validate:"required,language"`
|
||||
}
|
||||
|
||||
// GetTemplate gets data to sep template
|
||||
func (s SEP) GetTemplate(ctx context.Context, req GetTemplateRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/getTemplate"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
10
pkg/cloudbroker/sep/ids.go
Normal file
10
pkg/cloudbroker/sep/ids.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package sep
|
||||
|
||||
// IDs gets array of SEPIDs from ListSEP struct
|
||||
func (ls ListSEP) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(ls.Data))
|
||||
for _, s := range ls.Data {
|
||||
res = append(res, s.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
87
pkg/cloudbroker/sep/list.go
Normal file
87
pkg/cloudbroker/sep/list.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of SEPs
|
||||
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 gId
|
||||
// Required: false
|
||||
GID uint64 `url:"gid,omitempty" json:"gid,omitempty"`
|
||||
|
||||
// Find by sep type
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||
|
||||
// Find by provided physical node id
|
||||
// Required: false
|
||||
ProvidedBy uint64 `url:"providedBy,omitempty" json:"providedBy,omitempty"`
|
||||
|
||||
// Find by techStatus
|
||||
// Required: false
|
||||
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||
|
||||
// Find by consumed physical node id
|
||||
// Required: false
|
||||
ConsumedBy uint64 `url:"consumedBy,omitempty" json:"consumedBy,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Sort by SEP IDs
|
||||
SepIDs []uint64 `url:"sep_ids,omitempty" json:"sep_ids,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of SEPs as a ListSEP struct
|
||||
func (s SEP) List(ctx context.Context, req ListRequest) (*ListSEP, error) {
|
||||
|
||||
res, err := s.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListSEP{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of SEPs as an array of bytes
|
||||
func (s SEP) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/list"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
51
pkg/cloudbroker/sep/list_available_sep_and_pools.go
Normal file
51
pkg/cloudbroker/sep/list_available_sep_and_pools.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// ListAvailableSEPAndPoolsRequest struct to get dict with entry count and list of dict with SEPs and pools details accessible by the Account and RG
|
||||
type ListAvailableSEPAndPoolsRequest struct {
|
||||
// Account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
|
||||
|
||||
// RG ID
|
||||
// Required: false
|
||||
RGID uint64 `url:"rg_id,omitempty" json:"rg_id,omitempty"`
|
||||
}
|
||||
|
||||
// ListAvailableSEPAndPools get dict with entry count and list of dict with SEPs and pools details accessible by the Account and RG
|
||||
func (s SEP) ListAvailableSEPAndPools(ctx context.Context, req ListAvailableSEPAndPoolsRequest) (*ListAvailableSEP, error) {
|
||||
res, err := s.ListAvailableSEPAndPoolsRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListAvailableSEP{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list as an array of bytes
|
||||
func (s SEP) ListAvailableSEPAndPoolsRaw(ctx context.Context, req ListAvailableSEPAndPoolsRequest) ([]byte, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/listAvailableSepAndPools"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
296
pkg/cloudbroker/sep/models.go
Normal file
296
pkg/cloudbroker/sep/models.go
Normal file
@@ -0,0 +1,296 @@
|
||||
package sep
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// Total resource information
|
||||
type Total struct {
|
||||
// Capacity limit
|
||||
CapacityLimit uint64 `json:"capacity_limit"`
|
||||
|
||||
// Disk count
|
||||
DiskCount uint64 `json:"disk_count"`
|
||||
|
||||
// Disk usage
|
||||
DiskUsage uint64 `json:"disk_usage"`
|
||||
|
||||
// Snapshot count
|
||||
SnapshotCount uint64 `json:"snapshot_count"`
|
||||
|
||||
// Snapshot usage
|
||||
SnapshotUsage uint64 `json:"snapshot_usage"`
|
||||
|
||||
// Usage
|
||||
Usage uint64 `json:"usage"`
|
||||
|
||||
// Usage limit
|
||||
UsageLimit uint64 `json:"usage_limit"`
|
||||
}
|
||||
|
||||
type ByPool struct {
|
||||
|
||||
// Disk count
|
||||
DiskCount uint64 `json:"disk_count"`
|
||||
|
||||
// Disk usage
|
||||
DiskUsage uint64 `json:"disk_usage"`
|
||||
|
||||
// Snapshot count
|
||||
SnapshotCount uint64 `json:"snapshot_count"`
|
||||
|
||||
// Snapshot usage
|
||||
SnapshotUsage uint64 `json:"snapshot_usage"`
|
||||
|
||||
// Usage
|
||||
Usage uint64 `json:"usage"`
|
||||
|
||||
// Usage limit
|
||||
UsageLimit uint64 `json:"usage_limit"`
|
||||
}
|
||||
|
||||
// List of Resource groups
|
||||
type ListConsumption struct {
|
||||
// Data
|
||||
Data []RecordConsumption `json:"data"`
|
||||
|
||||
// Enrtry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about consumption
|
||||
type RecordConsumption struct {
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
// By pool
|
||||
ByPool map[string]ByPool `json:"byPool"`
|
||||
|
||||
// Total resource information
|
||||
Total Total `json:"total"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// Consumed by
|
||||
ConsumedBy []uint64 `json:"consumedBy"`
|
||||
}
|
||||
|
||||
// Main information about URI
|
||||
type ItemURI struct {
|
||||
// IP
|
||||
IP string `json:"ip"`
|
||||
|
||||
// Port
|
||||
Port uint64 `json:"port"`
|
||||
}
|
||||
|
||||
// List URIs
|
||||
type ListURIs []ItemURI
|
||||
|
||||
// Detailed information about SEP pool
|
||||
type RecordPool struct {
|
||||
// List access account IDs
|
||||
AccessAccountIDs []uint64 `json:"accessAccountIds"`
|
||||
|
||||
// List access resource group IDs
|
||||
AccessResGroupIDs []uint64 `json:"accessResGroupIds"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Page cache ratio
|
||||
PageCacheRatio uint64 `json:"pagecache_ratio"`
|
||||
|
||||
// Reference ID
|
||||
ReferenceID string `json:"referenceId"`
|
||||
|
||||
// List types
|
||||
Types []string `json:"types"`
|
||||
|
||||
// List URIs
|
||||
URIs ListURIs `json:"uris"`
|
||||
|
||||
// Usage Limit
|
||||
UsageLimit uint64 `json:"usage_limit"`
|
||||
}
|
||||
|
||||
// SEP config
|
||||
type SEPConfig map[string]interface{}
|
||||
|
||||
// Detailed information about SEP
|
||||
type RecordSEP struct {
|
||||
// Config
|
||||
Config SEPConfig `json:"config"`
|
||||
|
||||
// Consumed by
|
||||
ConsumedBy []uint64 `json:"consumedBy"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// MultipathNum
|
||||
MultipathNum uint64 `json:"multipathNum"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Object status
|
||||
ObjStatus string `json:"objStatus"`
|
||||
|
||||
// Provided by
|
||||
ProvidedBy []uint64 `json:"providedBy"`
|
||||
|
||||
// Shared with
|
||||
SharedWith []uint64 `json:"sharedWith"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// List SEPs
|
||||
type ListSEP struct {
|
||||
// Data
|
||||
Data []RecordSEP `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
type Pool struct {
|
||||
// Pool name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Pool types
|
||||
Types []string `json:"types"`
|
||||
|
||||
// System
|
||||
System bool `json:"system"`
|
||||
}
|
||||
|
||||
type SEPData struct {
|
||||
// SEP ID
|
||||
SEPID uint64 `json:"sepId"`
|
||||
|
||||
// SEP name
|
||||
SEPName string `json:"sepName"`
|
||||
|
||||
// Sep type
|
||||
SEPType string `json:"sepType"`
|
||||
|
||||
// Pools
|
||||
Pools []Pool `json:"pools"`
|
||||
}
|
||||
|
||||
type ListAvailableSEP struct {
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
|
||||
// Data
|
||||
Data []SEPData `json:"data"`
|
||||
}
|
||||
|
||||
// Disk clean settings
|
||||
type DiskCleanSettings struct {
|
||||
// Block size
|
||||
BlockSize string `json:"blocksize"`
|
||||
|
||||
// Write bytes per second
|
||||
WBPS uint64 `json:"wbps"`
|
||||
|
||||
// Write I/O operations per second
|
||||
WIOPS uint64 `json:"wiops"`
|
||||
}
|
||||
|
||||
// Pool configuration
|
||||
type PoolConfig struct {
|
||||
// Disk clean
|
||||
DiskClean *string `json:"disk_clean"`
|
||||
|
||||
// Disk clean settings
|
||||
DiskCleanSettings DiskCleanSettings `json:"disk_clean_settings"`
|
||||
|
||||
// Pool name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Usage limit
|
||||
UsageLimit uint64 `json:"usage_limit"`
|
||||
|
||||
// Additional properties
|
||||
AdditionalProperties map[string]interface{} `json:"-"`
|
||||
}
|
||||
|
||||
func (p *PoolConfig) UnmarshalJSON(data []byte) error {
|
||||
type tmpAlias PoolConfig
|
||||
if err := json.Unmarshal(data, (*tmpAlias)(p)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
all := make(map[string]interface{})
|
||||
if err := json.Unmarshal(data, &all); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
delete(all, "disk_clean")
|
||||
delete(all, "disk_clean_settings")
|
||||
delete(all, "name")
|
||||
delete(all, "usage_limit")
|
||||
|
||||
if len(all) > 0 {
|
||||
p.AdditionalProperties = all
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sep configuration information
|
||||
type RecordConfigFieldEdit struct {
|
||||
// Format
|
||||
Format string `json:"format"`
|
||||
|
||||
// Pools
|
||||
Pools []PoolConfig `json:"pools"`
|
||||
|
||||
// Protocol
|
||||
Protocol string `json:"protocol"`
|
||||
|
||||
// Additional properties
|
||||
AdditionalProperties map[string]interface{} `json:"-"`
|
||||
}
|
||||
|
||||
func (r *RecordConfigFieldEdit) UnmarshalJSON(data []byte) error {
|
||||
type tmpAlias RecordConfigFieldEdit
|
||||
if err := json.Unmarshal(data, (*tmpAlias)(r)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
all := make(map[string]interface{})
|
||||
if err := json.Unmarshal(data, &all); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
delete(all, "format")
|
||||
delete(all, "pools")
|
||||
delete(all, "protocol")
|
||||
|
||||
if len(all) > 0 {
|
||||
r.AdditionalProperties = all
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
18
pkg/cloudbroker/sep/sep.go
Normal file
18
pkg/cloudbroker/sep/sep.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Operator actions for handling interventions on a storage endpoint provider
|
||||
package sep
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to storage endpoint provider
|
||||
type SEP struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for SEP endpoints
|
||||
func New(client interfaces.Caller) *SEP {
|
||||
return &SEP{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
79
pkg/cloudbroker/sep/serialize.go
Normal file
79
pkg/cloudbroker/sep/serialize.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lsep ListSEP) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lsep.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lsep, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lsep)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (rsep RecordSEP) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(rsep, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(rsep)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lsep ListAvailableSEP) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lsep.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(lsep, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(lsep)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (rsep SEPData) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(rsep, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(rsep)
|
||||
}
|
||||
87
pkg/cloudbroker/sep/shared_lock_start.go
Normal file
87
pkg/cloudbroker/sep/shared_lock_start.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// SharedLockStartRequest struct to start shared locks
|
||||
type SharedLockStartRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// List of node IDs for start locks
|
||||
// Required: false
|
||||
Nodes []uint64 `url:"nodes,omitempty" json:"nodes,omitempty"`
|
||||
|
||||
// List of pool names for start locks
|
||||
// Required: false
|
||||
VGNames []string `url:"vg_names,omitempty" json:"vg_names,omitempty"`
|
||||
|
||||
// If there are LOCKs, ignore them
|
||||
// Default: false
|
||||
// Required: false
|
||||
IgnoreStartedLock bool `url:"ignore_started_lock" json:"ignore_started_lock"`
|
||||
}
|
||||
|
||||
type wrapperSharedLockStartRequest struct {
|
||||
SharedLockStartRequest
|
||||
|
||||
AsyncMode bool `url:"sync"`
|
||||
}
|
||||
|
||||
// SharedLockStart start shared locks without AsyncMode
|
||||
func (s SEP) SharedLockStart(ctx context.Context, req SharedLockStartRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperSharedLockStartRequest{
|
||||
SharedLockStartRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/sharedLockStart"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// SharedLockStartAsync start shared locks with AsyncMode
|
||||
func (s SEP) SharedLockStartAsync(ctx context.Context, req SharedLockStartRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperSharedLockStartRequest{
|
||||
SharedLockStartRequest: req,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/sharedLockStart"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
82
pkg/cloudbroker/sep/shared_lock_stop.go
Normal file
82
pkg/cloudbroker/sep/shared_lock_stop.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// SharedLockStopRequest struct to stop shared locks
|
||||
type SharedLockStopRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// List of node IDs for stop locks
|
||||
// Required: false
|
||||
Nodes []uint64 `url:"nodes,omitempty" json:"nodes,omitempty"`
|
||||
|
||||
// List of pool names for stop locks
|
||||
// Required: false
|
||||
VGNames []string `url:"vg_names,omitempty" json:"vg_names,omitempty"`
|
||||
}
|
||||
|
||||
type wrapperSharedLockStopRequest struct {
|
||||
SharedLockStopRequest
|
||||
|
||||
AsyncMode bool `url:"sync"`
|
||||
}
|
||||
|
||||
// SharedLockStop stop shared locks without AsyncMode
|
||||
func (s SEP) SharedLockStop(ctx context.Context, req SharedLockStopRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperSharedLockStopRequest{
|
||||
SharedLockStopRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/sharedLockStop"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// SharedLockStopAsync stop shared locks with AsyncMode
|
||||
func (s SEP) SharedLockStopAsync(ctx context.Context, req SharedLockStopRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperSharedLockStopRequest{
|
||||
SharedLockStopRequest: req,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/sharedLockStop"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
48
pkg/cloudbroker/sep/update.go
Normal file
48
pkg/cloudbroker/sep/update.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v15/internal/validators"
|
||||
)
|
||||
|
||||
// UpdateRequest struct to update SEP object
|
||||
type UpdateRequest struct {
|
||||
// ID of SEP to update
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required,min=1"`
|
||||
|
||||
// New SEP name
|
||||
// Required: false
|
||||
// Default: null
|
||||
SEPName string `url:"name,omitempty" json:"name,omitempty" validate:"omitempty,min=1,max=256,sepName"`
|
||||
|
||||
// New description
|
||||
// Required: false
|
||||
// Default: null
|
||||
Description string `url:"description,omitempty" json:"description,omitempty" validate:"omitempty,max=4096,sepDescription"`
|
||||
}
|
||||
|
||||
// Update updates SEP object
|
||||
func (s SEP) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/update"
|
||||
|
||||
res, err := s.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
|
||||
}
|
||||
Reference in New Issue
Block a user