v1.8.0
This commit is contained in:
@@ -15,11 +15,11 @@ type GetConsumptionRequest struct {
|
||||
|
||||
// Epoch represents the start time
|
||||
// Required: true
|
||||
Start uint64 `url:"start" json:"start" validate:"required"`
|
||||
Start float64 `url:"start" json:"start" validate:"required"`
|
||||
|
||||
// Epoch represents the end time
|
||||
// Required: true
|
||||
End uint64 `url:"end" json:"end" validate:"required"`
|
||||
End float64 `url:"end" json:"end" validate:"required"`
|
||||
}
|
||||
|
||||
// GetConsumption downloads the resources tracking files for an account within a given period
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of accounts
|
||||
@@ -24,6 +26,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -35,6 +41,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets a list of all accounts the user has access to a ListAccounts struct
|
||||
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
|
||||
|
||||
res, err := a.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -52,6 +59,11 @@ func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, erro
|
||||
|
||||
// ListRaw gets a list of all accounts the user has access to as an array of bytes
|
||||
func (a Account) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/list"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -46,6 +46,10 @@ type ListComputesRequest struct {
|
||||
// Required: false
|
||||
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -57,6 +61,7 @@ type ListComputesRequest struct {
|
||||
|
||||
// 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 := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get a list of deleted accounts
|
||||
@@ -27,10 +29,20 @@ type ListDeletedRequest struct {
|
||||
// Find by access control list
|
||||
// Required: false
|
||||
ACL string `url:"acl,omitempty" json:"acl,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
}
|
||||
|
||||
// ListDeleted gets list of all deleted accounts the user has access to
|
||||
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAccounts, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/listDeleted"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -30,6 +30,10 @@ type ListDisksRequest struct {
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -41,6 +45,7 @@ type ListDisksRequest struct {
|
||||
|
||||
// ListDisks gets list all currently unattached disks under specified account
|
||||
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (*ListDisks, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -49,6 +49,7 @@ type ListFLIPGroupsRequest struct {
|
||||
|
||||
// ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user
|
||||
func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (*ListFLIPGroups, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -41,10 +41,15 @@ type ListRGRequest struct {
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
}
|
||||
|
||||
// ListRG gets list of all resource groups under specified account, accessible by the user
|
||||
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (*ListRG, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -30,6 +30,10 @@ type ListTemplatesRequest struct {
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -41,6 +45,7 @@ type ListTemplatesRequest struct {
|
||||
|
||||
// ListTemplates gets list of templates which can be managed by this account
|
||||
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (*ListTemplates, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -30,6 +30,10 @@ type ListVINSRequest struct {
|
||||
// Required: false
|
||||
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -41,6 +45,7 @@ type ListVINSRequest struct {
|
||||
|
||||
// ListVINS gets list of all ViNSes under specified account, accessible by the user
|
||||
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -53,6 +53,9 @@ type ItemAccount struct {
|
||||
// Access Control List
|
||||
ACL []RecordACL `json:"acl"`
|
||||
|
||||
// Compute Features
|
||||
ComputeFeatures []string `json:"computeFeatures"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
@@ -176,6 +179,9 @@ type RecordAccount struct {
|
||||
// Company URL
|
||||
CompanyURL string `json:"companyurl"`
|
||||
|
||||
// Compute Features
|
||||
ComputeFeatures []string `json:"computeFeatures"`
|
||||
|
||||
// Computes
|
||||
Computes Computes `json:"computes"`
|
||||
|
||||
@@ -374,6 +380,12 @@ type ItemVINS struct {
|
||||
// External IP
|
||||
ExternalIP string `json:"externalIP"`
|
||||
|
||||
// Extnet ID
|
||||
ExtnetId uint64 `json:"extnetId"`
|
||||
|
||||
// Free IPs
|
||||
FreeIPs uint64 `json:"freeIPs"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
|
||||
@@ -74,6 +74,16 @@ type GroupAddRequest struct {
|
||||
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
func (r GroupAddRequest) GetRAM() map[string]uint64 {
|
||||
|
||||
res := make(map[string]uint64, 1)
|
||||
|
||||
res["RAM"] = r.RAM
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// GroupAdd creates new Compute Group within BasicService.
|
||||
// Compute Group is NOT started automatically,
|
||||
// so you need to explicitly start it
|
||||
|
||||
@@ -43,6 +43,16 @@ type GroupUpdateRequest struct {
|
||||
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
func (r GroupUpdateRequest) GetRAM() map[string]uint64 {
|
||||
|
||||
res := make(map[string]uint64, 1)
|
||||
|
||||
res["RAM"] = r.RAM
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// GroupUpdate updates existing Compute group within Basic Service and apply new settings to its computes as necessary
|
||||
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of BasicService instances
|
||||
@@ -40,6 +42,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -51,6 +57,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of BasicService instances associated with the specified Resource Group as a ListBasicServices struct
|
||||
func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices, error) {
|
||||
|
||||
res, err := b.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -68,6 +75,11 @@ func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices
|
||||
|
||||
// ListRaw gets list of BasicService instances associated with the specified Resource Group as an array of bytes
|
||||
func (b BService) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/list"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get list of deleted BasicService instances
|
||||
@@ -16,6 +18,10 @@ type ListDeletedRequest struct {
|
||||
// Required: false
|
||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -27,6 +33,11 @@ type ListDeletedRequest struct {
|
||||
|
||||
// ListDeleted gets list of deleted BasicService instances associated with the specified Resource Group
|
||||
func (b BService) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListBasicServices, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/listDeleted"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -39,6 +39,7 @@ type AffinityRuleAddRequest struct {
|
||||
|
||||
// Value that must match the key to be taken into account when analyzing this rule
|
||||
// Required: false
|
||||
// Not required on purpose: despite required tag on platform, empty string is allowed
|
||||
Value string `url:"value" json:"value"`
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ type AffinityRuleRemoveRequest struct {
|
||||
|
||||
// Value that must match the key to be taken into account when analyzing this rule
|
||||
// Required: false
|
||||
// Not required on purpose: despite required tag on platform, empty string is allowed
|
||||
Value string `url:"value" json:"value"`
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ type AntiAffinityRuleAddRequest struct {
|
||||
|
||||
// Value that must match the key to be taken into account when analyzing this rule
|
||||
// Required: false
|
||||
// Not required on purpose: despite required tag on platform, empty string is allowed
|
||||
Value string `url:"value" json:"value"`
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ type AntiAffinityRuleRemoveRequest struct {
|
||||
|
||||
// Value that must match the key to be taken into account when analyzing this rule
|
||||
// Required: false
|
||||
// Not required on purpose: despite required tag on platform, empty string is allowed
|
||||
Value string `url:"value" json:"value"`
|
||||
}
|
||||
|
||||
|
||||
42
pkg/cloudapi/compute/boot_disk_set.go
Normal file
42
pkg/cloudapi/compute/boot_disk_set.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// BootDiskSetRequest struct to set boot disk for compute
|
||||
type BootDiskSetRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the disk to set as boot
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// BootDiskSet sets boot disk for compute
|
||||
func (c Compute) BootDiskSet(ctx context.Context, req BootDiskSetRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/bootDiskSet"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
112
pkg/cloudapi/compute/create_template_from_blank.go
Normal file
112
pkg/cloudapi/compute/create_template_from_blank.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// CreateTemplateFromBlankRequest struct to create template from boot disk of current compute
|
||||
type CreateTemplateFromBlankRequest struct {
|
||||
// ID of the compute to create template from
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Name of the rescue disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Boot type of image BIOS or UEFI
|
||||
// Required: true
|
||||
BootType string `url:"boottype" json:"boottype" validate:"imageBootType"`
|
||||
|
||||
// Image type linux, windows or other
|
||||
// Required: true
|
||||
ImageType string `url:"imagetype" json:"imagetype" validate:"imageType"`
|
||||
|
||||
// Username for the image
|
||||
// Required: false
|
||||
Username string `url:"username,omitempty" json:"username,omitempty"`
|
||||
|
||||
// Password for the image
|
||||
// Required: false
|
||||
Password string `url:"password,omitempty" json:"password,omitempty"`
|
||||
|
||||
// Account ID to make the image exclusive
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// SEP ID
|
||||
// Required: false
|
||||
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||
|
||||
// Pool for image create
|
||||
// Required: false
|
||||
PoolName string `url:"poolName,omitempty" json:"poolName,omitempty"`
|
||||
|
||||
// Does this machine supports hot resize
|
||||
// Default: false
|
||||
// Required: false
|
||||
HotResize bool `url:"hotresize" json:"hotresize"`
|
||||
}
|
||||
|
||||
type wrapperCreateTemplateFromBlankRequest struct {
|
||||
CreateTemplateFromBlankRequest
|
||||
AsyncMode bool `url:"asyncMode"`
|
||||
}
|
||||
|
||||
// CreateTemplateFromBlank creates template from boot disk of current compute in sync mode.
|
||||
// It returns id of created compute and error.
|
||||
func (c Compute) CreateTemplateFromBlank(ctx context.Context, req CreateTemplateFromBlankRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateTemplateFromBlankRequest{
|
||||
CreateTemplateFromBlankRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/createTemplateFromBlank"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CreateTemplateFromBlankAsync creates template from boot disk of current compute in async mode.
|
||||
// It returns guid of task and error.
|
||||
func (c Compute) CreateTemplateFromBlankAsync(ctx context.Context, req CreateTemplateFromBlankRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateTemplateFromBlankRequest{
|
||||
CreateTemplateFromBlankRequest: req,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/createTemplateFromBlank"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
53
pkg/cloudapi/compute/disk_migrate.go
Normal file
53
pkg/cloudapi/compute/disk_migrate.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// DiskMigrateRequest struct to migrate compute's disk to target disk
|
||||
type DiskMigrateRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID source disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// ID target disk
|
||||
// Required: true
|
||||
TargetDiskID uint64 `url:"targetDiskId" json:"targetDiskId" validate:"required"`
|
||||
|
||||
// Migration mode. 1 - Data migration and domain update were already completed by third-party software.
|
||||
// Use this if target disk already connected to compute and you only need to save changes for next reboot.
|
||||
// Required: true
|
||||
Mode int64 `url:"mode" json:"mode" validate:"required"`
|
||||
}
|
||||
|
||||
// DiskMigrate - migrate compute's disk to target disk. Source disk will be detached, target disk will be attached to the same PCI slot.
|
||||
// (WARNING) Current realisation is limited. No actual data migration will be performed.
|
||||
// Use this API if target disk already connected to compute and you only need to save changes for next reboot (mode: 1).
|
||||
func (c Compute) DiskMigrate(ctx context.Context, req DiskMigrateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/diskMigrate"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
46
pkg/cloudapi/compute/disk_switch_to_replication.go
Normal file
46
pkg/cloudapi/compute/disk_switch_to_replication.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// DiskSwitchToReplicationRequest struct to switch disk to it's replication
|
||||
type DiskSwitchToReplicationRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// ID of the disk to switch
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Delete replication relationship
|
||||
// Required: false
|
||||
StopReplication bool `url:"stopReplication" json:"stopReplication"`
|
||||
}
|
||||
|
||||
// DiskSwitchToReplication switches disk to it's replication
|
||||
func (c Compute) DiskSwitchToReplication(ctx context.Context, req DiskSwitchToReplicationRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/diskSwitchToReplication"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of available computes
|
||||
@@ -52,6 +54,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -64,6 +70,7 @@ type ListRequest struct {
|
||||
// List gets list of the available computes.
|
||||
// Filtering based on status is possible
|
||||
func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, error) {
|
||||
|
||||
res, err := c.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -81,6 +88,11 @@ func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, erro
|
||||
|
||||
// ListRaw gets list of the available computes.
|
||||
func (c Compute) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/list"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get deleted computes list
|
||||
@@ -44,6 +46,10 @@ type ListDeletedRequest struct {
|
||||
// Required: false
|
||||
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -55,6 +61,11 @@ type ListDeletedRequest struct {
|
||||
|
||||
// ListDeleted gets list all deleted computes
|
||||
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListComputes, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/listDeleted"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -30,6 +30,10 @@ type ListPCIDeviceRequest struct {
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -41,6 +45,7 @@ type ListPCIDeviceRequest struct {
|
||||
|
||||
// ListPCIDevice gets list PCI device
|
||||
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (*ListPCIDevices, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -26,6 +26,10 @@ type ListVGPURequest struct {
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -41,6 +45,7 @@ type ListVGPURequest struct {
|
||||
|
||||
// ListVGPU gets list vGPU
|
||||
func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) (*ListVGPUs, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -305,6 +305,9 @@ type RecordCompute struct {
|
||||
// Boot disk size
|
||||
BootDiskSize uint64 `json:"bootdiskSize"`
|
||||
|
||||
// cd Image Id
|
||||
CdImageId uint64 `json:"cdImageId"`
|
||||
|
||||
// Clone reference
|
||||
CloneReference uint64 `json:"cloneReference"`
|
||||
|
||||
@@ -314,6 +317,9 @@ type RecordCompute struct {
|
||||
// Compute CI ID
|
||||
ComputeCIID uint64 `json:"computeciId"`
|
||||
|
||||
// CPU Pin
|
||||
CPUPin bool `json:"cpupin"`
|
||||
|
||||
// Number of cores
|
||||
CPU uint64 `json:"cpus"`
|
||||
|
||||
@@ -350,6 +356,9 @@ type RecordCompute struct {
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// HPBacked
|
||||
HPBacked bool `json:"hpBacked"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
@@ -383,6 +392,12 @@ type RecordCompute struct {
|
||||
// NeedReboot
|
||||
NeedReboot bool `json:"needReboot"`
|
||||
|
||||
// Numa Affinity
|
||||
NumaAffinity string `json:"numaAffinity"`
|
||||
|
||||
//NumaNodeId
|
||||
NumaNodeId int64 `json:"numaNodeId"`
|
||||
|
||||
// Natable VINS ID
|
||||
NatableVINSID uint64 `json:"natableVinsId"`
|
||||
|
||||
@@ -539,6 +554,9 @@ type ItemVNFInterface struct {
|
||||
// Network type
|
||||
NetType string `json:"netType"`
|
||||
|
||||
// NodeID
|
||||
NodeID int64 `json:"nodeId"`
|
||||
|
||||
// PCI slot
|
||||
PCISlot int64 `json:"pciSlot"`
|
||||
|
||||
@@ -654,6 +672,9 @@ type ItemComputeDisk struct {
|
||||
// Reality device number
|
||||
RealityDeviceNumber uint64 `json:"realityDeviceNumber"`
|
||||
|
||||
// Replication
|
||||
Replication interface{} `json:"replication"`
|
||||
|
||||
// Resource ID
|
||||
ResID string `json:"resId"`
|
||||
|
||||
@@ -761,6 +782,7 @@ type IOTune struct {
|
||||
type ItemCompute struct {
|
||||
// Access Control List
|
||||
ACL ListACL `json:"acl"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
@@ -788,6 +810,9 @@ type ItemCompute struct {
|
||||
// Boot disk size
|
||||
BootDiskSize uint64 `json:"bootdiskSize"`
|
||||
|
||||
// cd Image Id
|
||||
CdImageId uint64 `json:"cdImageId"`
|
||||
|
||||
// Clone reference
|
||||
CloneReference uint64 `json:"cloneReference"`
|
||||
|
||||
@@ -797,6 +822,9 @@ type ItemCompute struct {
|
||||
// Compute CI ID
|
||||
ComputeCIID uint64 `json:"computeciId"`
|
||||
|
||||
// CPU Pin
|
||||
CPUPin bool `json:"cpupin"`
|
||||
|
||||
// Number of cores
|
||||
CPU uint64 `json:"cpus"`
|
||||
|
||||
@@ -833,6 +861,9 @@ type ItemCompute struct {
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// HPBacked
|
||||
HPBacked bool `json:"hpBacked"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
@@ -863,6 +894,12 @@ type ItemCompute struct {
|
||||
// NeedReboot
|
||||
NeedReboot bool `json:"needReboot"`
|
||||
|
||||
// Numa Affinity
|
||||
NumaAffinity string `json:"numaAffinity"`
|
||||
|
||||
//NumaNodeId
|
||||
NumaNodeId int64 `json:"numaNodeId"`
|
||||
|
||||
// Pinned or not
|
||||
Pinned bool `json:"pinned"`
|
||||
|
||||
@@ -948,17 +985,106 @@ type ListComputes struct {
|
||||
// List VGPUs
|
||||
type ListVGPUs struct {
|
||||
// Data
|
||||
Data []interface{} `json:"data"`
|
||||
Data []ItemVGPU `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about vgpu device
|
||||
type ItemVGPU struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Created Time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted Time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// GID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Last Claimed By
|
||||
LastClaimedBy uint64 `json:"lastClaimedBy"`
|
||||
|
||||
// Last Update Time
|
||||
LastUpdateTime uint64 `json:"lastUpdateTime"`
|
||||
|
||||
// Mode
|
||||
Mode string `json:"mode"`
|
||||
|
||||
// PCI Slot
|
||||
PCISlot uint64 `json:"pciSlot"`
|
||||
|
||||
// PGPUID
|
||||
PGPUID uint64 `json:"pgpuid"`
|
||||
|
||||
// Profile ID
|
||||
ProfileID uint64 `json:"profileId"`
|
||||
|
||||
// RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// Reference ID
|
||||
ReferenceID string `json:"referenceId"`
|
||||
|
||||
// RG ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// VM ID
|
||||
VMID uint64 `json:"vmid"`
|
||||
}
|
||||
|
||||
// Main information about PCI device
|
||||
type ItemPCIDevice struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// HwPath
|
||||
HwPath string `json:"hwPath"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Stack ID
|
||||
StackID uint64 `json:"stackId"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// System name
|
||||
SystemName string `json:"systemName"`
|
||||
}
|
||||
|
||||
// List PCI devices
|
||||
type ListPCIDevices struct {
|
||||
// Data
|
||||
Data []interface{} `json:"data"`
|
||||
|
||||
Data []ItemPCIDevice `json:"data"`
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ type PFWAddRequest struct {
|
||||
PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
||||
|
||||
// Internal base port number
|
||||
// Required: true
|
||||
LocalBasePort uint64 `url:"localBasePort" json:"localBasePort" validate:"required"`
|
||||
// Required: false
|
||||
LocalBasePort uint64 `url:"localBasePort,omitempty" json:"localBasePort,omitempty"`
|
||||
|
||||
// Network protocol
|
||||
// either "tcp" or "udp"
|
||||
|
||||
@@ -29,6 +29,16 @@ type ResizeRequest struct {
|
||||
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
func (r ResizeRequest) GetRAM() map[string]uint64 {
|
||||
|
||||
res := make(map[string]uint64, 1)
|
||||
|
||||
res["RAM"] = r.RAM
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// Resize resizes compute instance
|
||||
func (c Compute) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
|
||||
127
pkg/cloudapi/disks/from_platform_disk.go
Normal file
127
pkg/cloudapi/disks/from_platform_disk.go
Normal file
@@ -0,0 +1,127 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// FromPlatformDiskRequest struct to create template from platform disk
|
||||
type FromPlatformDiskRequest struct {
|
||||
// ID of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Name of the rescue disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Boot type of image BIOS or UEFI
|
||||
// Required: true
|
||||
BootType string `url:"boottype" json:"boottype" validate:"imageBootType"`
|
||||
|
||||
// Image type linux, windows or other
|
||||
// Required: true
|
||||
ImageType string `url:"imagetype" json:"imagetype" validate:"imageType"`
|
||||
|
||||
// Binary architecture of this image
|
||||
// Should be:
|
||||
// - X86_64
|
||||
// - PPC64_LE
|
||||
// Required: true
|
||||
Architecture string `url:"architecture" json:"architecture" validate:"imageArchitecture"`
|
||||
|
||||
// Username for the image
|
||||
// Required: false
|
||||
Username string `url:"username,omitempty" json:"username,omitempty"`
|
||||
|
||||
// Password for the image
|
||||
// Required: false
|
||||
Password string `url:"password,omitempty" json:"password,omitempty"`
|
||||
|
||||
// Account ID to make the image exclusive
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// SEP ID
|
||||
// Required: false
|
||||
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||
|
||||
// Pool for image create
|
||||
// Required: false
|
||||
PoolName string `url:"poolName,omitempty" json:"poolName,omitempty"`
|
||||
|
||||
// List of types of compute suitable for image
|
||||
// Example: [ "KVM_X86" ]
|
||||
// Required: false
|
||||
Drivers []string `url:"drivers" json:"drivers" validate:"min=1,max=2,imageDrivers"`
|
||||
|
||||
// Does this machine supports hot resize
|
||||
// Required: false
|
||||
HotResize bool `url:"hotresize" json:"hotresize"`
|
||||
|
||||
// Bootable image
|
||||
// Required: true
|
||||
Bootable bool `url:"bootable" json:"bootable"`
|
||||
}
|
||||
|
||||
type wrapperFromPlatformDiskRequest struct {
|
||||
FromPlatformDiskRequest
|
||||
AsyncMode bool `url:"asyncMode"`
|
||||
}
|
||||
|
||||
// FromPlatformDisk creates template from platform disk in sync mode.
|
||||
// It returns id of created disk and error.
|
||||
func (d Disks) FromPlatformDisk(ctx context.Context, req FromPlatformDiskRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/fromPlatformDisk"
|
||||
|
||||
reqWrapped := wrapperFromPlatformDiskRequest{
|
||||
FromPlatformDiskRequest: req,
|
||||
AsyncMode: false,
|
||||
}
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FromPlatformDiskAsync creates template from platform disk in async mode.
|
||||
// It returns guid of task and error.
|
||||
func (d Disks) FromPlatformDiskAsync(ctx context.Context, req FromPlatformDiskRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/fromPlatformDisk"
|
||||
|
||||
reqWrapped := wrapperFromPlatformDiskRequest{
|
||||
FromPlatformDiskRequest: req,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of disks
|
||||
@@ -48,6 +50,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -59,6 +65,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of the created disks belonging to an account as a ListDisks struct
|
||||
func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) {
|
||||
|
||||
res, err := d.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -76,6 +83,11 @@ func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) {
|
||||
|
||||
// ListRaw gets list of the created disks belonging to an account as an array of bytes
|
||||
func (d Disks) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/list"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get list of deleted disks
|
||||
@@ -36,6 +38,10 @@ type ListDeletedRequest struct {
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -47,6 +53,11 @@ type ListDeletedRequest struct {
|
||||
|
||||
// ListDeleted gets list the deleted disks belonging to an account
|
||||
func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListDisks, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/listDeleted"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,13 +4,19 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListTypesRequest struct to get list types of disks
|
||||
type ListTypesRequest struct {
|
||||
// Show detailed disk types by seps
|
||||
// Required: true
|
||||
Detailed bool `url:"detailed" json:"detailed" validate:"required"`
|
||||
Detailed bool `url:"detailed" json:"detailed"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
@@ -23,6 +29,11 @@ type ListTypesRequest struct {
|
||||
|
||||
// ListTypes gets list defined disk types
|
||||
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) (*ListTypes, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/listTypes"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListUnattachedRequest struct to get list of unattached disk
|
||||
@@ -40,6 +42,10 @@ type ListUnattachedRequest struct {
|
||||
// Required: false
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -51,6 +57,11 @@ type ListUnattachedRequest struct {
|
||||
|
||||
// ListUnattached gets list of unattached disks
|
||||
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (*ListDisksUnattached, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/listUnattached"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -74,6 +74,9 @@ type ItemDisk struct {
|
||||
// Purge time
|
||||
PurgeTime uint64 `json:"purgeTime"`
|
||||
|
||||
// Replication
|
||||
Replication interface{} `json:"replication"`
|
||||
|
||||
// Resource ID
|
||||
ResID string `json:"resId"`
|
||||
|
||||
@@ -403,6 +406,9 @@ type RecordDisk struct {
|
||||
// Purge time
|
||||
PurgeTime uint64 `json:"purgeTime"`
|
||||
|
||||
// Replication
|
||||
Replication interface{} `json:"replication"`
|
||||
|
||||
// Resource ID
|
||||
ResID string `json:"resId"`
|
||||
|
||||
|
||||
52
pkg/cloudapi/disks/replicate.go
Normal file
52
pkg/cloudapi/disks/replicate.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ReplicateRequest struct to create an empty disk in chosen SEP and pool combination.
|
||||
type ReplicateRequest struct {
|
||||
// Id of the disk to replicate. This disk will become master in replication
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Name of replica disk to create
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// ID of SEP to create slave disk
|
||||
// Required: true
|
||||
SepID uint64 `url:"sepId" json:"sepId" validate:"required"`
|
||||
|
||||
// Pool name to create slave disk in
|
||||
// Required: true
|
||||
PoolName string `url:"poolName" json:"poolName" validate:"required"`
|
||||
}
|
||||
|
||||
// Create an empty disk in chosen SEP and pool combination.
|
||||
// Starts replication between chosen disk and newly created disk
|
||||
// Note: only TATLIN type SEP are supported for replications between
|
||||
func (d Disks) Replicate(ctx context.Context, req ReplicateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/replicate"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudapi/disks/replication_resume.go
Normal file
38
pkg/cloudapi/disks/replication_resume.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ReplicationResume struct to resume suspended replication
|
||||
type ReplicationResumeRequest struct {
|
||||
// Id of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// ReplicationResume resume suspended replication
|
||||
func (d Disks) ReplicationResume(ctx context.Context, req ReplicationResumeRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/replicationResume"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudapi/disks/replication_reverse.go
Normal file
38
pkg/cloudapi/disks/replication_reverse.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ReplicationReverseRequest struct to change role between disks replications
|
||||
type ReplicationReverseRequest struct {
|
||||
// Id of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// ReplicationReverse change role between disks replications
|
||||
func (d Disks) ReplicationReverse(ctx context.Context, req ReplicationReverseRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/replicationReverse"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
43
pkg/cloudapi/disks/replication_start.go
Normal file
43
pkg/cloudapi/disks/replication_start.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ReplicationStartRequest struct to starts replication between two chosen disks
|
||||
type ReplicationStartRequest struct {
|
||||
// Id of the disk to replicate. Primary disk in replication
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// ID of target disk. Secondary disk in replication
|
||||
// Required: true
|
||||
TargetDiskID uint64 `url:"targetDiskId" json:"targetDiskId" validate:"required"`
|
||||
}
|
||||
|
||||
// ReplicationStart starts replication between two chosen disks. It's required for both disks to have same size to avoid replication conflicts
|
||||
// Note: Source disk's SEP and target SEP supported only of TATLIN type.
|
||||
func (d Disks) ReplicationStart(ctx context.Context, req ReplicationStartRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/replicationStart"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
37
pkg/cloudapi/disks/replication_status.go
Normal file
37
pkg/cloudapi/disks/replication_status.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ReplicationStatusRequest struct to get replication status
|
||||
type ReplicationStatusRequest struct {
|
||||
// Id of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// ReplicationStatus get replication status
|
||||
func (d Disks) ReplicationStatus(ctx context.Context, req ReplicationStatusRequest) (interface{}, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/replicationStatus"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// result, err := strconv.ParseBool(string(res))
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
return res, nil
|
||||
}
|
||||
38
pkg/cloudapi/disks/replication_stop.go
Normal file
38
pkg/cloudapi/disks/replication_stop.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ReplicationStopRequest struct to remove replication between disks completely
|
||||
type ReplicationStopRequest struct {
|
||||
// Id of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// ReplicationStop remove replication between disks completely
|
||||
func (d Disks) ReplicationStop(ctx context.Context, req ReplicationStopRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/replicationStop"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudapi/disks/replication_suspend.go
Normal file
38
pkg/cloudapi/disks/replication_suspend.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ReplicationSuspendRequest struct to pause replication with possibility to resume from pause moment
|
||||
type ReplicationSuspendRequest struct {
|
||||
// Id of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// ReplicationSuspend pause replication with possibility to resume from pause moment
|
||||
func (d Disks) ReplicationSuspend(ctx context.Context, req ReplicationSuspendRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/replicationSuspend"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -18,6 +18,14 @@ type SearchRequest struct {
|
||||
// If false, then disks having one of the statuses are not listed
|
||||
// Required: false
|
||||
ShowAll bool `url:"show_all,omitempty" json:"show_all,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// Search searches disks
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of external network
|
||||
@@ -36,6 +38,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -47,6 +53,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of all available external networks as a ListExtNets struct
|
||||
func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNets, error) {
|
||||
|
||||
res, err := e.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -64,6 +71,11 @@ func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNets, error)
|
||||
|
||||
// ListRaw gets list of all available external networks as an array of bytes
|
||||
func (e ExtNet) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/extnet/list"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -22,6 +22,10 @@ type ListComputesRequest struct {
|
||||
// Required: false
|
||||
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -33,6 +37,7 @@ type ListComputesRequest struct {
|
||||
|
||||
// ListComputes gets computes from account with extnets
|
||||
func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (*ListExtNetComputes, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of FLIPGroup available to the current user
|
||||
@@ -28,6 +30,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"`
|
||||
|
||||
// Find by accountId
|
||||
// Required: false
|
||||
AccountId uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by resource group ID
|
||||
// Required: false
|
||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||
@@ -43,10 +49,23 @@ type ListRequest struct {
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Find by connId
|
||||
// Required: false
|
||||
ConnId uint64 `url:"connId,omitempty" json:"connId,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of FLIPGroup managed cluster instances available to the current user as a ListFLIPGroups struct
|
||||
func (f FLIPGroup) List(ctx context.Context, req ListRequest) (*ListFLIPGroups, error) {
|
||||
|
||||
res, err := f.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -64,6 +83,11 @@ func (f FLIPGroup) List(ctx context.Context, req ListRequest) (*ListFLIPGroups,
|
||||
|
||||
// ListRaw gets list of FLIPGroup managed cluster instances available to the current user as an array of bytes
|
||||
func (f FLIPGroup) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/flipgroup/list"
|
||||
|
||||
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -18,10 +18,6 @@ type CreateRequest struct {
|
||||
// Required: true
|
||||
URL string `url:"url" json:"url" validate:"required,url"`
|
||||
|
||||
// Grid (platform) ID where this template should be create in
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// Boot type of image bios or UEFI
|
||||
// Required: true
|
||||
BootType string `url:"boottype" json:"boottype" validate:"required,imageBootType"`
|
||||
@@ -34,6 +30,17 @@ type CreateRequest struct {
|
||||
// Required: true
|
||||
ImageType string `url:"imagetype" json:"imagetype" validate:"required,imageType"`
|
||||
|
||||
// Account ID to make the image exclusive
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming
|
||||
// Should be:
|
||||
// - eth
|
||||
// - ens (default value)
|
||||
// Required: false
|
||||
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
|
||||
|
||||
// Does this machine supports hot resize
|
||||
// Required: false
|
||||
HotResize bool `url:"hotresize,omitempty" json:"hotresize,omitempty"`
|
||||
@@ -46,10 +53,6 @@ type CreateRequest struct {
|
||||
// Required: false
|
||||
Password string `url:"password,omitempty" json:"password,omitempty"`
|
||||
|
||||
// Account ID to make the image exclusive
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Username for upload binary media
|
||||
// Required: false
|
||||
UsernameDL string `url:"usernameDL,omitempty" json:"usernameDL,omitempty"`
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of available images
|
||||
@@ -56,6 +58,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
Bootable bool `url:"bootable,omitempty" json:"bootable,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -67,6 +73,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of available images as a ListImages struct, optionally filtering by account ID
|
||||
func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
|
||||
|
||||
res, err := i.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -84,6 +91,11 @@ func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
|
||||
|
||||
// ListRaw gets list of available images as an array of bytes
|
||||
func (i Image) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/image/list"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -35,6 +35,9 @@ type ItemImage struct {
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// NetworkInterfaceNaming
|
||||
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
|
||||
|
||||
// Pool
|
||||
Pool string `json:"pool"`
|
||||
|
||||
@@ -104,6 +107,9 @@ type RecordImage struct {
|
||||
// Bootable
|
||||
Bootable bool `json:"bootable"`
|
||||
|
||||
// CdPresentedTo
|
||||
CdPresentedTo interface{} `json:"cdPresentedTo"`
|
||||
|
||||
// ComputeCI ID
|
||||
ComputeCIID uint64 `json:"computeciId"`
|
||||
|
||||
@@ -146,6 +152,9 @@ type RecordImage struct {
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// NetworkInterfaceNaming
|
||||
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
|
||||
|
||||
// Password
|
||||
Password string `json:"password"`
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of information about images
|
||||
@@ -36,6 +38,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
IncludeDisabled bool `url:"includeDisabled,omitempty" json:"includeDisabled,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -47,6 +53,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of all k8ci catalog items available to the current user as a ListK8CI struct
|
||||
func (k K8CI) List(ctx context.Context, req ListRequest) (*ListK8CI, error) {
|
||||
|
||||
res, err := k.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -64,6 +71,11 @@ func (k K8CI) List(ctx context.Context, req ListRequest) (*ListK8CI, error) {
|
||||
|
||||
// ListRaw gets list of all k8ci catalog items available to the current user as an array of bytes
|
||||
func (k K8CI) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8ci/list"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,9 +4,11 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get list information about deleted images
|
||||
// ListDeletedRequest struct to get list information about deleted k8ci items
|
||||
type ListDeletedRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
@@ -28,6 +30,10 @@ type ListDeletedRequest struct {
|
||||
// Required: false
|
||||
NetworkPlugins string `url:"netPlugins,omitempty" json:"netPlugins,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -39,6 +45,11 @@ type ListDeletedRequest struct {
|
||||
|
||||
// ListDeleted gets list all deleted k8ci catalog items available to the current user
|
||||
func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8CI, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8ci/listDeleted"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// type Params []string
|
||||
|
||||
// CreateRequest struct to create kubernetes cluster
|
||||
type CreateRequest struct {
|
||||
// Name of Kubernetes cluster
|
||||
@@ -74,7 +72,7 @@ type CreateRequest struct {
|
||||
|
||||
// Master node RAM volume in MB
|
||||
// Required: false
|
||||
MasterRAM uint `url:"masterRam,omitempty" json:"masterRam,omitempty"`
|
||||
MasterRAM uint64 `url:"masterRam,omitempty" json:"masterRam,omitempty"`
|
||||
|
||||
// Master node boot disk size in GB If 0 is specified, size is defined by the OS image size
|
||||
// Required: false
|
||||
@@ -90,7 +88,7 @@ type CreateRequest struct {
|
||||
|
||||
// Worker node RAM volume in MB
|
||||
// Required: false
|
||||
WorkerRAM uint `url:"workerRam,omitempty" json:"workerRam,omitempty"`
|
||||
WorkerRAM uint64 `url:"workerRam,omitempty" json:"workerRam,omitempty"`
|
||||
|
||||
// Worker node boot disk size in GB. If 0 is specified, size is defined by the OS image size
|
||||
// Required: false
|
||||
@@ -111,7 +109,7 @@ type CreateRequest struct {
|
||||
|
||||
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||
// Required: false
|
||||
LbSysctlParams string `url:"lbSysctlParams,omitempty" json:"lbSysctlParams,omitempty"`
|
||||
LbSysctlParams []map[string]interface{} `url:"lbSysctlParams,omitempty" json:"lbSysctlParams,omitempty"`
|
||||
|
||||
// Use Highly Available schema for LB deploy
|
||||
// Required: false
|
||||
@@ -166,10 +164,16 @@ type CreateRequest struct {
|
||||
OidcCertificate string `url:"oidcCertificate,omitempty" json:"oidcCertificate,omitempty"`
|
||||
}
|
||||
|
||||
// type wrapperCreateRequest struct {
|
||||
// CreateRequest
|
||||
// Params []string `url:"lbSysctlParams,omitempty"`
|
||||
// }
|
||||
// GetRAM returns RAM field values
|
||||
func (r CreateRequest) GetRAM() map[string]uint64 {
|
||||
|
||||
res := make(map[string]uint64, 2)
|
||||
|
||||
res["MasterRAM"] = r.MasterRAM
|
||||
res["WorkerRAM"] = r.WorkerRAM
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// Create creates a new Kubernetes cluster in the specified Resource Group
|
||||
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||
@@ -178,28 +182,6 @@ func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
// var params []string
|
||||
|
||||
// if len(req.LbSysctlParams) != 0 {
|
||||
// params = make([]string, 0, len(req.LbSysctlParams))
|
||||
|
||||
// for r := range req.LbSysctlParams {
|
||||
// b, err := json.Marshal(req.LbSysctlParams[r])
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
|
||||
// params = append(params, string(b))
|
||||
// }
|
||||
// } else {
|
||||
// params = []string{"[]"}
|
||||
// }
|
||||
|
||||
// reqWrapped := wrapperCreateRequest{
|
||||
// CreateRequest: req,
|
||||
// Params: params,
|
||||
// }
|
||||
|
||||
url := "/cloudapi/k8s/create"
|
||||
|
||||
res, err := k8s.client.DecortApiCallMP(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list information K8S
|
||||
@@ -44,6 +46,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -55,6 +61,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of all kubernetes clusters the user has access to as a ListK8SClusters
|
||||
func (k8s K8S) List(ctx context.Context, req ListRequest) (*ListK8SClusters, error) {
|
||||
|
||||
res, err := k8s.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -72,6 +79,11 @@ func (k8s K8S) List(ctx context.Context, req ListRequest) (*ListK8SClusters, err
|
||||
|
||||
// ListRaw gets list of all kubernetes clusters the user has access to as an array of bytes
|
||||
func (k8s K8S) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/list"
|
||||
|
||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get list of deleted kubernetes cluster
|
||||
@@ -36,6 +38,10 @@ type ListDeletedRequest struct {
|
||||
// Required: false
|
||||
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -47,6 +53,11 @@ type ListDeletedRequest struct {
|
||||
|
||||
// ListDeleted gets all deleted kubernetes clusters the user has access to
|
||||
func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8SClusters, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/listDeleted"
|
||||
|
||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -62,6 +62,16 @@ type WorkersGroupAddRequest struct {
|
||||
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
func (r WorkersGroupAddRequest) GetRAM() map[string]uint64 {
|
||||
|
||||
res := make(map[string]uint64, 1)
|
||||
|
||||
res["WorkerRAM"] = r.WorkerRAM
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// WorkersGroupAdd adds workers group to Kubernetes cluster
|
||||
func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
|
||||
@@ -26,6 +26,35 @@ type Interface struct {
|
||||
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
|
||||
}
|
||||
|
||||
// DataDisk detailed struct for DataDisks field in CreateRequest and CreateBlankRequest
|
||||
type DataDisk struct {
|
||||
// Name for disk
|
||||
// Required: true
|
||||
DiskName string `url:"diskName" json:"diskName" validate:"required"`
|
||||
|
||||
// Disk size in GB
|
||||
// Required: true
|
||||
Size uint64 `url:"size" json:"size" validate:"required"`
|
||||
|
||||
// Storage endpoint provider ID
|
||||
// By default the same with boot disk
|
||||
// Required: false
|
||||
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||
|
||||
// Pool name
|
||||
// By default will be chosen automatically
|
||||
// Required: false
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Optional description
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
|
||||
// Specify image id for create disk from template
|
||||
// Required: false
|
||||
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
|
||||
}
|
||||
|
||||
// CreateRequest struct to create KVM PowerPC VM
|
||||
type CreateRequest struct {
|
||||
// ID of the resource group, which will own this VM
|
||||
@@ -63,6 +92,12 @@ type CreateRequest struct {
|
||||
// Required: false
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Slice of structs with data disk description. Each disk has parameters: required - diskName, size; optional - sepId, pool, desc and imageId.
|
||||
// If not specified, compute will be created without disks.
|
||||
// To create compute without disks, pass initialized empty slice .
|
||||
// Required: false
|
||||
DataDisks []DataDisk `url:"-" json:"dataDisks,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// If not specified, compute will be created with default interface from RG.
|
||||
// To create compute without interfaces, pass initialized empty slice .
|
||||
@@ -90,9 +125,20 @@ type CreateRequest struct {
|
||||
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
func (r CreateRequest) GetRAM() map[string]uint64 {
|
||||
|
||||
res := make(map[string]uint64, 1)
|
||||
|
||||
res["RAM"] = r.RAM
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
type wrapperCreateRequest struct {
|
||||
CreateRequest
|
||||
Interfaces []string `url:"interfaces,omitempty"`
|
||||
DataDisks []string `url:"dataDisks,omitempty"`
|
||||
}
|
||||
|
||||
// Create creates KVM PowerPC VM based on specified OS image
|
||||
@@ -119,9 +165,25 @@ func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
var dataDisks []string
|
||||
|
||||
if req.DataDisks != nil && len(req.DataDisks) != 0 {
|
||||
dataDisks = make([]string, 0, len(req.DataDisks))
|
||||
|
||||
for i := range req.DataDisks {
|
||||
b, err := json.Marshal(req.DataDisks[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
dataDisks = append(dataDisks, string(b))
|
||||
}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateRequest{
|
||||
CreateRequest: req,
|
||||
Interfaces: interfaces,
|
||||
DataDisks: dataDisks,
|
||||
}
|
||||
|
||||
url := "/cloudapi/kvmppc/create"
|
||||
|
||||
@@ -41,6 +41,12 @@ type CreateBlankRequest struct {
|
||||
// Required: true
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
|
||||
// Slice of structs with data disk description. Each disk has parameters: required - diskName, size; optional - sepId, pool, desc and imageId.
|
||||
// If not specified, compute will be created without disks.
|
||||
// To create compute without disks, pass initialized empty slice .
|
||||
// Required: false
|
||||
DataDisks []DataDisk `url:"-" json:"dataDisks,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// If not specified, compute will be created with default interface from RG.
|
||||
// To create compute without interfaces, pass initialized empty slice .
|
||||
@@ -52,9 +58,20 @@ type CreateBlankRequest struct {
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
func (r CreateBlankRequest) GetRAM() map[string]uint64 {
|
||||
|
||||
res := make(map[string]uint64, 1)
|
||||
|
||||
res["RAM"] = r.RAM
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
type wrapperCreateBlankRequest struct {
|
||||
CreateBlankRequest
|
||||
Interfaces []string `url:"interfaces,omitempty"`
|
||||
DataDisks []string `url:"dataDisks,omitempty"`
|
||||
}
|
||||
|
||||
// CreateBlank creates KVM PowerPC VM from scratch
|
||||
@@ -81,9 +98,25 @@ func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
var dataDisks []string
|
||||
|
||||
if req.DataDisks != nil && len(req.DataDisks) != 0 {
|
||||
dataDisks = make([]string, 0, len(req.DataDisks))
|
||||
|
||||
for i := range req.DataDisks {
|
||||
b, err := json.Marshal(req.DataDisks[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
dataDisks = append(dataDisks, string(b))
|
||||
}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateBlankRequest{
|
||||
CreateBlankRequest: req,
|
||||
Interfaces: interfaces,
|
||||
DataDisks: dataDisks,
|
||||
}
|
||||
|
||||
url := "/cloudapi/kvmppc/createBlank"
|
||||
|
||||
@@ -26,6 +26,35 @@ type Interface struct {
|
||||
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
|
||||
}
|
||||
|
||||
// DataDisk detailed struct for DataDisks field in CreateRequest and CreateBlankRequest
|
||||
type DataDisk struct {
|
||||
// Name for disk
|
||||
// Required: true
|
||||
DiskName string `url:"diskName" json:"diskName" validate:"required"`
|
||||
|
||||
// Disk size in GB
|
||||
// Required: true
|
||||
Size uint64 `url:"size" json:"size" validate:"required"`
|
||||
|
||||
// Storage endpoint provider ID
|
||||
// By default the same with boot disk
|
||||
// Required: false
|
||||
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||
|
||||
// Pool name
|
||||
// By default will be chosen automatically
|
||||
// Required: false
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Optional description
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
|
||||
// Specify image id for create disk from template
|
||||
// Required: false
|
||||
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
|
||||
}
|
||||
|
||||
// CreateRequest struct to create KVM x86 VM
|
||||
type CreateRequest struct {
|
||||
// ID of the resource group, which will own this VM
|
||||
@@ -63,6 +92,12 @@ type CreateRequest struct {
|
||||
// Required: false
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Slice of structs with data disk description. Each disk has parameters: required - diskName, size; optional - sepId, pool, desc and imageId.
|
||||
// If not specified, compute will be created without disks.
|
||||
// To create compute without disks, pass initialized empty slice .
|
||||
// Required: false
|
||||
DataDisks []DataDisk `url:"-" json:"dataDisks,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// If not specified, compute will be created with default interface from RG.
|
||||
// To create compute without interfaces, pass initialized empty slice .
|
||||
@@ -98,9 +133,20 @@ type CreateRequest struct {
|
||||
Driver string `url:"driver,omitempty" json:"driver,omitempty" validate:"omitempty,computeDriver"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
func (r CreateRequest) GetRAM() map[string]uint64 {
|
||||
|
||||
res := make(map[string]uint64, 1)
|
||||
|
||||
res["RAM"] = r.RAM
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
type wrapperCreateRequest struct {
|
||||
CreateRequest
|
||||
Interfaces []string `url:"interfaces,omitempty"`
|
||||
DataDisks []string `url:"dataDisks,omitempty"`
|
||||
}
|
||||
|
||||
// Create creates KVM x86 VM based on specified OS image
|
||||
@@ -127,9 +173,25 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
var dataDisks []string
|
||||
|
||||
if req.DataDisks != nil && len(req.DataDisks) != 0 {
|
||||
dataDisks = make([]string, 0, len(req.DataDisks))
|
||||
|
||||
for i := range req.DataDisks {
|
||||
b, err := json.Marshal(req.DataDisks[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
dataDisks = append(dataDisks, string(b))
|
||||
}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateRequest{
|
||||
CreateRequest: req,
|
||||
Interfaces: interfaces,
|
||||
DataDisks: dataDisks,
|
||||
}
|
||||
|
||||
url := "/cloudapi/kvmx86/create"
|
||||
|
||||
@@ -41,6 +41,12 @@ type CreateBlankRequest struct {
|
||||
// Required: true
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
|
||||
// Slice of structs with data disk description. Each disk has parameters: required - diskName, size; optional - sepId, pool, desc and imageId.
|
||||
// If not specified, compute will be created without disks.
|
||||
// To create compute without disks, pass initialized empty slice .
|
||||
// Required: false
|
||||
DataDisks []DataDisk `url:"-" json:"dataDisks,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Slice of structs with net interface description.
|
||||
// If not specified, compute will be created with default interface from RG.
|
||||
// To create compute without interfaces, pass initialized empty slice .
|
||||
@@ -56,9 +62,20 @@ type CreateBlankRequest struct {
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
// GetRAM returns RAM field values
|
||||
func (r CreateBlankRequest) GetRAM() map[string]uint64 {
|
||||
|
||||
res := make(map[string]uint64, 1)
|
||||
|
||||
res["RAM"] = r.RAM
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
type wrapperCreateBlankRequest struct {
|
||||
CreateBlankRequest
|
||||
Interfaces []string `url:"interfaces,omitempty"`
|
||||
DataDisks []string `url:"dataDisks,omitempty"`
|
||||
}
|
||||
|
||||
// CreateBlank creates KVM x86 VM from scratch
|
||||
@@ -85,9 +102,25 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
|
||||
interfaces = []string{"[]"}
|
||||
}
|
||||
|
||||
var dataDisks []string
|
||||
|
||||
if req.DataDisks != nil && len(req.DataDisks) != 0 {
|
||||
dataDisks = make([]string, 0, len(req.DataDisks))
|
||||
|
||||
for i := range req.DataDisks {
|
||||
b, err := json.Marshal(req.DataDisks[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
dataDisks = append(dataDisks, string(b))
|
||||
}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateBlankRequest{
|
||||
CreateBlankRequest: req,
|
||||
Interfaces: interfaces,
|
||||
DataDisks: dataDisks,
|
||||
}
|
||||
|
||||
url := "/cloudapi/kvmx86/createBlank"
|
||||
|
||||
@@ -10,8 +10,6 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type Params []string
|
||||
|
||||
// CreateRequest struct to create load balancer
|
||||
type CreateRequest struct {
|
||||
// ID of the resource group where this load balancer instance will be located
|
||||
@@ -33,7 +31,7 @@ type CreateRequest struct {
|
||||
|
||||
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||
// Required: false
|
||||
SysctlParams Params `url:"-" json:"sysctlParams,omitempty" validate:"omitempty,dive"`
|
||||
SysctlParams []map[string]interface{} `url:"-" json:"sysctlParams,omitempty" validate:"omitempty,dive"`
|
||||
|
||||
// Use Highly Available schema for LB deploy
|
||||
// Required: false
|
||||
@@ -68,14 +66,12 @@ func (l LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
|
||||
if len(req.SysctlParams) != 0 {
|
||||
params = make([]string, 0, len(req.SysctlParams))
|
||||
|
||||
for r := range req.SysctlParams {
|
||||
b, err := json.Marshal(req.SysctlParams[r])
|
||||
for _, m := range req.SysctlParams {
|
||||
encodeStr, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
params = append(params, string(b))
|
||||
params = append(params, string(encodeStr))
|
||||
}
|
||||
} else {
|
||||
params = []string{}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of load balancers
|
||||
@@ -44,6 +46,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -55,6 +61,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of all load balancers as a ListLB struct
|
||||
func (l LB) List(ctx context.Context, req ListRequest) (*ListLB, error) {
|
||||
|
||||
res, err := l.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -72,6 +79,11 @@ func (l LB) List(ctx context.Context, req ListRequest) (*ListLB, error) {
|
||||
|
||||
// ListRaw gets list of all load balancers as an array of bytes
|
||||
func (l LB) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/list"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get list of deleted load balancers
|
||||
@@ -18,7 +20,7 @@ type ListDeletedRequest struct {
|
||||
|
||||
// Find by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by resource group ID
|
||||
// Required: false
|
||||
@@ -36,6 +38,10 @@ type ListDeletedRequest struct {
|
||||
// Required: false
|
||||
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -47,6 +53,11 @@ type ListDeletedRequest struct {
|
||||
|
||||
// ListDeleted gets list of deleted load balancers
|
||||
func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListLB, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/listDeleted"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -50,6 +50,12 @@ type RecordLB struct {
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// ManagerId
|
||||
ManagerId uint64 `json:"managerId"`
|
||||
|
||||
// ManagerType
|
||||
ManagerType string `json:"managerType"`
|
||||
|
||||
// Image ID
|
||||
ImageID uint64 `json:"imageId"`
|
||||
|
||||
@@ -89,6 +95,9 @@ type RecordLB struct {
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// UserManaged
|
||||
UserManaged bool `json:"userManaged"`
|
||||
|
||||
// VINS ID
|
||||
VINSID uint64 `json:"vinsId"`
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func (l LB) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/start"
|
||||
url := "/cloudapi/lb/stop"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -17,7 +17,7 @@ type UpdateSysctParamsRequest struct {
|
||||
|
||||
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||
// Required: true
|
||||
SysctlParams Params `url:"-" json:"sysctlParams" validate:"required,dive"`
|
||||
SysctlParams []map[string]interface{} `url:"-" json:"sysctlParams" validate:"required,dive"`
|
||||
}
|
||||
|
||||
type wrapperUpdateSysctParamsRequest struct {
|
||||
@@ -26,7 +26,7 @@ type wrapperUpdateSysctParamsRequest struct {
|
||||
}
|
||||
|
||||
// UpdateSysctParams updates sysct paarams for lb
|
||||
func (l LB) UpdateSysctParams(ctx context.Context, req UpdateSysctParamsRequest) (bool, error) {
|
||||
func (l LB) UpdateSysctlParams(ctx context.Context, req UpdateSysctParamsRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
@@ -36,14 +36,12 @@ func (l LB) UpdateSysctParams(ctx context.Context, req UpdateSysctParamsRequest)
|
||||
|
||||
if len(req.SysctlParams) != 0 {
|
||||
params = make([]string, 0, len(req.SysctlParams))
|
||||
|
||||
for r := range req.SysctlParams {
|
||||
b, err := json.Marshal(req.SysctlParams[r])
|
||||
for _, m := range req.SysctlParams {
|
||||
encodeStr, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
params = append(params, string(b))
|
||||
params = append(params, string(encodeStr))
|
||||
}
|
||||
} else {
|
||||
params = []string{}
|
||||
@@ -54,7 +52,7 @@ func (l LB) UpdateSysctParams(ctx context.Context, req UpdateSysctParamsRequest)
|
||||
Params: params,
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/updateSysctParams"
|
||||
url := "/cloudapi/lb/updateSysctlParams"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
if err != nil {
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of locations
|
||||
@@ -31,10 +33,15 @@ type ListRequest struct {
|
||||
// Find by code location
|
||||
// Required: false
|
||||
LocationCode string `url:"locationCode,omitempty" json:"locationCode,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
}
|
||||
|
||||
// List gets list of all locations as a ListLocations struct
|
||||
func (l Locations) List(ctx context.Context, req ListRequest) (*ListLocations, error) {
|
||||
|
||||
res, err := l.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -52,6 +59,11 @@ func (l Locations) List(ctx context.Context, req ListRequest) (*ListLocations, e
|
||||
|
||||
// ListRaw gets list of all locations as an array of bytes
|
||||
func (l Locations) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/locations/list"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
8
pkg/cloudapi/pcidevice.go
Normal file
8
pkg/cloudapi/pcidevice.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package cloudapi
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/pcidevice"
|
||||
|
||||
// Accessing the PCI Device method group
|
||||
func (ca *CloudAPI) PCIDevice() *pcidevice.PCIDevice {
|
||||
return pcidevice.New(ca.client)
|
||||
}
|
||||
10
pkg/cloudapi/pcidevice/ids.go
Normal file
10
pkg/cloudapi/pcidevice/ids.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package pcidevice
|
||||
|
||||
// IDs gets array of PCIDeviceIDs from ListPCIDevices struct
|
||||
func (lpd ListPCIDevices) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lpd.Data))
|
||||
for _, lb := range lpd.Data {
|
||||
res = append(res, lb.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
76
pkg/cloudapi/pcidevice/list.go
Normal file
76
pkg/cloudapi/pcidevice/list.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package pcidevice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of pci devices
|
||||
type ListRequest struct {
|
||||
// Find by id
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by computeId
|
||||
// Required: false
|
||||
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by rgId
|
||||
// Required: false
|
||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of all pci devices as a ListPCIDevices struct
|
||||
func (p PCIDevice) List(ctx context.Context, req ListRequest) (*ListPCIDevices, error) {
|
||||
|
||||
res, err := p.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListPCIDevices{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of all pci devices as an array of bytes
|
||||
func (p PCIDevice) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/pcidevice/list"
|
||||
|
||||
res, err := p.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
50
pkg/cloudapi/pcidevice/models.go
Normal file
50
pkg/cloudapi/pcidevice/models.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package pcidevice
|
||||
|
||||
// Main information about PCI device
|
||||
type ItemPCIDevice struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// HwPath
|
||||
HwPath string `json:"hwPath"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Stack ID
|
||||
StackID uint64 `json:"stackId"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// System name
|
||||
SystemName string `json:"systemName"`
|
||||
}
|
||||
|
||||
// List PCI devices
|
||||
type ListPCIDevices struct {
|
||||
// Data
|
||||
Data []ItemPCIDevice `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
15
pkg/cloudapi/pcidevice/pcidevice.go
Normal file
15
pkg/cloudapi/pcidevice/pcidevice.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package pcidevice
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to PCI device
|
||||
type PCIDevice struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for PCI device endpoints
|
||||
func New(client interfaces.Caller) *PCIDevice {
|
||||
return &PCIDevice{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
42
pkg/cloudapi/pcidevice/serialize.go
Normal file
42
pkg/cloudapi/pcidevice/serialize.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package pcidevice
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (l ListPCIDevices) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(l.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(l, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(l)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (i ItemPCIDevice) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(i, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(i)
|
||||
}
|
||||
@@ -55,12 +55,10 @@ func (lrc ListResourceConsumption) IDs() []uint64 {
|
||||
}
|
||||
|
||||
// IDs gets array of ResourceGroupIDs from ListAffinityGroup struct
|
||||
func (lag ListAffinityGroups) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lag.Data))
|
||||
for _, ag := range lag.Data {
|
||||
for _, v := range ag {
|
||||
res = append(res, v...)
|
||||
}
|
||||
func (lag ListAffinityGroup) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lag))
|
||||
for _, ag := range lag {
|
||||
res = append(res, ag.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of resource groups
|
||||
@@ -44,6 +46,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -55,6 +61,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of all resource groups the user has access to as a ListResourceGroups struct
|
||||
func (r RG) List(ctx context.Context, req ListRequest) (*ListResourceGroups, error) {
|
||||
|
||||
res, err := r.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -72,6 +79,11 @@ func (r RG) List(ctx context.Context, req ListRequest) (*ListResourceGroups, err
|
||||
|
||||
// ListRaw gets list of all resource groups the user has access to as an array of bytes
|
||||
func (r RG) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/list"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -46,6 +46,10 @@ type ListComputesRequest struct {
|
||||
// Required: false
|
||||
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -57,6 +61,7 @@ type ListComputesRequest struct {
|
||||
|
||||
// ListComputes gets list of all compute instances under specified resource group, accessible by the user
|
||||
func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListDeletedRequest struct to get list deleted resource groups
|
||||
@@ -36,6 +38,10 @@ type ListDeletedRequest struct {
|
||||
// Required: false
|
||||
LockStatus string `url:"lockStatus,omitempty" json:"lockStatus,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -47,6 +53,11 @@ type ListDeletedRequest struct {
|
||||
|
||||
// ListDeleted gets list all deleted resource groups the user has access to
|
||||
func (r RG) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListResourceGroups, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listDeleted"
|
||||
|
||||
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -24,7 +24,7 @@ type ListLBRequest struct {
|
||||
|
||||
// Find by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Find by tech status
|
||||
// Required: false
|
||||
@@ -42,6 +42,10 @@ type ListLBRequest struct {
|
||||
// Required: false
|
||||
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -53,6 +57,7 @@ type ListLBRequest struct {
|
||||
|
||||
// ListLB gets list all load balancers in the specified resource group, accessible by the user
|
||||
func (r RG) ListLB(ctx context.Context, req ListLBRequest) (*ListLB, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -17,6 +17,7 @@ type ListPFWRequest struct {
|
||||
|
||||
// ListPFW gets list port forward rules for the specified resource group
|
||||
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (*ListPortForwards, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -30,6 +30,10 @@ type ListVINSRequest struct {
|
||||
// Required: false
|
||||
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -41,6 +45,7 @@ type ListVINSRequest struct {
|
||||
|
||||
// ListVINS gets list all ViNSes under specified resource group, accessible by the user
|
||||
func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) {
|
||||
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
|
||||
@@ -77,6 +77,9 @@ type RecordResourceGroup struct {
|
||||
// Access Control List
|
||||
ACL ListACL `json:"acl"`
|
||||
|
||||
// Compute Features
|
||||
ComputeFeatures []string `json:"computeFeatures"`
|
||||
|
||||
// CPU allocation parameter
|
||||
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
||||
|
||||
@@ -170,6 +173,9 @@ type ItemResourceGroup struct {
|
||||
// Access Control List
|
||||
ACL ListACL `json:"acl"`
|
||||
|
||||
// Compute Features
|
||||
ComputeFeatures []string `json:"computeFeatures"`
|
||||
|
||||
// CPU allocation parameter
|
||||
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
||||
|
||||
@@ -331,10 +337,19 @@ type ItemAffinityGroupComputes struct {
|
||||
// List of affinity groups
|
||||
type ListAffinityGroupsComputes []ItemAffinityGroupComputes
|
||||
|
||||
// Main information about
|
||||
type ItemAffinityGroup struct {
|
||||
ID uint64 `json:"id"`
|
||||
NodeID uint64 `json:"node_id"`
|
||||
}
|
||||
|
||||
// List of affinity group
|
||||
type ListAffinityGroup []ItemAffinityGroup
|
||||
|
||||
// List of affinity groups
|
||||
type ListAffinityGroups struct {
|
||||
// Data
|
||||
Data []map[string][]uint64 `json:"data"`
|
||||
Data []map[string]ListAffinityGroup `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
@@ -768,6 +783,12 @@ type ItemVINS struct {
|
||||
// External IP
|
||||
ExternalIP string `json:"externalIP"`
|
||||
|
||||
// Extnet ID
|
||||
ExtnetId uint64 `json:"extnetId"`
|
||||
|
||||
// Free IPs
|
||||
FreeIPs uint64 `json:"freeIPs"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct for list of the available flavors
|
||||
@@ -16,6 +18,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
Location string `url:"location,omitempty" json:"location,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -27,6 +33,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of the available flavors as a ListSizes struct, filtering can be based on the user which is doing the request
|
||||
func (s Sizes) List(ctx context.Context, req ListRequest) (*ListSizes, error) {
|
||||
|
||||
res, err := s.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -44,6 +51,11 @@ func (s Sizes) List(ctx context.Context, req ListRequest) (*ListSizes, error) {
|
||||
|
||||
// ListRaw gets list of the available flavors as an array of bytes
|
||||
func (s Sizes) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/sizes/list"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of stacks
|
||||
@@ -24,6 +26,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
@@ -35,6 +41,7 @@ type ListRequest struct {
|
||||
|
||||
// List gets list of stacks as a ListStacks struct
|
||||
func (i Stack) List(ctx context.Context, req ListRequest) (*ListStacks, error) {
|
||||
|
||||
res, err := i.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -52,6 +59,11 @@ func (i Stack) List(ctx context.Context, req ListRequest) (*ListStacks, error) {
|
||||
|
||||
// ListRaw gets list of stacks as an array of bytes
|
||||
func (i Stack) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/stack/list"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -4,21 +4,51 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of tasks
|
||||
type ListRequest struct {
|
||||
// Find by guId
|
||||
// Required: false
|
||||
TaskID string `url:"taskId,omitempty" json:"taskId,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by completed True or False
|
||||
// Default: false
|
||||
// Required: false
|
||||
Completed bool `url:"completed" json:"completed"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Find all tasks after point in time (unixtime)
|
||||
// Required: false
|
||||
UpdateTimeAt uint64 `url:"page,updateTimeAt" json:"updateTimeAt,omitempty"`
|
||||
|
||||
// Find all tasks before point in time (unixtime)
|
||||
// Required: false
|
||||
UpdateTimeTo uint64 `url:"page,updateTimeTo" json:"updateTimeTo,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Default: 0
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Default: 0
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of user API tasks with status PROCESSING as a ListTasks struct
|
||||
func (t Tasks) List(ctx context.Context, req ListRequest) (*ListTasks, error) {
|
||||
|
||||
res, err := t.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -36,6 +66,11 @@ func (t Tasks) List(ctx context.Context, req ListRequest) (*ListTasks, error) {
|
||||
|
||||
// ListRaw gets list of user API tasks with status PROCESSING as an array of bytes
|
||||
func (t Tasks) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/tasks/list"
|
||||
|
||||
res, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
|
||||
@@ -1,46 +1,13 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Global variable for converting field to desired data type
|
||||
type TaskResult int
|
||||
|
||||
// Method for convert field
|
||||
func (r *TaskResult) UnmarshalJSON(b []byte) error {
|
||||
if b[0] == '"' {
|
||||
b := b[1 : len(b)-1]
|
||||
if len(b) == 0 {
|
||||
*r = 0
|
||||
return nil
|
||||
}
|
||||
n, err := strconv.Atoi(string(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*r = TaskResult(n)
|
||||
} else if b[0] == '[' {
|
||||
res := []interface{}{}
|
||||
if err := json.Unmarshal(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
if n, ok := res[0].(float64); ok {
|
||||
*r = TaskResult(n)
|
||||
} else {
|
||||
return fmt.Errorf("could not unmarshal %v into int", res[0])
|
||||
}
|
||||
} else {
|
||||
n, err := strconv.Atoi(string(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*r = TaskResult(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
// Result structure of the task to provide methods
|
||||
type Result struct {
|
||||
Result interface{} `json:"result"`
|
||||
}
|
||||
|
||||
// Detailed information about task
|
||||
@@ -57,8 +24,8 @@ type RecordAsyncTask struct {
|
||||
// List of logs
|
||||
Log []string `json:"log"`
|
||||
|
||||
// Final result
|
||||
Result TaskResult `json:"result"`
|
||||
// Final Result
|
||||
Result
|
||||
|
||||
// Stage
|
||||
Stage string `json:"stage"`
|
||||
@@ -78,32 +45,10 @@ type RecordAsyncTask struct {
|
||||
|
||||
// Detailed information about task
|
||||
type ItemAsyncTask struct {
|
||||
// Audit ID
|
||||
AuditID string `json:"auditId"`
|
||||
RecordAsyncTask
|
||||
|
||||
// Completed
|
||||
Completed bool `json:"completed"`
|
||||
|
||||
// Error
|
||||
Error string `json:"error"`
|
||||
|
||||
// List of logs
|
||||
Log []string `json:"log"`
|
||||
|
||||
// Final result
|
||||
Result TaskResult `json:"result"`
|
||||
|
||||
// Stage
|
||||
Stage string `json:"stage"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Update time
|
||||
UpdateTime uint64 `json:"updateTime"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
}
|
||||
|
||||
// List of tasks
|
||||
@@ -112,3 +57,90 @@ type ListTasks struct {
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// ID returns ID of cluster or WG or any other resource successfully created as a Result of the task.
|
||||
// It returns error if Result does not contain any resource ID.
|
||||
func (r Result) ID() (int, error) {
|
||||
// check id from cluster - it comes as slice, like [1234, "cluster-name"]
|
||||
slice, ok := r.Result.([]interface{})
|
||||
if ok {
|
||||
if len(slice) == 0 {
|
||||
return 0, fmt.Errorf("could not get ID from empty slice")
|
||||
}
|
||||
|
||||
idFloat64, ok := slice[0].(float64)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("could not get ID from first slice element (%v)", slice[0])
|
||||
}
|
||||
|
||||
return int(idFloat64), nil
|
||||
}
|
||||
|
||||
// check id from other resources - it comes as id
|
||||
idFloat64, ok := r.Result.(float64)
|
||||
if ok {
|
||||
return int(idFloat64), nil
|
||||
}
|
||||
|
||||
return 0, errors.New("could not get ID because result is neither slice nor number (%v)")
|
||||
}
|
||||
|
||||
// Name returns name of cluster or WG successfully created as a Result of the task.
|
||||
// It returns error if Result does not contain k8s name.
|
||||
func (r Result) Name() (string, error) {
|
||||
slice, ok := r.Result.([]interface{})
|
||||
if !ok {
|
||||
return "", fmt.Errorf("could not convert Result (%v) to slice", r.Result)
|
||||
}
|
||||
|
||||
if len(slice) < 2 {
|
||||
return "", fmt.Errorf("could not get name from second slice element")
|
||||
}
|
||||
|
||||
var name string
|
||||
name, ok = slice[1].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("could not get name from second slice element (%v)", slice[1])
|
||||
}
|
||||
|
||||
return name, nil
|
||||
}
|
||||
|
||||
// ToMaps converts Result to a slice of maps containing back-up information as a result of the task.
|
||||
// It returns error if Result does not contain back-up information.
|
||||
func (r Result) ToMaps() ([]map[string]interface{}, error) {
|
||||
slice, ok := r.Result.([]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("could not convert Result (%v) to slice", r.Result)
|
||||
}
|
||||
|
||||
if len(slice) == 0 {
|
||||
return nil, fmt.Errorf("could not get maps from empty slice")
|
||||
}
|
||||
|
||||
result := make([]map[string]interface{}, 0, len(slice))
|
||||
for _, s := range slice {
|
||||
elem, ok := s.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("could not get map[string]interface{} from slice element (%v)", s)
|
||||
}
|
||||
result = append(result, elem)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ToString converts Result to non-empty string.
|
||||
// It returns error if Result is not a string or is an empty string.
|
||||
func (r Result) ToString() (string, error) {
|
||||
status, ok := r.Result.(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("could not convert Result (%v) to string", r.Result)
|
||||
}
|
||||
|
||||
if status == "" {
|
||||
return "", fmt.Errorf("info contains empty string")
|
||||
}
|
||||
|
||||
return status, nil
|
||||
}
|
||||
|
||||
7
pkg/cloudapi/user.go
Normal file
7
pkg/cloudapi/user.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package cloudapi
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/user"
|
||||
|
||||
func (ca *CloudAPI) User() *user.User {
|
||||
return user.New(ca.client)
|
||||
}
|
||||
41
pkg/cloudapi/user/api_list.go
Normal file
41
pkg/cloudapi/user/api_list.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// APIListRequest struct for getting API list.
|
||||
type APIListRequest struct {
|
||||
// ID of the user.
|
||||
// Required: true
|
||||
UserID string `url:"userId" json:"userId" validate:"required"`
|
||||
}
|
||||
|
||||
// APIList gets a list of all API functions that a given user has
|
||||
// access to according to their apiaccess group membership.
|
||||
func (u User) APIList(ctx context.Context, req APIListRequest) (*APIsEndpoints, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/apiList"
|
||||
|
||||
info := APIsEndpoints{}
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
38
pkg/cloudapi/user/authenticate.go
Normal file
38
pkg/cloudapi/user/authenticate.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// AuthenticateRequest struct to authenticate user.
|
||||
type AuthenticateRequest struct {
|
||||
// Username
|
||||
// Required: true
|
||||
Username string `url:"username" json:"username" validate:"required"`
|
||||
|
||||
// Password
|
||||
// Required: true
|
||||
Password string `url:"password" json:"password" validate:"required"`
|
||||
}
|
||||
|
||||
// Authenticate evaluates the provided username and password and returns a session key.
|
||||
// The session key can be used for doing api requests. E.g this is the authkey parameter in every actor request.
|
||||
// A session key is only vallid for a limited time.
|
||||
func (u User) Authenticate(ctx context.Context, req AuthenticateRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/authenticate"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
26
pkg/cloudapi/user/brief.go
Normal file
26
pkg/cloudapi/user/brief.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Brief gets information about user's enabled and disabled resources.
|
||||
func (u User) Brief(ctx context.Context) (*BriefResources, error) {
|
||||
url := "/cloudapi/user/brief"
|
||||
|
||||
info := BriefResources{}
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
46
pkg/cloudapi/user/get.go
Normal file
46
pkg/cloudapi/user/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get user details.
|
||||
type GetRequest struct {
|
||||
// Username
|
||||
// Required: true
|
||||
Username string `url:"username" json:"username" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets user details as an ItemUser struct.
|
||||
func (u User) Get(ctx context.Context, req GetRequest) (*ItemUser, error) {
|
||||
res, err := u.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
item := ItemUser{}
|
||||
|
||||
err = json.Unmarshal(res, &item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// GetRaw gets user details as an array of bytes
|
||||
func (u User) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/get"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
53
pkg/cloudapi/user/get_audit.go
Normal file
53
pkg/cloudapi/user/get_audit.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// GetAuditRequest struct for getting user's audits.
|
||||
type GetAuditRequest struct {
|
||||
// Find by api call.
|
||||
// Required: false
|
||||
Call string `url:"call,omitempty" json:"call,omitempty"`
|
||||
|
||||
// Find by HTTP status code
|
||||
// Required: false
|
||||
StatusCode uint64 `url:"statuscode,omitempty" json:"statuscode,omitempty"`
|
||||
|
||||
// Find all audits after point in time (unixtime)
|
||||
// Required: false
|
||||
TimestampAt uint64 `url:"timestampAt,omitempty" json:"timestampAt,omitempty"`
|
||||
|
||||
// Find all audits before point in time (unixtime)
|
||||
// Required: false
|
||||
TimestampTo uint64 `url:"timestampTo,omitempty" json:"timestampTo,omitempty"`
|
||||
|
||||
// Page number.
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size, maximum - 100.
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// GetAudit gets user's audits.
|
||||
func (u User) GetAudit(ctx context.Context, req GetAuditRequest) (ListAudits, error) {
|
||||
url := "/cloudapi/user/getAudit"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return ListAudits{}, err
|
||||
}
|
||||
|
||||
list := ListAudits{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return ListAudits{}, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
26
pkg/cloudapi/user/get_resource_consumption.go
Normal file
26
pkg/cloudapi/user/get_resource_consumption.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// GetResourceConsumption gets amount of consumed and reserved resources (cpu, ram, disk) by current user
|
||||
func (u User) GetResourceConsumption(ctx context.Context) (*ResourceConsumption, error) {
|
||||
url := "/cloudapi/user/getResourceConsumption"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
item := ResourceConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &item, nil
|
||||
}
|
||||
44
pkg/cloudapi/user/is_valid_invite_user_token.go
Normal file
44
pkg/cloudapi/user/is_valid_invite_user_token.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to check if the inviteusertoken and emailaddress pair are valid and matching.
|
||||
type IsValidInviteUserTokenRequest struct {
|
||||
// InviteUserToken
|
||||
// The token that was previously sent to the invited user email
|
||||
// Required: true
|
||||
InviteUserToken string `url:"inviteusertoken" json:"inviteusertoken" validate:"required"`
|
||||
|
||||
// EmailAddress
|
||||
// Email address for the user
|
||||
// Required: true
|
||||
EmailAddress string `url:"emailaddress" json:"emailaddress" validate:"required"`
|
||||
}
|
||||
|
||||
// IsValidInviteUserToken checks if the inviteusertoken and emailaddress pair are valid and matching.
|
||||
func (u User) IsValidInviteUserToken(ctx context.Context, req IsValidInviteUserTokenRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/isValidInviteUserToken"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
178
pkg/cloudapi/user/models.go
Normal file
178
pkg/cloudapi/user/models.go
Normal file
@@ -0,0 +1,178 @@
|
||||
package user
|
||||
|
||||
import "strconv"
|
||||
|
||||
type ItemUser struct {
|
||||
// Data
|
||||
Data interface{} `json:"data"`
|
||||
|
||||
// EmailAddresses
|
||||
EmailAddresses []string `json:"emailaddresses"`
|
||||
|
||||
// Username
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type ItemAudit struct {
|
||||
// Call
|
||||
Call string `json:"Call"`
|
||||
|
||||
// Response time
|
||||
ResponseTime ResponseTime `json:"Response Time"`
|
||||
|
||||
// StatusCode
|
||||
StatusCode StatusCode `json:"Status Code"`
|
||||
|
||||
// Time
|
||||
Time float64 `json:"Time"`
|
||||
}
|
||||
|
||||
type ListAudits struct {
|
||||
// Data
|
||||
Data []ItemAudit `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
type ResponseTime float64
|
||||
|
||||
func (r *ResponseTime) UnmarshalJSON(b []byte) error {
|
||||
if string(b) == "null" {
|
||||
*r = ResponseTime(-1)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
res, err := strconv.ParseFloat(string(b), 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*r = ResponseTime(res)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type StatusCode int64
|
||||
|
||||
func (s *StatusCode) UnmarshalJSON(b []byte) error {
|
||||
if string(b) == "null" {
|
||||
*s = StatusCode(-1)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
res, err := strconv.ParseInt(string(b), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*s = StatusCode(res)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type BriefResources struct {
|
||||
Accounts Accounts `json:"Accounts,omitempty"`
|
||||
CSs CSs `json:"CSs,omitempty"`
|
||||
Computes Computes `json:"Computes,omitempty"`
|
||||
RGs RGs `json:"RGs,omitempty"`
|
||||
VMs VMs `json:"VMs,omitempty"`
|
||||
}
|
||||
|
||||
type Accounts struct {
|
||||
Disabled uint64 `json:"DISABLED,omitempty"`
|
||||
Enabled uint64 `json:"ENABLED,omitempty"`
|
||||
}
|
||||
|
||||
type CSs struct {
|
||||
Disabled uint64 `json:"DISABLED,omitempty"`
|
||||
Enabled uint64 `json:"ENABLED,omitempty"`
|
||||
}
|
||||
|
||||
type Computes struct {
|
||||
Started uint64 `json:"Started,omitempty"`
|
||||
Stopped uint64 `json:"Stopped,omitempty"`
|
||||
}
|
||||
|
||||
type RGs struct {
|
||||
Disabled uint64 `json:"DISABLED,omitempty"`
|
||||
Enabled uint64 `json:"ENABLED,omitempty"`
|
||||
}
|
||||
|
||||
type VMs struct {
|
||||
Halted uint64 `json:"Halted,omitempty"`
|
||||
Running uint64 `json:"Running,omitempty"`
|
||||
}
|
||||
|
||||
type APIsEndpoints struct {
|
||||
CloudAPI CloudAPIEndpoints `json:"cloudapi,omitempty"`
|
||||
CloudBroker CloudBrokerEndpoints `json:"cloudbroker,omitempty"`
|
||||
LibCloud LibCloudEndpoints `json:"libcloud,omitempty"`
|
||||
System SystemEndpoints `json:"system,omitempty"`
|
||||
}
|
||||
|
||||
type CloudAPIEndpoints struct {
|
||||
All bool `json:"ALL,omitempty"`
|
||||
}
|
||||
|
||||
type CloudBrokerEndpoints struct {
|
||||
All bool `json:"ALL,omitempty"`
|
||||
}
|
||||
|
||||
type LibCloudEndpoints struct {
|
||||
All bool `json:"ALL,omitempty"`
|
||||
}
|
||||
|
||||
type SystemEndpoints struct {
|
||||
All bool `json:"ALL,omitempty"`
|
||||
}
|
||||
|
||||
type ResourceConsumption struct {
|
||||
// Consumed
|
||||
Consumed Resources `json:"Consumed"`
|
||||
|
||||
// Reserved
|
||||
Reserved Resources `json:"Reserved"`
|
||||
|
||||
// Username
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type Resources struct {
|
||||
// CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// Disksize
|
||||
DiskSize uint64 `json:"disksize"`
|
||||
|
||||
// DiskSizeMax
|
||||
DiskSizeMax uint64 `json:"disksizemax"`
|
||||
|
||||
// ExtIPs
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
|
||||
// ExtTraffic
|
||||
ExtTraffic uint64 `json:"exttraffic"`
|
||||
|
||||
// GPU
|
||||
GPU uint64 `json:"gpu"`
|
||||
|
||||
// RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// SEPs
|
||||
SEPs map[string]map[string]DiskUsage `json:"seps"`
|
||||
}
|
||||
|
||||
// Disk usage
|
||||
type DiskUsage struct {
|
||||
// Disk size
|
||||
DiskSize float64 `json:"disksize"`
|
||||
|
||||
// Disk size max
|
||||
DiskSizeMax float64 `json:"disksizemax"`
|
||||
}
|
||||
|
||||
type FoundElements []interface{}
|
||||
33
pkg/cloudapi/user/search.go
Normal file
33
pkg/cloudapi/user/search.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// SearchRequest struct for searching user's elements.
|
||||
type SearchRequest struct {
|
||||
// Text to search
|
||||
// Required: true
|
||||
Text string `url:"text" json:"text" validate:"required"`
|
||||
}
|
||||
|
||||
// Search searches for user's elements.
|
||||
func (u User) Search(ctx context.Context, req SearchRequest) (*FoundElements, error) {
|
||||
url := "/cloudapi/user/search"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := FoundElements{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
38
pkg/cloudapi/user/set_data.go
Normal file
38
pkg/cloudapi/user/set_data.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// SetDataRequest struct for setting extra user information.
|
||||
type SetDataRequest struct {
|
||||
// Data to set to user in json format
|
||||
// Required: true
|
||||
Data string `url:"data" json:"data" validation:"required"`
|
||||
}
|
||||
|
||||
// SetData sets extra user information.
|
||||
func (u User) SetData(ctx context.Context, req SetDataRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/setData"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
15
pkg/cloudapi/user/user.go
Normal file
15
pkg/cloudapi/user/user.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package user
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to User
|
||||
type User struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for User endpoints
|
||||
func New(client interfaces.Caller) *User {
|
||||
return &User{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
8
pkg/cloudapi/vfpool.go
Normal file
8
pkg/cloudapi/vfpool.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package cloudapi
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vfpool"
|
||||
|
||||
// Accessing the VFPool method group
|
||||
func (ca *CloudAPI) VFPool() *vfpool.VFPool {
|
||||
return vfpool.New(ca.client)
|
||||
}
|
||||
99
pkg/cloudapi/vfpool/filter.go
Normal file
99
pkg/cloudapi/vfpool/filter.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package vfpool
|
||||
|
||||
// FilterByID returns ListVFPool with specified ID.
|
||||
func (lvfp ListVFPool) FilterByID(id uint64) ListVFPool {
|
||||
predicate := func(ivfp ItemVFPool) bool {
|
||||
return ivfp.ID == id
|
||||
}
|
||||
|
||||
return lvfp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByGID returns ListVFPool with specified GID.
|
||||
func (lvfp ListVFPool) FilterByGID(gid uint64) ListVFPool {
|
||||
predicate := func(ivfp ItemVFPool) bool {
|
||||
return ivfp.GID == gid
|
||||
}
|
||||
|
||||
return lvfp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListVFPool with specified Name.
|
||||
func (lvfp ListVFPool) FilterByName(name string) ListVFPool {
|
||||
predicate := func(ivfp ItemVFPool) bool {
|
||||
return ivfp.Name == name
|
||||
}
|
||||
|
||||
return lvfp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDescription returns ListVFPool with specified Description.
|
||||
func (lvfp ListVFPool) FilterByDescription(description string) ListVFPool {
|
||||
predicate := func(ivfp ItemVFPool) bool {
|
||||
return ivfp.Description == description
|
||||
}
|
||||
|
||||
return lvfp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListVFPool with specified Status.
|
||||
func (lvfp ListVFPool) FilterByStatus(status string) ListVFPool {
|
||||
predicate := func(ivfp ItemVFPool) bool {
|
||||
return ivfp.Status == status
|
||||
}
|
||||
|
||||
return lvfp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByAccountAccess returns ListVFPool with specified AccountAccess.
|
||||
func (lvfp ListVFPool) FilterByAccountAccess(accountAccess uint64) ListVFPool {
|
||||
predicate := func(ivfp ItemVFPool) bool {
|
||||
for _, i := range ivfp.AccountAccess {
|
||||
if i == accountAccess {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lvfp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByRGAccess returns ListVFPool with specified RGAccess.
|
||||
func (lvfp ListVFPool) FilterByRGAccess(rgAccess uint64) ListVFPool {
|
||||
predicate := func(ivfp ItemVFPool) bool {
|
||||
for _, i := range ivfp.RGAccess {
|
||||
if i == rgAccess {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lvfp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListVFPool based on a user-specified predicate.
|
||||
func (lvfp ListVFPool) FilterFunc(predicate func(ItemVFPool) bool) ListVFPool {
|
||||
var result ListVFPool
|
||||
|
||||
for _, item := range lvfp.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemVFPool
|
||||
// If none was found, returns an empty struct.
|
||||
func (lvfp ListVFPool) FindOne() ItemVFPool {
|
||||
if lvfp.EntryCount == 0 {
|
||||
return ItemVFPool{}
|
||||
}
|
||||
|
||||
return lvfp.Data[0]
|
||||
}
|
||||
138
pkg/cloudapi/vfpool/filter_test.go
Normal file
138
pkg/cloudapi/vfpool/filter_test.go
Normal file
@@ -0,0 +1,138 @@
|
||||
package vfpool
|
||||
|
||||
import "testing"
|
||||
|
||||
var vfpools = ListVFPool{
|
||||
Data: []ItemVFPool{
|
||||
{
|
||||
AccountAccess: []uint64{1, 2},
|
||||
Description: "descr",
|
||||
GID: 1,
|
||||
ID: 1,
|
||||
Name: "name",
|
||||
RGAccess: []uint64{3, 4},
|
||||
Status: "ENABLED",
|
||||
},
|
||||
{
|
||||
AccountAccess: []uint64{},
|
||||
Description: "",
|
||||
GID: 2,
|
||||
ID: 2,
|
||||
Name: "name2",
|
||||
RGAccess: []uint64{},
|
||||
Status: "DISABLED",
|
||||
},
|
||||
{
|
||||
AccountAccess: []uint64{7, 8},
|
||||
Description: "",
|
||||
GID: 215,
|
||||
ID: 3,
|
||||
Name: "name3",
|
||||
RGAccess: []uint64{5, 6},
|
||||
Status: "DISABLED",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := vfpools.FilterByID(1).FindOne()
|
||||
|
||||
if actual.ID != 1 {
|
||||
t.Fatal("expected ID 1, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByGID(t *testing.T) {
|
||||
var gid uint64 = 1
|
||||
actual := vfpools.FilterByGID(gid).FindOne()
|
||||
|
||||
if actual.GID != gid {
|
||||
t.Fatal("expected ", gid, " found: ", actual.GID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
name := "name"
|
||||
actual := vfpools.FilterByName(name).FindOne()
|
||||
|
||||
if actual.Name != name {
|
||||
t.Fatal("expected ", name, " found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByDescription(t *testing.T) {
|
||||
description := "descr"
|
||||
actual := vfpools.FilterByDescription(description).FindOne()
|
||||
|
||||
if actual.Description != description {
|
||||
t.Fatal("expected ", description, " found: ", actual.Description)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := vfpools.FilterByStatus("ENABLED")
|
||||
|
||||
if len(actual.Data) != 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByAccountAccess(t *testing.T) {
|
||||
var account uint64 = 1
|
||||
actual := vfpools.FilterByAccountAccess(account)
|
||||
|
||||
if len(actual.Data) != 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
var found bool
|
||||
for _, a := range item.AccountAccess {
|
||||
if a == account {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Fatalf("expected account access %d, found: %v", account, item.AccountAccess)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByRGAccess(t *testing.T) {
|
||||
var rg uint64 = 3
|
||||
actual := vfpools.FilterByRGAccess(rg)
|
||||
|
||||
if len(actual.Data) != 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
var found bool
|
||||
for _, r := range item.RGAccess {
|
||||
if r == rg {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Fatalf("expected account access %d, found: %v", rg, item.RGAccess)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := vfpools.FilterFunc(func(ivfpool ItemVFPool) bool {
|
||||
return ivfpool.GID == ivfpool.ID
|
||||
})
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 elements, found: ", len(actual.Data))
|
||||
}
|
||||
}
|
||||
46
pkg/cloudapi/vfpool/get.go
Normal file
46
pkg/cloudapi/vfpool/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package vfpool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get detailed information about vfpool device
|
||||
type GetRequest struct {
|
||||
// ID of vfpool device
|
||||
// Required: true
|
||||
VFPoolID uint64 `url:"id" json:"id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets detailed information about vfpool device as a RecordVFPool struct
|
||||
func (v VFPool) Get(ctx context.Context, req GetRequest) (*RecordVFPool, error) {
|
||||
res, err := v.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordVFPool{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets detailed information about vfpool device as an array of bytes
|
||||
func (v VFPool) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/vfpool/get"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user