Refactoring

This commit is contained in:
stSolo
2022-08-11 16:39:39 +03:00
parent 9563097dcb
commit 39a6f9a1ce
300 changed files with 64 additions and 58 deletions

View File

@@ -0,0 +1,15 @@
package account
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type Account struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *Account {
return &Account{
client,
}
}

View File

@@ -0,0 +1,68 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AddUserRequest struct {
AccountId uint64 `url:"accountId"`
UserId string `url:"userId"`
AccessType string `url:"accesstype"`
}
func (arq AddUserRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
if arq.UserId == "" {
return errors.New("validation-error: field UserId can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
}
func (a Account) AddUser(ctx context.Context, req AddUserRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/addUser"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,54 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AuditsRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq AuditsRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (AccountAuditsList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/audits"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
auditsRaw, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
audits := AccountAuditsList{}
err = json.Unmarshal([]byte(auditsRaw), &audits)
if err != nil {
return nil, err
}
return audits, nil
}

View File

@@ -0,0 +1,65 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type CreateRequest struct {
Name string `url:"name"`
Username string `url:"username"`
EmailAddress string `url:"emailaddress,omitempty"`
MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"`
MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"`
MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"`
MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"`
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
GpuUnits uint `url:"gpu_units,omitempty"`
}
func (arq CreateRequest) Validate() error {
if arq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
if arq.Username == "" {
return errors.New("validation-error: field Username can not be empty")
}
return nil
}
func (a Account) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/account/create"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, 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
}

View File

@@ -0,0 +1,52 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DeleteRequest struct {
AccountId uint64 `url:"accountId"`
Permanently bool `url:"permanently,omitempty"`
}
func (arq DeleteRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId must be set")
}
return nil
}
func (a Account) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/delete"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,58 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DeleteUserRequest struct {
AccountId uint64 `url:"accountId"`
UserId string `url:"userId"`
RecursiveDelete bool `url:"recursivedelete,omitempty"`
}
func (arq DeleteUserRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
if arq.UserId == "" {
return errors.New("validation-error: field UserId can not be empty")
}
return nil
}
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/deleteUser"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,80 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DisabelEnableRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq DisabelEnableRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/disable"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/enable"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,55 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq GetRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*AccountWithResources, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/get"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
account := &AccountWithResources{}
err = json.Unmarshal(res, &account)
if err != nil {
return nil, err
}
return account, nil
}

View File

@@ -0,0 +1,55 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetConsumedAccountUnitsRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq GetConsumedAccountUnitsRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/getConsumedAccountUnits"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
rl := &ResourceLimits{}
err = json.Unmarshal(res, &rl)
if err != nil {
return nil, err
}
return rl, nil
}

View File

@@ -0,0 +1,64 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetConsumedCloudUnitsByTypeRequest struct {
AccountId uint64 `url:"accountId"`
CUType string `url:"cutype"`
}
func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
if arq.CUType == "" {
return errors.New("validation-error: field CUType can not be empty")
}
isValid := validators.StringInSlice(arq.CUType, []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"})
if !isValid {
return errors.New("validation-error: field AccessType can be only CU_M, CU_C, CU_D, CU_S, CU_A, CU_NO, CU_I or CU_NP")
}
return nil
}
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest, options ...opts.DecortOpts) (float64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/account/getConsumedCloudUnitsByType"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseFloat(string(res), 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,83 @@
package account
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetConsumtionRequest struct {
AccountId uint64 `url:"accountId"`
Start uint64 `url:"start"`
End uint64 `url:"end"`
}
func (arq GetConsumtionRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
if arq.Start == 0 {
return errors.New("validation-error: field Start can not be empty or equal to 0")
}
if arq.End == 0 {
return errors.New("validation-error: field End can not be empty or equal to 0")
}
return nil
}
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/account/getConsumtion"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return "", err
}
return string(res), nil
}
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/account/getConsumtion"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.GET, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,55 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetReservedAccountUnitsRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq GetReservedAccountUnitsRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest, options ...opts.DecortOpts) (*ResourceLimits, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/getReservedAccountUnits"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
rl := &ResourceLimits{}
err = json.Unmarshal(res, &rl)
if err != nil {
return nil, err
}
return rl, nil
}

View File

@@ -0,0 +1,42 @@
package account
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListRequest struct {
Page uint64 `url:"page"`
Size uint64 `url:"size"`
}
func (a Account) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
url := "/account/list"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
accountList := AccountCloudApiList{}
err = json.Unmarshal(res, &accountList)
if err != nil {
return nil, err
}
return accountList, nil
}

View File

@@ -0,0 +1,55 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListComputesRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq ListComputesRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (AccountComputesList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listComputes"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
accountComputesList := AccountComputesList{}
err = json.Unmarshal(res, &accountComputesList)
if err != nil {
return nil, err
}
return accountComputesList, nil
}

View File

@@ -0,0 +1,42 @@
package account
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListDeletedRequest struct {
Page uint64 `url:"page"`
Size uint64 `url:"size"`
}
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (AccountCloudApiList, error) {
url := "/account/listDeleted"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
accountList := AccountCloudApiList{}
err = json.Unmarshal(res, &accountList)
if err != nil {
return nil, err
}
return accountList, nil
}

View File

@@ -0,0 +1,55 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListDisksRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq ListDisksRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest, options ...opts.DecortOpts) (AccountDisksList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listDisks"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
accountDisksList := AccountDisksList{}
err = json.Unmarshal(res, &accountDisksList)
if err != nil {
return nil, err
}
return accountDisksList, nil
}

View File

@@ -0,0 +1,55 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListFlipGroupsRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq ListFlipGroupsRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest, options ...opts.DecortOpts) (AccountFlipGroupsList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listFlipGroups"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
accountFlipGroupsList := AccountFlipGroupsList{}
err = json.Unmarshal(res, &accountFlipGroupsList)
if err != nil {
return nil, err
}
return accountFlipGroupsList, nil
}

View File

@@ -0,0 +1,55 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListRGRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq ListRGRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) ListRG(ctx context.Context, req ListRGRequest, options ...opts.DecortOpts) (AccountRGList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listRG"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
accountRGList := AccountRGList{}
err = json.Unmarshal(res, &accountRGList)
if err != nil {
return nil, err
}
return accountRGList, nil
}

View File

@@ -0,0 +1,56 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListTemplatesRequest struct {
AccountId uint64 `url:"accountId"`
IncludeDeleted bool `url:"includedeleted"`
}
func (arq ListTemplatesRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest, options ...opts.DecortOpts) (AccountTemplatesList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listTemplates"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
accountTemplatesList := AccountTemplatesList{}
err = json.Unmarshal(res, &accountTemplatesList)
if err != nil {
return nil, err
}
return accountTemplatesList, nil
}

View File

@@ -0,0 +1,55 @@
package account
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListVinsRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq ListVinsRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) ListVins(ctx context.Context, req ListVinsRequest, options ...opts.DecortOpts) (AccountVinsList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/account/listVins"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
accountVinsList := AccountVinsList{}
err = json.Unmarshal(res, &accountVinsList)
if err != nil {
return nil, err
}
return accountVinsList, nil
}

View File

@@ -0,0 +1,229 @@
package account
type AccountAclRecord struct {
IsExplicit bool `json:"explicit"`
GUID string `json:"guid"`
Rights string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
UgroupID string `json:"userGroupId"`
CanBeDeleted bool `json:"canBeDeleted"`
}
type ResourceLimits struct {
CUC float64 `json:"CU_C"`
CUD float64 `json:"CU_D"`
CUI float64 `json:"CU_I"`
CUM float64 `json:"CU_M"`
CUNP float64 `json:"CU_NP"`
GpuUnits float64 `json:"gpu_units"`
}
type AccountRecord struct {
DCLocation string `json:"DCLocation"`
CKey string `jspn:"_ckey"`
Meta []interface{} `json:"_meta"`
Acl []AccountAclRecord `json:"acl"`
Company string `json:"company"`
CompanyUrl string `json:"companyurl"`
CreatedBy string `jspn:"createdBy"`
CreatedTime int `json:"createdTime"`
DeactiovationTime float64 `json:"deactivationTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
DisplayName string `json:"displayname"`
GUID int `json:"guid"`
ID int `json:"id"`
Name string `json:"name"`
ResourceLimits ResourceLimits `json:"resourceLimits"`
SendAccessEmails bool `json:"sendAccessEmails"`
ServiceAccount bool `json:"serviceAccount"`
Status string `json:"status"`
UpdatedTime int `json:"updatedTime"`
Version int `json:"version"`
Vins []int `json:"vins"`
}
type AccountList []AccountRecord
type AccountCloudApi struct {
Acl []AccountAclRecord `json:"acl"`
CreatedTime int `json:"createdTime"`
DeletedTime int `json:"deletedTime"`
ID int `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
UpdatedTime int `json:"updatedTime"`
}
type AccountCloudApiList []AccountCloudApi
type Resource struct {
CPU int `json:"cpu"`
Disksize int `json:"disksize"`
Extips int `json:"extips"`
Exttraffic int `json:"exttraffic"`
GPU int `json:"gpu"`
RAM int `json:"ram"`
}
type Resources struct {
Current Resource `json:"Current"`
Reserved Resource `json:"Reserved"`
}
type Computes struct {
Started int `json:"started"`
Stopped int `json:"stopped"`
}
type Machines struct {
Running int `json:"running"`
Halted int `json:"halted"`
}
type AccountWithResources struct {
Account
Resources Resources `json:"Resources"`
Computes Computes `json:"computes"`
Machines Machines `json:"machines"`
Vinses int `json:"vinses"`
}
type AccountCompute struct {
AccountId int `json:"accountId"`
AccountName string `json:"accountName"`
CPUs int `json:"cpus"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
ComputeId int `json:"id"`
ComputeName string `json:"name"`
RAM int `json:"ram"`
Registered bool `json:"registered"`
RGId int `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
TotalDisksSize int `json:"totalDisksSize"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
UserManaged bool `json:"userManaged"`
VinsConnected int `json:"vinsConnected"`
}
type AccountComputesList []AccountCompute
type AccountDisk struct {
ID int `json:"id"`
Name string `json:"name"`
Pool string `json:"pool"`
SepId int `json:"sepId"`
SizeMax int `json:"sizeMax"`
Type string `json:"type"`
}
type AccountDisksList []AccountDisk
type AccountVin struct {
AccountId int `json:"accountId"`
AccountName string `json:"accountName"`
Computes int `json:"computes"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
ExternalIP string `json:"externalIP"`
ID int `json:"id"`
Name string `json:"name"`
Network string `json:"network"`
PriVnfDevId int `json:"priVnfDevId"`
RGId int `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
}
type AccountVinsList []AccountVin
type AccountAudit struct {
Call string `json:"call"`
ResponseTime float64 `json:"responsetime"`
StatusCode int `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
}
type AccountAuditsList []AccountAudit
type AccountRGComputes struct {
Started int `json:"Started"`
Stopped int `json:"Stopped"`
}
type AccountRGResources struct {
Consumed Resource `json:"Consumed"`
Limits Resource `json:"Limits"`
Reserved Resource `json:"Reserved"`
}
type AccountRG struct {
Computes AccountRGComputes `json:"Computes"`
Resources AccountRGResources `json:"Resources"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
RGID int `json:"id"`
Milestones int `json:"milestones"`
RGName string `json:"name"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
Vinses int `json:"vinses"`
}
type AccountRGList []AccountRG
type AccountTemplate struct {
UNCPath string `json:"UNCPath"`
AccountId int `json:"accountId"`
Description string `json:"desc"`
ID int `json:"id"`
Name string `json:"name"`
Public bool `json:"public"`
Size int `json:"size"`
Status string `json:"status"`
Type string `json:"type"`
Username string `json:"username"`
}
type AccountTemplatesList []AccountTemplate
type AccountFlipGroup struct {
AccountId int `json:"accountId"`
ClientType string `json:"clientType"`
ConnType string `json:"connType"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DefaultGW string `json:"defaultGW"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
Description string `json:"desc"`
GID int `json:"gid"`
GUID int `json:"guid"`
ID int `json:"id"`
IP string `json:"ip"`
Milestones int `json:"milestones"`
Name string `json:"name"`
NetID int `json:"netId"`
NetType string `json:"netType"`
NetMask int `json:"netmask"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
}
type AccountFlipGroupsList []AccountFlipGroup

View File

@@ -0,0 +1,53 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RestoreRequest struct {
AccountId uint64 `url:"accountId"`
}
func (arq RestoreRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/restore"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,60 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type UpdateRequest struct {
AccountId uint64 `url:"accountId"`
Name string `url:"name,omitempty"`
MaxMemoryCapacity uint `url:"maxMemoryCapacity,omitempty"`
MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"`
MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"`
MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"`
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
GpuUnits uint `url:"gpu_units,omitempty"`
}
func (arq UpdateRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
return nil
}
func (a Account) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/update"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,68 @@
package account
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type UpdateUserRequest struct {
AccountId uint64 `url:"accountId"`
UserId string `url:"userId"`
AccessType string `url:"accesstype"`
}
func (arq UpdateUserRequest) Validate() error {
if arq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
if arq.UserId == "" {
return errors.New("validation-error: field UserId can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
}
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/account/updateUser"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := a.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}