v9.0.0
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/v9/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/v9/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/v9/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/v9/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/v9/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) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/addConsumerNodes"
|
||||
|
||||
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
|
||||
}
|
||||
43
pkg/cloudbroker/sep/add_pool.go
Normal file
43
pkg/cloudbroker/sep/add_pool.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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"`
|
||||
|
||||
// method Async/Sync
|
||||
// Default: true
|
||||
// Required: false
|
||||
Sync bool `url:"sync" json:"sync"`
|
||||
|
||||
// Pool structure which contains fields such as "name", "types", "accessAccountIds", "accessResGroupIds"
|
||||
// Required: true
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
}
|
||||
|
||||
// AddPool adds pool to SEP
|
||||
func (s SEP) AddPool(ctx context.Context, req AddPoolRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/addPool"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := 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/v9/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) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/addProviderNodes"
|
||||
|
||||
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
|
||||
}
|
||||
56
pkg/cloudbroker/sep/config_field_edit.go
Normal file
56
pkg/cloudbroker/sep/config_field_edit.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/configFieldEdit"
|
||||
|
||||
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_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/v9/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/v9/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/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ConsumptionRequest struct to get consumption info
|
||||
type ConsumptionRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Consumption gets SEP consumption info
|
||||
func (s SEP) Consumption(ctx context.Context, req ConsumptionRequest) (*RecordConsumption, 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 := RecordConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
66
pkg/cloudbroker/sep/create.go
Normal file
66
pkg/cloudbroker/sep/create.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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"`
|
||||
|
||||
// SEP config
|
||||
// Required: true
|
||||
Config string `url:"config" json:"config" validate:"required"`
|
||||
|
||||
// Description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// List of provider node IDs
|
||||
// Required: false
|
||||
ProviderNIDs []uint64 `url:"provider_nids,omitempty" json:"provider_nids,omitempty"`
|
||||
|
||||
// List of consumer node IDs
|
||||
// Required: false
|
||||
ConsumerNIDs []uint64 `url:"consumer_nids,omitempty" json:"consumer_nids,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/v9/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
|
||||
}
|
||||
42
pkg/cloudbroker/sep/del_consumer_nodes.go
Normal file
42
pkg/cloudbroker/sep/del_consumer_nodes.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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"`
|
||||
}
|
||||
|
||||
// DelConsumerNodes excludes consumer nodes from SEP parameters
|
||||
func (s SEP) DelConsumerNodes(ctx context.Context, req DelConsumerNodesRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/delConsumerNodes"
|
||||
|
||||
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/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/v9/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/v9/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/v9/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/v9/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/v9/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
|
||||
}
|
||||
71
pkg/cloudbroker/sep/filter.go
Normal file
71
pkg/cloudbroker/sep/filter.go
Normal file
@@ -0,0 +1,71 @@
|
||||
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]
|
||||
}
|
||||
187
pkg/cloudbroker/sep/filter_test.go
Normal file
187
pkg/cloudbroker/sep/filter_test.go
Normal file
@@ -0,0 +1,187 @@
|
||||
package sep
|
||||
|
||||
import "testing"
|
||||
|
||||
var seps = ListSEP{
|
||||
Data: []RecordSEP{
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"osismodel",
|
||||
"cloudbroker",
|
||||
"sep",
|
||||
1,
|
||||
},
|
||||
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",
|
||||
},
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"osismodel",
|
||||
"cloudbroker",
|
||||
"sep",
|
||||
1,
|
||||
},
|
||||
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",
|
||||
},
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"osismodel",
|
||||
"cloudbroker",
|
||||
"sep",
|
||||
1,
|
||||
},
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
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/v9/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/v9/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/v9/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
|
||||
}
|
||||
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
|
||||
}
|
||||
84
pkg/cloudbroker/sep/list.go
Normal file
84
pkg/cloudbroker/sep/list.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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"`
|
||||
|
||||
// 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
|
||||
}
|
||||
157
pkg/cloudbroker/sep/models.go
Normal file
157
pkg/cloudbroker/sep/models.go
Normal file
@@ -0,0 +1,157 @@
|
||||
package sep
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// Main information about consumption
|
||||
type RecordConsumption struct {
|
||||
// By pool
|
||||
ByPool map[string]ByPool `json:"byPool"`
|
||||
|
||||
// Total resource information
|
||||
Total Total `json:"total"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// 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"`
|
||||
}
|
||||
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/v9/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,
|
||||
}
|
||||
}
|
||||
43
pkg/cloudbroker/sep/serialize.go
Normal file
43
pkg/cloudbroker/sep/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package sep
|
||||
|
||||
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 (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)
|
||||
}
|
||||
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/v9/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/v9/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
|
||||
}
|
||||
38
pkg/cloudbroker/sep/update_capacity_limit.go
Normal file
38
pkg/cloudbroker/sep/update_capacity_limit.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// UpdateCapacityLimitRequest struct to update capacity limits
|
||||
type UpdateCapacityLimitRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
}
|
||||
|
||||
// UpdateCapacityLimit updates SEP capacity limit
|
||||
func (s SEP) UpdateCapacityLimit(ctx context.Context, req UpdateCapacityLimitRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/updateCapacityLimit"
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user