v1.0.0
This commit is contained in:
53
pkg/cloudbroker/sep/access_grant.go
Normal file
53
pkg/cloudbroker/sep/access_grant.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for grant access to SEP
|
||||
type AccessGrantRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
func (srq AccessGrantRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if srq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessGrant grant access to SEP
|
||||
func (s SEP) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
60
pkg/cloudbroker/sep/access_grant_to_pool.go
Normal file
60
pkg/cloudbroker/sep/access_grant_to_pool.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for grant access to pool SEP
|
||||
type AccessGrantToPoolRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// Pool name
|
||||
// Required: true
|
||||
PoolName string `url:"pool_name"`
|
||||
|
||||
// Account ID to grant access to the specified pool SEP
|
||||
// Required: false
|
||||
AccountID uint64 `url:"account_id,omitempty"`
|
||||
|
||||
// Resource group to grant access to the specified pool SEP
|
||||
// Required: false
|
||||
RGID uint64 `url:"resgroup_id,omitempty"`
|
||||
}
|
||||
|
||||
func (srq AccessGrantToPoolRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if srq.PoolName == "" {
|
||||
return errors.New("validation-error: field PoolName must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessGrantToPool grant access to pool SEP
|
||||
func (s SEP) AccessGrantToPool(ctx context.Context, req AccessGrantToPoolRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/sep/access_revoke.go
Normal file
52
pkg/cloudbroker/sep/access_revoke.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for revoke access to SEP
|
||||
type AccessRevokeRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// Account ID to revoke access to the specified SEP
|
||||
// Required: true
|
||||
AccountID uint64 `url:"account_id"`
|
||||
}
|
||||
|
||||
func (srq AccessRevokeRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if srq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessRevoke revoke access to SEP
|
||||
func (s SEP) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
60
pkg/cloudbroker/sep/access_revoke_to_pool.go
Normal file
60
pkg/cloudbroker/sep/access_revoke_to_pool.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for revoke access to pool SEP
|
||||
type AccessRevokeToPoolRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// Pool name
|
||||
// Required: true
|
||||
PoolName string `url:"pool_name"`
|
||||
|
||||
// Account ID to grant access to the specified pool SEP
|
||||
// Required: false
|
||||
AccountID uint64 `url:"account_id,omitempty"`
|
||||
|
||||
// Resource group ID to grant access to the specified pool SEP
|
||||
// Required: false
|
||||
RGID uint64 `url:"resgroup_id,omitempty"`
|
||||
}
|
||||
|
||||
func (srq AccessRevokeToPoolRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if srq.PoolName == "" {
|
||||
return errors.New("validation-error: field PoolName must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessRevokeToPool revoke access to pool SEP
|
||||
func (s SEP) AccessRevokeToPool(ctx context.Context, req AccessRevokeToPoolRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/sep/add_consumer_nodes.go
Normal file
52
pkg/cloudbroker/sep/add_consumer_nodes.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for add consumer nodes
|
||||
type AddConsumerNodesRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// List of nodes IDs
|
||||
// Required: true
|
||||
ConsumerNIDs []uint64 `url:"consumer_nids"`
|
||||
}
|
||||
|
||||
func (srq AddConsumerNodesRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if len(srq.ConsumerNIDs) == 0 {
|
||||
return errors.New("validation-error: field ConsumerNIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddConsumerNodes add consumer nodes to SEP parameters
|
||||
func (s SEP) AddConsumerNodes(ctx context.Context, req AddConsumerNodesRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/sep/add_provider_nodes.go
Normal file
52
pkg/cloudbroker/sep/add_provider_nodes.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for add provider nodes
|
||||
type AddProviderNodesRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// List of node IDs
|
||||
// Required: true
|
||||
ProviderNIDs []uint64 `url:"provider_nids"`
|
||||
}
|
||||
|
||||
func (srq AddProviderNodesRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if len(srq.ProviderNIDs) == 0 {
|
||||
return errors.New("validation-error: field ProviderNIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddProviderNodes add provider nodes to SEP parameters
|
||||
func (s SEP) AddProviderNodes(ctx context.Context, req AddProviderNodesRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
78
pkg/cloudbroker/sep/config_field_edit.go
Normal file
78
pkg/cloudbroker/sep/config_field_edit.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for edit config fields
|
||||
type ConfigFieldEditRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// Field name
|
||||
// Required: true
|
||||
FieldName string `url:"field_name"`
|
||||
|
||||
// Field value
|
||||
// Required: true
|
||||
FieldValue string `url:"field_value"`
|
||||
|
||||
// Field type
|
||||
// Should be one of:
|
||||
// - int
|
||||
// - str
|
||||
// - bool
|
||||
// - list
|
||||
// - dict
|
||||
// Required: true
|
||||
FieldType string `url:"field_type"`
|
||||
}
|
||||
|
||||
func (srq ConfigFieldEditRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if srq.FieldName == "" {
|
||||
return errors.New("validation-error: field FieldName must be set")
|
||||
}
|
||||
if srq.FieldValue == "" {
|
||||
return errors.New("validation-error: field FieldValue must be set")
|
||||
}
|
||||
if srq.FieldType == "" {
|
||||
return errors.New("validation-error: field FieldType must be set")
|
||||
}
|
||||
validate := validators.StringInSlice(srq.FieldType, []string{"int", "str", "bool", "list", "dict"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field FieldType must be one of int, str, bool, list, dict")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigFieldEdit edit SEP config field value
|
||||
func (s SEP) ConfigFieldEdit(ctx context.Context, req ConfigFieldEditRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/sep/config_insert.go
Normal file
52
pkg/cloudbroker/sep/config_insert.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for insert config
|
||||
type ConfigInsertRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// Storage provider config
|
||||
// Required: true
|
||||
Config string `url:"config"`
|
||||
}
|
||||
|
||||
func (srq ConfigInsertRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if srq.Config == "" {
|
||||
return errors.New("validation-error: feold Config must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigInsert insert config to SEP
|
||||
func (s SEP) ConfigInsert(ctx context.Context, req ConfigInsertRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/sep/config_validate.go
Normal file
52
pkg/cloudbroker/sep/config_validate.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for validate config
|
||||
type ConfigValidateRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// Storage provider config
|
||||
// Required: true
|
||||
Config string `url:"config"`
|
||||
}
|
||||
|
||||
func (srq ConfigValidateRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if srq.Config == "" {
|
||||
return errors.New("validation-error: feold Config must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigValidate verify config for the SEP
|
||||
func (s SEP) ConfigValidate(ctx context.Context, req ConfigValidateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
47
pkg/cloudbroker/sep/consumption.go
Normal file
47
pkg/cloudbroker/sep/consumption.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get consumption info
|
||||
type ConsumptionRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
}
|
||||
|
||||
func (srq ConsumptionRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Consumption get SEP consumption info
|
||||
func (s SEP) Consumption(ctx context.Context, req ConsumptionRequest) (*RecordConsumption, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, 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
|
||||
}
|
||||
79
pkg/cloudbroker/sep/create.go
Normal file
79
pkg/cloudbroker/sep/create.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for create SEP object
|
||||
type CreateRequest struct {
|
||||
// Grid ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
|
||||
// SEP name
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// Type of storage
|
||||
// Required: true
|
||||
SEPType string `url:"sep_type"`
|
||||
|
||||
// Description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty"`
|
||||
|
||||
// SEP config
|
||||
// Required: false
|
||||
Config string `url:"config,omitempty"`
|
||||
|
||||
// List of provider node IDs
|
||||
// Required: false
|
||||
ProviderNIDs []uint64 `url:"provider_nids,omitempty"`
|
||||
|
||||
// List of consumer node IDs
|
||||
// Required: false
|
||||
ConsumerNIDs []uint64 `url:"consumer_nids,omitempty"`
|
||||
|
||||
// Enable SEP after creation
|
||||
// Required: false
|
||||
Enable bool `url:"enable,omitempty"`
|
||||
}
|
||||
|
||||
func (srq CreateRequest) validate() error {
|
||||
if srq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if srq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if srq.SEPType == "" {
|
||||
return errors.New("validation-error: field SEPType must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates SEP object
|
||||
func (s SEP) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, 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
|
||||
}
|
||||
49
pkg/cloudbroker/sep/decommission.go
Normal file
49
pkg/cloudbroker/sep/decommission.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for decommission
|
||||
type DecommissionRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// Clear disks and images physically
|
||||
// Required: false
|
||||
ClearPhisically bool `url:"clear_physically,omitempty"`
|
||||
}
|
||||
|
||||
func (srq DecommissionRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decommission unlink everything that exists from SEP
|
||||
func (s SEP) Decommission(ctx context.Context, req DecommissionRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/sep/del_consumer_nodes.go
Normal file
52
pkg/cloudbroker/sep/del_consumer_nodes.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for exclude consumer nodes
|
||||
type DelConsumerNodesRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// List of consumer node IDs
|
||||
// Required: true
|
||||
ConsumerNIDs []uint64 `url:"consumer_nids"`
|
||||
}
|
||||
|
||||
func (srq DelConsumerNodesRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if len(srq.ConsumerNIDs) == 0 {
|
||||
return errors.New("validation-error: field ConsumerNIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelConsumerNodes exclude consumer nodes from SEP parameters
|
||||
func (s SEP) DelConsumerNodes(ctx context.Context, req DelConsumerNodesRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/sep/delete.go
Normal file
45
pkg/cloudbroker/sep/delete.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete SEP
|
||||
type DeleteRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
}
|
||||
|
||||
func (srq DeleteRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes SEP by ID
|
||||
func (s SEP) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/sep/disable.go
Normal file
45
pkg/cloudbroker/sep/disable.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for disable SEP
|
||||
type DisableRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
}
|
||||
|
||||
func (srq DisableRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable disables SEP by ID
|
||||
func (s SEP) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
51
pkg/cloudbroker/sep/disk_list.go
Normal file
51
pkg/cloudbroker/sep/disk_list.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of disk IDs
|
||||
type DiskListRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// Pool name
|
||||
// Required: false
|
||||
PoolName string `url:"pool_name,omitempty"`
|
||||
}
|
||||
|
||||
func (srq DiskListRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DiskList get list of disk IDs, who use this SEP and pool (if provided)
|
||||
func (s SEP) DiskList(ctx context.Context, req DiskListRequest) ([]uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, 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
|
||||
}
|
||||
45
pkg/cloudbroker/sep/enable.go
Normal file
45
pkg/cloudbroker/sep/enable.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for enable SEP
|
||||
type EnableRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
}
|
||||
|
||||
func (srq EnableRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enable enables SEP by ID
|
||||
func (s SEP) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
47
pkg/cloudbroker/sep/get.go
Normal file
47
pkg/cloudbroker/sep/get.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get SEP parameters
|
||||
type GetRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
}
|
||||
|
||||
func (srq GetRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get gets SEP parameters
|
||||
func (s SEP) Get(ctx context.Context, req GetRequest) (*RecordSEP, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/sep/get"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordSEP{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
47
pkg/cloudbroker/sep/get_config.go
Normal file
47
pkg/cloudbroker/sep/get_config.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get SEP config
|
||||
type GetConfigRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
}
|
||||
|
||||
func (srq GetConfigRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetConfig gets SEP config
|
||||
func (s SEP) GetConfig(ctx context.Context, req GetConfigRequest) (*SEPConfig, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, 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
|
||||
}
|
||||
54
pkg/cloudbroker/sep/get_pool.go
Normal file
54
pkg/cloudbroker/sep/get_pool.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get SEP pool config by name
|
||||
type GetPoolRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
|
||||
// Pool name
|
||||
// Required: true
|
||||
PoolName string `url:"pool_name"`
|
||||
}
|
||||
|
||||
func (srq GetPoolRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
if srq.PoolName == "" {
|
||||
return errors.New("validation-error: PoolName must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPool gets SEP pool config by name
|
||||
func (s SEP) GetPool(ctx context.Context, req GetPoolRequest) (*RecordPool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, 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
|
||||
}
|
||||
37
pkg/cloudbroker/sep/list.go
Normal file
37
pkg/cloudbroker/sep/list.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of SEPs
|
||||
type ListRequest struct {
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of SEPs
|
||||
func (s SEP) List(ctx context.Context, req ListRequest) (ListSEP, error) {
|
||||
url := "/cloudbroker/sep/list"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListSEP{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
127
pkg/cloudbroker/sep/models.go
Normal file
127
pkg/cloudbroker/sep/models.go
Normal file
@@ -0,0 +1,127 @@
|
||||
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"`
|
||||
}
|
||||
|
||||
// Main information about consumption
|
||||
type RecordConsumption struct {
|
||||
// By pool
|
||||
ByPool map[string]interface{} `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"`
|
||||
}
|
||||
|
||||
// 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 []RecordSEP
|
||||
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 (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to storage endpoint provider
|
||||
type SEP struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for SEP endpoints
|
||||
func New(client interfaces.Caller) *SEP {
|
||||
return &SEP{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
45
pkg/cloudbroker/sep/update_capacity_limit.go
Normal file
45
pkg/cloudbroker/sep/update_capacity_limit.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update capacity limits
|
||||
type UpdateCapacityLimitRequest struct {
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id"`
|
||||
}
|
||||
|
||||
func (srq UpdateCapacityLimitRequest) validate() error {
|
||||
if srq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SEPID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateCapacityLimit updates SEP capacity limit
|
||||
func (s SEP) UpdateCapacityLimit(ctx context.Context, req UpdateCapacityLimitRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, 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