Merge 'dev' into 'main'
This commit is contained in:
9
pkg/cloudbroker/account.go
Normal file
9
pkg/cloudbroker/account.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudbroker/account"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) Account() *account.Account {
|
||||
return account.New(cb.client)
|
||||
}
|
||||
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
|
||||
}
|
||||
13
pkg/cloudbroker/cloudbroker.go
Normal file
13
pkg/cloudbroker/cloudbroker.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package cloudbroker
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
|
||||
type CloudBroker struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *CloudBroker {
|
||||
return &CloudBroker{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
9
pkg/cloudbroker/compute.go
Normal file
9
pkg/cloudbroker/compute.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/compute"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) Compute() *compute.Compute {
|
||||
return compute.New(cb.client)
|
||||
}
|
||||
9
pkg/cloudbroker/computeci.go
Normal file
9
pkg/cloudbroker/computeci.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/computeci"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) ComputeCI() *computeci.ComputeCI {
|
||||
return computeci.New(cb.client)
|
||||
}
|
||||
9
pkg/cloudbroker/disks.go
Normal file
9
pkg/cloudbroker/disks.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudbroker/disks"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) Disks() *disks.Disks {
|
||||
return disks.New(cb.client)
|
||||
}
|
||||
64
pkg/cloudbroker/disks/create.go
Normal file
64
pkg/cloudbroker/disks/create.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
GID uint64 `url:"gid"`
|
||||
Name string `url:"name"`
|
||||
Description string `url:"description,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
Type string `url:"type"`
|
||||
SSDSize uint64 `url:"ssdSize"`
|
||||
IOPS uint64 `url:"iops,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
Pool string `url:"pool,omitempty"`
|
||||
}
|
||||
|
||||
func (drq CreateRequest) Validate() error {
|
||||
if drq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
if drq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
|
||||
if drq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
validate := validators.StringInSlice(drq.Type, []string{"B", "D", "T"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field must be B, D or T")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/create"
|
||||
|
||||
res, err := d.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
|
||||
}
|
||||
44
pkg/cloudbroker/disks/delete.go
Normal file
44
pkg/cloudbroker/disks/delete.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Detach bool `url:"detach,omitempty"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (drq DeleteRequest) Validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/delete"
|
||||
|
||||
res, err := d.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
|
||||
}
|
||||
46
pkg/cloudbroker/disks/delete_disks.go
Normal file
46
pkg/cloudbroker/disks/delete_disks.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DeleteDisksRequest struct {
|
||||
DiskIDS []uint64 `url:"diskIds"`
|
||||
Reason string `url:"reason"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (drq DeleteDisksRequest) Validate() error {
|
||||
if len(drq.DiskIDS) == 0 {
|
||||
return errors.New("validation-error: field DiskIDs must be set")
|
||||
}
|
||||
if drq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) DeleteDisks(ctx context.Context, req DeleteDisksRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/deleteDisks"
|
||||
|
||||
res, err := d.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
|
||||
}
|
||||
13
pkg/cloudbroker/disks/disks.go
Normal file
13
pkg/cloudbroker/disks/disks.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package disks
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
|
||||
type Disks struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *Disks {
|
||||
return &Disks{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
43
pkg/cloudbroker/disks/get.go
Normal file
43
pkg/cloudbroker/disks/get.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
}
|
||||
|
||||
func (drq GetRequest) Validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Get(ctx context.Context, req GetRequest) (*Disk, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/get"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
disk := Disk{}
|
||||
|
||||
err = json.Unmarshal(res, &disk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &disk, nil
|
||||
}
|
||||
55
pkg/cloudbroker/disks/limit_io.go
Normal file
55
pkg/cloudbroker/disks/limit_io.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type LimitIORequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
IOPS uint64 `url:"iops,omitempty"`
|
||||
TotalBytesSec uint64 `url:"total_bytes_sec,omitempty"`
|
||||
ReadBytesSec uint64 `url:"total_bytes_sec,omitempty"`
|
||||
WriteBytesSec uint64 `url:"write_bytes_sec,omitempty"`
|
||||
TotalIOPSSec uint64 `url:"total_iops_sec,omitempty"`
|
||||
ReadIOPSSec uint64 `url:"read_iops_sec,omitempty"`
|
||||
WriteIOPSSec uint64 `url:"write_iops_sec,omitempty"`
|
||||
TotalBytesSecMax uint64 `url:"total_bytes_sec_max,omitempty"`
|
||||
ReadBytesSecMax uint64 `url:"read_bytes_sec_max,omitempty"`
|
||||
WriteBytesSecMax uint64 `url:"write_bytes_sec_max,omitempty"`
|
||||
TotalIOPSSecMax uint64 `url:"total_iops_sec_max,omitempty"`
|
||||
ReadIOPSSecMax uint64 `url:"total_iops_sec_max,omitempty"`
|
||||
WriteIOPSSecMax uint64 `url:"write_iops_sec_max,omitempty"`
|
||||
SizeIOPSSec uint64 `url:"size_iops_sec,omitempty"`
|
||||
}
|
||||
|
||||
func (drq LimitIORequest) Validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/limitIO"
|
||||
|
||||
res, err := d.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
|
||||
}
|
||||
32
pkg/cloudbroker/disks/list.go
Normal file
32
pkg/cloudbroker/disks/list.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
Type string `url:"type,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (d Disks) List(ctx context.Context, req ListRequest) (ListDisks, error) {
|
||||
url := "/cloudbroker/disks/list"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
listDisks := ListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &listDisks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return listDisks, nil
|
||||
}
|
||||
41
pkg/cloudbroker/disks/list_deleted.go
Normal file
41
pkg/cloudbroker/disks/list_deleted.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListDeletedRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Type string `url:"type,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (drq ListDeletedRequest) Validate() error {
|
||||
if drq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeletedDisks, error) {
|
||||
url := "/cloudbroker/disks/listDeleted"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
deletedDisks := ListDeletedDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &deletedDisks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return deletedDisks, nil
|
||||
}
|
||||
30
pkg/cloudbroker/disks/list_types.go
Normal file
30
pkg/cloudbroker/disks/list_types.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListTypesRequest struct {
|
||||
Detailed bool `url:"detailed"`
|
||||
}
|
||||
|
||||
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface{}, error) {
|
||||
url := "/cloudbroker/disks/listTypes"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
typesList := make([]interface{}, 0)
|
||||
|
||||
err = json.Unmarshal(res, &typesList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return typesList, nil
|
||||
|
||||
}
|
||||
39
pkg/cloudbroker/disks/list_unattached.go
Normal file
39
pkg/cloudbroker/disks/list_unattached.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListUnattachedRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (drq ListUnattachedRequest) Validate() error {
|
||||
if drq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (ListUnattached, error) {
|
||||
url := "/cloudbroker/disks/listUnattached"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
diskList := ListUnattached{}
|
||||
|
||||
err = json.Unmarshal(res, &diskList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return diskList, nil
|
||||
|
||||
}
|
||||
101
pkg/cloudbroker/disks/models.go
Normal file
101
pkg/cloudbroker/disks/models.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package disks
|
||||
|
||||
type IOTune struct {
|
||||
ReadBytesSec uint64 `json:"read_bytes_sec"`
|
||||
ReadBytesSecMax uint64 `json:"read_bytes_sec_max"`
|
||||
ReadIOPSSec uint64 `json:"read_iops_sec"`
|
||||
ReadIOPSSecMax uint64 `json:"read_iops_sec_max"`
|
||||
SizeIOPSSec uint64 `json:"size_iops_sec"`
|
||||
TotalBytesSec uint64 `json:"total_bytes_sec"`
|
||||
TotalBytesSecMax uint64 `json:"total_bytes_sec_max"`
|
||||
TotalIOPSSec uint64 `json:"total_iops_sec"`
|
||||
TotalIOPSSecMax uint64 `json:"total_iops_sec_max"`
|
||||
WriteBytesSec uint64 `json:"write_bytes_sec"`
|
||||
WriteBytesSecMax uint64 `json:"write_bytes_sec_max"`
|
||||
WriteIOPSSec uint64 `json:"write_iops_sec"`
|
||||
WriteIOPSSecMax uint64 `json:"write_iops_sec_max"`
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
ACL map[string]interface{} `json:"acl"`
|
||||
BootPartition uint64 `json:"bootPartition"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Desc string `json:"desc"`
|
||||
DestructionTime uint64 `json:"destructionTime"`
|
||||
DiskPath string `json:"diskPath"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
ImageID uint64 `json:"imageId"`
|
||||
Images []uint64 `json:"images"`
|
||||
IOTune IOTune `json:"iotune"`
|
||||
Iqn string `json:"iqn"`
|
||||
Login string `json:"login"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Order uint64 `json:"order"`
|
||||
Params string `json:"params"`
|
||||
ParentID uint64 `json:"parentId"`
|
||||
Passwd string `json:"passwd"`
|
||||
PCISlot int64 `json:"pciSlot"`
|
||||
Pool string `json:"pool"`
|
||||
PurgeAttempts uint64 `json:"purgeAttempts"`
|
||||
PurgeTime uint64 `json:"purgeTime"`
|
||||
RealityDeviceNumber uint64 `json:"realityDeviceNumber"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
ResID string `json:"resId"`
|
||||
ResName string `json:"resName"`
|
||||
Role string `json:"role"`
|
||||
SepID uint64 `json:"sepId"`
|
||||
SizeMax uint64 `json:"sizeMax"`
|
||||
SizeUsed uint64 `json:"sizeUsed"`
|
||||
Snapshots []Snapshot `json:"snapshots"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
VMID uint64 `json:"vmid"`
|
||||
}
|
||||
|
||||
type Disk struct {
|
||||
DeviceName string `json:"devicename"`
|
||||
SepType string `json:"sepType"`
|
||||
Info
|
||||
}
|
||||
|
||||
type ListDisks []struct {
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
ComputeName string `json:"computeName"`
|
||||
MachineID uint64 `json:"machineId"`
|
||||
MachineName string `json:"machineName"`
|
||||
Disk
|
||||
}
|
||||
|
||||
type ListDeletedDisks []struct {
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
ComputeName string `json:"computeName"`
|
||||
MachineID uint64 `json:"machineId"`
|
||||
MachineName string `json:"machineName"`
|
||||
Disk
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type ListUnattached []struct {
|
||||
CKey string `json:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
Info
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
GUID string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
ResID string `json:"resId"`
|
||||
SnapSetGUID string `json:"snapSetGuid"`
|
||||
SnapSetTime uint64 `json:"snapSetTime"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
47
pkg/cloudbroker/disks/rename.go
Normal file
47
pkg/cloudbroker/disks/rename.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type RenameRequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Name string `url:"name"`
|
||||
}
|
||||
|
||||
func (drq RenameRequest) Validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
|
||||
if drq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/rename"
|
||||
|
||||
res, err := d.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
|
||||
|
||||
}
|
||||
67
pkg/cloudbroker/disks/resize.go
Normal file
67
pkg/cloudbroker/disks/resize.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ResizeRequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (drq ResizeRequest) Validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
if drq.Size == 0 {
|
||||
return errors.New("validation-error: field Size must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/resize"
|
||||
|
||||
res, err := d.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
|
||||
|
||||
}
|
||||
|
||||
func (d Disks) Resize2(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/resize2"
|
||||
|
||||
res, err := d.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
|
||||
|
||||
}
|
||||
46
pkg/cloudbroker/disks/restore.go
Normal file
46
pkg/cloudbroker/disks/restore.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type RestoreRequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Reason string `url:"reason"`
|
||||
}
|
||||
|
||||
func (drq RestoreRequest) Validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
if drq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/restore"
|
||||
|
||||
res, err := d.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/disks/search.go
Normal file
34
pkg/cloudbroker/disks/search.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SearchRequest struct {
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
Name string `url:"name,omitempty"`
|
||||
ShowAll bool `url:"show_all,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error) {
|
||||
url := "/cloudbroker/disks/search"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
diskList := ListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &diskList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return diskList, nil
|
||||
|
||||
}
|
||||
46
pkg/cloudbroker/disks/snapshot_delete.go
Normal file
46
pkg/cloudbroker/disks/snapshot_delete.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type SnapshotDeleteRequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Label string `url:"label"`
|
||||
}
|
||||
|
||||
func (drq SnapshotDeleteRequest) Validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
if drq.Label == "" {
|
||||
return errors.New("validation-error: field Label must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/snapshotDelete"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
50
pkg/cloudbroker/disks/snapshot_rollback.go
Normal file
50
pkg/cloudbroker/disks/snapshot_rollback.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type SnapshotRollbackRequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Label string `url:"label"`
|
||||
TimeStamp uint64 `url:"timestamp"`
|
||||
}
|
||||
|
||||
func (drq SnapshotRollbackRequest) Validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
if drq.Label == "" {
|
||||
return errors.New("validation-error: field Label must be set")
|
||||
}
|
||||
if drq.TimeStamp == 0 {
|
||||
return errors.New("validation-error: field TimeStamp must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/snapshotRollback"
|
||||
|
||||
res, err := d.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
|
||||
|
||||
}
|
||||
9
pkg/cloudbroker/extnet.go
Normal file
9
pkg/cloudbroker/extnet.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/extnet"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) ExtNet() *extnet.ExtNet {
|
||||
return extnet.New(cb.client)
|
||||
}
|
||||
9
pkg/cloudbroker/flipgroup.go
Normal file
9
pkg/cloudbroker/flipgroup.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/flipgroup"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) FlipGroup() *flipgroup.FlipGroup {
|
||||
return flipgroup.New(cb.client)
|
||||
}
|
||||
9
pkg/cloudbroker/image.go
Normal file
9
pkg/cloudbroker/image.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudbroker/image"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) Image() *image.Image {
|
||||
return image.New(cb.client)
|
||||
}
|
||||
45
pkg/cloudbroker/image/computeci_set.go
Normal file
45
pkg/cloudbroker/image/computeci_set.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ComputeCISetRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
ComputeCIID uint64 `url:"computeciId"`
|
||||
}
|
||||
|
||||
func (irq ComputeCISetRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
if irq.ComputeCIID == 0 {
|
||||
return errors.New("validation-error: field ComputeCIID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) ComputeCISet(ctx context.Context, req ComputeCISetRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/computeciSet"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
41
pkg/cloudbroker/image/computeci_unset.go
Normal file
41
pkg/cloudbroker/image/computeci_unset.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ComputeCIUnsetRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
}
|
||||
|
||||
func (irq ComputeCIUnsetRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) ComputeCIUnset(ctx context.Context, req ComputeCIUnsetRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/сomputeciUnset"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
68
pkg/cloudbroker/image/create_cdrom_image.go
Normal file
68
pkg/cloudbroker/image/create_cdrom_image.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CreateCDROMImageRequest struct {
|
||||
Name string `url:"name"`
|
||||
URL string `url:"url"`
|
||||
GID uint64 `url:"gid"`
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
SepID uint64 `url:"sep_id,omitempty"`
|
||||
PoolName string `url:"pool_name,omitempty"`
|
||||
UsernameDL string `url:"usernameDL,omitempty"`
|
||||
PasswordDl string `url:"passwordDL,omitempty"`
|
||||
Architecture string `url:"architecture,omitempty"`
|
||||
Drivers []string `url:"drivers"`
|
||||
}
|
||||
|
||||
func (irq CreateCDROMImageRequest) Validate() error {
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if irq.URL == "" {
|
||||
return errors.New("validation-error: field URL must be set")
|
||||
}
|
||||
if irq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
|
||||
if len(irq.Drivers) == 0 || len(irq.Drivers) > 1 {
|
||||
return errors.New("validation-error: field Drivers can not be empty or have 2 or more elements")
|
||||
}
|
||||
|
||||
for _, v := range irq.Drivers {
|
||||
validate := validators.StringInSlice(v, []string{"KVM_X86"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field Drivers can be KVM_X86 only")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) CreateCDROMImage(ctx context.Context, req CreateCDROMImageRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/createCDROMImage"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
78
pkg/cloudbroker/image/create_image.go
Normal file
78
pkg/cloudbroker/image/create_image.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
Name string `url:"name"`
|
||||
URL string `url:"url"`
|
||||
GID uint64 `url:"gid"`
|
||||
BootType string `url:"boottype"`
|
||||
ImageType string `url:"imagetype"`
|
||||
HotResize bool `url:"hotresize,omitempty"`
|
||||
Username string `url:"username,omitempty"`
|
||||
Password string `url:"password,omitempty"`
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
UsernameDL string `url:"usernameDL,omitempty"`
|
||||
PasswordDL string `url:"passwordDL,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
PoolName string `url:"poolName,omitempty"`
|
||||
Architecture string `url:"architecture,omitempty"`
|
||||
Drivers []string `url:"drivers,omitempty"`
|
||||
Bootable bool `url:"bootable,omitempty"`
|
||||
}
|
||||
|
||||
func (irq CreateRequest) Validate() error {
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if irq.URL == "" {
|
||||
return errors.New("validation-error: field URL must be set")
|
||||
}
|
||||
if irq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if irq.BootType == "" {
|
||||
return errors.New("validation-error: field BootType must be set")
|
||||
}
|
||||
if irq.ImageType == "" {
|
||||
return errors.New("validation-error: field ImageType must be set")
|
||||
}
|
||||
|
||||
validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field BootType can be bios or uefi")
|
||||
}
|
||||
validate = validators.StringInSlice(irq.ImageType, []string{"windows", "linux", "other"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field ImageType can be windows, linux or other")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) CreateImage(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/createImage"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
45
pkg/cloudbroker/image/create_virtual.go
Normal file
45
pkg/cloudbroker/image/create_virtual.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CreateVirtualRequest struct {
|
||||
Name string `url:"name"`
|
||||
TargetID uint64 `url:"targetId"`
|
||||
}
|
||||
|
||||
func (irq CreateVirtualRequest) Validate() error {
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if irq.TargetID == 0 {
|
||||
return errors.New("validation-error: field TargetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) CreateVirtual(ctx context.Context, req CreateVirtualRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/createVirtual"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
46
pkg/cloudbroker/image/delete.go
Normal file
46
pkg/cloudbroker/image/delete.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
Reason string `url:"reason"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (irq DeleteRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
if irq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/delete"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/image/delete_cdrom_image.go
Normal file
42
pkg/cloudbroker/image/delete_cdrom_image.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DeleteCDROMImageRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
Permanently bool `url:"permanently"`
|
||||
}
|
||||
|
||||
func (irq DeleteCDROMImageRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) DeleteCDROMImage(ctx context.Context, req DeleteCDROMImageRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/deleteCDROMImage"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
46
pkg/cloudbroker/image/delete_images.go
Normal file
46
pkg/cloudbroker/image/delete_images.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DeleteImagesRequest struct {
|
||||
ImageIDs []uint64 `url:"imageIds"`
|
||||
Reason string `url:"reason"`
|
||||
Permanently bool `url:"permanently"`
|
||||
}
|
||||
|
||||
func (irq DeleteImagesRequest) Validate() error {
|
||||
if len(irq.ImageIDs) == 0 {
|
||||
return errors.New("validation-error: field ImageIDs must be set")
|
||||
}
|
||||
if irq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) DeleteImages(ctx context.Context, req DeleteImagesRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/deleteImages"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
41
pkg/cloudbroker/image/disable.go
Normal file
41
pkg/cloudbroker/image/disable.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DisableRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
}
|
||||
|
||||
func (irq DisableRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/disable"
|
||||
|
||||
res, err := i.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/image/edit.go
Normal file
47
pkg/cloudbroker/image/edit.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type EditRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
Name string `url:"name,omitempty"`
|
||||
Username string `url:"username,omitempty"`
|
||||
Password string `url:"password,omitempty"`
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
HotResize bool `url:"hotresize,omitempty"`
|
||||
Bootable bool `url:"bootable,omitempty"`
|
||||
}
|
||||
|
||||
func (irq EditRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Edit(ctx context.Context, req EditRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/edit"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
41
pkg/cloudbroker/image/enable.go
Normal file
41
pkg/cloudbroker/image/enable.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type EnableRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
}
|
||||
|
||||
func (irq EnableRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must br set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/enable"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/cloudbroker/image/get.go
Normal file
43
pkg/cloudbroker/image/get.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
}
|
||||
|
||||
func (irq GetRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Get(ctx context.Context, req GetRequest) (*ImageRecord, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/get"
|
||||
|
||||
result := ImageRecord{}
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
13
pkg/cloudbroker/image/image.go
Normal file
13
pkg/cloudbroker/image/image.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package image
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
|
||||
type Image struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *Image {
|
||||
return &Image{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
45
pkg/cloudbroker/image/link.go
Normal file
45
pkg/cloudbroker/image/link.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type LinkRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
TargetID uint64 `url:"targetId"`
|
||||
}
|
||||
|
||||
func (irq LinkRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
if irq.TargetID == 0 {
|
||||
return errors.New("validation-error: field TargetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Link(ctx context.Context, req LinkRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/link"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
32
pkg/cloudbroker/image/list.go
Normal file
32
pkg/cloudbroker/image/list.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
SharedWith uint64 `url:"sharedWith,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) {
|
||||
url := "/cloudbroker/image/list"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListImages{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
45
pkg/cloudbroker/image/list_stacks.go
Normal file
45
pkg/cloudbroker/image/list_stacks.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListStacksRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (irq ListStacksRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (ListStacks, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/listStacks"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListStacks{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
82
pkg/cloudbroker/image/models.go
Normal file
82
pkg/cloudbroker/image/models.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package image
|
||||
|
||||
type ImageRecord struct {
|
||||
UNCPath string `json:"UNCPath"`
|
||||
CKey string `json:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
ACL []ACL `json:"acl"`
|
||||
Architecture string `json:"architecture"`
|
||||
BootType string `json:"bootType"`
|
||||
Bootable bool `json:"bootable"`
|
||||
ComputeCIID uint64 `json:"computeciId"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Desc string `json:"desc"`
|
||||
Drivers []string `json:"drivers"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Gid uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
History []History `json:"history"`
|
||||
HotResize bool `json:"hotResize"`
|
||||
ID uint64 `json:"id"`
|
||||
LastModified uint64 `json:"lastModified"`
|
||||
LinkTo uint64 `json:"linkTo"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"password"`
|
||||
Pool string `json:"pool"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
PurgeAttempts uint64 `json:"purgeAttempts"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
ResID string `json:"resId"`
|
||||
ResName string `json:"resName"`
|
||||
RescueCD bool `json:"rescuecd"`
|
||||
SepID uint64 `json:"sepId"`
|
||||
SharedWith []uint64 `json:"sharedWith"`
|
||||
Size uint64 `json:"size"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
Username string `json:"username"`
|
||||
Version string `json:"version"`
|
||||
Virtual bool `json:"virtual"`
|
||||
}
|
||||
|
||||
type ListImages []ImageRecord
|
||||
|
||||
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 History struct {
|
||||
GUID string `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type ListStacks []struct {
|
||||
CKey string `json:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
APIURL string `json:"apiUrl"`
|
||||
APIKey string `json:"apikey"`
|
||||
AppID string `json:"appId"`
|
||||
Desc string `json:"desc"`
|
||||
Drivers []string `json:"drivers"`
|
||||
Eco interface{} `json:"eco"`
|
||||
Error uint64 `json:"error"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Images []uint64 `json:"images"`
|
||||
Login string `json:"login"`
|
||||
Name string `json:"name"`
|
||||
Passwd string `json:"passwd"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
45
pkg/cloudbroker/image/rename.go
Normal file
45
pkg/cloudbroker/image/rename.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type RenameRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
Name string `url:"name"`
|
||||
}
|
||||
|
||||
func (irq RenameRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/rename"
|
||||
|
||||
res, err := i.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/image/share.go
Normal file
45
pkg/cloudbroker/image/share.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ShareRequest struct {
|
||||
ImageId uint64 `url:"imageId"`
|
||||
AccountIDs []uint64 `url:"accounts"`
|
||||
}
|
||||
|
||||
func (irq ShareRequest) Validate() error {
|
||||
if irq.ImageId == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
if len(irq.AccountIDs) == 0 || irq.AccountIDs == nil {
|
||||
return errors.New("validation-error: field must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) Share(ctx context.Context, req ShareRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/share"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
89
pkg/cloudbroker/image/sync_create_image.go
Normal file
89
pkg/cloudbroker/image/sync_create_image.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type SyncCreateRequest struct {
|
||||
Name string `url:"name"`
|
||||
URL string `url:"url"`
|
||||
GID uint64 `url:"gid"`
|
||||
BootType string `url:"boottype"`
|
||||
ImageType string `url:"imagetype"`
|
||||
HotResize bool `url:"hotresize,omitempty"`
|
||||
Username string `url:"username,omitempty"`
|
||||
Password string `url:"password,omitempty"`
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
UsernameDL string `url:"usernameDL,omitempty"`
|
||||
PasswordDL string `url:"passwordDL,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
PoolName string `url:"poolName,omitempty"`
|
||||
Architecture string `url:"architecture,omitempty"`
|
||||
Drivers []string `url:"drivers"`
|
||||
Bootable bool `url:"bootable,omitempty"`
|
||||
}
|
||||
|
||||
func (irq SyncCreateRequest) Validate() error {
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if irq.URL == "" {
|
||||
return errors.New("validation-error: field URL must be set")
|
||||
}
|
||||
if irq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if irq.BootType == "" {
|
||||
return errors.New("validation-error: field BootType must be set")
|
||||
}
|
||||
if irq.ImageType == "" {
|
||||
return errors.New("validation-error: field ImageType must be set")
|
||||
}
|
||||
|
||||
validate := validators.StringInSlice(irq.BootType, []string{"bios", "uefi"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field BootType can be bios or uefi")
|
||||
}
|
||||
validate = validators.StringInSlice(irq.ImageType, []string{"windows", "linux", "other"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field ImageType can be windows, linux or other")
|
||||
}
|
||||
|
||||
if len(irq.Drivers) == 0 || len(irq.Drivers) > 1 {
|
||||
return errors.New("validation-error: field Drivers can not be empty or have 2 or more elements")
|
||||
}
|
||||
|
||||
for _, v := range irq.Drivers {
|
||||
validate := validators.StringInSlice(v, []string{"KVM_X86"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field Drivers can be KVM_X86 only")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) SyncCreate(ctx context.Context, req SyncCreateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/syncCreateImage"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/image/update_nodes.go
Normal file
42
pkg/cloudbroker/image/update_nodes.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type UpdateNodesRequest struct {
|
||||
ImageID uint64 `url:"imageId"`
|
||||
EnabledStacks []uint64 `url:"enabledStacks,omitempty"`
|
||||
}
|
||||
|
||||
func (irq UpdateNodesRequest) Validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i Image) UpdateNodes(ctx context.Context, req UpdateNodesRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/updateNodes"
|
||||
|
||||
res, err := i.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
|
||||
}
|
||||
9
pkg/cloudbroker/k8ci.go
Normal file
9
pkg/cloudbroker/k8ci.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/k8ci"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) K8CI() *k8ci.K8CI {
|
||||
return k8ci.New(cb.client)
|
||||
}
|
||||
9
pkg/cloudbroker/k8s.go
Normal file
9
pkg/cloudbroker/k8s.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/k8s"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) K8S() *k8s.K8S {
|
||||
return k8s.New(cb.client)
|
||||
}
|
||||
7
pkg/cloudbroker/kvmppc.go
Normal file
7
pkg/cloudbroker/kvmppc.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package cloudbroker
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmppc"
|
||||
|
||||
func (cb *CloudBroker) KVMPPC() *kvmppc.KVMPPC {
|
||||
return kvmppc.New(cb.client)
|
||||
}
|
||||
9
pkg/cloudbroker/kvmx86.go
Normal file
9
pkg/cloudbroker/kvmx86.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) KVMX86() *kvmx86.KVMX86 {
|
||||
return kvmx86.New(cb.client)
|
||||
}
|
||||
7
pkg/cloudbroker/lb.go
Normal file
7
pkg/cloudbroker/lb.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package cloudbroker
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/lb"
|
||||
|
||||
func (cb *CloudBroker) LB() *lb.LB {
|
||||
return lb.New(cb.client)
|
||||
}
|
||||
7
pkg/cloudbroker/locatons.go
Normal file
7
pkg/cloudbroker/locatons.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package cloudbroker
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/locations"
|
||||
|
||||
func (cb *CloudBroker) Locations() *locations.Locations {
|
||||
return locations.New(cb.client)
|
||||
}
|
||||
7
pkg/cloudbroker/rg.go
Normal file
7
pkg/cloudbroker/rg.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package cloudbroker
|
||||
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/rg"
|
||||
|
||||
func (cb *CloudBroker) RG() *rg.RG {
|
||||
return rg.New(cb.client)
|
||||
}
|
||||
9
pkg/cloudbroker/sizes.go
Normal file
9
pkg/cloudbroker/sizes.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/sizes"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) Sizes() *sizes.Sizes {
|
||||
return sizes.New(cb.client)
|
||||
}
|
||||
9
pkg/cloudbroker/tasks.go
Normal file
9
pkg/cloudbroker/tasks.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/tasks"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) Tasks() *tasks.Tasks {
|
||||
return tasks.New(cb.client)
|
||||
}
|
||||
9
pkg/cloudbroker/vins.go
Normal file
9
pkg/cloudbroker/vins.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package cloudbroker
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/vins"
|
||||
)
|
||||
|
||||
func (cb *CloudBroker) VINS() *vins.VINS {
|
||||
return vins.New(cb.client)
|
||||
}
|
||||
Reference in New Issue
Block a user