v1.3.0
This commit is contained in:
@@ -2,7 +2,6 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,43 +12,27 @@ import (
|
||||
type AddUserRequest struct {
|
||||
// ID of account to add to
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Name of the user to be given rights
|
||||
// Required: true
|
||||
UserName string `url:"username" json:"username"`
|
||||
Username string `url:"username" json:"username" validate:"required"`
|
||||
|
||||
// Account permission types:
|
||||
// - 'R' for read only access
|
||||
// - 'RCX' for Write
|
||||
// - 'ARCXDU' for Admin
|
||||
// Required: true
|
||||
AccessType string `url:"accesstype" json:"accesstype"`
|
||||
}
|
||||
|
||||
func (arq AddUserRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
if arq.UserName == "" {
|
||||
return errors.New("validation-error: field UserName can not be empty")
|
||||
}
|
||||
if arq.AccessType == "" {
|
||||
return errors.New("validation-error: field AccessType can not be empty")
|
||||
}
|
||||
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
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"accessType"`
|
||||
}
|
||||
|
||||
// AddUser gives a user access rights.
|
||||
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/addUser"
|
||||
|
||||
@@ -3,29 +3,25 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for give list account audits
|
||||
type AuditsRequest struct {
|
||||
// ID of the account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (arq AuditsRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// Audits gets audit records for the specified account object
|
||||
func (a Account) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/audits"
|
||||
|
||||
@@ -2,24 +2,25 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for creating account
|
||||
type CreateRequest struct {
|
||||
// Display name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Name of the account
|
||||
// Required: true
|
||||
Username string `url:"username" json:"username"`
|
||||
Username string `url:"username" json:"username" validate:"required"`
|
||||
|
||||
// Email
|
||||
// Required: false
|
||||
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty"`
|
||||
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
|
||||
|
||||
// Max size of memory in MB
|
||||
// Required: false
|
||||
@@ -55,23 +56,14 @@ type CreateRequest struct {
|
||||
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
|
||||
}
|
||||
|
||||
func (arq CreateRequest) validate() error {
|
||||
if arq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if arq.Username == "" {
|
||||
return errors.New("validation-error: field Username can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/create"
|
||||
|
||||
@@ -2,41 +2,33 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete account
|
||||
type DeleteRequest struct {
|
||||
// ID of account to delete
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Reason to delete
|
||||
// Required: true
|
||||
Reason string `url:"reason" json:"reason"`
|
||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
||||
|
||||
// Whether to completely delete the account
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DeleteRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/delete"
|
||||
|
||||
@@ -2,41 +2,33 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete group accounts
|
||||
type DeleteAccountsRequest struct {
|
||||
// IDs of accounts
|
||||
// Required: true
|
||||
AccountsIDs []uint64 `url:"accountIds" json:"accountIds"`
|
||||
AccountsIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
|
||||
|
||||
// Reason for deletion
|
||||
// Required: true
|
||||
Reason string `url:"reason" json:"reason"`
|
||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
||||
|
||||
// Whether to completely destroy accounts or not
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
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 := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/deleteAccounts"
|
||||
|
||||
@@ -2,42 +2,34 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for revoke access to account
|
||||
type DeleteUserRequest struct {
|
||||
// ID of the account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// ID or emailaddress of the user to remove
|
||||
// Required: true
|
||||
UserName string `url:"username" json:"username"`
|
||||
UserName string `url:"username" json:"username" validate:"required"`
|
||||
|
||||
// Recursively revoke access rights from owned cloudspaces and vmachines
|
||||
// Required: false
|
||||
RecursiveDelete bool `url:"recursivedelete,omitempty" json:"recursivedelete,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DeleteUserRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.UserName == "" {
|
||||
return errors.New("validation-error: field UserName must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteUser revokes user access from the account
|
||||
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/deleteUser"
|
||||
|
||||
@@ -2,38 +2,30 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable account
|
||||
type DisableRequest struct {
|
||||
// ID of account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Reason to disable
|
||||
// Required: true
|
||||
Reason string `url:"reason" json:"reason"`
|
||||
}
|
||||
|
||||
func (arq DisableRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables an account
|
||||
func (a Account) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/disable"
|
||||
|
||||
@@ -2,30 +2,25 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable group accounts
|
||||
type DisableAccountsRequest struct {
|
||||
// IDs of accounts
|
||||
// Required: true
|
||||
AccountIDs []uint64 `url:"accountIds,omitempty" json:"accountIds,omitempty"`
|
||||
}
|
||||
|
||||
func (arq DisableAccountsRequest) validate() error {
|
||||
if len(arq.AccountIDs) == 0 {
|
||||
return errors.New("validation-error: field AccountIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
|
||||
}
|
||||
|
||||
// DisableAccounts disables accounts
|
||||
func (a Account) DisableAccounts(ctx context.Context, req DisableAccountsRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/disableAccounts"
|
||||
|
||||
@@ -2,38 +2,30 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for enable account
|
||||
type EnableRequest struct {
|
||||
// ID of account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Reason to enable
|
||||
// Required: true
|
||||
Reason string `url:"reason" json:"reason"`
|
||||
}
|
||||
|
||||
func (arq EnableRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Reason == "" {
|
||||
return errors.New("field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
||||
}
|
||||
|
||||
// Enable enables an account
|
||||
func (a Account) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/enable"
|
||||
|
||||
@@ -2,30 +2,25 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request for enable group accounts
|
||||
type EnableAccountsRequest struct {
|
||||
// IDs od accounts
|
||||
// Required: true
|
||||
AccountIDs []uint64 `url:"accountIds" json:"accountIds"`
|
||||
}
|
||||
|
||||
func (arq EnableAccountsRequest) validate() error {
|
||||
if len(arq.AccountIDs) == 0 {
|
||||
return errors.New("validation-error: field AccountIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
|
||||
}
|
||||
|
||||
// EnableAccounts enables accounts
|
||||
func (a Account) EnableAccounts(ctx context.Context, req EnableAccountsRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/enableAccounts"
|
||||
|
||||
@@ -3,30 +3,25 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get information about account
|
||||
type GetRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (arq GetRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets information about account
|
||||
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/get"
|
||||
|
||||
@@ -3,30 +3,25 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for a get list compute instances
|
||||
type ListComputesRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListComputesRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// 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 := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listComputes"
|
||||
|
||||
@@ -3,30 +3,25 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list deleted disks
|
||||
type ListDisksRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListDisksRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// 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 := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listDisks"
|
||||
|
||||
@@ -3,30 +3,25 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list FLIPGroups
|
||||
type ListFLIPGroupsRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListFLIPGroupsRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// 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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listFlipGroups"
|
||||
|
||||
@@ -3,30 +3,25 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list resource groups
|
||||
type ListRGRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListRGRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// 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 := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listRG"
|
||||
|
||||
@@ -3,30 +3,25 @@ package account
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list VINS
|
||||
type ListVINSRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (arq ListVINSRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// 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 := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/listVins"
|
||||
|
||||
@@ -2,37 +2,29 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restore a deleted account
|
||||
type RestoreRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Reason to restore
|
||||
// Required: true
|
||||
Reason string `url:"reason" json:"reason"`
|
||||
}
|
||||
|
||||
func (arq RestoreRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
||||
}
|
||||
|
||||
// Restore restores a deleted account
|
||||
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/restore"
|
||||
|
||||
@@ -2,28 +2,29 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update account
|
||||
type UpdateRequest struct {
|
||||
// ID of account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Display name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Name of the account
|
||||
// Required: true
|
||||
Username string `url:"username" json:"username"`
|
||||
Username string `url:"username,omitempty" json:"username,omitempty"`
|
||||
|
||||
// Email
|
||||
// Required: false
|
||||
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty"`
|
||||
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
|
||||
|
||||
// Max size of memory in MB
|
||||
// Required: false
|
||||
@@ -59,22 +60,13 @@ type UpdateRequest struct {
|
||||
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
|
||||
}
|
||||
|
||||
func (arq UpdateRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/update"
|
||||
|
||||
@@ -2,7 +2,6 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,7 +12,7 @@ import (
|
||||
type UpdateResourceTypesRequest struct {
|
||||
// ID of account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Resource types available to create in this account
|
||||
// Each element in a resource type slice must be one of:
|
||||
@@ -24,29 +23,15 @@ type UpdateResourceTypesRequest struct {
|
||||
// - lb
|
||||
// - flipgroup
|
||||
// Required: true
|
||||
ResTypes []string `url:"resourceTypes" json:"resourceTypes"`
|
||||
}
|
||||
|
||||
func (arq UpdateResourceTypesRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID 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
|
||||
ResTypes []string `url:"resourceTypes" json:"resourceTypes" validate:"min=1,resTypes"`
|
||||
}
|
||||
|
||||
func (a Account) UpdateResourceTypes(ctx context.Context, req UpdateResourceTypesRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/updateResourceTypes"
|
||||
|
||||
@@ -2,48 +2,37 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update user access rights
|
||||
type UpdateUserRequest struct {
|
||||
// ID of the account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Userid/Email for registered users or emailaddress for unregistered users
|
||||
// Required: true
|
||||
UserID string `url:"userId" json:"userId"`
|
||||
UserID string `url:"userId" json:"userId" validate:"required"`
|
||||
|
||||
// Account permission types:
|
||||
// - 'R' for read only access
|
||||
// - 'RCX' for Write
|
||||
// - 'ARCXDU' for Admin
|
||||
// Required: true
|
||||
AccessType string `url:"accesstype" json:"accesstype"`
|
||||
}
|
||||
|
||||
func (arq UpdateUserRequest) validate() error {
|
||||
if arq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
if arq.UserID == "" {
|
||||
return errors.New("validation-error: field UserID must be set")
|
||||
}
|
||||
if arq.AccessType == "" {
|
||||
return errors.New("validation-error: field AccessType must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"accessType"`
|
||||
}
|
||||
|
||||
// UpdateUser updates user access rights
|
||||
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/updateUser"
|
||||
|
||||
@@ -2,37 +2,29 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// 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" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Affinity group label
|
||||
// Required: true
|
||||
AffinityLabel string `url:"affinityLabel" json:"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
|
||||
AffinityLabel string `url:"affinityLabel" json:"affinityLabel" validate:"required"`
|
||||
}
|
||||
|
||||
// AffinityGroupCheckStart check all computes with current affinity label can start
|
||||
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/affinityGroupCheckStart"
|
||||
|
||||
@@ -2,31 +2,26 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for clear affinity label for compute
|
||||
type AffinityLabelRemoveRequest struct {
|
||||
// IDs of the compute instances
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
}
|
||||
|
||||
func (crq AffinityLabelRemoveRequest) validate() error {
|
||||
if len(crq.ComputeIDs) == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
}
|
||||
|
||||
// AffinityLabelRemove clear affinity label for compute
|
||||
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/affinityLabelRemove"
|
||||
|
||||
@@ -2,37 +2,29 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for set affinity label for compute
|
||||
type AffinityLabelSetRequest struct {
|
||||
// IDs of the compute instances
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Affinity group label
|
||||
// Required: true
|
||||
AffinityLabel string `url:"affinityLabel" json:"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
|
||||
AffinityLabel string `url:"affinityLabel" json:"affinityLabel" validate:"required"`
|
||||
}
|
||||
|
||||
// AffinityLabelSet set affinity label for compute
|
||||
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/affinityLabelSet"
|
||||
|
||||
@@ -3,34 +3,29 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get dict of computes
|
||||
type AffinityRelationsRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Affinity group label
|
||||
// Required: false
|
||||
AffinityLabel string `url:"affinityLabel,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/affinityRelations"
|
||||
|
||||
@@ -2,7 +2,6 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,20 +12,20 @@ import (
|
||||
type AffinityRuleAddRequest struct {
|
||||
// IDs of the compute instances
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Should be one of:
|
||||
// - node
|
||||
// - compute
|
||||
// Required: true
|
||||
Topology string `url:"topology" json:"topology"`
|
||||
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
|
||||
|
||||
// The degree of 'strictness' of this rule
|
||||
// Should be one of:
|
||||
// - RECOMMENDED
|
||||
// - REQUIRED
|
||||
// Required: true
|
||||
Policy string `url:"policy" json:"policy"`
|
||||
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
|
||||
|
||||
// The comparison mode is 'value', recorded by the specified 'key'
|
||||
// Should be one of:
|
||||
@@ -34,57 +33,24 @@ type AffinityRuleAddRequest struct {
|
||||
// - EN
|
||||
// - ANY
|
||||
// Required: true
|
||||
Mode string `url:"mode" json:"mode"`
|
||||
Mode string `url:"mode" json:"mode" validate:"computeMode"`
|
||||
|
||||
// Key that are taken into account when analyzing this rule will be identified
|
||||
// Required: true
|
||||
Key string `url:"key" json:"key"`
|
||||
Key string `url:"key" json:"key" validate:"required"`
|
||||
|
||||
// Value that must match the key to be taken into account when analyzing this rule
|
||||
// Required: true
|
||||
Value string `url:"value" json:"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
|
||||
Value string `url:"value" json:"value" validate:"required"`
|
||||
}
|
||||
|
||||
// AffinityRuleAdd add affinity rule
|
||||
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/affinityRuleAdd"
|
||||
|
||||
@@ -2,7 +2,6 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,18 +12,18 @@ import (
|
||||
type AffinityRuleRemoveRequest struct {
|
||||
// IDs of the compute instances
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Compute or node, for whom rule applies
|
||||
// Required: true
|
||||
Topology string `url:"topology" json:"topology"`
|
||||
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
|
||||
|
||||
// The degree of 'strictness' of this rule
|
||||
// Should be one of:
|
||||
// - RECOMMENDED
|
||||
// - REQUIRED
|
||||
// Required: true
|
||||
Policy string `url:"policy" json:"policy"`
|
||||
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
|
||||
|
||||
// The comparison mode is 'value', recorded by the specified 'key'
|
||||
// Should be one of:
|
||||
@@ -32,57 +31,24 @@ type AffinityRuleRemoveRequest struct {
|
||||
// - EN
|
||||
// - ANY
|
||||
// Required: true
|
||||
Mode string `url:"mode" json:"mode"`
|
||||
Mode string `url:"mode" json:"mode" validate:"computeMode"`
|
||||
|
||||
// Key that are taken into account when analyzing this rule will be identified
|
||||
// Required: true
|
||||
Key string `url:"key" json:"key"`
|
||||
Key string `url:"key" json:"key" validate:"required"`
|
||||
|
||||
// Value that must match the key to be taken into account when analyzing this rule
|
||||
// Required: true
|
||||
Value string `url:"value" json:"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
|
||||
Value string `url:"value" json:"value" validate:"required"`
|
||||
}
|
||||
|
||||
// AffinityRuleRemove remove affinity rule
|
||||
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/affinityRuleRemove"
|
||||
|
||||
@@ -2,31 +2,26 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for clear affinity rules
|
||||
type AffinityRulesClearRequest struct {
|
||||
// IDs of the compute instances
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
}
|
||||
|
||||
func (crq AffinityRulesClearRequest) validate() error {
|
||||
if len(crq.ComputeIDs) == 0 {
|
||||
return errors.New("validation-error: field ComputeIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
}
|
||||
|
||||
// AffinityRulesClear clear affinity rules
|
||||
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/affinityRulesClear"
|
||||
|
||||
@@ -2,7 +2,6 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,18 +12,18 @@ import (
|
||||
type AntiAffinityRuleAddRequest struct {
|
||||
// IDs of the compute instances
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Compute or node, for whom rule applies
|
||||
// Required: true
|
||||
Topology string `url:"topology" json:"topology"`
|
||||
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
|
||||
|
||||
// The degree of 'strictness' of this rule
|
||||
// Should be one of:
|
||||
// - RECOMMENDED
|
||||
// - REQUIRED
|
||||
// Required: true
|
||||
Policy string `url:"policy" json:"policy"`
|
||||
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
|
||||
|
||||
// The comparison mode is 'value', recorded by the specified 'key'
|
||||
// Should be one of:
|
||||
@@ -32,57 +31,24 @@ type AntiAffinityRuleAddRequest struct {
|
||||
// - EN
|
||||
// - ANY
|
||||
// Required: true
|
||||
Mode string `url:"mode" json:"mode"`
|
||||
Mode string `url:"mode" json:"mode" validate:"computeMode"`
|
||||
|
||||
// Key that are taken into account when analyzing this rule will be identified
|
||||
// Required: true
|
||||
Key string `url:"key" json:"key"`
|
||||
Key string `url:"key" json:"key" validate:"required"`
|
||||
|
||||
// Value that must match the key to be taken into account when analyzing this rule
|
||||
// Required: true
|
||||
Value string `url:"value" json:"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
|
||||
Value string `url:"value" json:"value" validate:"required"`
|
||||
}
|
||||
|
||||
// AntiAffinityRuleAdd add anti affinity rule
|
||||
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/antiAffinityRuleAdd"
|
||||
|
||||
@@ -2,31 +2,26 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for clear anti affinity rules
|
||||
type AntiAffinityRulesClearRequest struct {
|
||||
// IDs of the compute instances
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
}
|
||||
|
||||
func (crq AntiAffinityRulesClearRequest) validate() error {
|
||||
if len(crq.ComputeIDs) == 0 {
|
||||
return errors.New("validation-error: field ComputeIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
}
|
||||
|
||||
// AntiAffinityRulesClear clear anti affinity rules
|
||||
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/antiAffinityRulesClear"
|
||||
|
||||
@@ -2,7 +2,6 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,18 +12,18 @@ import (
|
||||
type AntiAffinityRuleRemoveRequest struct {
|
||||
// IDs of the compute instances
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Compute or node, for whom rule applies
|
||||
// Required: true
|
||||
Topology string `url:"topology" json:"topology"`
|
||||
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
|
||||
|
||||
// The degree of 'strictness' of this rule
|
||||
// Should be one of:
|
||||
// - RECOMMENDED
|
||||
// - REQUIRED
|
||||
// Required: true
|
||||
Policy string `url:"policy" json:"policy"`
|
||||
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
|
||||
|
||||
// The comparison mode is 'value', recorded by the specified 'key'
|
||||
// Should be one of:
|
||||
@@ -32,57 +31,24 @@ type AntiAffinityRuleRemoveRequest struct {
|
||||
// - EN
|
||||
// - ANY
|
||||
// Required: true
|
||||
Mode string `url:"mode" json:"mode"`
|
||||
Mode string `url:"mode" json:"mode" validate:"computeMode"`
|
||||
|
||||
// Key that are taken into account when analyzing this rule will be identified
|
||||
// Required: true
|
||||
Key string `url:"key" json:"key"`
|
||||
Key string `url:"key" json:"key" validate:"required"`
|
||||
|
||||
// Value that must match the key to be taken into account when analyzing this rule
|
||||
// Required: true
|
||||
Value string `url:"value" json:"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
|
||||
Value string `url:"value" json:"value" validate:"required"`
|
||||
}
|
||||
|
||||
// AntiAffinityRuleRemove remove anti affinity rule
|
||||
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/antiAffinityRuleRemove"
|
||||
|
||||
@@ -2,38 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for attach GPU for compute
|
||||
type AttachGPURequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Identifier vGPU
|
||||
// Required: true
|
||||
VGPUID uint64 `url:"vgpuId" json:"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
|
||||
VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
|
||||
}
|
||||
|
||||
// AttachGPU attach GPU for compute, returns vGPU ID on success
|
||||
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/attachGpu"
|
||||
|
||||
@@ -2,38 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for atttach PCI device
|
||||
type AttachPCIDeviceRequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// PCI device ID
|
||||
// Required: true
|
||||
DeviceID uint64 `url:"deviceId" json:"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
|
||||
DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
|
||||
}
|
||||
|
||||
// AttachPCIDevice attach PCI device
|
||||
func (c Compute) AttachPCIDevice(ctx context.Context, req AttachPCIDeviceRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/attachPciDevice"
|
||||
|
||||
@@ -3,30 +3,25 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get audit records
|
||||
type AuditsRequest struct {
|
||||
// ID of the compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq AuditsRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// Audits gets audit records for the specified compute object
|
||||
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListDetailedAudits, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/audits"
|
||||
|
||||
@@ -3,30 +3,25 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get boot order
|
||||
type BootOrderGetRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq BootOrderGetRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// BootOrderGet gets actual compute boot order information
|
||||
func (c Compute) BootOrderGet(ctx context.Context, req BootOrderGetRequest) ([]string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/bootOrderGet"
|
||||
|
||||
@@ -3,7 +3,6 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
@@ -13,7 +12,7 @@ import (
|
||||
type BootOrderSetRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// List of boot devices
|
||||
// Should be one of:
|
||||
@@ -21,30 +20,16 @@ type BootOrderSetRequest struct {
|
||||
// - network
|
||||
// - hd
|
||||
// Required: true
|
||||
Order []string `url:"order" json:"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
|
||||
Order []string `url:"order" json:"order" validate:"min=1,computeOrder"`
|
||||
}
|
||||
|
||||
// BootOrderSet sets compute boot order
|
||||
func (c Compute) BootOrderSet(ctx context.Context, req BootOrderSetRequest) ([]string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/bootOrderSet"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for eject CD image
|
||||
type CDEjectRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason to eject
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/cdEject"
|
||||
|
||||
@@ -2,41 +2,33 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for insert new CD image
|
||||
type CDInsertRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of CD-ROM image
|
||||
// Required: true
|
||||
CDROMID uint64 `url:"cdromId" json:"cdromId"`
|
||||
CDROMID uint64 `url:"cdromId" json:"cdromId" validate:"required"`
|
||||
|
||||
// Reason to insert
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/cdInsert"
|
||||
|
||||
@@ -2,20 +2,21 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for clone compute instance
|
||||
type CloneRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Name of the clone
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Timestamp of the parent's snapshot to create clone from
|
||||
// Required: false
|
||||
@@ -30,22 +31,13 @@ type CloneRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/clone"
|
||||
|
||||
@@ -2,38 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for set compute CI
|
||||
type ComputeCISetRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the Compute CI
|
||||
// Required: true
|
||||
ComputeCIID uint64 `url:"computeciId" json:"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
|
||||
ComputeCIID uint64 `url:"computeciId" json:"computeciId" validate:"required"`
|
||||
}
|
||||
|
||||
// ComputeCISet sets compute CI ID for compute
|
||||
func (c Compute) ComputeCISet(ctx context.Context, req ComputeCISetRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/computeciSet"
|
||||
|
||||
@@ -2,31 +2,26 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for unset compite CI
|
||||
type ComputeCIUnsetRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq ComputeCIUnsetRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// ComputeCIUnset unsets compute CI ID from compute
|
||||
func (c Compute) ComputeCIUnset(ctx context.Context, req ComputeCIUnsetRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/computeciUnset"
|
||||
|
||||
@@ -2,21 +2,22 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create template
|
||||
type CreateTemplateRequest struct {
|
||||
// ID of the compute to create template from
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Name to assign to the template being created
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
@@ -29,22 +30,13 @@ type CreateTemplateRequest struct {
|
||||
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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = true
|
||||
@@ -63,9 +55,11 @@ func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequ
|
||||
|
||||
// CreateTemplate create template from compute instance
|
||||
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = false
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete compute
|
||||
type DeleteRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Delete permanently
|
||||
// Required: false
|
||||
@@ -26,19 +27,13 @@ type DeleteRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/delete"
|
||||
|
||||
@@ -2,36 +2,31 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for detach VGPU for compute
|
||||
type DetachGPURequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Identifier virtual GPU
|
||||
// Required: false
|
||||
VGPUID int64 `url:"vgpuId,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/detachGpu"
|
||||
|
||||
@@ -2,38 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for detach PCI device
|
||||
type DetachPCIDeviceRequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// PCI device ID
|
||||
// Required: true
|
||||
DeviceID uint64 `url:"deviceId" json:"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
|
||||
DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
|
||||
}
|
||||
|
||||
// DetachPCIDevice detach PCI device
|
||||
func (c Compute) DetachPciDevice(ctx context.Context, req DetachPCIDeviceRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/detachPciDevice"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable compute
|
||||
type DisableRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/disable"
|
||||
|
||||
@@ -2,31 +2,32 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create and attach disk to compute
|
||||
type DiskAddRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Name for disk
|
||||
// Required: true
|
||||
DiskName string `url:"diskName" json:"diskName"`
|
||||
DiskName string `url:"diskName" json:"diskName" validate:"required"`
|
||||
|
||||
// Disk size in GB
|
||||
// Required: true
|
||||
Size uint64 `url:"size" json:"size"`
|
||||
Size uint64 `url:"size" json:"size" validate:"required"`
|
||||
|
||||
// Type of the disk
|
||||
// Should be one of:
|
||||
// - D
|
||||
// - B
|
||||
// Required: false
|
||||
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty"`
|
||||
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
|
||||
|
||||
// Storage endpoint provider ID
|
||||
// By default the same with boot disk
|
||||
@@ -47,25 +48,13 @@ type DiskAddRequest struct {
|
||||
ImageID uint64 `url:"imageId,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/diskAdd"
|
||||
|
||||
@@ -2,42 +2,34 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for attach disk to compute
|
||||
type DiskAttachRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the disk to attach
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/diskAttach"
|
||||
|
||||
@@ -2,46 +2,38 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for detach and delete disk from compute
|
||||
type DiskDelRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of disk instance
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// False if disk is to be deleted to recycle bin
|
||||
// Required: true
|
||||
Permanently bool `url:"permanently" json:"permanently"`
|
||||
Permanently bool `url:"permanently" json:"permanently" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/diskDel"
|
||||
|
||||
@@ -2,42 +2,34 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for detach disk from compute
|
||||
type DiskDetachRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the disk to detach
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/diskDetach"
|
||||
|
||||
@@ -2,45 +2,34 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for change QOS of the disk
|
||||
type DiskQOSRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the disk to apply limits
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Limit IO for a certain disk total and read/write options are not allowed to be combined
|
||||
// Required: true
|
||||
Limits string `url:"limits" json:"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
|
||||
Limits string `url:"limits" json:"limits" validate:"required"`
|
||||
}
|
||||
|
||||
// DiskQOS change QOS of the disk
|
||||
func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/diskQos"
|
||||
|
||||
@@ -2,49 +2,38 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for change disk size
|
||||
type DiskResizeRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the disk to resize
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// New disk size
|
||||
// Required: true
|
||||
Size uint64 `url:"size" json:"size"`
|
||||
Size uint64 `url:"size" json:"size" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/diskResize"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for enable compute
|
||||
type EnableRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/enable"
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
)
|
||||
|
||||
// FilterByID returns ListComputes with specified ID.
|
||||
func (lc ListComputes) FilterByID(id uint64) ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
@@ -50,6 +58,88 @@ func (lc ListComputes) FilterByDiskID(diskID uint64) ListComputes {
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByK8SID returns master and worker nodes (ListComputes) inside specified K8S cluster.
|
||||
func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListComputes, error) {
|
||||
caller := k8s.New(decortClient)
|
||||
|
||||
req := k8s.GetRequest{
|
||||
K8SID: k8sID,
|
||||
}
|
||||
|
||||
cluster, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
for _, info := range cluster.K8SGroups.Masters.DetailedInfo {
|
||||
if info.ID == ic.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for _, worker := range cluster.K8SGroups.Workers {
|
||||
for _, info := range worker.DetailedInfo {
|
||||
if info.ID == ic.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate), nil
|
||||
}
|
||||
|
||||
// K8SMasters is used to filter master nodes. Best used after FilterByK8SID function.
|
||||
func (lc ListComputes) FilterByK8SMasters() ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
for _, rule := range ic.AntiAffinityRules {
|
||||
if rule.Value == "master" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// K8SMasters is used to filter worker nodes. Best used after FilterByK8SID function.
|
||||
func (lc ListComputes) FilterByK8SWorkers() ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
for _, rule := range ic.AntiAffinityRules {
|
||||
if rule.Value == "worker" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByLBID is used to filter ListComputes used by specified Load Balancer.
|
||||
func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListComputes, error) {
|
||||
caller := lb.New(decortClient)
|
||||
|
||||
req := lb.GetRequest{
|
||||
LBID: lbID,
|
||||
}
|
||||
|
||||
foundLB, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
return ic.ID == foundLB.PrimaryNode.ComputeID || ic.ID == foundLB.SecondaryNode.ComputeID
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate), nil
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListComputes based on a user-specified predicate.
|
||||
func (lc ListComputes) FilterFunc(predicate func(ItemCompute) bool) ListComputes {
|
||||
var result ListComputes
|
||||
|
||||
@@ -3,34 +3,29 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request for get information about compute
|
||||
type GetRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason to action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/get"
|
||||
|
||||
@@ -3,34 +3,29 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get compute audits
|
||||
type GetAuditsRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason to action
|
||||
// Required: true
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/getAudits"
|
||||
|
||||
@@ -2,31 +2,26 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get console URL
|
||||
type GetConsoleURLRequest struct {
|
||||
// ID of compute instance to get console for
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq GetConsoleURLRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// GetConsoleURL gets computes console URL
|
||||
func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/getConsoleUrl"
|
||||
|
||||
@@ -2,37 +2,29 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get compute logs
|
||||
type GetLogRequest struct {
|
||||
// ID of compute instance to get log for
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Path to log file
|
||||
// Required: true
|
||||
Path string `url:"path" json:"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
|
||||
Path string `url:"path" json:"path" validate:"required"`
|
||||
}
|
||||
|
||||
// GetLog gets compute's log file by path
|
||||
func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/getLog"
|
||||
|
||||
@@ -3,34 +3,29 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list GPU for compute
|
||||
type ListGPURequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Also list destroyed
|
||||
// Required: false
|
||||
ListDestroyed bool `url:"list_destroyed,omitempty" json:"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) ListGPU(ctx context.Context, req ListGPURequest) ([]interface{}, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/listGpu"
|
||||
|
||||
@@ -3,30 +3,25 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list PCI devices
|
||||
type ListPCIDeviceRequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq ListPCIDeviceRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// ListPCIDevice gets list PCI device
|
||||
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (ListPCIDevices, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/listPciDevice"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete several computes
|
||||
type MassDeleteRequest struct {
|
||||
// IDs of compute instances to delete
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Delete computes permanently
|
||||
// Required: false
|
||||
@@ -22,19 +23,13 @@ type MassDeleteRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/massDelete"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for reboot several computes
|
||||
type MassRebootRequest struct {
|
||||
// IDs of compute instances to reboot
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/massReboot"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// 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" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/massRepairBootFs"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for start several computes
|
||||
type MassStartRequest struct {
|
||||
// IDs of compute instances to start
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/massStart"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for several stop computes
|
||||
type MassStopRequest struct {
|
||||
// IDs of compute instances to stop
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Force stop compute
|
||||
// Required: false
|
||||
@@ -22,19 +23,13 @@ type MassStopRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/massStop"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for migrate compute
|
||||
type MigrateRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Particular Stack ID to migrate this compute to
|
||||
// Required: false
|
||||
@@ -27,19 +28,13 @@ type MigrateRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/migrate"
|
||||
|
||||
@@ -2,49 +2,33 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for migration
|
||||
type MigrateStorageRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// SEP ID to migrate disks
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sepId" json:"sepId"`
|
||||
SEPID uint64 `url:"sepId" json:"sepId" validate:"required"`
|
||||
|
||||
// SEP pool name to migrate disks
|
||||
// Required: true
|
||||
PoolName string `url:"poolName" json:"poolName"`
|
||||
PoolName string `url:"poolName" json:"poolName" validate:"required"`
|
||||
|
||||
// Target stack ID
|
||||
// Required: true
|
||||
StackID uint64 `url:"stackId" json:"stackId"`
|
||||
StackID uint64 `url:"stackId" json:"stackId" validate:"required"`
|
||||
|
||||
// Async API call
|
||||
// Required: true
|
||||
Sync bool `url:"sync" json:"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
|
||||
Sync bool `url:"sync" json:"sync" validate:"required"`
|
||||
}
|
||||
|
||||
// MigrateStorage gets complex compute migration
|
||||
@@ -52,9 +36,11 @@ func (crq MigrateStorageRequest) validate() error {
|
||||
// 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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/migrateStorage"
|
||||
|
||||
@@ -2,31 +2,26 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for abort migration
|
||||
type MigrateStorageAbortRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq MigrateStorageAbortRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// MigrateStorageAbort abort complex compute migration job
|
||||
func (c Compute) MigrateStorageAbort(ctx context.Context, req MigrateStorageAbortRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/migrateStorageAbort"
|
||||
|
||||
@@ -2,33 +2,28 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for cleanup resources after finished migration
|
||||
type MigrateStorageCleanUpRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq MigrateStorageCleanUpRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// 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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/migrateStorageCleanup"
|
||||
|
||||
@@ -2,31 +2,26 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get info about migration
|
||||
type MigrateStorageInfoRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq MigrateStorageInfoRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// MigrateStorageInfo gets info about last (include ongoing) storage migration
|
||||
func (c Compute) MigrateStorageInfo(ctx context.Context, req MigrateStorageInfoRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/migrateStorageInfo"
|
||||
|
||||
@@ -2,20 +2,21 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for move compute new resource group
|
||||
type MoveToRGRequest struct {
|
||||
// ID of the compute instance to move
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the target resource group
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// New name for the compute upon successful move,
|
||||
// if name change required.
|
||||
@@ -33,22 +34,13 @@ type MoveToRGRequest struct {
|
||||
ForceStop bool `url:"forceStop,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/moveToRg"
|
||||
|
||||
@@ -3,7 +3,6 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
@@ -13,19 +12,19 @@ import (
|
||||
type NetAttachRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Network type
|
||||
// 'EXTNET' for connect to external network directly
|
||||
// and 'VINS' for connect to ViNS
|
||||
// Required: true
|
||||
NetType string `url:"netType" json:"netType"`
|
||||
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
|
||||
|
||||
// Network ID for connect to
|
||||
// For EXTNET - external network ID
|
||||
// For VINS - VINS ID
|
||||
// Required: true
|
||||
NetID uint64 `url:"netId" json:"netId"`
|
||||
NetID uint64 `url:"netId" json:"netId" validate:"required"`
|
||||
|
||||
// Directly required IP address for new network interface
|
||||
// Required: true
|
||||
@@ -36,29 +35,13 @@ type NetAttachRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/netAttach"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for detach networ to compute
|
||||
type NetDetachRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// IP of the network interface
|
||||
// Required: false
|
||||
@@ -26,19 +27,13 @@ type NetDetachRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/netDetach"
|
||||
|
||||
@@ -2,7 +2,6 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,18 +12,18 @@ import (
|
||||
type NetQOSRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Network ID
|
||||
// Required: true
|
||||
NetID uint64 `url:"netId" json:"netId"`
|
||||
NetID uint64 `url:"netId" json:"netId" validate:"required"`
|
||||
|
||||
// Network type
|
||||
// Should be one of:
|
||||
// - VINS
|
||||
// - EXTNET
|
||||
// Required: true
|
||||
NetType string `url:"netType" json:"netType"`
|
||||
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
|
||||
|
||||
// Internal traffic, kbit
|
||||
// Required: false
|
||||
@@ -39,29 +38,13 @@ type NetQOSRequest struct {
|
||||
EgressRate uint64 `url:"egress_rate,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/netQos"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for pause compute
|
||||
type PauseRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/pause"
|
||||
|
||||
@@ -2,7 +2,6 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,11 +12,11 @@ import (
|
||||
type PFWAddRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// External start port number for the rule
|
||||
// Required: true
|
||||
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart"`
|
||||
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
||||
|
||||
// End port number (inclusive) for the ranged rule
|
||||
// Required: false
|
||||
@@ -25,46 +24,27 @@ type PFWAddRequest struct {
|
||||
|
||||
// Internal base port number
|
||||
// Required: true
|
||||
LocalBasePort uint64 `url:"localBasePort" json:"localBasePort"`
|
||||
LocalBasePort uint64 `url:"localBasePort" json:"localBasePort" validate:"required"`
|
||||
|
||||
// Network protocol
|
||||
// Should be one of:
|
||||
// - tcp
|
||||
// - udp
|
||||
// Required: true
|
||||
Proto string `url:"proto" json:"proto"`
|
||||
Proto string `url:"proto" json:"proto" validate:"proto"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/pfwAdd"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete port forward rule
|
||||
type PFWDelRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the rule to delete. If specified, all other arguments will be ignored
|
||||
// Required: false
|
||||
@@ -34,26 +35,20 @@ type PFWDelRequest struct {
|
||||
// - tcp
|
||||
// - udp
|
||||
// Required: false
|
||||
Proto string `url:"proto,omitempty" json:"proto,omitempty"`
|
||||
Proto string `url:"proto,omitempty" json:"proto,omitempty" validate:"omitempty,proto"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/pfwDel"
|
||||
|
||||
@@ -3,34 +3,29 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list port forwards
|
||||
type PFWListRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/pfwList"
|
||||
|
||||
@@ -2,42 +2,34 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for pin comptute to stack
|
||||
type PinToStackRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Stack ID to pin to
|
||||
// Required: true
|
||||
TargetStackID uint64 `url:"targetStackId" json:"targetStackId"`
|
||||
TargetStackID uint64 `url:"targetStackId" json:"targetStackId" validate:"required"`
|
||||
|
||||
// Try to migrate or not if compute in running states
|
||||
// Required: false
|
||||
Force bool `url:"force" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/pinToStack"
|
||||
|
||||
@@ -2,31 +2,26 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for force stop and start compute
|
||||
type PowerCycleRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq PowerCycleRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// PowerCycle makes force stop and start compute
|
||||
func (c Compute) PowerCycle(ctx context.Context, req PowerCycleRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/powerCycle"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for reboot compute
|
||||
type RebootRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/reboot"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for redeploy
|
||||
type RedeployRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the new OS image, if image change is required
|
||||
// Required: false
|
||||
@@ -27,7 +28,7 @@ type RedeployRequest struct {
|
||||
// - DETACH
|
||||
// - DESTROY
|
||||
// Required: false
|
||||
DataDisks string `url:"dataDisks,omitempty" json:"dataDisks,omitempty"`
|
||||
DataDisks string `url:"dataDisks,omitempty" json:"dataDisks,omitempty" validate:"omitempty,computeDataDisks"`
|
||||
|
||||
// Should the compute be restarted upon successful redeploy
|
||||
// Required: false
|
||||
@@ -42,19 +43,13 @@ type RedeployRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/redeploy"
|
||||
|
||||
@@ -2,38 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for set compute registered in RT
|
||||
type RegistrationRequest struct {
|
||||
// ID of the Compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Unique compute registration key
|
||||
// Required: true
|
||||
RegistrationKey string `url:"registrationKey" json:"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
|
||||
RegistrationKey string `url:"registrationKey" json:"registrationKey" validate:"required"`
|
||||
}
|
||||
|
||||
// Registration sets compute registered in RT
|
||||
func (c Compute) Registration(ctx context.Context, req RegistrationRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/registration"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for repair filesystem
|
||||
type RepairBootFSRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/repairBootFs"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for reset compute
|
||||
type ResetRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/reset"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for resize compute
|
||||
type ResizeRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// New CPU count.
|
||||
// Pass 0 if no change to CPU count is required
|
||||
@@ -32,19 +33,13 @@ type ResizeRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/resize"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restore compute
|
||||
type RestoreRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/restore"
|
||||
|
||||
@@ -2,35 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for resume compute
|
||||
type ResumeRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/resume"
|
||||
|
||||
@@ -2,39 +2,31 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create snapshot
|
||||
type SnapshotCreateRequest struct {
|
||||
// ID of the compute instance to create snapshot for
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Text label for snapshot.
|
||||
// Must be unique among this compute snapshots
|
||||
// Required: true
|
||||
Label string `url:"label" json:"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
|
||||
Label string `url:"label" json:"label" validate:"required"`
|
||||
}
|
||||
|
||||
// SnapshotCreate create compute snapshot
|
||||
func (c Compute) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/snapshotCreate"
|
||||
|
||||
@@ -2,38 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete snapshot
|
||||
type SnapshotDeleteRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Text label of snapshot to delete
|
||||
// Required: true
|
||||
Label string `url:"label" json:"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
|
||||
Label string `url:"label" json:"label" validate:"required"`
|
||||
}
|
||||
|
||||
// SnapshotDelete delete specified compute snapshot
|
||||
func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/snapshotDelete"
|
||||
|
||||
@@ -2,38 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for evict specified disk
|
||||
type SnapshotEvictDiskRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" valdiate:"required"`
|
||||
|
||||
// ID of the disk instance
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"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
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// 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()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/snapshotEvictDisk"
|
||||
|
||||
@@ -3,30 +3,25 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list snapshots
|
||||
type SnapshotListRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq SnapshotListRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// SnapshotList gets list compute snapshots
|
||||
func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapshots, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/snapshotList"
|
||||
|
||||
@@ -2,38 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for rollback
|
||||
type SnapshotRollbackRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Text label of snapshot to rollback
|
||||
// Required: true
|
||||
Label string `url:"label" json:"label"`
|
||||
}
|
||||
|
||||
func (crq SnapshotRollbackRequest) 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
|
||||
Label string `url:"label" json:"label" validate:"required"`
|
||||
}
|
||||
|
||||
// SnapshotRollback rollback specified compute snapshot
|
||||
func (c Compute) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/snapshotRollback"
|
||||
|
||||
@@ -3,15 +3,16 @@ package compute
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get compute snapshot real size on storage
|
||||
type SnapshotUsageRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Specify to show usage exact for this snapshot.
|
||||
// Leave empty for get usage for all compute snapshots
|
||||
@@ -19,21 +20,15 @@ type SnapshotUsageRequest struct {
|
||||
Label string `url:"label,omitempty" json:"label,omitempty"`
|
||||
}
|
||||
|
||||
func (crq SnapshotUsageRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SnapshotUsage Get compute snapshot real size on storage.
|
||||
// Always returns list of json objects, and first json object contains summary about all related
|
||||
// snapshots.
|
||||
func (c Compute) SnapshotUsage(ctx context.Context, req SnapshotUsageRequest) (ListSnapshotUsage, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/snapshotUsage"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for start compute
|
||||
type StartRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of CD-ROM live image to boot
|
||||
// Required: false
|
||||
@@ -26,19 +27,13 @@ type StartRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (crq StartRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field computeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start starts compute
|
||||
func (c Compute) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/start"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for stop compute
|
||||
type StopRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Force stop compute
|
||||
// Required: false
|
||||
@@ -22,19 +23,13 @@ type StopRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (crq StopRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field computeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop stops compute
|
||||
func (c Compute) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/stop"
|
||||
|
||||
@@ -2,45 +2,34 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add tag to compute
|
||||
type TagAddRequest struct {
|
||||
// IDs of the compute instances
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Tag key
|
||||
// Required: true
|
||||
Key string `url:"key" json:"key"`
|
||||
Key string `url:"key" json:"key" validate:"required"`
|
||||
|
||||
// Tag value
|
||||
// Required: true
|
||||
Value string `url:"value" json:"value"`
|
||||
}
|
||||
|
||||
func (crq TagAddRequest) validate() error {
|
||||
if len(crq.ComputeIDs) == 0 {
|
||||
return errors.New("validation-error: field ComputeIDs must be set")
|
||||
}
|
||||
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
|
||||
Value string `url:"value" json:"value" validate:"required"`
|
||||
}
|
||||
|
||||
// TagAdd add tag to compute tags dict
|
||||
func (c Compute) TagAdd(ctx context.Context, req TagAddRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/tagAdd"
|
||||
|
||||
@@ -2,38 +2,30 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove tag from compute
|
||||
type TagRemoveRequest struct {
|
||||
// IDs of the compute instances
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds"`
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
|
||||
// Tag key
|
||||
// Required: true
|
||||
Key string `url:"key" json:"key"`
|
||||
}
|
||||
|
||||
func (crq TagRemoveRequest) validate() error {
|
||||
if len(crq.ComputeIDs) == 0 {
|
||||
return errors.New("validation-error: field ComputeIDs must be set")
|
||||
}
|
||||
if crq.Key == "" {
|
||||
return errors.New("validation-error: field Key must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
Key string `url:"key" json:"key" validate:"required"`
|
||||
}
|
||||
|
||||
// TagRemove removes tag from compute tags dict
|
||||
func (c Compute) TagRemove(ctx context.Context, req TagRemoveRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/tagRemove"
|
||||
|
||||
@@ -2,31 +2,26 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for unpin from stack
|
||||
type UnpinFromStackRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (crq UnpinFromStackRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// UnpinFromStack unpin compute from current stack
|
||||
func (c Compute) UnpinFromStack(ctx context.Context, req UnpinFromStackRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/unpinFromStack"
|
||||
|
||||
@@ -2,16 +2,17 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update compute
|
||||
type UpdateRequest struct {
|
||||
// ID of the compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// New name
|
||||
// Required: false
|
||||
@@ -26,19 +27,13 @@ type UpdateRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (crq UpdateRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates some properties of the compute
|
||||
func (c Compute) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/update"
|
||||
|
||||
@@ -2,7 +2,6 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,11 +12,11 @@ import (
|
||||
type UserGrantRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Name of the user to add
|
||||
// Required: true
|
||||
Username string `url:"userName" json:"userName"`
|
||||
Username string `url:"userName" json:"userName" validate:"required"`
|
||||
|
||||
// Access type
|
||||
// Should be one of:
|
||||
@@ -25,32 +24,16 @@ type UserGrantRequest struct {
|
||||
// - 'RCX' for Write
|
||||
// - 'ARCXDU' for Admin
|
||||
// Required: true
|
||||
AccessType string `url:"accesstype" json:"accesstype"`
|
||||
}
|
||||
|
||||
func (crq UserGrantRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID must be set")
|
||||
}
|
||||
if crq.Username == "" {
|
||||
return errors.New("validation-error: field Username must be set")
|
||||
}
|
||||
if crq.AccessType == "" {
|
||||
return errors.New("validation-error: field AccessType must be set")
|
||||
}
|
||||
validator := validators.StringInSlice(crq.AccessType, []string{"R", "RCX", "ARCXDU"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"accessType"`
|
||||
}
|
||||
|
||||
// UserGrant grant user access to the compute
|
||||
func (c Compute) UserGrant(ctx context.Context, req UserGrantRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/userGrant"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user