v1.3.0
This commit is contained in:
@@ -23,7 +23,7 @@ type AddUserRequest struct {
|
||||
// - 'RCX' for Write
|
||||
// - 'ARCXDU' for Admin
|
||||
// Required: true
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"required,accountAccessType"`
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"required,accessType"`
|
||||
}
|
||||
|
||||
// AddUser gives a user access rights.
|
||||
|
||||
@@ -23,7 +23,7 @@ type UpdateUserRequest struct {
|
||||
// - 'RCX' for Write
|
||||
// - 'ARCXDU' for Admin
|
||||
// Required: true
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"required,accountAccessType"`
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"required,accessType"`
|
||||
}
|
||||
|
||||
// UpdateUser updates user access rights
|
||||
|
||||
@@ -43,7 +43,7 @@ type GroupAddRequest struct {
|
||||
// - KVM_X86
|
||||
// - KVM_PPC
|
||||
// Required: true
|
||||
Driver string `url:"driver" json:"driver" validate:"bserviceDriver"`
|
||||
Driver string `url:"driver" json:"driver" validate:"driver"`
|
||||
|
||||
// Storage endpoint provider ID
|
||||
// Required: false
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||
)
|
||||
|
||||
// FilterByID returns ListComputes with specified ID.
|
||||
func (lc ListComputes) FilterByID(id uint64) ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
@@ -36,7 +44,7 @@ func (lc ListComputes) FilterByTechStatus(techStatus string) ListComputes {
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDiskID return ListComputes with specified DiskID.
|
||||
// FilterByDiskID returns ListComputes with specified DiskID.
|
||||
func (lc ListComputes) FilterByDiskID(diskID uint64) ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
for _, disk := range ic.Disks {
|
||||
@@ -50,6 +58,88 @@ func (lc ListComputes) FilterByDiskID(diskID uint64) ListComputes {
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByK8SID returns master and worker nodes (ListComputes) inside specified K8S cluster.
|
||||
func (lc ListComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListComputes, error) {
|
||||
caller := k8s.New(decortClient)
|
||||
|
||||
req := k8s.GetRequest{
|
||||
K8SID: k8sID,
|
||||
}
|
||||
|
||||
cluster, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
for _, info := range cluster.K8SGroups.Masters.DetailedInfo {
|
||||
if info.ID == ic.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for _, worker := range cluster.K8SGroups.Workers {
|
||||
for _, info := range worker.DetailedInfo {
|
||||
if info.ID == ic.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate), nil
|
||||
}
|
||||
|
||||
// K8SMasters is used to filter master nodes. Best used after FilterByK8SID function.
|
||||
func (lc ListComputes) FilterByK8SMasters() ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
for _, rule := range ic.AntiAffinityRules {
|
||||
if rule.Value == "master" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// K8SMasters is used to filter worker nodes. Best used after FilterByK8SID function.
|
||||
func (lc ListComputes) FilterByK8SWorkers() ListComputes {
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
for _, rule := range ic.AntiAffinityRules {
|
||||
if rule.Value == "worker" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByLBID returns ListComputes used by specified Load Balancer.
|
||||
func (lc ListComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListComputes, error) {
|
||||
caller := lb.New(decortClient)
|
||||
|
||||
req := lb.GetRequest{
|
||||
LBID: lbID,
|
||||
}
|
||||
|
||||
foundLB, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
predicate := func(ic ItemCompute) bool {
|
||||
return ic.ID == foundLB.PrimaryNode.ComputeID || ic.ID == foundLB.SecondaryNode.ComputeID
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate), nil
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListComputes based on a user-specified predicate.
|
||||
func (lc ListComputes) FilterFunc(predicate func(ItemCompute) bool) ListComputes {
|
||||
var result ListComputes
|
||||
|
||||
@@ -29,7 +29,7 @@ type PFWAddRequest struct {
|
||||
// Network protocol
|
||||
// either "tcp" or "udp"
|
||||
// Required: true
|
||||
Proto string `url:"proto" json:"proto" validate:"computeProto"`
|
||||
Proto string `url:"proto" json:"proto" validate:"proto"`
|
||||
}
|
||||
|
||||
// PFWAdd add port forward rule
|
||||
|
||||
@@ -24,7 +24,7 @@ type UserGrantRequest struct {
|
||||
// - 'RCX' for Write
|
||||
// - 'ARCXDU' for Admin
|
||||
// Required: true
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"accountAccessType"`
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"accessType"`
|
||||
}
|
||||
|
||||
// UserGrant grant user access to the compute
|
||||
|
||||
@@ -24,7 +24,7 @@ type UserUpdateRequest struct {
|
||||
// - 'RCX' for Write
|
||||
// - 'ARCXDU' for Admin
|
||||
// Required: true
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"accountAccessType"`
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"accessType"`
|
||||
}
|
||||
|
||||
// UserUpdate updates user access to the compute
|
||||
|
||||
@@ -2,7 +2,6 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,15 +12,15 @@ import (
|
||||
type CreateRequest struct {
|
||||
// ID of the account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// ID of the grid (platform)
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid"`
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// Name of disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Description of disk
|
||||
// Required: false
|
||||
@@ -36,7 +35,7 @@ type CreateRequest struct {
|
||||
// - D=Data
|
||||
// - T=Temp
|
||||
// Required: true
|
||||
Type string `url:"type" json:"type"`
|
||||
Type string `url:"type" json:"type" validate:"diskType"`
|
||||
|
||||
// Size in GB default is 0
|
||||
// Required: false
|
||||
@@ -55,29 +54,13 @@ type CreateRequest struct {
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
}
|
||||
|
||||
func (drq CreateRequest) validate() error {
|
||||
if drq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.GID == 0 {
|
||||
return errors.New("validation-error: field GID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
validType := validators.StringInSlice(drq.Type, []string{"B", "D", "T"})
|
||||
if !validType {
|
||||
return errors.New("validation-error: field Type must be set as B, D or T")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates a disk
|
||||
func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/create"
|
||||
|
||||
@@ -2,16 +2,17 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request for delete disk
|
||||
type DeleteRequest struct {
|
||||
// ID of disk to delete
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Detach disk from machine first
|
||||
// Required: false
|
||||
@@ -26,19 +27,13 @@ type DeleteRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (d DeleteRequest) validate() error {
|
||||
if d.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes disk by ID
|
||||
func (d Disks) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/delete"
|
||||
|
||||
@@ -2,42 +2,34 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for multiple disks
|
||||
type DisksDeleteRequest struct {
|
||||
// List of disk ids to delete
|
||||
// Required: true
|
||||
DisksIDs []uint64 `url:"diskIds" json:"diskIds"`
|
||||
DisksIDs []uint64 `url:"diskIds" json:"diskIds" validate:"required"`
|
||||
|
||||
// Reason for deleting the disks
|
||||
// Required: true
|
||||
Reason string `url:"reason" json:"reason"`
|
||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
||||
|
||||
// Whether to completely delete the disks, works only with non attached disks
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (drq DisksDeleteRequest) validate() error {
|
||||
if len(drq.DisksIDs) == 0 {
|
||||
return errors.New("validation-error: field DisksIDs must include one or more disks ids")
|
||||
}
|
||||
if drq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteDisks deletes multiple disks permanently
|
||||
func (d Disks) DeleteDisks(ctx context.Context, req DisksDeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/deleteDisks"
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||
)
|
||||
|
||||
// FilterByID returns ListDisks with specified ID.
|
||||
func (ld ListDisks) FilterByID(id uint64) ListDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
@@ -36,6 +45,69 @@ func (ld ListDisks) FilterByTechStatus(techStatus string) ListDisks {
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByComputeID is used to filter ListDisks attached to specified compute.
|
||||
func (ld ListDisks) FilterByComputeID(computeID uint64) ListDisks {
|
||||
predicate := func(idisk ItemDisk) bool {
|
||||
for k := range idisk.Computes {
|
||||
if k == strconv.FormatUint(computeID, 10) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return ld.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByK8SID is used to filter ListDisks by specified K8S cluster.
|
||||
func (ld ListDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListDisks, error) {
|
||||
caller := k8s.New(decortClient)
|
||||
|
||||
req := k8s.GetRequest{
|
||||
K8SID: k8sID,
|
||||
}
|
||||
|
||||
cluster, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result ListDisks
|
||||
|
||||
for _, masterCompute := range cluster.K8SGroups.Masters.DetailedInfo {
|
||||
result = append(result, ld.FilterByComputeID(masterCompute.ID)...)
|
||||
}
|
||||
|
||||
for _, workerGroup := range cluster.K8SGroups.Workers {
|
||||
for _, workerCompute := range workerGroup.DetailedInfo {
|
||||
result = append(result, ld.FilterByComputeID(workerCompute.ID)...)
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FilterByLBID is used to filter ListDisks used by computes inside specified Load Balancer.
|
||||
func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListDisks, error) {
|
||||
caller := lb.New(decortClient)
|
||||
|
||||
req := lb.GetRequest{
|
||||
LBID: lbID,
|
||||
}
|
||||
|
||||
foundLB, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result ListDisks
|
||||
result = append(result, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID)...)
|
||||
result = append(result, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID)...)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListDisks based on a user-specified predicate.
|
||||
func (ld ListDisks) FilterFunc(predicate func(ItemDisk) bool) ListDisks {
|
||||
var result ListDisks
|
||||
|
||||
@@ -3,31 +3,26 @@ package disks
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get information about disk
|
||||
type GetRequest struct {
|
||||
// ID of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
}
|
||||
|
||||
func (drq GetRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets disk details
|
||||
// Notice: the devicename field is the name as it is passed to the kernel (kname in linux) for unattached disks this field has no relevant value
|
||||
func (d Disks) Get(ctx context.Context, req GetRequest) (*RecordDisk, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/get"
|
||||
|
||||
@@ -2,16 +2,17 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for limit IO
|
||||
type LimitIORequest struct {
|
||||
// ID of the disk to limit
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Alias for total_iops_sec for backwards compatibility
|
||||
// Required: false
|
||||
@@ -70,21 +71,15 @@ type LimitIORequest struct {
|
||||
SizeIOPSSec uint64 `url:"size_iops_sec,omitempty" json:"size_iops_sec,omitempty"`
|
||||
}
|
||||
|
||||
func (drq LimitIORequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LimitIO limit IO for a certain disk
|
||||
// total and read/write options are not allowed to be combined
|
||||
// see http://libvirt.org/formatdomain.html#elementsDisks iotune section for more details
|
||||
func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/limitIO"
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
type ListTypesRequest struct {
|
||||
// Show detailed disk types by seps
|
||||
// Required: false
|
||||
Detailed bool `url:"detailed" json:"detailed"`
|
||||
Detailed bool `url:"detailed,omitempty" json:"detailed,omitempty"`
|
||||
}
|
||||
|
||||
// ListTypes gets list defined disk types
|
||||
|
||||
@@ -2,38 +2,30 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for rename disk
|
||||
type RenameRequest struct {
|
||||
// ID of the disk to rename
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// New name of disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
}
|
||||
|
||||
func (drq RenameRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
}
|
||||
|
||||
// Rename rename disk
|
||||
func (d Disks) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/rename"
|
||||
|
||||
@@ -2,31 +2,21 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for resize disk
|
||||
type ResizeRequest struct {
|
||||
// ID of the disk to resize
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// New size of the disk in GB
|
||||
// Required: true
|
||||
Size uint64 `url:"size" json:"size"`
|
||||
}
|
||||
|
||||
func (drq ResizeRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.Size == 0 {
|
||||
return errors.New("validation-error: field Size can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
Size uint64 `url:"size" json:"size" validate:"required"`
|
||||
}
|
||||
|
||||
// Resize resize disk
|
||||
@@ -34,9 +24,11 @@ func (drq ResizeRequest) validate() error {
|
||||
// in that case please stop and start your machine after changing the disk size, for your changes to be reflected.
|
||||
// This method will not be used for disks, assigned to computes. Only unassigned disks and disks, assigned with "old" virtual machines.
|
||||
func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/resize"
|
||||
@@ -59,9 +51,11 @@ func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
// in that case please stop and start your machine after changing the disk size, for your changes to be reflected.
|
||||
// This method will not be used for disks, assigned to "old" virtual machines. Only unassigned disks and disks, assigned with computes.
|
||||
func (d Disks) Resize2(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/resize2"
|
||||
|
||||
@@ -2,38 +2,30 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restore a deleted unattached disk
|
||||
type RestoreRequest struct {
|
||||
// ID of the disk to restore
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Reason for restoring the disk
|
||||
// Required: true
|
||||
Reason string `url:"reason" json:"reason"`
|
||||
}
|
||||
|
||||
func (drq RestoreRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
||||
}
|
||||
|
||||
// Restore restore a deleted unattached disk from recycle bin
|
||||
func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/restore"
|
||||
|
||||
@@ -2,31 +2,26 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for share data disk
|
||||
type ShareRequest struct {
|
||||
// ID of the disk to share
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
}
|
||||
|
||||
func (drq ShareRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// Share shares data disk
|
||||
func (d Disks) Share(ctx context.Context, req ShareRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/share"
|
||||
|
||||
@@ -2,39 +2,30 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete snapshot
|
||||
type SnapshotDeleteRequest struct {
|
||||
// ID of disk to delete
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Label of the snapshot to delete
|
||||
// Required: false
|
||||
Label string `url:"label" json:"label"`
|
||||
}
|
||||
|
||||
func (drq SnapshotDeleteRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if drq.Label == "" {
|
||||
return errors.New("validation-error: field Label can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
// Required: true
|
||||
Label string `url:"label" json:"label" validate:"required"`
|
||||
}
|
||||
|
||||
// SnapshotDelete deletes a snapshot
|
||||
func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/snapshotDelete"
|
||||
|
||||
@@ -2,42 +2,34 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for rollback snapshot
|
||||
type SnapshotRollbackRequest struct {
|
||||
// ID of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Label of the snapshot to rollback
|
||||
// Required: true
|
||||
Label string `url:"label" json:"label"`
|
||||
// Required: false
|
||||
Label string `url:"label,omitempty" json:"label,omitempty"`
|
||||
|
||||
// Timestamp of the snapshot to rollback
|
||||
// Required: true
|
||||
TimeStamp uint64 `url:"timestamp" json:"timestamp"`
|
||||
}
|
||||
|
||||
func (drq SnapshotRollbackRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
if drq.Label == "" && drq.TimeStamp == 0 {
|
||||
return errors.New("validation-error: field Label or field TimeStamp can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
// Required: false
|
||||
TimeStamp uint64 `url:"timestamp,omitempty" json:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
// SnapshotRollback rollback an individual disk snapshot
|
||||
func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/snapshotRollback"
|
||||
|
||||
@@ -2,31 +2,26 @@ package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for unshare data disk
|
||||
type UnshareRequest struct {
|
||||
// ID of the disk to unshare
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId"`
|
||||
}
|
||||
|
||||
func (drq UnshareRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
}
|
||||
|
||||
// Unshare unshares data disk
|
||||
func (d Disks) Unshare(ctx context.Context, req UnshareRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/unshare"
|
||||
|
||||
@@ -3,30 +3,25 @@ package extnet
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about external network
|
||||
type GetRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
}
|
||||
|
||||
func (erq GetRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets detailed information about external network
|
||||
func (e ExtNet) Get(ctx context.Context, req GetRequest) (*RecordExtNet, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/extnet/get"
|
||||
|
||||
@@ -3,30 +3,25 @@ package extnet
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list computes
|
||||
type ListComputesRequest struct {
|
||||
// Filter by account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (erq ListComputesRequest) validate() error {
|
||||
if erq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// ListComputes gets computes from account with extnets
|
||||
func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (ListExtNetComputes, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/extnet/listComputes"
|
||||
|
||||
@@ -2,38 +2,30 @@ package flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add compute instance
|
||||
type ComputeAddRequest struct {
|
||||
// ID of the Floating IP group to add compute instance to
|
||||
// Required: true
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId"`
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||
|
||||
// ID of the compute instance to add to this group
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (frq ComputeAddRequest) validate() error {
|
||||
if frq.FLIPGroupID == 0 {
|
||||
return errors.New("field FLIPGroupID can not be empty or equal to 0")
|
||||
}
|
||||
if frq.ComputeID == 0 {
|
||||
return errors.New("field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// ComputeAdd add compute instance to the Floating IP group
|
||||
func (f FLIPGroup) ComputeAdd(ctx context.Context, req ComputeAddRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/flipgroup/computeAdd"
|
||||
|
||||
@@ -2,38 +2,30 @@ package flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove compute instance
|
||||
type ComputeRemoveRequest struct {
|
||||
// ID of the Floating IP group to remove compute instance from
|
||||
// Required: true
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId"`
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||
|
||||
// ID of the compute instance to remove
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
}
|
||||
|
||||
func (frq ComputeRemoveRequest) validate() error {
|
||||
if frq.FLIPGroupID == 0 {
|
||||
return errors.New("field FLIPGroupID can not be empty or equal to 0")
|
||||
}
|
||||
if frq.ComputeID == 0 {
|
||||
return errors.New("field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// ComputeRemove remove compute instance from the Floating IP group
|
||||
func (f FLIPGroup) ComputeRemove(ctx context.Context, req ComputeRemoveRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/flipgroup/computeRemove"
|
||||
|
||||
@@ -3,7 +3,6 @@ package flipgroup
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
@@ -13,28 +12,28 @@ import (
|
||||
type CreateRequest struct {
|
||||
// Account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// FLIPGroup name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Network type
|
||||
// Should be one of:
|
||||
// - EXTNET
|
||||
// - VINS
|
||||
// Required: true
|
||||
NetType string `url:"netType" json:"netType"`
|
||||
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
|
||||
|
||||
// ID of external network or VINS
|
||||
// Required: true
|
||||
NetID uint64 `url:"netId" json:"netId"`
|
||||
NetID uint64 `url:"netId" json:"netId" validate:"required"`
|
||||
|
||||
// Type of client
|
||||
// - 'compute'
|
||||
// - 'vins' (will be later)
|
||||
// Required: true
|
||||
ClientType string `url:"clientType" json:"clientType"`
|
||||
ClientType string `url:"clientType" json:"clientType" validate:"flipgroupClientType"`
|
||||
|
||||
// IP address to associate with this group. If empty, the platform will autoselect IP address
|
||||
// Required: false
|
||||
@@ -45,33 +44,13 @@ type CreateRequest struct {
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (frq CreateRequest) validate() error {
|
||||
if frq.AccountID == 0 {
|
||||
return errors.New("field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
if frq.NetID == 0 {
|
||||
return errors.New("field NetID can not be empty or equal to 0")
|
||||
}
|
||||
if frq.Name == "" {
|
||||
return errors.New("field Name can not be empty")
|
||||
}
|
||||
validator := validators.StringInSlice(frq.NetType, []string{"EXTNET", "VINS"})
|
||||
if !validator {
|
||||
return errors.New("field Name can be only EXTNET or VINS")
|
||||
}
|
||||
validator = validators.StringInSlice(frq.ClientType, []string{"compute", "node"})
|
||||
if !validator {
|
||||
return errors.New("field Name can be only compute or node")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create method will create a new FLIPGorup in the specified Account
|
||||
func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGroup, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/flipgroup/create"
|
||||
|
||||
@@ -2,31 +2,26 @@ package flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete FLIPGroup
|
||||
type DeleteRequest struct {
|
||||
// FLIPGroup ID
|
||||
// Required: true
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId"`
|
||||
}
|
||||
|
||||
func (frq DeleteRequest) validate() error {
|
||||
if frq.FLIPGroupID == 0 {
|
||||
return errors.New("field FLIPGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||
}
|
||||
|
||||
// Delete method wil delete Floating IP group
|
||||
func (f FLIPGroup) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/flipgroup/delete"
|
||||
|
||||
@@ -2,39 +2,34 @@ package flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for edit FLIPGroup
|
||||
type EditRequest struct {
|
||||
// FLIPGroup ID
|
||||
// Required: true
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId"`
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||
|
||||
// FLIPGroup name
|
||||
// Required: true
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// FLIPGroup description
|
||||
// Required: true
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (frq EditRequest) validate() error {
|
||||
if frq.FLIPGroupID == 0 {
|
||||
return errors.New("field FLIPGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Edit edits FLIPGroup fields
|
||||
func (f FLIPGroup) Edit(ctx context.Context, req EditRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/flipgroup/edit"
|
||||
|
||||
@@ -3,30 +3,25 @@ package flipgroup
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get information about FLIPGroup
|
||||
type GetRequest struct {
|
||||
// FLIPGroup ID
|
||||
// Required: true
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId"`
|
||||
}
|
||||
|
||||
func (frq GetRequest) validate() error {
|
||||
if frq.FLIPGroupID == 0 {
|
||||
return errors.New("field FLIPGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets details of the specified Floating IP group
|
||||
func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*ItemFLIPGroup, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/flipgroup/get"
|
||||
|
||||
@@ -24,7 +24,7 @@ type CreateRequest struct {
|
||||
|
||||
// Boot type of image bios or UEFI
|
||||
// Required: true
|
||||
BootType string `url:"boottype" json:"boottype" validate:"required,bootType"`
|
||||
BootType string `url:"boottype" json:"boottype" validate:"required,imageBootType"`
|
||||
|
||||
// Image type
|
||||
// Should be:
|
||||
|
||||
@@ -3,29 +3,25 @@ package k8ci
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get information about K8CI
|
||||
type GetRequest struct {
|
||||
// ID of the K8 catalog item to get
|
||||
// Required: true
|
||||
K8CIID uint64 `url:"k8ciId" json:"k8ciId"`
|
||||
}
|
||||
|
||||
func (krq GetRequest) validate() error {
|
||||
if krq.K8CIID == 0 {
|
||||
return errors.New("field K8CIID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets details of the specified K8 catalog item
|
||||
func (k K8CI) Get(ctx context.Context, req GetRequest) (*RecordK8CI, error) {
|
||||
if err := req.validate(); err != nil {
|
||||
return nil, err
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8ci/get"
|
||||
|
||||
@@ -2,28 +2,29 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create kubernetes cluster
|
||||
type CreateRequest struct {
|
||||
// Name of Kubernetes cluster
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Resource Group ID for cluster placement
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// ID of Kubernetes catalog item (k8sci) for cluster
|
||||
// Required: true
|
||||
K8SCIID uint64 `url:"k8ciId" json:"k8ciId"`
|
||||
K8SCIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
|
||||
|
||||
// Name for first worker group created with cluster
|
||||
// Required: true
|
||||
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName"`
|
||||
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"`
|
||||
|
||||
// ID of SEP to create boot disks for master nodes. Uses images SEP ID if not set
|
||||
// Required: false
|
||||
@@ -102,28 +103,13 @@ type CreateRequest struct {
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateRequest) validate() error {
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.K8SCIID == 0 {
|
||||
return errors.New("validation-error: field K8SCIID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkerGroupName == "" {
|
||||
return errors.New("validation-error: field WorkerGroupName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates a new Kubernetes cluster in the specified Resource Group
|
||||
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/create"
|
||||
|
||||
@@ -2,36 +2,31 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete kubernetes cluster
|
||||
type DeleteRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// True if cluster is destroyed permanently.
|
||||
// Otherwise it can be restored from Recycle Bin
|
||||
// Required: true
|
||||
Permanently bool `url:"permanently" json:"permanently"`
|
||||
}
|
||||
|
||||
func (krq DeleteRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
Permanently bool `url:"permanently" json:"permanently" validate:"required"`
|
||||
}
|
||||
|
||||
// Delete deletes kubernetes cluster
|
||||
func (k8s K8S) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/delete"
|
||||
|
||||
@@ -2,45 +2,34 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete master from group
|
||||
type DeleteMasterFromGroupRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// ID of the masters compute group
|
||||
// Required: true
|
||||
MasterGroupID uint64 `url:"masterGroupId" json:"masterGroupId"`
|
||||
MasterGroupID uint64 `url:"masterGroupId" json:"masterGroupId" validate:"required"`
|
||||
|
||||
// List of Compute IDs of master nodes to delete
|
||||
// Required: true
|
||||
MasterIDs []string `url:"masterIds" json:"masterIds"`
|
||||
}
|
||||
|
||||
func (krq DeleteMasterFromGroupRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.MasterGroupID == 0 {
|
||||
return errors.New("validation-error: field MasterGroupID can not be empty or equal to 0")
|
||||
}
|
||||
if len(krq.MasterIDs) == 0 {
|
||||
return errors.New("validation-error: field MasterIDs can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
MasterIDs []string `url:"masterIds" json:"masterIds" validate:"min=1"`
|
||||
}
|
||||
|
||||
// DeleteMasterFromGroup deletes compute from masters group in selected Kubernetes cluster
|
||||
func (k8s K8S) DeleteMasterFromGroup(ctx context.Context, req DeleteMasterFromGroupRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/deleteMasterFromGroup"
|
||||
|
||||
@@ -2,45 +2,34 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete worker from group
|
||||
type DeleteWorkerFromGroupRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId"`
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||
|
||||
// Compute ID of worker node to delete
|
||||
// Required: true
|
||||
WorkerID uint64 `url:"workerId" json:"workerId"`
|
||||
}
|
||||
|
||||
func (krq DeleteWorkerFromGroupRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkerID == 0 {
|
||||
return errors.New("validation-error: field WorkerID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
WorkerID uint64 `url:"workerId" json:"workerId" validate:"required"`
|
||||
}
|
||||
|
||||
// DeleteWorkerFromGroup deletes worker compute from workers group in selected Kubernetes cluster
|
||||
func (k8s K8S) DeleteWorkerFromGroup(ctx context.Context, req DeleteWorkerFromGroupRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/deleteWorkerFromGroup"
|
||||
|
||||
@@ -2,31 +2,26 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable/enable kubernetes cluster
|
||||
type DisabelEnableRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq DisabelEnableRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables kubernetes cluster by ID
|
||||
func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/disable"
|
||||
@@ -46,9 +41,11 @@ func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest) (bool, err
|
||||
|
||||
// Enable enables kubernetes cluster by ID
|
||||
func (k8s K8S) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/enable"
|
||||
|
||||
@@ -3,42 +3,34 @@ package k8s
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get information about group of kubernetes cluster
|
||||
type FindGroupByLabelRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// List of labels to search
|
||||
// Required: true
|
||||
Labels []string `url:"labels" json:"labels"`
|
||||
Labels []string `url:"labels" json:"labels" validate:"min=1"`
|
||||
|
||||
// If true and more than one label provided, select only groups that have all provided labels.
|
||||
// If false - groups that have at least one label
|
||||
// Required: true
|
||||
Strict bool `url:"strict" json:"strict"`
|
||||
}
|
||||
|
||||
func (krq FindGroupByLabelRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if len(krq.Labels) == 0 {
|
||||
return errors.New("validation-error: field Labels can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
// Required: false
|
||||
Strict bool `url:"strict,omitempty" json:"strict,omitempty"`
|
||||
}
|
||||
|
||||
// FindGroupByLabel find worker group information by one on more labels
|
||||
func (k8s K8S) FindGroupByLabel(ctx context.Context, req FindGroupByLabelRequest) (ListK8SGroups, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/findGroupByLabel"
|
||||
|
||||
@@ -3,30 +3,25 @@ package k8s
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about kubernetes cluster
|
||||
type GetRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq GetRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets information about Kubernetes cluster
|
||||
func (k8s K8S) Get(ctx context.Context, req GetRequest) (*RecordK8S, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/get"
|
||||
|
||||
@@ -2,30 +2,25 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get configuration of kubernetes cluster
|
||||
type GetConfigRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq GetConfigRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
}
|
||||
|
||||
// GetConfig gets configuration data to access Kubernetes cluster
|
||||
func (k8s K8S) GetConfig(ctx context.Context, req GetConfigRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/getConfig"
|
||||
|
||||
@@ -2,37 +2,29 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get node annotations
|
||||
type GetNodeAnnotationsRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// Node ID
|
||||
// Required: true
|
||||
NodeID uint64 `url:"nodeId" json:"nodeId"`
|
||||
}
|
||||
|
||||
func (krq GetNodeAnnotationsRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.NodeID == 0 {
|
||||
return errors.New("validation-error: field NodeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
NodeID uint64 `url:"nodeId" json:"nodeId" validate:"required"`
|
||||
}
|
||||
|
||||
// GetNodeAnnotations gets kubernetes cluster worker node annotations
|
||||
func (k8s K8S) GetNodeAnnotations(ctx context.Context, req GetNodeAnnotationsRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/getNodeAnnotations"
|
||||
|
||||
@@ -2,37 +2,29 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get node labels
|
||||
type GetNodeLabelsRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// Node ID
|
||||
// Required: false
|
||||
NodeID uint64 `url:"nodeId" json:"nodeId"`
|
||||
}
|
||||
|
||||
func (krq GetNodeLabelsRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.NodeID == 0 {
|
||||
return errors.New("validation-error: field NodeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
// Required: true
|
||||
NodeID uint64 `url:"nodeId" json:"nodeId" validate:"required"`
|
||||
}
|
||||
|
||||
// GetNodeLabels gets kubernetes cluster worker node labels
|
||||
func (k8s K8S) GetNodeLabels(ctx context.Context, req GetNodeLabelsRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/getNodeLabels"
|
||||
|
||||
@@ -2,37 +2,29 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get node taints
|
||||
type GetNodeTaintsRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// Node ID
|
||||
// Required: false
|
||||
NodeID uint64 `url:"nodeId" json:"nodeId"`
|
||||
}
|
||||
|
||||
func (krq GetNodeTaintsRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.NodeID == 0 {
|
||||
return errors.New("validation-error: field NodeID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
// Required: true
|
||||
NodeID uint64 `url:"nodeId" json:"nodeId" validate:"required"`
|
||||
}
|
||||
|
||||
// GetNodeTaints gets kubernetes cluster worker node taints
|
||||
func (k8s K8S) GetNodeTaints(ctx context.Context, req GetNodeTaintsRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/getNodeTaints"
|
||||
|
||||
@@ -2,31 +2,26 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restore kubernetes cluster
|
||||
type RestoreRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq RestoreRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
}
|
||||
|
||||
// Restore restore kubernetes cluster from Recycle Bin
|
||||
func (k8s K8S) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/restore"
|
||||
|
||||
@@ -2,31 +2,26 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for start kubernetes cluster
|
||||
type StartRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq StartRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
}
|
||||
|
||||
// Start starts kubernetes cluster by ID
|
||||
func (k8s K8S) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/start"
|
||||
|
||||
@@ -2,31 +2,26 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for stop kubernetes cluster
|
||||
type StopRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq StopRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
}
|
||||
|
||||
// Stop stops kubernetes cluster by ID
|
||||
func (k8s K8S) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/stop"
|
||||
|
||||
@@ -2,16 +2,17 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update kubernetes cluster
|
||||
type UpdateRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// New name to set.
|
||||
// If empty string is passed, name is not updated
|
||||
@@ -24,19 +25,13 @@ type UpdateRequest struct {
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (krq UpdateRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates name or description of Kubernetes cluster
|
||||
func (k8s K8S) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/update"
|
||||
|
||||
@@ -2,45 +2,34 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add worker to a kubernetes cluster
|
||||
type WorkerAddRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId"`
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||
|
||||
// How many worker nodes to add
|
||||
// Required: true
|
||||
Num uint64 `url:"num" json:"num"`
|
||||
}
|
||||
|
||||
func (krq WorkerAddRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.Num == 0 {
|
||||
return errors.New("validation-error: field Num can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
Num uint64 `url:"num" json:"num" validate:"required"`
|
||||
}
|
||||
|
||||
// WorkerAdd add worker nodes to a Kubernetes cluster
|
||||
func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/workerAdd"
|
||||
|
||||
@@ -2,45 +2,34 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for hard reset kubernetes cluster
|
||||
type WorkerResetRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId"`
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||
|
||||
// Compute ID of worker node to reset
|
||||
// Required: true
|
||||
WorkerID uint64 `url:"workerId" json:"workerId"`
|
||||
}
|
||||
|
||||
func (krq WorkerResetRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkerID == 0 {
|
||||
return errors.New("validation-error: field WorkerID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
WorkerID uint64 `url:"workerId" json:"workerId" validate:"required"`
|
||||
}
|
||||
|
||||
// WorkerReset hard reset (compute start + stop) worker node of the Kubernetes cluster
|
||||
func (k8s K8S) WorkerReset(ctx context.Context, req WorkerResetRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/workerReset"
|
||||
|
||||
@@ -2,45 +2,34 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restart worker node
|
||||
type WorkerRestartRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId"`
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||
|
||||
// Compute ID of worker node to restart
|
||||
// Required: true
|
||||
WorkerID uint64 `url:"workerId" json:"workerId"`
|
||||
}
|
||||
|
||||
func (krq WorkerRestartRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkerID == 0 {
|
||||
return errors.New("validation-error: field WorkerID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
WorkerID uint64 `url:"workerId" json:"workerId" validate:"required"`
|
||||
}
|
||||
|
||||
// WorkerRestart soft restart (reboot OS) worker node of the Kubernetes cluster
|
||||
func (k8s K8S) WorkerRestart(ctx context.Context, req WorkerRestartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/workerRestart"
|
||||
|
||||
@@ -2,20 +2,21 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add workers group
|
||||
type WorkersGroupAddRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// Worker group name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// ID of SEP to create boot disks for default worker nodes group. Uses images SEP ID if not set
|
||||
// Required: false
|
||||
@@ -57,21 +58,13 @@ type WorkersGroupAddRequest struct {
|
||||
WorkerDisk uint64 `url:"workerDisk,omitempty" json:"workerDisk,omitempty"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupAddRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkersGroupAdd adds workers group to Kubernetes cluster
|
||||
func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/workersGroupAdd"
|
||||
|
||||
@@ -2,38 +2,30 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete workers group
|
||||
type WorkersGroupDeleteRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// Worker group ID
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupDeleteRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||
}
|
||||
|
||||
// WorkersGroupDelete deletes workers group from Kubernetes cluster
|
||||
func (k8s K8S) WorkersGroupDelete(ctx context.Context, req WorkersGroupDeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/workersGroupDelete"
|
||||
|
||||
@@ -3,37 +3,29 @@ package k8s
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get information about worker group
|
||||
type WorkersGroupGetByNameRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId"`
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
|
||||
// Worker group name
|
||||
// Required: true
|
||||
GroupName string `url:"groupName" json:"groupName"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupGetByNameRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.GroupName == "" {
|
||||
return errors.New("validation-error: field WorkersGroupID can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
GroupName string `url:"groupName" json:"groupName" validate:"required"`
|
||||
}
|
||||
|
||||
// WorkersGroupGetByName gets worker group metadata by name
|
||||
func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*RecordK8SGroups, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/k8s/workersGroupGetByName"
|
||||
|
||||
@@ -2,34 +2,35 @@ package kvmppc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create KVM PowerPC VM
|
||||
type CreateRequest struct {
|
||||
// ID of the resource group, which will own this VM
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Name of this VM.
|
||||
// Must be unique among all VMs (including those in DELETED state) in target resource group
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Number CPUs to allocate to this VM
|
||||
// Required: true
|
||||
CPU uint64 `url:"cpu" json:"cpu"`
|
||||
CPU uint64 `url:"cpu" json:"cpu" validate:"required"`
|
||||
|
||||
// Volume of RAM in MB to allocate to this VM
|
||||
// Required: true
|
||||
RAM uint64 `url:"ram" json:"ram"`
|
||||
RAM uint64 `url:"ram" json:"ram" validate:"required"`
|
||||
|
||||
// ID of the OS image to base this VM on;
|
||||
// Could be boot disk image or CD-ROM image
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId"`
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// Size of the boot disk in GB
|
||||
// Required: false
|
||||
@@ -50,7 +51,7 @@ type CreateRequest struct {
|
||||
// - EXTNET
|
||||
// - NONE
|
||||
// Required: false
|
||||
NetType string `url:"netType,omitempty" json:"netType,omitempty"`
|
||||
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"`
|
||||
|
||||
// Network ID for connect to,
|
||||
// for EXTNET - external network ID,
|
||||
@@ -84,31 +85,13 @@ type CreateRequest struct {
|
||||
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateRequest) validate() error {
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if krq.CPU == 0 {
|
||||
return errors.New("validation-error: field CPU can not be empty or equal to 0")
|
||||
}
|
||||
if krq.RAM == 0 {
|
||||
return errors.New("validation-error: field RAM can not be empty or equal to 0")
|
||||
}
|
||||
if krq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates KVM PowerPC VM based on specified OS image
|
||||
func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/kvmppc/create"
|
||||
|
||||
@@ -2,42 +2,43 @@ package kvmppc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create KVM PowerPC VM from scratch
|
||||
type CreateBlankRequest struct {
|
||||
// ID of the resource group, which will own this VM
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Name of this VM.
|
||||
// Must be unique among all VMs (including those in DELETED state) in target resource group
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Number CPUs to allocate to this VM
|
||||
// Required: true
|
||||
CPU uint64 `url:"cpu" json:"cpu"`
|
||||
CPU uint64 `url:"cpu" json:"cpu" validate:"required"`
|
||||
|
||||
// Volume of RAM in MB to allocate to this VM
|
||||
// Required: true
|
||||
RAM uint64 `url:"ram" json:"ram"`
|
||||
RAM uint64 `url:"ram" json:"ram" validate:"required"`
|
||||
|
||||
// Size of the boot disk in GB
|
||||
// Required: true
|
||||
BootDisk uint64 `url:"bootDisk" json:"bootDisk"`
|
||||
BootDisk uint64 `url:"bootDisk" json:"bootDisk" validate:"required"`
|
||||
|
||||
// ID of SEP to create boot disk on.
|
||||
// Uses images SEP ID if not set
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sepId" json:"sepId"`
|
||||
SEPID uint64 `url:"sepId" json:"sepId" validate:"required"`
|
||||
|
||||
// Pool to use if SEP ID is set, can be also empty if needed to be chosen by system
|
||||
// Required: true
|
||||
Pool string `url:"pool" json:"pool"`
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
|
||||
// Network type
|
||||
// Should be one of:
|
||||
@@ -45,7 +46,7 @@ type CreateBlankRequest struct {
|
||||
// - EXTNET
|
||||
// - NONE
|
||||
// Required: false
|
||||
NetType string `url:"netType,omitempty" json:"netType,omitempty"`
|
||||
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"`
|
||||
|
||||
// Network ID for connect to,
|
||||
// for EXTNET - external network ID,
|
||||
@@ -63,37 +64,13 @@ type CreateBlankRequest struct {
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateBlankRequest) validate() error {
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if krq.CPU == 0 {
|
||||
return errors.New("validation-error: field CPU can not be empty or equal to 0")
|
||||
}
|
||||
if krq.RAM == 0 {
|
||||
return errors.New("validation-error: field RAM can not be empty or equal to 0")
|
||||
}
|
||||
if krq.BootDisk == 0 {
|
||||
return errors.New("validation-error: field BootDisk can not be empty or equal to 0")
|
||||
}
|
||||
if krq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SepID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.Pool == "" {
|
||||
return errors.New("validation-error: field Pool can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateBlank creates KVM PowerPC VM from scratch
|
||||
func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/kvmppc/createBlank"
|
||||
|
||||
@@ -2,34 +2,35 @@ package kvmx86
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create KVM x86 VM
|
||||
type CreateRequest struct {
|
||||
// ID of the resource group, which will own this VM
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Name of this VM.
|
||||
// Must be unique among all VMs (including those in DELETED state) in target resource group
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Number CPUs to allocate to this VM
|
||||
// Required: true
|
||||
CPU uint64 `url:"cpu" json:"cpu"`
|
||||
CPU uint64 `url:"cpu" json:"cpu" validate:"required"`
|
||||
|
||||
// Volume of RAM in MB to allocate to this VM
|
||||
// Required: true
|
||||
RAM uint64 `url:"ram" json:"ram"`
|
||||
RAM uint64 `url:"ram" json:"ram" validate:"required"`
|
||||
|
||||
// ID of the OS image to base this VM on;
|
||||
// Could be boot disk image or CD-ROM image
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId"`
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// Size of the boot disk in GB
|
||||
// Required: false
|
||||
@@ -50,7 +51,7 @@ type CreateRequest struct {
|
||||
// - EXTNET
|
||||
// - NONE
|
||||
// Required: false
|
||||
NetType string `url:"netType,omitempty" json:"netType,omitempty"`
|
||||
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"`
|
||||
|
||||
// Network ID for connect to,
|
||||
// for EXTNET - external network ID,
|
||||
@@ -84,31 +85,13 @@ type CreateRequest struct {
|
||||
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateRequest) validate() error {
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if krq.CPU == 0 {
|
||||
return errors.New("validation-error: field CPU can not be empty or equal to 0")
|
||||
}
|
||||
if krq.RAM == 0 {
|
||||
return errors.New("validation-error: field RAM can not be empty or equal to 0")
|
||||
}
|
||||
if krq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates KVM x86 VM based on specified OS image
|
||||
func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/kvmx86/create"
|
||||
|
||||
@@ -2,42 +2,43 @@ package kvmx86
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create KVM x86 VM from scratch
|
||||
type CreateBlankRequest struct {
|
||||
// ID of the resource group, which will own this VM
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Name of this VM.
|
||||
// Must be unique among all VMs (including those in DELETED state) in target resource group
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Number CPUs to allocate to this VM
|
||||
// Required: true
|
||||
CPU uint64 `url:"cpu" json:"cpu"`
|
||||
CPU uint64 `url:"cpu" json:"cpu" validate:"required"`
|
||||
|
||||
// Volume of RAM in MB to allocate to this VM
|
||||
// Required: true
|
||||
RAM uint64 `url:"ram" json:"ram"`
|
||||
RAM uint64 `url:"ram" json:"ram" validate:"required"`
|
||||
|
||||
// Size of the boot disk in GB
|
||||
// Required: true
|
||||
BootDisk uint64 `url:"bootDisk" json:"bootDisk"`
|
||||
BootDisk uint64 `url:"bootDisk" json:"bootDisk" validate:"required"`
|
||||
|
||||
// ID of SEP to create boot disk on.
|
||||
// Uses images SEP ID if not set
|
||||
// Required: true
|
||||
SEPID uint64 `url:"sepId" json:"sepId"`
|
||||
SEPID uint64 `url:"sepId" json:"sepId" validate:"required"`
|
||||
|
||||
// Pool to use if sepId is set, can be also empty if needed to be chosen by system
|
||||
// Required: true
|
||||
Pool string `url:"pool" json:"pool"`
|
||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||
|
||||
// Network type
|
||||
// Should be one of:
|
||||
@@ -45,7 +46,7 @@ type CreateBlankRequest struct {
|
||||
// - EXTNET
|
||||
// - NONE
|
||||
// Required: false
|
||||
NetType string `url:"netType,omitempty" json:"netType,omitempty"`
|
||||
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"`
|
||||
|
||||
// Network ID for connect to,
|
||||
// for EXTNET - external network ID,
|
||||
@@ -63,37 +64,13 @@ type CreateBlankRequest struct {
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateBlankRequest) validate() error {
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if krq.CPU == 0 {
|
||||
return errors.New("validation-error: field CPU can not be empty or equal to 0")
|
||||
}
|
||||
if krq.RAM == 0 {
|
||||
return errors.New("validation-error: field RAM can not be empty or equal to 0")
|
||||
}
|
||||
if krq.BootDisk == 0 {
|
||||
return errors.New("validation-error: field BootDisk can not be empty or equal to 0")
|
||||
}
|
||||
if krq.SEPID == 0 {
|
||||
return errors.New("validation-error: field SepID can not be empty or equal to 0")
|
||||
}
|
||||
if krq.Pool == "" {
|
||||
return errors.New("validation-error: field Pool can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateBlank creates KVM x86 VM from scratch
|
||||
func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/kvmx86/createBlank"
|
||||
|
||||
@@ -2,20 +2,21 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create backend
|
||||
type BackendCreateRequest struct {
|
||||
// ID of the load balancer instance to backendCreate
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must be unique among all backends of this load balancer - name of the new backend to create
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName"`
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Algorithm
|
||||
// Should be one of:
|
||||
@@ -23,7 +24,7 @@ type BackendCreateRequest struct {
|
||||
// - static-rr
|
||||
// - leastconn
|
||||
// Required: false
|
||||
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty"`
|
||||
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty" validate:"omitempty,lbAlgorithm"`
|
||||
|
||||
// Interval in milliseconds between two consecutive availability
|
||||
// checks of the server that is considered available
|
||||
@@ -66,22 +67,13 @@ type BackendCreateRequest struct {
|
||||
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq BackendCreateRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// BackendCreate creates new backend on the specified load balancer
|
||||
func (l LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendCreate"
|
||||
|
||||
@@ -2,39 +2,31 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete backend
|
||||
type BackendDeleteRequest struct {
|
||||
// ID of the load balancer instance to BackendDelete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Cannot be emtpy string - name of the backend to delete
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName"`
|
||||
}
|
||||
|
||||
func (lbrq BackendDeleteRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
}
|
||||
|
||||
// BackendDelete deletes backend from the specified load balancer.
|
||||
// Warning: you cannot undo this action!
|
||||
func (l LB) BackendDelete(ctx context.Context, req BackendDeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendDelete"
|
||||
|
||||
@@ -2,32 +2,33 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add server definition to the backend
|
||||
type BackendServerAddRequest struct {
|
||||
// ID of the load balancer instance to BackendServerAdd
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must match one of the existing backens - name of the backend to add servers to
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName"`
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Must be unique among all servers defined for this backend - name of the server definition to add
|
||||
// Required: true
|
||||
ServerName string `url:"serverName" json:"serverName"`
|
||||
ServerName string `url:"serverName" json:"serverName" validate:"required"`
|
||||
|
||||
// IP address of the server
|
||||
// Required: true
|
||||
Address string `url:"address" json:"address"`
|
||||
Address string `url:"address" json:"address" validate:"required"`
|
||||
|
||||
// Port number on the server
|
||||
// Required: true
|
||||
Port uint64 `url:"port" json:"port"`
|
||||
Port uint64 `url:"port" json:"port" validate:"required"`
|
||||
|
||||
// Set to disabled if this server should be used regardless of its state
|
||||
// Required: false
|
||||
@@ -71,31 +72,13 @@ type BackendServerAddRequest struct {
|
||||
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq BackendServerAddRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
if lbrq.ServerName == "" {
|
||||
return errors.New("validation-error: field ServerName can not be empty")
|
||||
}
|
||||
if lbrq.Address == "" {
|
||||
return errors.New("validation-error: field Address can not be empty")
|
||||
}
|
||||
if lbrq.Port == 0 {
|
||||
return errors.New("validation-error: field Port can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// BackendServerAdd adds server definition to the backend on the specified load balancer
|
||||
func (l LB) BackendServerAdd(ctx context.Context, req BackendServerAddRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendServerAdd"
|
||||
|
||||
@@ -2,46 +2,35 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete server definition
|
||||
type BackendServerDeleteRequest struct {
|
||||
// ID of the load balancer instance to BackendServerDelete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must match one of the existing backens - name of the backend to add servers to
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName"`
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Must be unique among all servers defined for this backend - name of the server definition to add
|
||||
// Required: true
|
||||
ServerName string `url:"serverName" json:"serverName"`
|
||||
}
|
||||
|
||||
func (lbrq BackendServerDeleteRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
if lbrq.ServerName == "" {
|
||||
return errors.New("validation-error: field ServerName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
ServerName string `url:"serverName" json:"serverName" validate:"required"`
|
||||
}
|
||||
|
||||
// BackendServerDelete deletes server definition from the backend on the specified load balancer.
|
||||
// Warning: you cannot undo this action!
|
||||
func (l LB) BackendServerDelete(ctx context.Context, req BackendServerDeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendServerDelete"
|
||||
|
||||
@@ -2,32 +2,33 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update server
|
||||
type BackendServerUpdateRequest struct {
|
||||
// ID of the load balancer instance to BackendServerAdd
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must match one of the existing backens - name of the backend to add servers to
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName"`
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Must be unique among all servers defined for this backend - name of the server definition to add
|
||||
// Required: true
|
||||
ServerName string `url:"serverName" json:"serverName"`
|
||||
ServerName string `url:"serverName" json:"serverName" validate:"required"`
|
||||
|
||||
// IP address of the server
|
||||
// Required: true
|
||||
Address string `url:"address" json:"address"`
|
||||
Address string `url:"address" json:"address" validate:"required"`
|
||||
|
||||
// Port number on the server
|
||||
// Required: true
|
||||
Port uint64 `url:"port" json:"port"`
|
||||
Port uint64 `url:"port" json:"port" validate:"required"`
|
||||
|
||||
// Set to disabled if this server should be used regardless of its state
|
||||
// Required: false
|
||||
@@ -71,31 +72,13 @@ type BackendServerUpdateRequest struct {
|
||||
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq BackendServerUpdateRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
if lbrq.ServerName == "" {
|
||||
return errors.New("validation-error: field ServerName can not be empty")
|
||||
}
|
||||
if lbrq.Address == "" {
|
||||
return errors.New("validation-error: field Address can not be empty")
|
||||
}
|
||||
if lbrq.Port == 0 {
|
||||
return errors.New("validation-error: field Port can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// BackendServerUpdate updates server definition on the backend of load balancer
|
||||
func (l LB) BackendServerUpdate(ctx context.Context, req BackendServerUpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendServerUpdate"
|
||||
|
||||
@@ -2,20 +2,21 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update backend
|
||||
type BackendUpdateRequest struct {
|
||||
// ID of the load balancer instance to backendCreate
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must be unique among all backends of this load balancer - name of the new backend to create
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName"`
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Algorithm
|
||||
// Should be one of:
|
||||
@@ -23,7 +24,7 @@ type BackendUpdateRequest struct {
|
||||
// - static-rr
|
||||
// - leastconn
|
||||
// Required: false
|
||||
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty"`
|
||||
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty" validate:"omitempty,lbAlgorithm"`
|
||||
|
||||
// Interval in milliseconds between two consecutive availability
|
||||
// checks of the server that is considered available
|
||||
@@ -66,22 +67,13 @@ type BackendUpdateRequest struct {
|
||||
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq BackendUpdateRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// BackendUpdate updates existing backend on the specified load balancer. Note that backend name cannot be changed
|
||||
func (l LB) BackendUpdate(ctx context.Context, req BackendUpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/backendUpdate"
|
||||
|
||||
@@ -2,32 +2,27 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for reset config
|
||||
type ConfigResetRequest struct {
|
||||
// ID of the load balancer instance to ConfigReset
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq ConfigResetRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigReset reset current software configuration of the specified load balancer.
|
||||
// Warning: this action cannot be undone!
|
||||
func (l LB) ConfigReset(ctx context.Context, req ConfigResetRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/configReset"
|
||||
|
||||
@@ -2,61 +2,47 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create load balancer
|
||||
type CreateRequest struct {
|
||||
// ID of the resource group where this load balancer instance will be located
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Name of the load balancer.
|
||||
// Must be unique among all load balancers in this Resource Group
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// External network to connect this load balancer to
|
||||
// Required: true
|
||||
ExtNetID uint64 `url:"extnetId" json:"extnetId"`
|
||||
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||
|
||||
// Internal network (VINS) to connect this load balancer to
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId"`
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||
|
||||
// Start now Load balancer
|
||||
// Required: false
|
||||
Start bool `url:"start" json:"start"`
|
||||
// Required: true
|
||||
Start bool `url:"start" json:"start" validate:"required"`
|
||||
|
||||
// Text description of this load balancer
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq CreateRequest) validate() error {
|
||||
if lbrq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if lbrq.ExtNetID == 0 {
|
||||
return errors.New("validation-error: field ExtNetID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create method will create a new load balancer instance
|
||||
func (l LB) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/create"
|
||||
|
||||
@@ -2,35 +2,30 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete load balancer
|
||||
type DeleteRequest struct {
|
||||
// ID of the load balancer instance to delete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Set to true to delete load balancer immediately bypassing recycle bin
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq DeleteRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes specified load balancer
|
||||
func (l LB) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/delete"
|
||||
|
||||
@@ -2,31 +2,26 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable/enable load balancer
|
||||
type DisableEnableRequest struct {
|
||||
// ID of the load balancer instance to disable/enable
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq DisableEnableRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables specified load balancer instance
|
||||
func (l LB) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/disable"
|
||||
@@ -46,9 +41,11 @@ func (l LB) Disable(ctx context.Context, req DisableEnableRequest) (bool, error)
|
||||
|
||||
// Enable enables specified load balancer instance
|
||||
func (l LB) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/enable"
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
)
|
||||
|
||||
// FilterByID returns ListLB with specified ID.
|
||||
func (ll ListLB) FilterByID(id uint64) ListLB {
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
@@ -36,6 +43,26 @@ func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
|
||||
return ll.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByK8SID returns ListLB used by specified K8S cluster.
|
||||
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListLB, error) {
|
||||
caller := k8s.New(decortClient)
|
||||
|
||||
req := k8s.GetRequest{
|
||||
K8SID: k8sID,
|
||||
}
|
||||
|
||||
cluster, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
predicate := func(ill ItemLoadBalancer) bool {
|
||||
return cluster.LBID == ill.ID
|
||||
}
|
||||
|
||||
return ll.FilterFunc(predicate), nil
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListLB based on a user-specified predicate.
|
||||
func (ll ListLB) FilterFunc(predicate func(ItemLoadBalancer) bool) ListLB {
|
||||
var result ListLB
|
||||
|
||||
@@ -2,20 +2,21 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for frontend bind
|
||||
type FrontendBindRequest struct {
|
||||
// ID of the load balancer instance to FrontendBind
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Name of the frontend to update
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName"`
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
|
||||
// Name of the binding to update
|
||||
// Required: true
|
||||
@@ -33,25 +34,13 @@ type FrontendBindRequest struct {
|
||||
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendBindRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
if lbrq.BindingName == "" {
|
||||
return errors.New("validation-error: field BindingName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FrontendBind bind frontend from specified load balancer instance
|
||||
func (l LB) FrontendBind(ctx context.Context, req FrontendBindRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendBind"
|
||||
|
||||
@@ -2,45 +2,34 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete bind
|
||||
type FrontendBindDeleteRequest struct {
|
||||
// ID of the load balancer instance to FrontendBindDelete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Name of the frontend to delete
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName"`
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
|
||||
// Name of the binding to delete
|
||||
// Required: true
|
||||
BindingName string `url:"bindingName" json:"bindingName"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendBindDeleteRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
if lbrq.BindingName == "" {
|
||||
return errors.New("validation-error: field BindingName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
BindingName string `url:"bindingName" json:"bindingName" validate:"required"`
|
||||
}
|
||||
|
||||
// FrontendBindDelete deletes binding from the specified load balancer frontend
|
||||
func (l LB) FrontendBindDelete(ctx context.Context, req FrontendBindDeleteRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendBindDelete"
|
||||
|
||||
@@ -2,24 +2,25 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update binding
|
||||
type FrontendBindUpdateRequest struct {
|
||||
// ID of the load balancer instance to FrontendBindUpdate
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Name of the frontend to update
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName"`
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
|
||||
// Name of the binding to update
|
||||
// Required: true
|
||||
BindingName string `url:"bindingName" json:"bindingName"`
|
||||
BindingName string `url:"bindingName" json:"bindingName" validate:"required"`
|
||||
|
||||
// If specified must be within the IP range of either Ext Net or ViNS,
|
||||
// where this load balancer is connected - new IP address to use for this binding.
|
||||
@@ -33,25 +34,13 @@ type FrontendBindUpdateRequest struct {
|
||||
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendBindUpdateRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
if lbrq.BindingName == "" {
|
||||
return errors.New("validation-error: field BindingName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FrontendBindUpdate updates binding for the specified load balancer frontend
|
||||
func (l LB) FrontendBindUpdate(ctx context.Context, req FrontendBindUpdateRequest) (string, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendBindingUpdate"
|
||||
|
||||
@@ -2,47 +2,36 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create frontend
|
||||
type FrontendCreateRequest struct {
|
||||
// ID of the load balancer instance to FrontendCreate
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must be unique among all frontends of
|
||||
// this load balancer - name of the new frontend to create
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName"`
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
|
||||
// Should be one of the backends existing on
|
||||
// this load balancer - name of the backend to use
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendCreateRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
}
|
||||
|
||||
// FrontendCreate creates new frontend on the specified load balancer
|
||||
func (l LB) FrontendCreate(ctx context.Context, req FrontendCreateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendCreate"
|
||||
|
||||
@@ -2,39 +2,31 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete frontend
|
||||
type FrontendDeleteRequest struct {
|
||||
// ID of the load balancer instance to FrontendDelete
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Name of the frontend to delete
|
||||
// Required: true
|
||||
FrontendName string `url:"frontendName" json:"frontendName"`
|
||||
}
|
||||
|
||||
func (lbrq FrontendDeleteRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.FrontendName == "" {
|
||||
return errors.New("validation-error: field FrontendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
|
||||
}
|
||||
|
||||
// FrontendDelete deletes frontend from the specified load balancer.
|
||||
// Warning: you cannot undo this action!
|
||||
func (l LB) FrontendDelete(ctx context.Context, req FrontendDeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/frontendDelete"
|
||||
|
||||
@@ -3,30 +3,25 @@ package lb
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about load balancer
|
||||
type GetRequest struct {
|
||||
// ID of the load balancer to get details for
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq GetRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets detailed information about load balancer
|
||||
func (l LB) Get(ctx context.Context, req GetRequest) (*RecordLB, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/get"
|
||||
|
||||
@@ -2,31 +2,26 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restart load balancer
|
||||
type RestartRequest struct {
|
||||
// ID of the load balancer instance to restart
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq RestartRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Restart restarts specified load balancer instance
|
||||
func (l LB) Restart(ctx context.Context, req RestartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/restart"
|
||||
|
||||
@@ -2,31 +2,26 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restore load balancer
|
||||
type RestoreRequest struct {
|
||||
// ID of the load balancer instance to restore
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq RestoreRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Restore restore load balancer from recycle bin
|
||||
func (l LB) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/restore"
|
||||
|
||||
@@ -2,31 +2,26 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for start load balancer
|
||||
type StartRequest struct {
|
||||
// ID of the load balancer instance to start
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq StartRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Start starts specified load balancer instance
|
||||
func (l LB) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/start"
|
||||
|
||||
@@ -2,31 +2,26 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for stop load balancer
|
||||
type StopRequest struct {
|
||||
// ID of the load balancer instance to stop
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
}
|
||||
|
||||
func (lbrq StopRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
}
|
||||
|
||||
// Stop stops specified load balancer instance
|
||||
func (l LB) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/start"
|
||||
|
||||
@@ -2,39 +2,31 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update load balancer
|
||||
type UpdateRequest struct {
|
||||
// ID of the load balancer to update
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// New description of this load balancer.
|
||||
// If omitted, current description is retained
|
||||
// Required: true
|
||||
Description string `url:"desc" json:"desc"`
|
||||
}
|
||||
|
||||
func (lbrq UpdateRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.Description == "" {
|
||||
return errors.New("validation-error: field Description can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
Description string `url:"desc" json:"desc" validate:"required"`
|
||||
}
|
||||
|
||||
// Update updates some of load balancer attributes
|
||||
func (l LB) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/lb/update"
|
||||
|
||||
@@ -2,7 +2,6 @@ package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,44 +12,31 @@ import (
|
||||
type AccessGrantRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// User or group name to grant access
|
||||
// Required: true
|
||||
User string `url:"user" json:"user"`
|
||||
User string `url:"user" json:"user" validate:"required"`
|
||||
|
||||
// Access rights to set, one of:
|
||||
// - "R"
|
||||
// - "RCX"
|
||||
// - "ARCXDU"
|
||||
// Required: true
|
||||
Right string `url:"right" json:"right"`
|
||||
Right string `url:"right" json:"right" validate:"accessType"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq AccessGrantRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if rgrq.User == "" {
|
||||
return errors.New("field User can not be empty")
|
||||
}
|
||||
validate := validators.StringInSlice(rgrq.Right, []string{"R", "RCX", "ARCXDU"})
|
||||
if !validate {
|
||||
return errors.New("field Right can only be one of 'R', 'RCX' or 'ARCXDU'")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessGrant grants user or group access to the resource group as specified
|
||||
func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/accessGrant"
|
||||
|
||||
@@ -2,42 +2,34 @@ package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for revoke access
|
||||
type AccessRevokeRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// User or group name to revoke access
|
||||
// Required: true
|
||||
User string `url:"user" json:"user"`
|
||||
User string `url:"user" json:"user" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq AccessRevokeRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if rgrq.User == "" {
|
||||
return errors.New("field User can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessRevoke revokes specified user or group access from the resource group
|
||||
func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/accessRevoke"
|
||||
|
||||
@@ -3,37 +3,29 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list of all computes with their relationships
|
||||
type AffinityGroupComputesRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Affinity group label
|
||||
// Required: true
|
||||
AffinityGroup string `url:"affinityGroup" json:"affinityGroup"`
|
||||
}
|
||||
|
||||
func (rgrq AffinityGroupComputesRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if rgrq.AffinityGroup == "" {
|
||||
return errors.New("field AffinityGroup cat not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
AffinityGroup string `url:"affinityGroup" json:"affinityGroup" validate:"required"`
|
||||
}
|
||||
|
||||
// AffinityGroupComputes gets list of all computes with their relationships to another computes
|
||||
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (ListAffinityGroups, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/affinityGroupComputes"
|
||||
|
||||
@@ -3,37 +3,29 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list computes from affinity group
|
||||
type AffinityGroupsGetRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Label affinity group
|
||||
// Required: true
|
||||
AffinityGroup string `url:"affinityGroup" json:"affinityGroup"`
|
||||
}
|
||||
|
||||
func (rgrq AffinityGroupsGetRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if rgrq.AffinityGroup == "" {
|
||||
return errors.New("field AffinityGroup cat not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
AffinityGroup string `url:"affinityGroup" json:"affinityGroup" validate:"required"`
|
||||
}
|
||||
|
||||
// AffinityGroupsGet gets list computes in the specified affinity group
|
||||
func (r RG) AffinityGroupsGet(ctx context.Context, req AffinityGroupsGetRequest) ([]uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/affinityGroupsGet"
|
||||
|
||||
@@ -3,30 +3,25 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list of affinity groups from resource group
|
||||
type AffinityGroupsListRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
}
|
||||
|
||||
func (rgrq AffinityGroupsListRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs
|
||||
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (map[string][]uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/affinityGroupsList"
|
||||
|
||||
@@ -3,30 +3,25 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get audit
|
||||
type AuditsRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
}
|
||||
|
||||
func (rgrq AuditsRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// Audits gets audit records for the specified resource group object
|
||||
func (r RG) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/audits"
|
||||
|
||||
@@ -2,24 +2,25 @@ package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create resource group
|
||||
type CreateRequest struct {
|
||||
// Account, which will own this resource group
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
|
||||
// Grid ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid"`
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// Name of this resource group. Must be unique within the account
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required,min=2"`
|
||||
|
||||
// Max size of memory in MB
|
||||
// Required: false
|
||||
@@ -53,7 +54,7 @@ type CreateRequest struct {
|
||||
// - PUBLIC
|
||||
// - NONE
|
||||
// Required: false
|
||||
DefNet string `url:"def_net,omitempty" json:"def_net,omitempty"`
|
||||
DefNet string `url:"def_net,omitempty" json:"def_net,omitempty" validate:"omitempty,rgDefNet"`
|
||||
|
||||
// Private network IP CIDR if default network PRIVATE
|
||||
// Required: false
|
||||
@@ -80,25 +81,13 @@ type CreateRequest struct {
|
||||
RegisterComputes bool `url:"registerComputes,omitempty" json:"registerComputes,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq CreateRequest) validate() error {
|
||||
if rgrq.AccountID == 0 {
|
||||
return errors.New("field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
if rgrq.GID == 0 {
|
||||
return errors.New("field GID can not be empty or equal to 0")
|
||||
}
|
||||
if len(rgrq.Name) < 2 {
|
||||
return errors.New("field Name can not be shorter than two bytes")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates resource group
|
||||
func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/create"
|
||||
|
||||
@@ -2,16 +2,17 @@ package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete resource group
|
||||
type DeleteRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Set to True if you want force delete non-empty resource group
|
||||
// Required: false
|
||||
@@ -27,19 +28,13 @@ type DeleteRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq DeleteRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes resource group
|
||||
func (r RG) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/delete"
|
||||
|
||||
@@ -2,35 +2,30 @@ package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable resource group
|
||||
type DisableRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq DisableRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable disables resource group
|
||||
func (r RG) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/disable"
|
||||
|
||||
@@ -2,35 +2,30 @@ package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for enable resource group
|
||||
type EnableRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq EnableRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enable enables resource group
|
||||
func (r RG) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/enable"
|
||||
|
||||
@@ -3,34 +3,29 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about resource group
|
||||
type GetRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq GetRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get gets current configuration of the resource group
|
||||
func (r RG) Get(ctx context.Context, req GetRequest) (*RecordResourceGroup, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/get"
|
||||
|
||||
@@ -3,34 +3,29 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list of computes
|
||||
type ListComputesRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq ListComputesRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listComputes"
|
||||
|
||||
@@ -3,30 +3,25 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list load balancers
|
||||
type ListLBRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
}
|
||||
|
||||
func (rgrq ListLBRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// 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 := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listLb"
|
||||
|
||||
@@ -3,30 +3,25 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list port forward rules
|
||||
type ListPFWRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
}
|
||||
|
||||
func (rgrq ListPFWRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
}
|
||||
|
||||
// ListPFW gets list port forward rules for the specified resource group
|
||||
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPortForwards, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listPFW"
|
||||
|
||||
@@ -3,34 +3,29 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list VINSes
|
||||
type ListVINSRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq ListVINSRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/listVins"
|
||||
|
||||
@@ -2,35 +2,30 @@ package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restore resource group
|
||||
type RestoreRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq RestoreRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Restore restores resource group from recycle bin
|
||||
func (r RG) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/restore"
|
||||
|
||||
@@ -2,7 +2,6 @@ package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -13,40 +12,31 @@ import (
|
||||
type SetDefNetRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Network type
|
||||
// Should be one of:
|
||||
// - "PUBLIC"
|
||||
// - "PRIVATE"
|
||||
// Required: true
|
||||
NetType string `url:"netType" json:"netType"`
|
||||
NetType string `url:"netType" json:"netType" validate:"rgNetType"`
|
||||
|
||||
// Network ID
|
||||
// Required: false
|
||||
NetID uint64 `url:"netId" json:"netId"`
|
||||
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq SetDefNetRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
if !validators.StringInSlice(rgrq.NetType, []string{"PUBLIC", "PRIVATE"}) {
|
||||
return errors.New("field NetType can only be one of 'PUBLIC' or 'PRIVATE'")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetDefNet sets default network for attach associated virtual machines
|
||||
func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/setDefNet"
|
||||
|
||||
@@ -2,16 +2,17 @@ package rg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update resource group
|
||||
type UpdateRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// New name
|
||||
// Required: false
|
||||
@@ -50,19 +51,13 @@ type UpdateRequest struct {
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq UpdateRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates resource group
|
||||
func (r RG) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/update"
|
||||
|
||||
@@ -3,34 +3,29 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get report of resource usage
|
||||
type UsageRequest struct {
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId" json:"rgId"`
|
||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq UsageRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Usage gets report resource usage on the resource group
|
||||
func (r RG) Usage(ctx context.Context, req UsageRequest) (*RecordResourceUsage, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/rg/usage"
|
||||
|
||||
@@ -3,30 +3,25 @@ package tasks
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get infromation about task
|
||||
type GetRequest struct {
|
||||
// ID of audit
|
||||
// Required: true
|
||||
AuditID string `url:"auditId" json:"auditId"`
|
||||
}
|
||||
|
||||
func (trq GetRequest) validate() error {
|
||||
if trq.AuditID == "" {
|
||||
return errors.New("validation-error: field AuditID can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
AuditID string `url:"auditId" json:"auditId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets background API task status and result
|
||||
func (t Tasks) Get(ctx context.Context, req GetRequest) (*RecordAsyncTask, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/tasks/get"
|
||||
|
||||
@@ -32,6 +32,12 @@ func (r *TaskResult) UnmarshalJSON(b []byte) error {
|
||||
} 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
|
||||
|
||||
@@ -3,30 +3,25 @@ package vins
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get audits
|
||||
type AuditsRequest struct {
|
||||
// ID of the VINS
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId"`
|
||||
}
|
||||
|
||||
func (vrq AuditsRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||
}
|
||||
|
||||
// Audits gets audit records for the specified VINS object
|
||||
func (v VINS) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/vins/audits"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user