v12.0.0
This commit is contained in:
51
pkg/cloudbroker/stpolicy/add_pool.go
Normal file
51
pkg/cloudbroker/stpolicy/add_pool.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
type AddPoolRequest struct {
|
||||
// ID of storage policy
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
|
||||
// Storage endpoint provider ID to add
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Pool to add
|
||||
// Required: true
|
||||
PoolName string `url:"pool_name" json:"pool_name" validate:"required"`
|
||||
}
|
||||
|
||||
func (sp StPolicy) AddPool(ctx context.Context, req AddPoolRequest) (*InfoStoragePolicyWithID, error) {
|
||||
res, err := sp.AddPoolRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := InfoStoragePolicyWithID{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (sp StPolicy) AddPoolRaw(ctx context.Context, req AddPoolRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/storage_policy/add_pool"
|
||||
|
||||
res, err := sp.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
63
pkg/cloudbroker/stpolicy/create.go
Normal file
63
pkg/cloudbroker/stpolicy/create.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/constants"
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
type AccessSEPsPool struct {
|
||||
|
||||
// Storage endpoint provider ID
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Names of pools
|
||||
// Required: true
|
||||
PoolNames []string `url:"pool_names" json:"pool_names" validate:"required"`
|
||||
}
|
||||
|
||||
type CreateRequest struct {
|
||||
// Name of the storage policy
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// List of storage endpoint access objects
|
||||
// Required: true
|
||||
AccessSEPsPools []AccessSEPsPool `url:"access_seps_pools" json:"access_seps_pools" validate:"required"`
|
||||
|
||||
// Description of the storage policy
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// Maximum IOPS limit
|
||||
// Default: 2000
|
||||
// Required: false
|
||||
LimitIOPS uint64 `url:"limit_iops,omitempty" json:"limit_iops,omitempty"`
|
||||
}
|
||||
|
||||
// Create creates a new storage policy
|
||||
func (sp StPolicy) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/storage_policy/create"
|
||||
|
||||
res, err := sp.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
36
pkg/cloudbroker/stpolicy/delete.go
Normal file
36
pkg/cloudbroker/stpolicy/delete.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
// ID of storage policy to delete
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (sp StPolicy) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/storage_policy/delete"
|
||||
|
||||
res, err := sp.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/stpolicy/delete_pool.go
Normal file
51
pkg/cloudbroker/stpolicy/delete_pool.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
type DeletePoolRequest struct {
|
||||
// ID of storage policy
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
|
||||
// Storage endpoint provider ID to delete
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
|
||||
|
||||
// Pool to delete
|
||||
// Required: true
|
||||
PoolName string `url:"pool_name" json:"pool_name" validate:"required"`
|
||||
}
|
||||
|
||||
func (sp StPolicy) DeletePool(ctx context.Context, req DeletePoolRequest) (*InfoStoragePolicyWithID, error) {
|
||||
res, err := sp.DeletePoolRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := InfoStoragePolicyWithID{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (sp StPolicy) DeletePoolRaw(ctx context.Context, req DeletePoolRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/storage_policy/delete_pool"
|
||||
|
||||
res, err := sp.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
36
pkg/cloudbroker/stpolicy/disable.go
Normal file
36
pkg/cloudbroker/stpolicy/disable.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
type DisableRequest struct {
|
||||
// ID of storage policy to disable
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (sp StPolicy) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/storage_policy/disable"
|
||||
|
||||
res, err := sp.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
|
||||
}
|
||||
36
pkg/cloudbroker/stpolicy/enable.go
Normal file
36
pkg/cloudbroker/stpolicy/enable.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
type EnableRequest struct {
|
||||
// ID of storage policy to enable
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (sp StPolicy) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/storage_policy/enable"
|
||||
|
||||
res, err := sp.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/stpolicy/filter.go
Normal file
71
pkg/cloudbroker/stpolicy/filter.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package stpolicy
|
||||
|
||||
// FilterByID returns ListStoragePolicies with specified ID.
|
||||
func (lsp ListStoragePolicies) FilterByID(id uint64) ListStoragePolicies {
|
||||
predicate := func(isp ItemStoragePolicy) bool {
|
||||
return isp.ID == id
|
||||
}
|
||||
|
||||
return lsp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListStoragePolicies with specified Name.
|
||||
func (lsp ListStoragePolicies) FilterByName(name string) ListStoragePolicies {
|
||||
predicate := func(isp ItemStoragePolicy) bool {
|
||||
return isp.Name == name
|
||||
}
|
||||
|
||||
return lsp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListStoragePolicies with specified Status.
|
||||
func (lsp ListStoragePolicies) FilterByStatus(status string) ListStoragePolicies {
|
||||
predicate := func(isp ItemStoragePolicy) bool {
|
||||
return isp.Status == status
|
||||
}
|
||||
|
||||
return lsp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListStoragePolicies with specified Desc.
|
||||
func (lsp ListStoragePolicies) FilterByDesc(desc string) ListStoragePolicies {
|
||||
predicate := func(isp ItemStoragePolicy) bool {
|
||||
return isp.Description == desc
|
||||
}
|
||||
|
||||
return lsp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByLimitIOPS returns ListStoragePolicies with specified IOPS.
|
||||
func (lsp ListStoragePolicies) FilterByLimitIOPS(limitIOPS uint64) ListStoragePolicies {
|
||||
predicate := func(isp ItemStoragePolicy) bool {
|
||||
return isp.LimitIOPS == limitIOPS
|
||||
}
|
||||
|
||||
return lsp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListStoragePolicies based on a user-specified predicate.
|
||||
func (lsp ListStoragePolicies) FilterFunc(predicate func(ItemStoragePolicy) bool) ListStoragePolicies {
|
||||
var result ListStoragePolicies
|
||||
|
||||
for _, item := range lsp.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemStoragePolicy
|
||||
// If none was found, returns an empty struct.
|
||||
func (lsp ListStoragePolicies) FindOne() ItemStoragePolicy {
|
||||
if len(lsp.Data) == 0 {
|
||||
return ItemStoragePolicy{}
|
||||
}
|
||||
|
||||
return lsp.Data[0]
|
||||
}
|
||||
110
pkg/cloudbroker/stpolicy/filter_test.go
Normal file
110
pkg/cloudbroker/stpolicy/filter_test.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package stpolicy
|
||||
|
||||
import "testing"
|
||||
|
||||
var asp9 = AccessSEPPool{
|
||||
SEPID: 9,
|
||||
PoolNames: []string{"data03"},
|
||||
}
|
||||
|
||||
var asp7 = AccessSEPPool{
|
||||
SEPID: 7,
|
||||
PoolNames: []string{"pool_QA"},
|
||||
}
|
||||
|
||||
var asp8 = AccessSEPPool{
|
||||
SEPID: 8,
|
||||
PoolNames: []string{
|
||||
"alpha_pool_block",
|
||||
"alpha_pool_stripe",
|
||||
"alpha_pool_file",
|
||||
},
|
||||
}
|
||||
|
||||
var storagePolicyItems = ListStoragePolicies{
|
||||
Data: []ItemStoragePolicy{
|
||||
{
|
||||
ID: 1,
|
||||
GUID: 1,
|
||||
Name: "storagePolicy01",
|
||||
Description: "desc",
|
||||
AccessSEPPools: ListAccessSEPPools{asp7},
|
||||
Status: "ENABLED",
|
||||
LimitIOPS: 2000,
|
||||
Usage: Usage{},
|
||||
},
|
||||
{
|
||||
ID: 3,
|
||||
GUID: 3,
|
||||
Name: "storagePolicy03",
|
||||
Description: "desc",
|
||||
AccessSEPPools: ListAccessSEPPools{asp7, asp8, asp9},
|
||||
Status: "ENABLED",
|
||||
LimitIOPS: 2500,
|
||||
Usage: Usage{},
|
||||
},
|
||||
{
|
||||
ID: 5,
|
||||
GUID: 5,
|
||||
Name: "storagePolicy05",
|
||||
Description: "another desc",
|
||||
AccessSEPPools: ListAccessSEPPools{asp8, asp9},
|
||||
Status: "DISABLED",
|
||||
LimitIOPS: 2000,
|
||||
Usage: Usage{},
|
||||
},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := storagePolicyItems.FilterByID(1).FindOne()
|
||||
|
||||
if actual.ID != 1 {
|
||||
t.Fatal("expected 1 ID, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := storagePolicyItems.FilterByName("storagePolicy01").FindOne()
|
||||
|
||||
if actual.Name != "storagePolicy01" {
|
||||
t.Fatal("expected Name 'storagePolicy01', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := storagePolicyItems.FilterByStatus("ENABLED")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByDesc(t *testing.T) {
|
||||
actual := storagePolicyItems.FilterByDesc("desc")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Description != "desc" {
|
||||
t.Fatal("expected Description 'desc', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByLimitIOPS(t *testing.T) {
|
||||
actual := storagePolicyItems.FilterByLimitIOPS(2500).FindOne()
|
||||
|
||||
if actual.LimitIOPS != 2500 {
|
||||
t.Fatal("expected LimitIOPS '2500', found: ", actual.LimitIOPS)
|
||||
}
|
||||
}
|
||||
43
pkg/cloudbroker/stpolicy/get.go
Normal file
43
pkg/cloudbroker/stpolicy/get.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
// ID of storage policy
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (sp StPolicy) Get(ctx context.Context, req GetRequest) (*InfoStoragePolicy, error) {
|
||||
res, err := sp.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := InfoStoragePolicy{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (sp StPolicy) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/storage_policy/get"
|
||||
|
||||
res, err := sp.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
90
pkg/cloudbroker/stpolicy/list.go
Normal file
90
pkg/cloudbroker/stpolicy/list.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
|
||||
// Search by storage policy ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Search by storage policy name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Search by storage policy status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Search by storage policy desc
|
||||
// Required: false
|
||||
Desc string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
|
||||
// Search by storage policy iops limit
|
||||
// Required: false
|
||||
LimitIOPS uint64 `url:"limit_iops,omitempty" json:"limit_iops,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format ±<field>
|
||||
// Required: false
|
||||
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
|
||||
|
||||
// ID of account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
|
||||
|
||||
// Search by resgroup id
|
||||
// Required: false
|
||||
ResgroupID uint64 `url:"resgroup_id,omitempty" json:"resgroup_id,omitempty"`
|
||||
|
||||
// Search by sep id
|
||||
// Required: false
|
||||
SepID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
|
||||
|
||||
// Search by pool name
|
||||
// Required: false
|
||||
PoolName string `url:"pool_name,omitempty" json:"pool_name,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of storage policies as a ListStoragePolicies struct
|
||||
func (sp StPolicy) List(ctx context.Context, req ListRequest) (*ListStoragePolicies, error) {
|
||||
|
||||
res, err := sp.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListStoragePolicies{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of storage policies as an array of bytes
|
||||
func (sp StPolicy) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/storage_policy/list"
|
||||
|
||||
res, err := sp.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
108
pkg/cloudbroker/stpolicy/models.go
Normal file
108
pkg/cloudbroker/stpolicy/models.go
Normal file
@@ -0,0 +1,108 @@
|
||||
package stpolicy
|
||||
|
||||
type InfoStoragePolicyWithID struct {
|
||||
// ID of the storage policy
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// Name of the storage policy
|
||||
Name string `json:"name"`
|
||||
|
||||
// Description of the storage policy
|
||||
Description string `json:"description"`
|
||||
|
||||
// List of pools in SEP for storage policy
|
||||
AccessSEPPools ListAccessSEPPools `json:"access_seps_pools"`
|
||||
|
||||
// Status of the storage policy
|
||||
Status string `json:"status"`
|
||||
|
||||
// Max IOPS for the sotrage policy
|
||||
LimitIOPS uint64 `json:"limit_iops"`
|
||||
|
||||
// ID of the storage policy
|
||||
StoragePolicyID uint64 `json:"storage_policy_id"`
|
||||
}
|
||||
|
||||
type ListStoragePolicies struct {
|
||||
// List
|
||||
Data []ItemStoragePolicy `json:"data"`
|
||||
|
||||
// Entry Count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
type ItemStoragePolicy struct {
|
||||
// ID of the storage policy
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// Name of the storage policy
|
||||
Name string `json:"name"`
|
||||
|
||||
// Description of the storage policy
|
||||
Description string `json:"description"`
|
||||
|
||||
// List of pools in SEP for storage policy
|
||||
AccessSEPPools ListAccessSEPPools `json:"access_seps_pools"`
|
||||
|
||||
// Status of the storage policy
|
||||
Status string `json:"status"`
|
||||
|
||||
// Max IOPS for the sotrage policy
|
||||
LimitIOPS uint64 `json:"limit_iops"`
|
||||
|
||||
// Which accounts and resource groups use the storage policy
|
||||
Usage Usage `json:"usage"`
|
||||
}
|
||||
|
||||
type InfoStoragePolicy struct {
|
||||
// ID of the storage policy
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// Name of the storage policy
|
||||
Name string `json:"name"`
|
||||
|
||||
// Description of the storage policy
|
||||
Description string `json:"description"`
|
||||
|
||||
// List of pools in SEP for storage policy
|
||||
AccessSEPPools ListAccessSEPPools `json:"access_seps_pools"`
|
||||
|
||||
// Status of the storage policy
|
||||
Status string `json:"status"`
|
||||
|
||||
// Max IOPS for the storage policy
|
||||
LimitIOPS uint64 `json:"limit_iops"`
|
||||
|
||||
// Which accounts and resource groups use the storage policy
|
||||
Usage Usage `json:"usage"`
|
||||
}
|
||||
|
||||
type ListAccessSEPPools []AccessSEPPool
|
||||
|
||||
type AccessSEPPool struct {
|
||||
// SEP ID
|
||||
SEPID uint64 `json:"sep_id"`
|
||||
|
||||
// SEP name
|
||||
Name string `json:"sep_name"`
|
||||
|
||||
// Pool names
|
||||
PoolNames []string `json:"pool_names"`
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
// List of accounts
|
||||
Accounts []uint64 `json:"accounts"`
|
||||
|
||||
// List of resource groups
|
||||
Resgroups []uint64 `json:"resgroups"`
|
||||
}
|
||||
15
pkg/cloudbroker/stpolicy/storage_policy.go
Normal file
15
pkg/cloudbroker/stpolicy/storage_policy.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package stpolicy
|
||||
|
||||
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/interfaces"
|
||||
|
||||
// Structure for creating request to storage policy
|
||||
type StPolicy struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for stack endpoint
|
||||
func New(client interfaces.Caller) *StPolicy {
|
||||
return &StPolicy{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
56
pkg/cloudbroker/stpolicy/update.go
Normal file
56
pkg/cloudbroker/stpolicy/update.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
|
||||
)
|
||||
|
||||
type UpdateRequest struct {
|
||||
// ID of storage policy
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
|
||||
// New name for the storage policy
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// New value for limit IOPS
|
||||
// Required: false
|
||||
LimitIOPS uint64 `url:"limit_iops,omitempty" json:"limit_iops,omitempty"`
|
||||
|
||||
// New description of the storage policy
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
}
|
||||
|
||||
// Update updates storage policy
|
||||
func (sp StPolicy) Update(ctx context.Context, req UpdateRequest) (*InfoStoragePolicyWithID, error) {
|
||||
res, err := sp.UpdateRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := InfoStoragePolicyWithID{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (sp StPolicy) UpdateRaw(ctx context.Context, req UpdateRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/storage_policy/update"
|
||||
|
||||
res, err := sp.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
Reference in New Issue
Block a user