This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/rudecs/decort-sdk/pkg/cloudbroker/account"
)
// Accessing the Account method group
func (cb *CloudBroker) Account() *account.Account {
return account.New(cb.client)
}

View File

@@ -1,11 +1,14 @@
// API Actor API for managing account
package account
import "github.com/rudecs/decort-sdk/interfaces"
// Structure for creating request to account
type Account struct {
client interfaces.Caller
}
// Builder for account endpoints
func New(client interfaces.Caller) *Account {
return &Account{
client: client,

View File

@@ -9,35 +9,45 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for adding permission to access to account for a user
type AddUserRequest struct {
AccountID uint64 `url:"accountId"`
UserName string `url:"username"`
// ID of account to add to
// Required: true
AccountID uint64 `url:"accountId"`
// Name of the user to be given rights
// Required: true
UserName string `url:"username"`
// Account permission types:
// - 'R' for read only access
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype"`
}
func (arq AddUserRequest) Validate() error {
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 {
validate := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !validate {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
}
// AddUser gives a user access rights.
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,19 +7,23 @@ import (
"net/http"
)
// Request struct for give list account audits
type AuditsRequest struct {
// ID of the account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq AuditsRequest) Validate() error {
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()
// Audits gets audit records for the specified account object
func (a Account) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -30,11 +34,13 @@ func (a Account) Audits(ctx context.Context, req AuditsRequest) (AccountAuditsLi
if err != nil {
return nil, err
}
result := AccountAuditsList{}
err = json.Unmarshal(res, &result)
list := ListAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return result, nil
return list, nil
}

View File

@@ -5,34 +5,92 @@ import (
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for creating account
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"`
// Display name
// Required: true
Name string `url:"name"`
// Name of the account
// Required: true
Username string `url:"username"`
// Email
// Required: false
EmailAddress string `url:"emailaddress,omitempty"`
// Max size of memory in MB
// Required: false
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
// Max size of aggregated vdisks in GB
// Required: false
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
// Max number of CPU cores
// Required: false
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// Max sent/received network transfer peering
// Required: false
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
// Max number of assigned public IPs
// Required: false
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
// If true send emails when a user is granted access to resources
// Required: false
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
// Limit (positive) or disable (0) GPU resources
// Required: false
GPUUnits uint64 `url:"gpu_units,omitempty"`
// List of strings with pools
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,omitempty"`
// Resource types available to create in this account
// Each element in a resource type slice must be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: false
ResTypes []string `url:"resourceTypes,omitempty"`
}
func (arq CreateRequest) Validate() error {
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")
}
if len(arq.ResTypes) > 0 {
for _, value := range arq.ResTypes {
validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"})
if !validate {
return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]")
}
}
}
return nil
}
// Create creates account
// Setting a cloud unit maximum to -1 or empty will not put any restrictions on the resource
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}
@@ -44,10 +102,10 @@ func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error)
return 0, err
}
id, err := strconv.ParseUint(string(res), 10, 64)
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return id, nil
return result, nil
}

View File

@@ -6,24 +6,35 @@ import (
"net/http"
)
// Request struct for delete account
type DeleteRequest struct {
AccountID uint64 `url:"accountId"`
Reason string `url:"reason"`
Permanently bool `url:"permanently,omitempty"`
// ID of account to delete
// Required: true
AccountID uint64 `url:"accountId"`
// Reason to delete
// Required: true
Reason string `url:"reason"`
// Whether to completely delete the account
// Required: false
Permanently bool `url:"permanently,omitempty"`
}
func (arq DeleteRequest) Validate() error {
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
}
// Delete completes delete an account from the system Returns true if account is deleted or was already deleted or never existed
func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -6,24 +6,35 @@ import (
"net/http"
)
// Request struct for delete group accounts
type DeleteAccountsRequest struct {
// IDs of accounts
// Required: true
AccountsIDs []uint64 `url:"accountIds"`
Reason string `url:"reason"`
Permanently bool `url:"permanently,omitempty"`
// Reason for deletion
// Required: true
Reason string `url:"reason"`
// Whether to completely destroy accounts or not
// Required: false
Permanently bool `url:"permanently,omitempty"`
}
func (arq DeleteAccountsRequest) Validate() error {
if arq.AccountsIDs == nil || len(arq.AccountsIDs) == 0 {
func (arq DeleteAccountsRequest) validate() error {
if 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
}
// DeleteAccounts destroy a group of accounts
func (a Account) DeleteAccounts(ctx context.Context, req DeleteAccountsRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,13 +7,22 @@ import (
"strconv"
)
// Request struct for revoke access to account
type DeleteUserRequest struct {
AccountID uint64 `url:"accountId"`
UserName string `url:"username"`
RecursiveDelete bool `url:"recursivedelete,omitempty"`
// ID of the account
// Required: true
AccountID uint64 `url:"accountId"`
// ID or emailaddress of the user to remove
// Required: true
UserName string `url:"username"`
// Recursively revoke access rights from owned cloudspaces and vmachines
// Required: false
RecursiveDelete bool `url:"recursivedelete,omitempty"`
}
func (arq DeleteUserRequest) Validate() error {
func (arq DeleteUserRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
@@ -24,8 +33,9 @@ func (arq DeleteUserRequest) Validate() error {
return nil
}
// DeleteUser revokes user access from the account
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -41,5 +51,6 @@ func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, e
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,23 +7,31 @@ import (
"strconv"
)
// Request struct for disable account
type DisableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId"`
Reason string `url:"reason"`
// Reason to disable
// Required: true
Reason string `url:"reason"`
}
func (arq DisableRequest) Validate() error {
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
}
// Disable disables an account
func (a Account) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -6,19 +6,24 @@ import (
"net/http"
)
// Request struct for disable group accounts
type DisableAccountsRequest struct {
// IDs of accounts
// Required: true
AccountIDs []uint64 `url:"accountIds,omitempty"`
}
func (arq DisableAccountsRequest) Validate() error {
if arq.AccountIDs == nil || len(arq.AccountIDs) == 0 {
func (arq DisableAccountsRequest) validate() error {
if len(arq.AccountIDs) == 0 {
return errors.New("validation-error: field AccountIDs must be set")
}
return nil
}
// DisableAccounts disables accounts
func (a Account) DisableAccounts(ctx context.Context, req DisableAccountsRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,23 +7,31 @@ import (
"strconv"
)
// Request struct for enable account
type EnableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId"`
Reason string `url:"reason"`
// Reason to enable
// Required: true
Reason string `url:"reason"`
}
func (arq EnableRequest) Validate() error {
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
}
// Enable enables an account
func (a Account) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -6,19 +6,24 @@ import (
"net/http"
)
// Request for enable group accounts
type EnableAccountsRequest struct {
// IDs od accounts
// Required: true
AccountIDs []uint64 `url:"accountIds"`
}
func (arq EnableAccountsRequest) Validate() error {
if arq.AccountIDs == nil || len(arq.AccountIDs) == 0 {
func (arq EnableAccountsRequest) validate() error {
if len(arq.AccountIDs) == 0 {
return errors.New("validation-error: field AccountIDs must be set")
}
return nil
}
// EnableAccounts enables accounts
func (a Account) EnableAccounts(ctx context.Context, req EnableAccountsRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,35 +7,41 @@ import (
"net/http"
)
// Request struct for get information about account
type GetRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq GetRequest) Validate() error {
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()
// Get gets information about account
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
err := req.validate()
if err != nil {
return GetResponse{}, err
return nil, err
}
url := "/cloudbroker/account/get"
result := GetResponse{}
info := RecordAccount{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return GetResponse{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
err = json.Unmarshal(res, &info)
if err != nil {
return GetResponse{}, err
return nil, err
}
return result, nil
return &info, nil
}

View File

@@ -6,23 +6,32 @@ import (
"net/http"
)
// Request struct for get list of accounts
type ListRequest struct {
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page"`
// Page size
// Required: false
Size uint64 `url:"size"`
}
func (a Account) List(ctx context.Context, req ListRequest) (ListInfoResponse, error) {
// List gets list all accounts the user has access to
func (a Account) List(ctx context.Context, req ListRequest) (ListAccounts, 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 nil, err
}
return result, nil
list := ListAccounts{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for a get list compute instances
type ListComputesRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListComputesRequest) Validate() error {
func (arq ListComputesRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
@@ -19,25 +22,26 @@ func (arq ListComputesRequest) Validate() error {
return nil
}
// ListComputes gets list all compute instances under specified account, accessible by the user
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return ListComputes{}, err
return nil, err
}
url := "/cloudbroker/account/listComputes"
result := ListComputes{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListComputes{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListComputes{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListComputes{}, err
return nil, err
}
return result, nil
return list, nil
}

View File

@@ -6,24 +6,32 @@ import (
"net/http"
)
// Request struct for get list deleted accounts
type ListDeletedRequest struct {
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page"`
// Page size
// Required: false
Size uint64 `url:"size"`
}
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListInfoResponse, error) {
// ListDeleted gets list all deleted accounts the user has access to
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListAccounts, error) {
url := "/cloudbroker/account/listDeleted"
result := ListInfoResponse{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListInfoResponse{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListAccounts{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListInfoResponse{}, err
return nil, err
}
return result, err
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list deleted disks
type ListDisksRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListDisksRequest) Validate() error {
func (arq ListDisksRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
@@ -19,25 +22,26 @@ func (arq ListDisksRequest) Validate() error {
return nil
}
// ListDisks gets list all currently unattached disks under specified account
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return ListDisks{}, err
return nil, err
}
url := "/cloudbroker/account/listDisks"
result := ListDisks{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListDisks{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListDisks{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListDisks{}, err
return nil, err
}
return result, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
type ListFlipGroupsRequest struct {
// Request struct for get list FLIPGroups
type ListFLIPGroupsRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListFlipGroupsRequest) Validate() error {
func (arq ListFLIPGroupsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
@@ -19,25 +22,26 @@ func (arq ListFlipGroupsRequest) Validate() error {
return nil
}
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest) (ListFlipGroups, error) {
err := req.Validate()
// ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user
func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (ListFLIPGroups, error) {
err := req.validate()
if err != nil {
return ListFlipGroups{}, err
return nil, err
}
url := "/cloudbroker/account/listFlipGroups"
result := ListFlipGroups{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListFlipGroups{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListFLIPGroups{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListFlipGroups{}, err
return nil, err
}
return result, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list resource groups
type ListRGRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListRGRequest) Validate() error {
func (arq ListRGRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
@@ -19,25 +22,26 @@ func (arq ListRGRequest) Validate() error {
return nil
}
// ListRG gets list all resource groups under specified account, accessible by the user
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return ListRG{}, err
return nil, err
}
url := "/cloudbroker/account/listRG"
result := ListRG{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListRG{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListRG{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListRG{}, err
return nil, err
}
return result, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list VINS
type ListVINSRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListVINSRequest) Validate() error {
func (arq ListVINSRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
@@ -19,25 +22,26 @@ func (arq ListVINSRequest) Validate() error {
return nil
}
// ListVINS gets list all ViNSes under specified account, accessible by the user
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return ListVINS{}, err
return nil, 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)
list := ListVINS{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListVINS{}, err
return nil, err
}
return result, nil
return list, nil
}

View File

@@ -1,214 +1,500 @@
package account
type AccountAudit struct {
Call string `json:"call"`
// Main info about audit
type ItemAudit struct {
// Call
Call string `json:"call"`
// Response time
ResponseTime float64 `json:"responsetime"`
StatusCode uint64 `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// User
User string `json:"user"`
}
type AccountAuditsList []AccountAudit
// List of audirs
type ListAudits []ItemAudit
type Resources struct {
Current Current `json:"Current"`
Reserved Reserved `json:"Reserved"`
type RecordResources struct {
// Current information about resources
Current Resource `json:"Current"`
// Reserved information about resources
Reserved Resource `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 Resource struct {
// Number of cores
CPU int64 `json:"cpu"`
// Disk size
DiskSize int64 `json:"disksize"`
// Number of External IPs
ExtIPs int64 `json:"extips"`
// External traffic
ExtTraffic int64 `json:"exttraffic"`
// Number of grafic cores
GPU int64 `json:"gpu"`
// Number of RAM
RAM int64 `json:"ram"`
}
// Access Control List
type ACL struct {
Explicit bool `json:"explicit"`
GUID string `json:"guid"`
Right string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
// Whether access is explicitly specified
Explicit bool `json:"explicit"`
// GUID
GUID string `json:"guid"`
// Access rights
Right string `json:"right"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// User group ID
UserGroupID string `json:"userGroupId"`
}
// Resource limits
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"`
// CuC
CuC float64 `json:"CU_C"`
// CuD
CuD float64 `json:"CU_D"`
// CuI
CuI float64 `json:"CU_I"`
// CuM
CuM float64 `json:"CU_M"`
// CuNP
CuNP float64 `json:"CU_NP"`
// GPUUnits
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
}
// Main information about account
type InfoAccount struct {
// DCLocation
DCLocation string `json:"DCLocation"`
type ListInfoResponse []struct {
Meta []interface{} `json:"_meta"`
InfoResponse
}
// CKey
CKey string `json:"_ckey"`
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"`
}
// Access Control List
ACL []ACL `json:"acl"`
type ListDisks []Disk
// Company
Company string `json:"company"`
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"`
}
// Company URL
CompanyURL string `json:"companyurl"`
type ListFlipGroups []FlipGroup
// Created by
CreatedBy string `json:"createdBy"`
type FlipGroup struct {
AccountID uint64 `json:"accountId"`
ClientType string `json:"clientType"`
ConnType string `json:"connType"`
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
DefaultGW string `json:"defaultGW"`
DeletedBy string `json:"deletedBy"`
// Deactivation time
DeactivationTime float64 `json:"deactivationTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
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"`
// Display name
DisplayName string `json:"displayname"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Resource limits
ResourceLimits ResourceLimits `json:"resourceLimits"`
// Send access emails
SendAccessEmails bool `json:"sendAccessEmails"`
// Status
Status string `json:"status"`
// UpdatedTime
UpdatedTime uint64 `json:"updatedTime"`
// Version
Version uint64 `json:"version"`
// List of VINS IDs
VINS []uint64 `json:"vins"`
}
// Deatailed information about account
type RecordAccount struct {
// Resources
Resources RecordResources `json:"Resources"`
// Main information about account
InfoAccount
}
// More information about account
type ItemAccount struct {
// Meta
Meta []interface{} `json:"_meta"`
// Main information about account
InfoAccount
}
// List of accounts
type ListAccounts []ItemAccount
// List of computes
type ListComputes []ItemCompute
// Main information about compute
type ItemCompute struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Number of CPU
CPUs uint64 `json:"cpus"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Number of RAM
RAM uint64 `json:"ram"`
// Registered
Registered bool `json:"registered"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RgName string `json:"rgName"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Total disks size
TotalDisksSize uint64 `json:"totalDisksSize"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// User managed
UserManaged bool `json:"userManaged"`
// VINS Connected
VINSConnected uint64 `json:"vinsConnected"`
}
// List of disks
type ListDisks []ItemDisk
// Main information about disks
type ItemDisk struct {
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Pool
Pool string `json:"pool"`
// SepID
SepID uint64 `json:"sepId"`
// Size max
SizeMax uint64 `json:"sizeMax"`
// Type
Type string `json:"type"`
}
// List of FLIPGroups
type ListFLIPGroups []ItemFLIPGroup
// Main information about FLIPGroup
type ItemFLIPGroup struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Client type
ClientType string `json:"clientType"`
// Connection type
ConnType string `json:"connType"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Default GW
DefaultGW string `json:"defaultGW"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// IP
IP string `json:"ip"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Network ID
NetID uint64 `json:"netId"`
// Network type
NetType string `json:"netType"`
// Network mask
Netmask uint64 `json:"netmask"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
// Computes info
type Computes struct {
// Started
Started uint64 `json:"Started"`
// Stopped
Stopped uint64 `json:"Stopped"`
}
// Consumed
type Consumed struct {
CPU uint64 `json:"cpu"`
DiskSize uint64 `json:"disksize"`
ExtIPs uint64 `json:"extips"`
// Number of CPU
CPU uint64 `json:"cpu"`
// Disk size
DiskSize uint64 `json:"disksize"`
// External IPs
ExtIPs uint64 `json:"extips"`
// External traffic
ExtTraffic uint64 `json:"exttraffic"`
GPU uint64 `json:"gpu"`
RAM uint64 `json:"ram"`
// Number of GPU
GPU uint64 `json:"gpu"`
// Number of RAM
RAM uint64 `json:"ram"`
}
// Limits
type Limits struct {
CPU int64 `json:"cpu"`
DiskSize int64 `json:"disksize"`
ExtIPs int64 `json:"extips"`
// Number of CPU
CPU int64 `json:"cpu"`
// Disk size
DiskSize int64 `json:"disksize"`
// External IPs
ExtIPs int64 `json:"extips"`
// External traffic
ExtTraffic int64 `json:"exttraffic"`
GPU int64 `json:"gpu"`
RAM int64 `json:"ram"`
// Number of GPU
GPU int64 `json:"gpu"`
// Number of RAM
RAM int64 `json:"ram"`
}
// Resources of resource group
type RGResuorces struct {
// Consumed
Consumed Consumed `json:"Consumed"`
Limits Limits `json:"Limits"`
Reserved Reserved `json:"Reserved"`
// Limits
Limits Limits `json:"Limits"`
// Reserved
Reserved Resource `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"`
}
// Main information about Resource group
type ItemRG struct {
// Compute
Computes Computes `json:"Computes"`
type ListRG []RG
// Resources of resource group
Resources RGResuorces `json:"Resources"`
type VINS struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
Computes uint64 `json:"computes"`
CreatedBy string `json:"createdBy"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
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"`
// ID
ID uint64 `json:"id"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Number of VINSes
VINSes uint64 `json:"vinses"`
}
// List of resource groups
type ListRG []ItemRG
// Main information about VINS
type ItemVINS struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Computes
Computes uint64 `json:"computes"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// External IP
ExternalIP string `json:"externalIP"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Network
Network string `json:"network"`
// PriVNFDevID
PriVNFDevID uint64 `json:"priVnfDevId"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RGName string `json:"rgName"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
type ListVINS []VINS
// List of VINSes
type ListVINS []ItemVINS

View File

@@ -6,12 +6,18 @@ import (
"net/http"
)
// Request struct for restore a deleted account
type RestoreRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
Reason string `url:"reason"`
// Reason to restore
// Required: true
Reason string `url:"reason"`
}
func (arq RestoreRequest) Validate() error {
func (arq RestoreRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
@@ -22,8 +28,9 @@ func (arq RestoreRequest) Validate() error {
return nil
}
// Restore restores a deleted account
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -36,4 +43,4 @@ func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error)
}
return true, nil
}
}

View File

@@ -5,33 +5,95 @@ import (
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for update account
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"`
// ID of account
// Required: true
AccountID uint64 `url:"accountId"`
// Display name
// Required: true
Name string `url:"name"`
// Name of the account
// Required: true
Username string `url:"username"`
// Email
// Required: false
EmailAddress string `url:"emailaddress,omitempty"`
// Max size of memory in MB
// Required: false
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
// Max size of aggregated vdisks in GB
// Required: false
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
// Max number of CPU cores
// Required: false
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// Max sent/received network transfer peering
// Required: false
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
GPUUnits uint64 `url:"gpu_units,omitempty"`
// Max number of assigned public IPs
// Required: false
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
// If true send emails when a user is granted access to resources
// Required: false
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
// Limit (positive) or disable (0) GPU resources
// Required: false
GPUUnits uint64 `url:"gpu_units,omitempty"`
// List of strings with pools
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,omitempty"`
// Resource types available to create in this account
// Each element in a resource type slice must be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: false
ResTypes []string `url:"resourceTypes,omitempty"`
}
func (arq UpdateRequest) Validate() error {
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")
}
if len(arq.ResTypes) > 0 {
for _, value := range arq.ResTypes {
validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"})
if !validate {
return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]")
}
}
}
return nil
}
// Update updates an account name and resource types and limits
func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,13 +7,25 @@ import (
"strconv"
)
// Request struct for update user access rights
type UpdateUserRequest struct {
AccountID uint64 `url:"accountId"`
UserID string `url:"userId"`
// ID of the account
// Required: true
AccountID uint64 `url:"accountId"`
// Userid/Email for registered users or emailaddress for unregistered users
// Required: true
UserID string `url:"userId"`
// Account permission types:
// - 'R' for read only access
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype"`
}
func (arq UpdateUserRequest) Validate() error {
func (arq UpdateUserRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
@@ -27,8 +39,9 @@ func (arq UpdateUserRequest) Validate() error {
return nil
}
// UpdateUser updates user access rights
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -1,11 +1,14 @@
// List of method groups for the admin
package cloudbroker
import "github.com/rudecs/decort-sdk/interfaces"
// Structure for creating request to CloudBroker groups
type CloudBroker struct {
client interfaces.Caller
}
// Builder to get access to CloudBroker
func New(client interfaces.Caller) *CloudBroker {
return &CloudBroker{
client: client,

View File

@@ -1,9 +1,10 @@
package cloudbroker
import (
"github.com/rudecs/decort-sdk/pkg/cloudapi/compute"
"github.com/rudecs/decort-sdk/pkg/cloudbroker/compute"
)
// Accessing the Compute method group
func (cb *CloudBroker) Compute() *compute.Compute {
return compute.New(cb.client)
}

View File

@@ -0,0 +1,46 @@
package compute
import (
"context"
"errors"
"net/http"
)
// Request struct for check all computes with current affinity label can start
type AffinityGroupCheckStartRequest struct {
// ID of the resource group
// Required: true
RGID uint64 `url:"rgId"`
// Affinity group label
// Required: true
AffinityLabel string `url:"affinityLabel"`
}
func (crq AffinityGroupCheckStartRequest) validate() error {
if crq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if crq.AffinityLabel == "" {
return errors.New("validation-error: field AffinityLabel must be set")
}
return nil
}
// AffinityGroupCheckStart check all computes with current affinity label can start
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
err := req.validate()
if err != nil {
return "", err
}
url := "/cloudbroker/compute/affinityGroupCheckStart"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,45 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for clear affinity label for compute
type AffinityLabelRemoveRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
}
func (crq AffinityLabelRemoveRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// AffinityLabelRemove clear affinity label for compute
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/affinityLabelRemove"
res, err := c.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
}

View File

@@ -0,0 +1,51 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for set affinity label for compute
type AffinityLabelSetRequest struct {
// IDs of the compute instances
ComputeIDs []uint64 `url:"computeIds"`
// Affinity group label
// Required: true
AffinityLabel string `url:"affinityLabel"`
}
func (crq AffinityLabelSetRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
if crq.AffinityLabel == "" {
return errors.New("validation-error: field AffinityLabel must be set")
}
return nil
}
// AffinityLabelSet set affinity label for compute
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/affinityLabelSet"
res, err := c.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
}

View File

@@ -0,0 +1,51 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
// Request struct for get dict of computes
type AffinityRelationsRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Affinity group label
// Required: false
AffinityLabel string `url:"affinityLabel,omitempty"`
}
func (crq AffinityRelationsRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
}
// AffinityRelations gets dict of computes divided by affinity and anti affinity rules
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*RecordAffinityRelations, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/affinityRelations"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := RecordAffinityRelations{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,103 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for add affinity rule
type AffinityRuleAddRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
// Should be one of:
// - node
// - compute
// Required: true
Topology string `url:"topology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value"`
}
func (crq AffinityRuleAddRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
if crq.Topology == "" {
return errors.New("validation-error: field Topology must be set")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy must be set")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode must be set")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key must be set")
}
if crq.Value == "" {
return errors.New("validation-error: field Value must be set")
}
return nil
}
// AffinityRuleAdd add affinity rule
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/affinityRuleAdd"
res, err := c.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
}

View File

@@ -0,0 +1,101 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for remove affinity rule
type AffinityRuleRemoveRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value"`
}
func (crq AffinityRuleRemoveRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
if crq.Topology == "" {
return errors.New("validation-error: field Topology must be set")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy must be set")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode must be set")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key must be set")
}
if crq.Value == "" {
return errors.New("validation-error: field Value must be set")
}
return nil
}
// AffinityRuleRemove remove affinity rule
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/affinityRuleRemove"
res, err := c.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
}

View File

@@ -0,0 +1,45 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for clear affinity rules
type AffinityRulesClearRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
}
func (crq AffinityRulesClearRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
return nil
}
// AffinityRulesClear clear affinity rules
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/affinityRulesClear"
res, err := c.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
}

View File

@@ -0,0 +1,101 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for add anti affinity rule
type AntiAffinityRuleAddRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value"`
}
func (crq AntiAffinityRuleAddRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
if crq.Topology == "" {
return errors.New("validation-error: field Topology must be set")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy must be set")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode must be set")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key must be set")
}
if crq.Value == "" {
return errors.New("validation-error: field Value must be set")
}
return nil
}
// AntiAffinityRuleAdd add anti affinity rule
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/antiAffinityRuleAdd"
res, err := c.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
}

View File

@@ -0,0 +1,45 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for clear anti affinity rules
type AntiAffinityRulesClearRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
}
func (crq AntiAffinityRulesClearRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
return nil
}
// AntiAffinityRulesClear clear anti affinity rules
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/antiAffinityRulesClear"
res, err := c.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
}

View File

@@ -0,0 +1,101 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for remove anti affinity rule
type AntiAffinityRuleRemoveRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: true
Value string `url:"value"`
}
func (crq AntiAffinityRuleRemoveRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
if crq.Topology == "" {
return errors.New("validation-error: field Topology must be set")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy must be set")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode must be set")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key must be set")
}
if crq.Value == "" {
return errors.New("validation-error: field Value must be set")
}
return nil
}
// AntiAffinityRuleRemove remove anti affinity rule
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/antiAffinityRuleRemove"
res, err := c.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
}

View File

@@ -0,0 +1,52 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for attach GPU for compute
type AttachGPURequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
// Identifier vGPU
// Required: true
VGPUID uint64 `url:"vgpuId"`
}
func (crq AttachGPURequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.VGPUID == 0 {
return errors.New("validation-error: field VGPUID must be set")
}
return nil
}
// AttachGPU attach GPU for compute, returns vGPU ID on success
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
err := req.validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/compute/attachGpu"
res, err := c.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
}

View File

@@ -0,0 +1,52 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for atttach PCI device
type AttachPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
// PCI device ID
// Required: true
DeviceID uint64 `url:"deviceId"`
}
func (crq AttachPCIDeviceRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.DeviceID == 0 {
return errors.New("validation-error: field DeviceID must be set")
}
return nil
}
// AttachPCIDevice attach PCI device
func (c Compute) AttachPCIDevice(ctx context.Context, req AttachPCIDeviceRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/attachPciDevice"
res, err := c.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
}

View File

@@ -0,0 +1,47 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
// Request struct for get audit records
type AuditsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq AuditsRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// Audits gets audit records for the specified compute object
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListDetailedAudits, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/audits"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListDetailedAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,47 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
// Request struct for get boot order
type BootOrderGetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq BootOrderGetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// BootOrderGet gets actual compute boot order information
func (c Compute) BootOrderGet(ctx context.Context, req BootOrderGetRequest) ([]string, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/bootOrderGet"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
orders := make([]string, 0)
err = json.Unmarshal(res, &orders)
if err != nil {
return nil, err
}
return orders, nil
}

View File

@@ -0,0 +1,65 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for set boot order
type BootOrderSetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// List of boot devices
// Should be one of:
// - cdrom
// - network
// - hd
// Required: true
Order []string `url:"order"`
}
func (crq BootOrderSetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if len(crq.Order) == 0 {
return errors.New("validation-error: field Order must be set")
}
for _, value := range crq.Order {
if validate := validators.StringInSlice(value, []string{"cdrom", "network", "hd"}); !validate {
return errors.New("validation-error: field ImageType can be cdrom, network, hd")
}
}
return nil
}
// BootOrderSet sets compute boot order
func (c Compute) BootOrderSet(ctx context.Context, req BootOrderSetRequest) ([]string, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/bootOrderSet"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
orders := make([]string, 0)
err = json.Unmarshal(res, &orders)
if err != nil {
return nil, err
}
return orders, nil
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for eject CD image
type CDEjectRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason to eject
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq CDEjectRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must ve set")
}
return nil
}
// CDEject eject CD image to compute's CD-ROM
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/cdEject"
res, err := c.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, err
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"errors"
"net/http"
)
// Request struct for insert new CD image
type CDInsertRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of CD-ROM image
// Required: true
CDROMID uint64 `url:"cdromId"`
// Reason to insert
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq CDInsertRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.CDROMID == 0 {
return errors.New("validation-error: field CDROMID must be set")
}
return nil
}
// CDInsert insert new CD image to compute's CD-ROM
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/cdInsert"
_, err = c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

View File

@@ -0,0 +1,64 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for clone compute instance
type CloneRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Name of the clone
// Required: true
Name string `url:"name"`
// Timestamp of the parent's snapshot to create clone from
// Required: false
SnapshotTimestamp uint64 `url:"snapshotTimestamp"`
// Name of the parent's snapshot to create clone from
// Required: false
SnapshotName string `url:"snapshotName"`
// Reason to clone
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq CloneRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
return nil
}
// Clone clones compute instance
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
err := req.validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/compute/clone"
res, err := c.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
}

View File

@@ -0,0 +1,16 @@
// API Actor for managing Compute. This actor is a final API for admin to manage Compute
package compute
import "github.com/rudecs/decort-sdk/interfaces"
// Structure for creating request to compute
type Compute struct {
client interfaces.Caller
}
// Builder for compute endpoints
func New(client interfaces.Caller) *Compute {
return &Compute{
client: client,
}
}

View File

@@ -0,0 +1,52 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for set compute CI
type ComputeCISetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the Compute CI
// Required: true
ComputeCIID uint64 `url:"computeciId"`
}
func (crq ComputeCISetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.ComputeCIID == 0 {
return errors.New("validation-error: field ComputeCIID must be set")
}
return nil
}
// ComputeCISet sets compute CI ID for compute
func (c Compute) ComputeCISet(ctx context.Context, req ComputeCISetRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/computeciSet"
res, err := c.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
}

View File

@@ -0,0 +1,45 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for unset compite CI
type ComputeCIUnsetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq ComputeCIUnsetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// ComputeCIUnset unsets compute CI ID from compute
func (c Compute) ComputeCIUnset(ctx context.Context, req ComputeCIUnsetRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/computeciUnset"
res, err := c.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
}

View File

@@ -0,0 +1,86 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"strings"
)
// Request struct for create template
type CreateTemplateRequest struct {
// ID of the compute to create template from
// Required: true
ComputeID uint64 `url:"computeId"`
// Name to assign to the template being created
// Required: true
Name string `url:"name"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
// Async API call
// For async call use CreateTemplateAsync
// For sync call use CreateTemplate
// Required: true
async bool `url:"async"`
}
func (crq CreateTemplateRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
return nil
}
// CreateTemplateAsync create template from compute instance
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) {
err := req.validate()
if err != nil {
return "", err
}
req.async = true
url := "/cloudbroker/compute/createTemplate"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}
// CreateTemplate create template from compute instance
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
err := req.validate()
if err != nil {
return 0, err
}
req.async = false
url := "/cloudbroker/compute/createTemplate"
res, err := c.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
}

View File

@@ -0,0 +1,57 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for delete compute
type DeleteRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Delete permanently
// Required: false
Permanently bool `url:"permanently,omitempty"`
// Set True if you want to detach data disks (if any) from the compute before its deletion
// Required: false
DetachDisks bool `url:"detachDisks,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq DeleteRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field computeID must be set")
}
return nil
}
// Delete deletes compute
func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/delete"
res, err := c.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
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for detach VGPU for compute
type DetachGPURequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
// Identifier virtual GPU
// Required: false
VGPUID int64 `url:"vgpuId,omitempty"`
}
func (crq DetachGPURequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// DetachGPU detach VGPU for compute.
// If param VGPU ID is equivalent -1, then detach all VGPU for compute
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/detachGpu"
res, err := c.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
}

View File

@@ -0,0 +1,52 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for detach PCI device
type DetachPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
// PCI device ID
// Required: true
DeviceID uint64 `url:"deviceId"`
}
func (crq DetachPCIDeviceRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.DeviceID == 0 {
return errors.New("validation-error: field DeviceID must be set")
}
return nil
}
// DetachPCIDevice detach PCI device
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPCIDeviceRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/detachPciDevice"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for disable compute
type DisableRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq DisableRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field computeID must be set")
}
return nil
}
// Disable disables compute
func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/disable"
res, err := c.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
}

View File

@@ -0,0 +1,84 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for create and attach disk to compute
type DiskAddRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Name for disk
// Required: true
DiskName string `url:"diskName"`
// Disk size in GB
// Required: true
Size uint64 `url:"size"`
// Type of the disk
// Should be one of:
// - D
// - B
// Required: false
DiskType string `url:"diskType,omitempty"`
// Storage endpoint provider ID
// By default the same with boot disk
// Required: false
SepID uint64 `url:"sepId,omitempty"`
// Pool name
// By default will be chosen automatically
// Required: false
Pool string `url:"pool,omitempty"`
// Optional description
// Required: false
Description string `url:"desc,omitempty"`
// Specify image id for create disk from template
// Required: false
ImageID uint64 `url:"imageId,omitempty"`
}
func (crq DiskAddRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.DiskName == "" {
return errors.New("validation-error: field DiskName must be set")
}
if crq.Size == 0 {
return errors.New("validation-error: field Size must be set")
}
return nil
}
// DiskAdd creates new disk and attach to compute
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) {
err := req.validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/compute/diskAdd"
res, err := c.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
}

View File

@@ -0,0 +1,56 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for attach disk to compute
type DiskAttachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the disk to attach
// Required: true
DiskID uint64 `url:"diskId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq DiskAttachRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID must be set")
}
return nil
}
// DiskAttach attach disk to compute
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/diskAttach"
res, err := c.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
}

View File

@@ -0,0 +1,60 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for detach and delete disk from compute
type DiskDelRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of disk instance
// Required: true
DiskID uint64 `url:"diskId"`
// False if disk is to be deleted to recycle bin
// Required: true
Permanently bool `url:"permanently"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq DiskDelRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID must be set")
}
return nil
}
// DiskDel delete disk and detach from compute
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/diskDel"
res, err := c.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
}

View File

@@ -0,0 +1,56 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for detach disk from compute
type DiskDetachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the disk to detach
// Required: true
DiskID uint64 `url:"diskId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq DiskDetachRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID must be set")
}
return nil
}
// DiskDetach detach disk from compute
func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/diskDetach"
res, err := c.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
}

View File

@@ -0,0 +1,59 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for change QOS of the disk
type DiskQOSRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the disk to apply limits
// Required: true
DiskID uint64 `url:"diskId"`
// Limit IO for a certain disk total and read/write options are not allowed to be combined
// Required: true
Limits string `url:"limits"`
}
func (crq DiskQOSRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID must be set")
}
if crq.Limits == "" {
return errors.New("validation-error: field Limits must be set")
}
return nil
}
// DiskQOS change QOS of the disk
func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/diskQos"
res, err := c.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
}

View File

@@ -0,0 +1,63 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for change disk size
type DiskResizeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the disk to resize
// Required: true
DiskID uint64 `url:"diskId"`
// New disk size
// Required: true
Size uint64 `url:"size"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq DiskResizeRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID must be set")
}
if crq.Size == 0 {
return errors.New("validation-error: field Size must be set")
}
return nil
}
// DiskResize change disk size
func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/diskResize"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for enable compute
type EnableRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq EnableRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field computeID must be set")
}
return nil
}
// Enable enables compute
func (c Compute) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/enable"
res, err := c.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
}

View File

@@ -0,0 +1,51 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
// Request for get information about compute
type GetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason to action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq GetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// Get gets information about compute
func (c Compute) Get(ctx context.Context, req GetRequest) (*RecordCompute, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/get"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := RecordCompute{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,51 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
// Request struct for get compute audits
type GetAuditsRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason to action
// Required: true
Reason string `url:"reason,omitempty"`
}
func (crq GetAuditsRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// GetAudits gets compute audits
func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest) (ListAudits, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/getAudits"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,44 @@
package compute
import (
"context"
"errors"
"net/http"
"strings"
)
// Request struct for get console URL
type GetConsoleURLRequest struct {
// ID of compute instance to get console for
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq GetConsoleURLRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// GetConsoleURL gets computes console URL
func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest) (string, error) {
err := req.validate()
if err != nil {
return "", err
}
url := "/cloudbroker/compute/getConsoleUrl"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
result = strings.ReplaceAll(result, "\\", "")
return result, nil
}

View File

@@ -0,0 +1,46 @@
package compute
import (
"context"
"errors"
"net/http"
)
// Request struct for get compute logs
type GetLogRequest struct {
// ID of compute instance to get log for
// Required: true
ComputeID uint64 `url:"computeId"`
// Path to log file
// Required: true
Path string `url:"path"`
}
func (crq GetLogRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.Path == "" {
return errors.New("validation-error: field Path must be set")
}
return nil
}
// GetLog gets compute's log file by path
func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error) {
err := req.validate()
if err != nil {
return "", err
}
url := "/cloudbroker/compute/getLog"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,42 @@
package compute
import (
"context"
"encoding/json"
"net/http"
)
// Request struct for get list available computes
type ListRequest struct {
// Include deleted computes
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
// List gets list of the available computes.
// Filtering based on status is possible
func (c Compute) List(ctx context.Context, req ListRequest) (ListComputes, error) {
url := "/cloudbroker/compute/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListComputes{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,37 @@
package compute
import (
"context"
"encoding/json"
"net/http"
)
// Request struct for get deleted computes list
type ListDeletedRequest struct {
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
// ListDeleted gets list all deleted computes
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListComputes, error) {
url := "/cloudbroker/compute/listDeleted"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListComputes{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,51 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
// Request struct for get list GPU for compute
type ListGPURequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Also list destroyed
// Required: false
ListDestroyed bool `url:"list_destroyed,omitempty"`
}
func (crq ListGPURequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// ListVGPU gets list GPU for compute
func (c Compute) ListVGPU(ctx context.Context, req ListGPURequest) ([]interface{}, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/listGpu"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := make([]interface{}, 0)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,47 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
// Request struct for get list PCI devices
type ListPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq ListPCIDeviceRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// ListPCIDevice gets list PCI device
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (ListPCIDevices, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/listPciDevice"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListPCIDevices{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,53 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for delete several computes
type MassDeleteRequest struct {
// IDs of compute instances to delete
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
// Delete computes permanently
// Required: false
Permanently bool `url:"permanently,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq MassDeleteRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
return nil
}
// MassDelete starts jobs to delete several computes
func (c Compute) MassDelete(ctx context.Context, req MassDeleteRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/massDelete"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for reboot several computes
type MassRebootRequest struct {
// IDs of compute instances to reboot
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq MassRebootRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
return nil
}
// MassReboot starts jobs to reboot several computes
func (c Compute) MassReboot(ctx context.Context, req MassRebootRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/massReboot"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for repair boot disk filesystem on several computes
type MassRepairBootFSRequest struct {
// IDs of compute instances which boot file systems will be repaired
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq MassRepairBootFSRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
return nil
}
// MassRepairBootFS repair boot disk filesystem on several computes
func (c Compute) MassRepairBootFS(ctx context.Context, req MassRepairBootFSRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/massRepairBootFs"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for start several computes
type MassStartRequest struct {
// IDs of compute instances to start
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq MassStartRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
return nil
}
// MassStart starts jobs to start several computes
func (c Compute) MassStart(ctx context.Context, req MassStartRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/massStart"
res, err := c.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
}

View File

@@ -0,0 +1,53 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for several stop computes
type MassStopRequest struct {
// IDs of compute instances to stop
// Required: true
ComputeIDs []uint64 `url:"computeIds"`
// Force stop compute
// Required: false
Force bool `url:"force,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq MassStopRequest) validate() error {
if len(crq.ComputeIDs) == 0 {
return errors.New("validation-error: field ComputeIDs must be set")
}
return nil
}
// MassStop starts jobs to stop several computes
func (c Compute) MassStop(ctx context.Context, req MassStopRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/massStop"
res, err := c.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
}

View File

@@ -0,0 +1,58 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for migrate compute
type MigrateRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Particular Stack ID to migrate this compute to
// Required: false
TargetStackID uint64 `url:"targetStackId,omitempty"`
// If live migration fails, destroy compute
// on source node and recreate on the target
// Required: false
Force bool `url:"force,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq MigrateRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// Migrate migrates compute to another stack
func (c Compute) Migrate(ctx context.Context, req MigrateRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/migrate"
res, err := c.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
}

View File

@@ -0,0 +1,70 @@
package compute
import (
"context"
"errors"
"net/http"
"strings"
)
// Request struct for migration
type MigrateStorageRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// SEP ID to migrate disks
// Required: true
SEPID uint64 `url:"sepId"`
// SEP pool name to migrate disks
// Required: true
PoolName string `url:"poolName"`
// Target stack ID
// Required: true
StackID uint64 `url:"stackId"`
// Async API call
// Required: true
Sync bool `url:"sync"`
}
func (crq MigrateStorageRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.SEPID == 0 {
return errors.New("validation-error: field SEPID must be set")
}
if crq.PoolName == "" {
return errors.New("validation-error: field PoolName must be set")
}
if crq.StackID == 0 {
return errors.New("validation-error: field StackID must be set")
}
return nil
}
// MigrateStorage gets complex compute migration
// Compute will be migrated to specified stack, and compute disks will
// be migrated to specified SEP to specified pool.
// This action can take up to 84 hours
func (c Compute) MigrateStorage(ctx context.Context, req MigrateStorageRequest) (string, error) {
err := req.validate()
if err != nil {
return "", err
}
url := "/cloudbroker/compute/migrateStorage"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,42 @@
package compute
import (
"context"
"errors"
"net/http"
"strings"
)
// Request struct for abort migration
type MigrateStorageAbortRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq MigrateStorageAbortRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// MigrateStorageAbort abort complex compute migration job
func (c Compute) MigrateStorageAbort(ctx context.Context, req MigrateStorageAbortRequest) (string, error) {
err := req.validate()
if err != nil {
return "", err
}
url := "/cloudbroker/compute/migrateStorageAbort"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,44 @@
package compute
import (
"context"
"errors"
"net/http"
"strings"
)
// Request struct for cleanup resources after finished migration
type MigrateStorageCleanUpRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq MigrateStorageCleanUpRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// MigrateStorageCleanUp cleanup resources after finished (success of failed) complex compute migration.
// If the migration was successful, then old disks will be removed, else new (target) disks will be removed.
// Do it wisely!
func (c Compute) MigrateStorageCleanUp(ctx context.Context, req MigrateStorageCleanUpRequest) (string, error) {
err := req.validate()
if err != nil {
return "", err
}
url := "/cloudbroker/compute/migrateStorageCleanup"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,42 @@
package compute
import (
"context"
"errors"
"net/http"
"strings"
)
// Request struct for get info about migration
type MigrateStorageInfoRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq MigrateStorageInfoRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// MigrateStorageInfo gets info about last (include ongoing) storage migration
func (c Compute) MigrateStorageInfo(ctx context.Context, req MigrateStorageInfoRequest) (string, error) {
err := req.validate()
if err != nil {
return "", err
}
url := "/cloudbroker/compute/migrateStorageInfo"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,778 @@
package compute
// Access Control List
type RecordACL struct {
// Account ACL list
AccountACL ListACL `json:"accountACL"`
// Compute ACL list
ComputeACL []ItemComputeACL `json:"computeACL"`
// Resource group ACL list
RGACL ListACL `json:"rgACL"`
}
// ACL information
type ItemACL struct {
// Explicit
Explicit bool `json:"explicit"`
// GUID
GUID string `json:"guid"`
// Right
Right string `json:"right"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// User group ID
UserGroupID string `json:"userGroupId"`
}
// ACL compute information
type ItemComputeACL struct {
// Explicit
Explicit string `json:"explicit"`
// GUID
GUID string `json:"guid"`
// Right
Right string `json:"right"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// User group ID
UserGroupID string `json:"userGroupId"`
}
// List ACL
type ListACL []ItemACL
// Main information about snapshot
type ItemSnapshot struct {
// List of disk IDs
Disks []uint64 `json:"disks"`
// GUID
GUID string `json:"guid"`
// Label
Label string `json:"label"`
// Timestamp
Timestamp uint64 `json:"timestamp"`
}
// List of snapshots
type ListSnapshots []ItemSnapshot
// Main information about snapshot usage
type ItemSnapshotUsage struct {
// Count
Count uint64 `json:"count,omitempty"`
// Stored
Stored float64 `json:"stored"`
// Label
Label string `json:"label,omitempty"`
// Timestamp
Timestamp uint64 `json:"timestamp,omitempty"`
}
// List of snapshot usage
type ListSnapshotUsage []ItemSnapshotUsage
// QOS
type QOS struct {
// ERate
ERate uint64 `json:"eRate"`
// GUID
GUID string `json:"guid"`
// InBurst
InBurst uint64 `json:"inBurst"`
// InRate
InRate uint64 `json:"inRate"`
}
// Main information about attached network
type RecordNetAttach struct {
// Connection ID
ConnID uint64 `json:"connId"`
// Connection type
ConnType string `json:"connType"`
// Default GW
DefGW string `json:"defGw"`
// FLIPGroup ID
FLIPGroupID uint64 `json:"flipgroupId"`
// GUID
GUID string `json:"guid"`
// IP address
IPAddress string `json:"ipAddress"`
// Listen SSH
ListenSSH bool `json:"listenSsh"`
// MAC
MAC string `json:"mac"`
// Name
Name string `json:"name"`
// Network ID
NetID uint64 `json:"netId"`
// Network mask
NetMask uint64 `json:"netMask"`
// Network type
NetType string `json:"netType"`
// PCI slot
PCISlot uint64 `json:"pciSlot"`
// QOS
QOS QOS `json:"qos"`
// Target
Target string `json:"target"`
// Type
Type string `json:"type"`
// List VNF IDs
VNFs []uint64 `json:"vnfs"`
}
// Main information about affinity relations
type RecordAffinityRelations struct {
// Other node
OtherNode []interface{} `json:"otherNode"`
// Other node indirect
OtherNodeIndirect []interface{} `json:"otherNodeIndirect"`
// Other node indirect soft
OtherNodeIndirectSoft []interface{} `json:"otherNodeIndirectSoft"`
// Other node soft
OtherNodeSoft []interface{} `json:"otherNodeSoft"`
// Same node
SameNode []interface{} `json:"sameNode"`
// Same node soft
SameNodeSoft []interface{} `json:"sameNodeSoft"`
}
// Detailed information about audit
type ItemDetailedAudit struct {
// Call
Call string `json:"call"`
// Response time
ResponseTime float64 `json:"responsetime"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// User
User string `json:"user"`
}
// List of detailed audit
type ListDetailedAudits []ItemDetailedAudit
// Main information about port forward
type ItemPFW struct {
// ID
ID uint64 `json:"id"`
// Local IP
LocalIP string `json:"localIp"`
// Local port
LocalPort uint64 `json:"localPort"`
// Protocol
Protocol string `json:"protocol"`
// Public port end
PublicPortEnd uint64 `json:"publicPortEnd"`
// Public port start
PublicPortStart uint64 `json:"publicPortStart"`
// Virtuel machine ID
VMID uint64 `json:"vmId"`
}
// List port forwards
type ListPFW []ItemPFW
// Main information about rule
type ItemRule struct {
// GUID
GUID string `json:"guid"`
// Key
Key string `json:"key"`
// Mode
Mode string `json:"mode"`
// Policy
Policy string `json:"policy"`
// Topology
Topology string `json:"topology"`
// Value
Value string `json:"value"`
}
// List rules
type ListRules []ItemRule
// Main information about IO tune
type IOTune struct {
// ReadBytesSec
ReadBytesSec uint64 `json:"read_bytes_sec"`
// ReadBytesSecMax
ReadBytesSecMax uint64 `json:"read_bytes_sec_max"`
// ReadIOPSSec
ReadIOPSSec uint64 `json:"read_iops_sec"`
// ReadIOPSSecMax
ReadIOPSSecMax uint64 `json:"read_iops_sec_max"`
// SizeIOPSSec
SizeIOPSSec uint64 `json:"size_iops_sec"`
// TotalBytesSec
TotalBytesSec uint64 `json:"total_bytes_sec"`
// TotalBytesSecMax
TotalBytesSecMax uint64 `json:"total_bytes_sec_max"`
// TotalIOPSSec
TotalIOPSSec uint64 `json:"total_iops_sec"`
// TotalIOPSSecMax
TotalIOPSSecMax uint64 `json:"total_iops_sec_max"`
// WriteBytesSec
WriteBytesSec uint64 `json:"write_bytes_sec"`
// WriteBytesSecMax
WriteBytesSecMax uint64 `json:"write_bytes_sec_max"`
// WriteIOPSSec
WriteIOPSSec uint64 `json:"write_iops_sec"`
// WriteIOPSSecMax
WriteIOPSSecMax uint64 `json:"write_iops_sec_max"`
}
// Detailed information about snapshot
type ItemSnapshotDetailed struct {
// GUID
GUID string `json:"guid"`
// Label
Label string `json:"label"`
// Resource ID
ResID string `json:"resId"`
// SnapSetGUID
SnapSetGUID string `json:"snapSetGuid"`
// SnapSetTime
SnapSetTime uint64 `json:"snapSetTime"`
// TimeStamp
TimeStamp uint64 `json:"timestamp"`
}
// List detailed snapshots
type ListDetailedSnapshots []ItemSnapshotDetailed
// Main information about disk
type ItemDisk struct {
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Account ID
AccountID uint64 `json:"accountId"`
// Access Control List
ACL ItemACL `json:"acl"`
// Boot partition
BootPartition uint64 `json:"bootPartition"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Destruction time
DestructionTime uint64 `json:"destructionTime"`
// Disk path
DiskPath string `json:"diskPath"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Image ID
ImageID uint64 `json:"imageId"`
// List image IDs
Images []uint64 `json:"images"`
// IOTune
IOTune IOTune `json:"iotune"`
// IQN
IQN string `json:"iqn"`
// Login
Login string `json:"login"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Order
Order uint64 `json:"order"`
// Params
Params string `json:"params"`
// Parent ID
ParentID uint64 `json:"parentId"`
// Password
Password string `json:"passwd"`
// PCI slot
PCISlot uint64 `json:"pciSlot"`
// Pool
Pool string `json:"pool"`
// Purge attempts
PurgeAttempts uint64 `json:"purgeAttempts"`
// Purge time
PurgeTime uint64 `json:"purgeTime"`
// Reality device number
RealityDeviceNumber uint64 `json:"realityDeviceNumber"`
// Reference ID
ReferenceID string `json:"referenceId"`
// Resource ID
ResID string `json:"resId"`
// Resource name
ResName string `json:"resName"`
// Role
Role string `json:"role"`
// SEP ID
SEPID uint64 `json:"sepId"`
// Size max
SizeMax uint64 `json:"sizeMax"`
// Size used
SizeUsed uint64 `json:"sizeUsed"`
// List detailed snapshots
Snapshots ListDetailedSnapshots `json:"snapshots"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
// Updated by
UpdatedBy uint64 `json:"updatedBy,omitempty"`
// Virtual machine ID
VMID uint64 `json:"vmid"`
}
// List disks
type ListDisks []ItemDisk
// Main information about interface
type ItemInterface struct {
// Connection ID
ConnID uint64 `json:"connId"`
// Connection type
ConnType string `json:"connType"`
// Default GW
DefGW string `json:"defGw"`
// FLIPGroup ID
FLIPGroupID uint64 `json:"flipgroupId"`
// GUID
GUID string `json:"guid"`
// IP address
IPAddress string `json:"ipAddress"`
// Listen SSH or not
ListenSSH bool `json:"listenSsh"`
// MAC
MAC string `json:"mac"`
// Name
Name string `json:"name"`
// Network ID
NetID uint64 `json:"netId"`
// Network mask
NetMask uint64 `json:"netMask"`
// Network type
NetType string `json:"netType"`
// PCI slot
PCISlot uint64 `json:"pciSlot"`
// QOS
QOS QOS `json:"qos"`
// Target
Target string `json:"target"`
// Type
Type string `json:"type"`
// List VNF IDs
VNFs []uint64 `json:"vnfs"`
}
// List interfaces
type ListInterfaces []ItemInterface
// Main information about OS user
type ItemOSUser struct {
// GUID
GUID string `json:"guid"`
// Login
Login string `json:"login"`
// Password
Password string `json:"password"`
// Public key
PubKey string `json:"pubkey"`
}
// List OS users
type ListOSUsers []ItemOSUser
// Information about compute
type InfoCompute struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Access Control List
ACL []interface{} `json:"acl"`
// Affinity label
AffinityLabel string `json:"affinityLabel"`
// Affinity rules
AffinityRules ListRules `json:"affinityRules"`
// Affinity weight
AffinityWeight uint64 `json:"affinityWeight"`
// Anti affinity rules
AntiAffinityRules ListRules `json:"antiAffinityRules"`
// Architecture
Arch string `json:"arch"`
// Boot order
BootOrder []string `json:"bootOrder"`
// Boot disk size
BootDiskSize uint64 `json:"bootdiskSize"`
// Clone reference
CloneReference uint64 `json:"cloneReference"`
// List clone IDs
Clones []uint64 `json:"clones"`
// Compute CI ID
ComputeCIID uint64 `json:"computeciId"`
// Number of CPU
CPUs uint64 `json:"cpus"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Custom fields
CustomFields map[string]interface{} `json:"customFields"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Devices
Devices interface{} `json:"devices"`
// Driver
Driver string `json:"driver"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Image ID
ImageID uint64 `json:"imageId"`
// List interfaces
Interfaces ListInterfaces `json:"interfaces"`
// Lock status
LockStatus string `json:"lockStatus"`
// Manager ID
ManagerID uint64 `json:"managerId"`
// Manager type
ManagerType string `json:"managerType"`
// Migration job
MigrationJob uint64 `json:"migrationjob"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// List OS users
OSUsers ListOSUsers `json:"osUsers"`
// Pinned
Pinned bool `json:"pinned"`
// Number of RAM
RAM uint64 `json:"ram"`
// Reference ID
ReferenceID string `json:"referenceId"`
// Registered
Registered bool `json:"registered"`
// Resource name
ResName string `json:"resName"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RGName string `json:"rgName"`
// SnapSets
SnapSets ListSnapshots `json:"snapSets"`
// Stack ID
StackID uint64 `json:"stackId"`
// Stack name
StackName string `json:"stackName"`
// Stateless SEP ID
StatelessSEPID uint64 `json:"statelessSepId"`
// Stateless SEP Type
StatelessSEPType string `json:"statelessSepType"`
// Status
Status string `json:"status"`
// Tags
Tags map[string]interface{} `json:"tags"`
// Tech status
TechStatus string `json:"techStatus"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// User managed
UserManaged bool `json:"userManaged"`
// Userdata
Userdata interface{} `json:"userdata"`
// List VGPU IDs
VGPUs []uint64 `json:"vgpus"`
// Virtual image ID
VirtualImageID uint64 `json:"virtualImageId"`
}
// Detailed information about compute
type RecordCompute struct {
// List disks
Disks ListDisks `json:"disks"`
// Main information about compute
InfoCompute
}
// Main information about compute for list
type ItemCompute struct {
// List of disk IDs
Disks []uint64 `json:"disks"`
// Main information about compute
InfoCompute
// Total disk size
TotalDiskSize uint64 `json:"totalDiskSize"`
// VINS connected
VINSConnected uint64 `json:"vinsConnected"`
}
// List computes
type ListComputes []ItemCompute
// Short information about audir
type ItemAudit struct {
// Epoch
Epoch float64 `json:"epoch"`
// Message
Message string `json:"message"`
}
// List audits
type ListAudits []ItemAudit
// Main information about PCI device
type ItemPCIDevice struct {
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Compute ID
ComputeID uint64 `json:"computeId"`
// Description
Description string `json:"description"`
// GUID
GUID uint64 `json:"guid"`
// HwPath
HwPath string `json:"hwPath"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Stack ID
StackID uint64 `json:"stackId"`
// Status
Status string `json:"status"`
// System name
SystemName string `json:"systemName"`
}
// List PCI devices
type ListPCIDevices []ItemPCIDevice

View File

@@ -0,0 +1,67 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for move compute new resource group
type MoveToRGRequest struct {
// ID of the compute instance to move
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the target resource group
// Required: true
RGID uint64 `url:"rgId"`
// New name for the compute upon successful move,
// if name change required.
// Pass empty string if no name change necessary
// Required: false
Name string `url:"name,omitempty"`
// Should the compute be restarted upon successful move
// Required: false
Autostart bool `url:"autostart,omitempty"`
// By default moving compute in a running state is not allowed.
// Set this flag to True to force stop running compute instance prior to move.
// Required: false
ForceStop bool `url:"forceStop,omitempty"`
}
func (crq MoveToRGRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
return nil
}
// MoveToRG moves compute instance to new resource group
func (c Compute) Validate(ctx context.Context, req MoveToRGRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/moveToRg"
res, err := c.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
}

View File

@@ -0,0 +1,79 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for attach network
type NetAttachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Network type
// 'EXTNET' for connect to external network directly
// and 'VINS' for connect to ViNS
// Required: true
NetType string `url:"netType"`
// Network ID for connect to
// For EXTNET - external network ID
// For VINS - VINS ID
// Required: true
NetID uint64 `url:"netId"`
// Directly required IP address for new network interface
// Required: true
IPAddr string `url:"ipAddr,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq NetAttachRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.NetType == "" {
return errors.New("validation-error: field NetType must be set")
}
validator := validators.StringInSlice(crq.NetType, []string{"EXTNET", "VINS"})
if !validator {
return errors.New("validation-error: field NetType can be only EXTNET or VINS")
}
if crq.NetID == 0 {
return errors.New("validation-error: field NetID must be set")
}
return nil
}
// NetAttach attach network to compute and gets info about network
func (c Compute) NetAttach(ctx context.Context, req NetAttachRequest) (*RecordNetAttach, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/netAttach"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := RecordNetAttach{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,57 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for detach networ to compute
type NetDetachRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// IP of the network interface
// Required: false
IPAddr string `url:"ipAddr,omitempty"`
// MAC of the network interface
// Required: false
MAC string `url:"mac,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq NetDetachRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// NetDetach detach network to compute
func (c Compute) NetDetach(ctx context.Context, req NetDetachRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/netDetach"
res, err := c.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
}

View File

@@ -0,0 +1,80 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for update QOS
type NetQOSRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Network ID
// Required: true
NetID uint64 `url:"netId"`
// Network type
// Should be one of:
// - VINS
// - EXTNET
// Required: true
NetType string `url:"netType"`
// Internal traffic, kbit
// Required: false
IngressRate uint64 `url:"ingress_rate,omitempty"`
// Internal traffic burst, kbit
// Required: false
IngressBurst uint64 `url:"ingress_burst,omitempty"`
// External traffic rate, kbit
// Required: false
EgressRate uint64 `url:"egress_rate,omitempty"`
}
func (crq NetQOSRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.NetType == "" {
return errors.New("validation-error: field NetType must be set")
}
validator := validators.StringInSlice(crq.NetType, []string{"EXTNET", "VINS"})
if !validator {
return errors.New("validation-error: field NetType can be only EXTNET or VINS")
}
if crq.NetID == 0 {
return errors.New("validation-error: field NetID must be set")
}
return nil
}
// NetQOS update compute interfaces QOS
func (c Compute) NetQOS(ctx context.Context, req NetQOSRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/netQos"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for pause compute
type PauseRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq PauseRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// Pause pause compute
func (c Compute) Pause(ctx context.Context, req PauseRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/pause"
res, err := c.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
}

View File

@@ -0,0 +1,83 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for add port forward rule
type PFWAddRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// External start port number for the rule
// Required: true
PublicPortStart uint64 `url:"publicPortStart"`
// End port number (inclusive) for the ranged rule
// Required: false
PublicPortEnd uint64 `url:"publicPortEnd,omitempty"`
// Internal base port number
// Required: true
LocalBasePort uint64 `url:"localBasePort"`
// Network protocol
// Should be one of:
// - tcp
// - udp
// Required: true
Proto string `url:"proto"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq PFWAddRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.PublicPortStart == 0 {
return errors.New("validation-error: field PublicPortStart must be set")
}
if crq.LocalBasePort == 0 {
return errors.New("validation-error: field LocalBasePort must be set")
}
if crq.Proto == "" {
return errors.New("validation-error: field Proto must be set")
}
validate := validators.StringInSlice(crq.Proto, []string{"tcp", "udp"})
if !validate {
return errors.New("validation-error: field Proto must be tcp or udp")
}
return nil
}
// PFWAdd add port forward rule
func (c Compute) PFWAdd(ctx context.Context, req PFWAddRequest) (uint64, error) {
err := req.validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/compute/pfwAdd"
res, err := c.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
}

View File

@@ -0,0 +1,72 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for delete port forward rule
type PFWDelRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the rule to delete. If specified, all other arguments will be ignored
// Required: false
RuleID uint64 `url:"ruleId,omitempty"`
// External start port number for the rule
// Required: false
PublicPortStart uint64 `url:"publicPortStart,omitempty"`
// End port number (inclusive) for the ranged rule
// Required: false
PublicPortEnd uint64 `url:"publicPortEnd,omitempty"`
// Internal base port number
// Required: false
LocalBasePort uint64 `url:"localBasePort,omitempty"`
// Network protocol
// Should be one of:
// - tcp
// - udp
// Required: false
Proto string `url:"proto,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq PFWDelRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// PFWDel delete port forward rule
func (c Compute) PFWDel(ctx context.Context, req PFWDelRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/pfwDel"
res, err := c.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
}

View File

@@ -0,0 +1,51 @@
package compute
import (
"context"
"encoding/json"
"errors"
"net/http"
)
// Request struct for get list port forwards
type PFWListRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq PFWListRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// PFWList gets compute port forwards list
func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (ListPFW, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudbroker/compute/pfwList"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListPFW{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,56 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for pin comptute to stack
type PinToStackRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Stack ID to pin to
// Required: true
TargetStackID uint64 `url:"targetStackId"`
// Try to migrate or not if compute in running states
// Required: false
Force bool `url:"force"`
}
func (crq PinToStackRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.TargetStackID == 0 {
return errors.New("validation-error: field TargetStackID must be set")
}
return nil
}
// PinToStack pin compute to current stack
func (c Compute) PinToStack(ctx context.Context, req PinToStackRequest) (uint64, error) {
err := req.validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/compute/pinToStack"
res, err := c.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
}

View File

@@ -0,0 +1,45 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for force stop and start compute
type PowerCycleRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (crq PowerCycleRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// PowerCycle makes force stop and start compute
func (c Compute) PowerCycle(ctx context.Context, req PowerCycleRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/powerCycle"
res, err := c.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
}

View File

@@ -0,0 +1,24 @@
package compute
import (
"context"
"net/http"
"strconv"
)
// RaiseDown starting all computes in "DOWN" tech status
func (c Compute) RaiseDown(ctx context.Context) (bool, error) {
url := "/cloudbroker/compute/raiseDown"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, nil)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for reboot compute
type RebootRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq RebootRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field computeID must be set")
}
return nil
}
// Reboot reboot compute
func (c Compute) Reboot(ctx context.Context, req RebootRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/reboot"
res, err := c.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
}

View File

@@ -0,0 +1,73 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for redeploy
type RedeployRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the new OS image, if image change is required
// Required: false
ImageID uint64 `url:"imageId,omitempty"`
// New size for the boot disk in GB, if boot disk size change is required
// Required: false
DiskSize uint64 `url:"diskSize,omitempty"`
// How to handle data disks connected to this compute instance
// Should be one of:
// - KEEP
// - DETACH
// - DESTROY
// Required: false
DataDisks string `url:"dataDisks,omitempty"`
// Should the compute be restarted upon successful redeploy
// Required: false
AutoStart bool `url:"autoStart,omitempty"`
// Set this flag to True to force stop running compute instance and redeploy next
// Required: false
ForceStop bool `url:"forceStop,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq RedeployRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// Redeploy redeploy compute
func (c Compute) Redeploy(ctx context.Context, req RedeployRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/redeploy"
res, err := c.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
}

View File

@@ -0,0 +1,52 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for set compute registered in RT
type RegistrationRequest struct {
// ID of the Compute
// Required: true
ComputeID uint64 `url:"computeId"`
// Unique compute registration key
// Required: true
RegistrationKey string `url:"registrationKey"`
}
func (crq RegistrationRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.RegistrationKey == "" {
return errors.New("validation-error: field RegistrationKey must be set")
}
return nil
}
// Registration sets compute registered in RT
func (c Compute) Registration(ctx context.Context, req RegistrationRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/registration"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for repair filesystem
type RepairBootFSRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq RepairBootFSRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// RepairBootFS repair compute boot disk filesystem
func (c Compute) RepairBootFS(ctx context.Context, req RepairBootFSRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/repairBootFs"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for reset compute
type ResetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq ResetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// Reset reset compute
func (c Compute) Reset(ctx context.Context, req ResetRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/reset"
res, err := c.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
}

View File

@@ -0,0 +1,63 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for resize compute
type ResizeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// New CPU count.
// Pass 0 if no change to CPU count is required
// Required: false
Force bool `url:"force,omitempty"`
// New RAM volume in MB.
// Pass 0 if no change to RAM volume is required
// Required: false
CPU uint64 `url:"cpu,omitempty"`
// Force compute resize
// Required: false
RAM uint64 `url:"ram,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq ResizeRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// Resize resize compute instance
func (c Compute) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/resize"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for restore compute
type RestoreRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq RestoreRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// Restore restore compute from recycle bin
func (c Compute) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/restore"
res, err := c.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
}

View File

@@ -0,0 +1,49 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for resume compute
type ResumeRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty"`
}
func (crq ResumeRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
return nil
}
// Resume resume Compute from paused state
func (c Compute) Resume(ctx context.Context, req ResumeRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/resume"
res, err := c.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
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"errors"
"net/http"
"strings"
)
// Request struct for create snapshot
type SnapshotCreateRequest struct {
// ID of the compute instance to create snapshot for
// Required: true
ComputeID uint64 `url:"computeId"`
// Text label for snapshot.
// Must be unique among this compute snapshots
// Required: true
Label string `url:"label"`
}
func (crq SnapshotCreateRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.Label == "" {
return errors.New("validation-error: field Label must be set")
}
return nil
}
// SnapshotCreate create compute snapshot
func (c Compute) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (string, error) {
err := req.validate()
if err != nil {
return "", err
}
url := "/cloudbroker/compute/snapshotCreate"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,52 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for delete snapshot
type SnapshotDeleteRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// Text label of snapshot to delete
// Required: true
Label string `url:"label"`
}
func (crq SnapshotDeleteRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.Label == "" {
return errors.New("validation-error: field Label must be set")
}
return nil
}
// SnapshotDelete delete specified compute snapshot
func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/snapshotDelete"
res, err := c.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
}

View File

@@ -0,0 +1,52 @@
package compute
import (
"context"
"errors"
"net/http"
"strconv"
)
// Request struct for evict specified disk
type SnapshotEvictDiskRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId"`
// ID of the disk instance
// Required: true
DiskID uint64 `url:"diskId"`
}
func (crq SnapshotEvictDiskRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID must be set")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID must be set")
}
return nil
}
// SnapshotEvictDisk evict specified disk from all snapshots of a compute instance
func (c Compute) SnapshotEvictDisk(ctx context.Context, req SnapshotEvictDiskRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudbroker/compute/snapshotEvictDisk"
res, err := c.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
}

Some files were not shown because too many files have changed in this diff Show More