Merge 'dev' into 'main'
This commit is contained in:
13
pkg/cloudbroker/account/account.go
Normal file
13
pkg/cloudbroker/account/account.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package account
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
|
||||
type Account struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *Account {
|
||||
return &Account{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
58
pkg/cloudbroker/account/add_user.go
Normal file
58
pkg/cloudbroker/account/add_user.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type AddUserRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
UserName string `url:"username"`
|
||||
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.UserName == "" {
|
||||
return errors.New("validation-error: field UserName 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) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/addUser"
|
||||
|
||||
res, err := a.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/account/audits.go
Normal file
40
pkg/cloudbroker/account/audits.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
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) (AccountAuditsList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/audits"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := AccountAuditsList{}
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
53
pkg/cloudbroker/account/create.go
Normal file
53
pkg/cloudbroker/account/create.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
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) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/create"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
id, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
39
pkg/cloudbroker/account/delete.go
Normal file
39
pkg/cloudbroker/account/delete.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Reason string `url:"reason"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DeleteRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/delete"
|
||||
|
||||
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
39
pkg/cloudbroker/account/delete_accounts.go
Normal file
39
pkg/cloudbroker/account/delete_accounts.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type DeleteAccountsRequest struct {
|
||||
AccountsIDs []uint64 `url:"accountIds"`
|
||||
Reason string `url:"reason"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DeleteAccountsRequest) Validate() error {
|
||||
if arq.AccountsIDs == nil || len(arq.AccountsIDs) == 0 {
|
||||
return errors.New("validation-error: field AccountIDs must be set")
|
||||
}
|
||||
if arq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) DeleteAccounts(ctx context.Context, req DeleteAccountsRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/deleteAccounts"
|
||||
|
||||
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
45
pkg/cloudbroker/account/delete_user.go
Normal file
45
pkg/cloudbroker/account/delete_user.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DeleteUserRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
UserName string `url:"username"`
|
||||
RecursiveDelete bool `url:"recursivedelete,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DeleteUserRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.UserName == "" {
|
||||
return errors.New("validation-error: field UserName must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/deleteUser"
|
||||
|
||||
res, err := a.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/account/disable.go
Normal file
44
pkg/cloudbroker/account/disable.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DisableRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Reason string `url:"reason"`
|
||||
}
|
||||
|
||||
func (arq DisableRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/disable"
|
||||
|
||||
res, err := a.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
|
||||
}
|
||||
34
pkg/cloudbroker/account/disable_accounts.go
Normal file
34
pkg/cloudbroker/account/disable_accounts.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type DisableAccountsRequest struct {
|
||||
AccountIDs []uint64 `url:"accountIds,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DisableAccountsRequest) Validate() error {
|
||||
if arq.AccountIDs == nil || len(arq.AccountIDs) == 0 {
|
||||
return errors.New("validation-error: field AccountIDs must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) DisableAccounts(ctx context.Context, req DisableAccountsRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/disableAccounts"
|
||||
|
||||
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
44
pkg/cloudbroker/account/enable.go
Normal file
44
pkg/cloudbroker/account/enable.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type EnableRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Reason string `url:"reason"`
|
||||
}
|
||||
|
||||
func (arq EnableRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Reason == "" {
|
||||
return errors.New("field Reason must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/enable"
|
||||
|
||||
res, err := a.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
|
||||
}
|
||||
34
pkg/cloudbroker/account/enable_accounts.go
Normal file
34
pkg/cloudbroker/account/enable_accounts.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type EnableAccountsRequest struct {
|
||||
AccountIDs []uint64 `url:"accountIds"`
|
||||
}
|
||||
|
||||
func (arq EnableAccountsRequest) Validate() error {
|
||||
if arq.AccountIDs == nil || len(arq.AccountIDs) == 0 {
|
||||
return errors.New("validation-error: field AccountIDs must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) EnableAccounts(ctx context.Context, req EnableAccountsRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/enableAccounts"
|
||||
|
||||
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
41
pkg/cloudbroker/account/get.go
Normal file
41
pkg/cloudbroker/account/get.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq GetRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Get(ctx context.Context, req GetRequest) (GetResponse, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return GetResponse{}, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/get"
|
||||
|
||||
result := GetResponse{}
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return GetResponse{}, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return GetResponse{}, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
28
pkg/cloudbroker/account/list.go
Normal file
28
pkg/cloudbroker/account/list.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (a Account) List(ctx context.Context, req ListRequest) (ListInfoResponse, error) {
|
||||
url := "/cloudbroker/account/list"
|
||||
|
||||
result := ListInfoResponse{}
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return ListInfoResponse{}, err
|
||||
}
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return ListInfoResponse{}, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/cloudbroker/account/list_computes.go
Normal file
43
pkg/cloudbroker/account/list_computes.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListComputesRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListComputesRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return ListComputes{}, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listComputes"
|
||||
|
||||
result := ListComputes{}
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return ListComputes{}, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return ListComputes{}, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
29
pkg/cloudbroker/account/list_deleted.go
Normal file
29
pkg/cloudbroker/account/list_deleted.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListDeletedRequest struct {
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListInfoResponse, error) {
|
||||
url := "/cloudbroker/account/listDeleted"
|
||||
|
||||
result := ListInfoResponse{}
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return ListInfoResponse{}, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return ListInfoResponse{}, err
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
43
pkg/cloudbroker/account/list_disks.go
Normal file
43
pkg/cloudbroker/account/list_disks.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListDisksRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListDisksRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return ListDisks{}, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listDisks"
|
||||
|
||||
result := ListDisks{}
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return ListDisks{}, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return ListDisks{}, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/cloudbroker/account/list_flip_groups.go
Normal file
43
pkg/cloudbroker/account/list_flip_groups.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListFlipGroupsRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListFlipGroupsRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest) (ListFlipGroups, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return ListFlipGroups{}, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listFlipGroups"
|
||||
|
||||
result := ListFlipGroups{}
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return ListFlipGroups{}, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return ListFlipGroups{}, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/cloudbroker/account/list_rg.go
Normal file
43
pkg/cloudbroker/account/list_rg.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListRGRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListRGRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return ListRG{}, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listRG"
|
||||
|
||||
result := ListRG{}
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return ListRG{}, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return ListRG{}, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/cloudbroker/account/list_vins.go
Normal file
43
pkg/cloudbroker/account/list_vins.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListVINSRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListVINSRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return ListVINS{}, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listVins"
|
||||
|
||||
result := ListVINS{}
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return ListVINS{}, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return ListVINS{}, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
214
pkg/cloudbroker/account/models.go
Normal file
214
pkg/cloudbroker/account/models.go
Normal file
@@ -0,0 +1,214 @@
|
||||
package account
|
||||
|
||||
type AccountAudit struct {
|
||||
Call string `json:"call"`
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
StatusCode uint64 `json:"statuscode"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
type AccountAuditsList []AccountAudit
|
||||
|
||||
type Resources struct {
|
||||
Current Current `json:"Current"`
|
||||
Reserved Reserved `json:"Reserved"`
|
||||
}
|
||||
|
||||
type Current struct {
|
||||
CPU uint64 `json:"cpu"`
|
||||
DiskSize uint64 `json:"disksize"`
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
ExtTraffic uint64 `json:"exttraffic"`
|
||||
GPU uint64 `json:"gpu"`
|
||||
RAM uint64 `json:"ram"`
|
||||
}
|
||||
|
||||
type Reserved struct {
|
||||
CPU uint64 `json:"cpu"`
|
||||
DiskSize uint64 `json:"disksize"`
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
ExtTraffic uint64 `json:"exttraffic"`
|
||||
GPU uint64 `json:"gpu"`
|
||||
RAM uint64 `json:"ram"`
|
||||
}
|
||||
|
||||
type ACL struct {
|
||||
Explicit bool `json:"explicit"`
|
||||
GUID string `json:"guid"`
|
||||
Right string `json:"right"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
UserGroupID string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
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 InfoResponse struct {
|
||||
DCLocation string `json:"DCLocation"`
|
||||
CKey string `json:"_ckey"`
|
||||
ACL []ACL `json:"acl"`
|
||||
Company string `json:"company"`
|
||||
CompanyURL string `json:"companyurl"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeactivationTime float64 `json:"deactivationTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
DisplayName string `json:"displayname"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
||||
Status string `json:"status"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
Version uint64 `json:"version"`
|
||||
VINS []uint64 `json:"vins"`
|
||||
}
|
||||
type GetResponse struct {
|
||||
Resources Resources `json:"Resources"`
|
||||
InfoResponse
|
||||
}
|
||||
|
||||
type ListInfoResponse []struct {
|
||||
Meta []interface{} `json:"_meta"`
|
||||
InfoResponse
|
||||
}
|
||||
|
||||
type ListComputes []Compute
|
||||
type Compute struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
CPUs uint64 `json:"cpus"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RAM uint64 `json:"ram"`
|
||||
Registered bool `json:"registered"`
|
||||
RgID uint64 `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
TotalDisksSize uint64 `json:"totalDisksSize"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
VINSConnected uint64 `json:"vinsConnected"`
|
||||
}
|
||||
|
||||
type ListDisks []Disk
|
||||
|
||||
type Disk struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Pool string `json:"pool"`
|
||||
SepID uint64 `json:"sepId"`
|
||||
SizeMax uint64 `json:"sizeMax"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type ListFlipGroups []FlipGroup
|
||||
|
||||
type FlipGroup struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
ClientType string `json:"clientType"`
|
||||
ConnType string `json:"connType"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DefaultGW string `json:"defaultGW"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Desc string `json:"desc"`
|
||||
Gid uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
IP string `json:"ip"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
NetID uint64 `json:"netId"`
|
||||
NetType string `json:"netType"`
|
||||
Netmask uint64 `json:"netmask"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type Computes struct {
|
||||
Started uint64 `json:"Started"`
|
||||
Stopped uint64 `json:"Stopped"`
|
||||
}
|
||||
|
||||
type Consumed struct {
|
||||
CPU uint64 `json:"cpu"`
|
||||
DiskSize uint64 `json:"disksize"`
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
ExtTraffic uint64 `json:"exttraffic"`
|
||||
GPU uint64 `json:"gpu"`
|
||||
RAM uint64 `json:"ram"`
|
||||
}
|
||||
|
||||
type Limits struct {
|
||||
CPU int64 `json:"cpu"`
|
||||
DiskSize int64 `json:"disksize"`
|
||||
ExtIPs int64 `json:"extips"`
|
||||
ExtTraffic int64 `json:"exttraffic"`
|
||||
GPU int64 `json:"gpu"`
|
||||
RAM int64 `json:"ram"`
|
||||
}
|
||||
|
||||
type RGResuorces struct {
|
||||
Consumed Consumed `json:"Consumed"`
|
||||
Limits Limits `json:"Limits"`
|
||||
Reserved Reserved `json:"Reserved"`
|
||||
}
|
||||
|
||||
type RG struct {
|
||||
Computes Computes `json:"Computes"`
|
||||
Resources RGResuorces `json:"Resources"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
ID uint64 `json:"id"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
VINSes uint64 `json:"vinses"`
|
||||
}
|
||||
|
||||
type ListRG []RG
|
||||
|
||||
type VINS struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Computes uint64 `json:"computes"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
ExternalIP string `json:"externalIP"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Network string `json:"network"`
|
||||
PriVnfDevID uint64 `json:"priVnfDevId"`
|
||||
RgID uint64 `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type ListVINS []VINS
|
||||
39
pkg/cloudbroker/account/restore.go
Normal file
39
pkg/cloudbroker/account/restore.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type RestoreRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Reason string `url:"reason"`
|
||||
}
|
||||
|
||||
func (arq RestoreRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/restore"
|
||||
|
||||
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
52
pkg/cloudbroker/account/update.go
Normal file
52
pkg/cloudbroker/account/update.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type UpdateRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Name string `url:"name"`
|
||||
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
|
||||
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
|
||||
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
|
||||
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
|
||||
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
|
||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
|
||||
GPUUnits uint64 `url:"gpu_units,omitempty"`
|
||||
}
|
||||
|
||||
func (arq UpdateRequest) Validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/update"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/account/update_user.go
Normal file
49
pkg/cloudbroker/account/update_user.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
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 must be set")
|
||||
}
|
||||
if arq.UserID == "" {
|
||||
return errors.New("validation-error: field UserID must be set")
|
||||
}
|
||||
if arq.AccessType == "" {
|
||||
return errors.New("validation-error: field AccessType must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/updateUser"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user