Compare commits
22 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
f0dee6360a | 5 days ago |
|
|
a267d35ddf | 4 weeks ago |
|
|
0bf073da93 | 4 weeks ago |
|
|
562b6019d0 | 2 months ago |
|
|
bf5c01b40b | 2 months ago |
|
|
095a18f27a | 2 months ago |
|
|
84a090f9e8 | 3 months ago |
|
|
befff7acd9 | 3 months ago |
|
|
abd35f858c | 3 months ago |
|
|
825b1a0a00 | 4 months ago |
|
|
e10ee7f801 | 4 months ago |
|
|
7dacf35cd6 | 5 months ago |
|
|
1f8637400f | 5 months ago |
|
|
89831894df | 6 months ago |
|
|
92431c5c65 | 7 months ago |
|
|
c7a2c4ed5a | 7 months ago |
|
|
0c44daa241 | 8 months ago |
|
|
650b1c158b | 8 months ago |
|
|
8a101c6fcb | 8 months ago |
|
|
3f21a89e80 | 9 months ago |
|
|
cbce7f434f | 10 months ago |
|
|
e04dc42d2b | 12 months ago |
@ -0,0 +1,106 @@
|
|||||||
|
package decortsdk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CheckInfo struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
Build uint64 `json:"build"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionURL = "/system/info/version"
|
||||||
|
|
||||||
|
func (de DecortClient) Check() (*CheckInfo, error) {
|
||||||
|
res, err := de.DecortApiCall(context.Background(), http.MethodGet, versionURL, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := CheckInfo{}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
|
||||||
|
if err != nil {
|
||||||
|
var v string
|
||||||
|
json.Unmarshal([]byte(res), &v)
|
||||||
|
if _, exists := constants.VersionMap[v]; exists {
|
||||||
|
info.Version = v
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("platform version isn't supported")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := constants.VersionMap[info.Version]; ok {
|
||||||
|
if v == "-" {
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New(fmt.Sprintf("SDK don't support platform version %s, please use %s SDK version", info.Version, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New(fmt.Sprintf("platform version %s isn't supported", info.Version))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bvs BVSDecortClient) Check() (*CheckInfo, error) {
|
||||||
|
res, err := bvs.DecortApiCall(context.Background(), http.MethodGet, versionURL, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := CheckInfo{}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
|
||||||
|
if err != nil {
|
||||||
|
var v string
|
||||||
|
json.Unmarshal([]byte(res), &v)
|
||||||
|
if _, exists := constants.VersionMap[v]; exists {
|
||||||
|
info.Version = v
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("platform version isn't supported")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := constants.VersionMap[info.Version]; ok {
|
||||||
|
if v == "-" {
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New(fmt.Sprintf("SDK don't support platform version %s, please use %s SDK version", info.Version, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New(fmt.Sprintf("platform version %s isn't supported", info.Version))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ldc LegacyDecortClient) Check() (*CheckInfo, error) {
|
||||||
|
res, err := ldc.DecortApiCall(context.Background(), http.MethodGet, versionURL, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := CheckInfo{}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
|
||||||
|
if err != nil {
|
||||||
|
var v string
|
||||||
|
json.Unmarshal([]byte(res), &v)
|
||||||
|
if _, exists := constants.VersionMap[v]; exists {
|
||||||
|
info.Version = v
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("platform version isn't supported")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := constants.VersionMap[info.Version]; ok {
|
||||||
|
if v == "-" {
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New(fmt.Sprintf("SDK don't support platform version %s, please use %s SDK version", info.Version, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New(fmt.Sprintf("platform version %s isn't supported", info.Version))
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package decortsdk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MockDecortClient struct {
|
||||||
|
apiCaller *MockCaller
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMockDecortClient(apiCaller *MockCaller) ClientInterface {
|
||||||
|
return &MockDecortClient{
|
||||||
|
apiCaller: apiCaller,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloudAPI builder
|
||||||
|
func (mdc *MockDecortClient) CloudAPI() *cloudapi.CloudAPI {
|
||||||
|
return cloudapi.New(mdc.apiCaller)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloudBroker builder
|
||||||
|
func (mdc *MockDecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
||||||
|
return cloudbroker.New(mdc.apiCaller)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDN builder
|
||||||
|
func (mdc *MockDecortClient) SDN() *sdn.SDN {
|
||||||
|
return sdn.New(mdc.apiCaller)
|
||||||
|
}
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
|
// Source: interfaces/caller.go
|
||||||
|
//
|
||||||
|
// Generated by this command:
|
||||||
|
//
|
||||||
|
// mockgen -package decortsdk -source interfaces/caller.go
|
||||||
|
//
|
||||||
|
|
||||||
|
// Package decortsdk is a generated GoMock package.
|
||||||
|
package decortsdk
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
reflect "reflect"
|
||||||
|
|
||||||
|
gomock "go.uber.org/mock/gomock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockCaller is a mock of Caller interface.
|
||||||
|
type MockCaller struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockCallerMockRecorder
|
||||||
|
isgomock struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockCallerMockRecorder is the mock recorder for MockCaller.
|
||||||
|
type MockCallerMockRecorder struct {
|
||||||
|
mock *MockCaller
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockCaller creates a new mock instance.
|
||||||
|
func NewMockCaller(ctrl *gomock.Controller) *MockCaller {
|
||||||
|
mock := &MockCaller{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockCallerMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockCaller) EXPECT() *MockCallerMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecortApiCall mocks base method.
|
||||||
|
func (m *MockCaller) DecortApiCall(ctx context.Context, method, url string, params any) ([]byte, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "DecortApiCall", ctx, method, url, params)
|
||||||
|
ret0, _ := ret[0].([]byte)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecortApiCall indicates an expected call of DecortApiCall.
|
||||||
|
func (mr *MockCallerMockRecorder) DecortApiCall(ctx, method, url, params any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DecortApiCall", reflect.TypeOf((*MockCaller)(nil).DecortApiCall), ctx, method, url, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecortApiCallCtype mocks base method.
|
||||||
|
func (m *MockCaller) DecortApiCallCtype(ctx context.Context, method, url, ctype string, params any) ([]byte, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "DecortApiCallCtype", ctx, method, url, ctype, params)
|
||||||
|
ret0, _ := ret[0].([]byte)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecortApiCallCtype indicates an expected call of DecortApiCallCtype.
|
||||||
|
func (mr *MockCallerMockRecorder) DecortApiCallCtype(ctx, method, url, ctype, params any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DecortApiCallCtype", reflect.TypeOf((*MockCaller)(nil).DecortApiCallCtype), ctx, method, url, ctype, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecortApiCallMP mocks base method.
|
||||||
|
func (m *MockCaller) DecortApiCallMP(ctx context.Context, method, url string, params any) ([]byte, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "DecortApiCallMP", ctx, method, url, params)
|
||||||
|
ret0, _ := ret[0].([]byte)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecortApiCallMP indicates an expected call of DecortApiCallMP.
|
||||||
|
func (mr *MockCallerMockRecorder) DecortApiCallMP(ctx, method, url, params any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DecortApiCallMP", reflect.TypeOf((*MockCaller)(nil).DecortApiCallMP), ctx, method, url, params)
|
||||||
|
}
|
||||||
@ -1,21 +1,25 @@
|
|||||||
module repository.basistech.ru/BASIS/decort-golang-sdk
|
module repository.basistech.ru/BASIS/decort-golang-sdk
|
||||||
|
|
||||||
go 1.20
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-playground/validator/v10 v10.11.2
|
github.com/go-playground/validator/v10 v10.28.0
|
||||||
github.com/google/go-querystring v1.1.0
|
github.com/google/go-querystring v1.1.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
|
github.com/stretchr/testify v1.9.0
|
||||||
|
go.uber.org/mock v0.6.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/google/go-cmp v0.5.9 // indirect
|
github.com/google/go-cmp v0.5.9 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
golang.org/x/crypto v0.15.0 // indirect
|
golang.org/x/crypto v0.42.0 // indirect
|
||||||
golang.org/x/sys v0.14.0 // indirect
|
golang.org/x/sys v0.36.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.29.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,75 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CreateRequest struct for creating account
|
|
||||||
type CreateRequest struct {
|
|
||||||
// Display name
|
|
||||||
// Required: true
|
|
||||||
Name string `url:"name" json:"name" validate:"required"`
|
|
||||||
|
|
||||||
// Name of the account
|
|
||||||
// Required: true
|
|
||||||
Username string `url:"username" json:"username" validate:"required"`
|
|
||||||
|
|
||||||
// Email
|
|
||||||
// Required: false
|
|
||||||
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
|
|
||||||
|
|
||||||
// Max size of memory in MB
|
|
||||||
// Required: false
|
|
||||||
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
|
||||||
|
|
||||||
// Max size of aggregated vdisks in GB
|
|
||||||
// Required: false
|
|
||||||
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
|
||||||
|
|
||||||
// Max number of CPU cores
|
|
||||||
// Required: false
|
|
||||||
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
|
||||||
|
|
||||||
// Max sent/received network transfer peering
|
|
||||||
// Required: false
|
|
||||||
MaxNetworkPeerTransfer int64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
|
||||||
|
|
||||||
// Max number of assigned public IPs
|
|
||||||
// Required: false
|
|
||||||
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
|
||||||
|
|
||||||
// If true send emails when a user is granted access to resources
|
|
||||||
// Required: false
|
|
||||||
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
|
||||||
// Required: false
|
|
||||||
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create creates account
|
|
||||||
// Setting a cloud unit maximum to -1 or empty will not put any restrictions on the resource
|
|
||||||
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/create"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
package audit
|
||||||
|
|
||||||
|
// FilterByID returns ListAudits with specified ID.
|
||||||
|
func (la ListAudits) FilterByID(guid string) ListAudits {
|
||||||
|
predicate := func(ia ItemAudit) bool {
|
||||||
|
return ia.GUID == guid
|
||||||
|
}
|
||||||
|
|
||||||
|
return la.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterByCall returns ListAudits with specified call.
|
||||||
|
func (la ListAudits) FilterByCall(call string) ListAudits {
|
||||||
|
predicate := func(ic ItemAudit) bool {
|
||||||
|
return ic.Call == call
|
||||||
|
}
|
||||||
|
|
||||||
|
return la.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterByCorrelationID returns ListAudits with specified correlation id.
|
||||||
|
func (la ListAudits) FilterByCorrelationID(correlationID string) ListAudits {
|
||||||
|
predicate := func(ic ItemAudit) bool {
|
||||||
|
return ic.CorrelationID == correlationID
|
||||||
|
}
|
||||||
|
|
||||||
|
return la.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterByRemoteAddr returns ListAudits with specified remote address.
|
||||||
|
func (la ListAudits) FilterByRemoteAddr(remoteAddr string) ListAudits {
|
||||||
|
predicate := func(ic ItemAudit) bool {
|
||||||
|
return ic.RemoteAddr == remoteAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
return la.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterByUser returns ListAudits with specified user name.
|
||||||
|
func (la ListAudits) FilterByUser(user string) ListAudits {
|
||||||
|
predicate := func(ic ItemAudit) bool {
|
||||||
|
return ic.User == user
|
||||||
|
}
|
||||||
|
|
||||||
|
return la.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterByStatusCode return ListAudits with specified status code.
|
||||||
|
func (la ListAudits) FilterByStatusCode(statusCode uint64) ListAudits {
|
||||||
|
predicate := func(ic ItemAudit) bool {
|
||||||
|
return ic.StatusCode == statusCode
|
||||||
|
}
|
||||||
|
|
||||||
|
return la.FilterFunc(predicate)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterFunc allows filtering ListAudits based on a user-specified predicate.
|
||||||
|
func (la ListAudits) FilterFunc(predicate func(ItemAudit) bool) ListAudits {
|
||||||
|
var result ListAudits
|
||||||
|
|
||||||
|
for _, item := range la.Data {
|
||||||
|
if predicate(item) {
|
||||||
|
result.Data = append(result.Data, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.EntryCount = uint64(len(result.Data))
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindOne returns first found ItemAudit
|
||||||
|
// If none was found, returns an empty struct.
|
||||||
|
func (la ListAudits) FindOne() ItemAudit {
|
||||||
|
if len(la.Data) == 0 {
|
||||||
|
return ItemAudit{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return la.Data[0]
|
||||||
|
}
|
||||||
@ -0,0 +1,115 @@
|
|||||||
|
package audit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var audits = ListAudits{
|
||||||
|
Data: []ItemAudit{
|
||||||
|
{
|
||||||
|
Args: "[]",
|
||||||
|
Call: "/restmachine/cloudapi/audit/linkedJobs",
|
||||||
|
GUID: "550e8400-e29b-41d4-a716-446655440001",
|
||||||
|
CorrelationID: "550e8400-e29b-41d4-a716-446655440001",
|
||||||
|
Kwargs: `{\"audit_guid\":\"dd8623a1-a887-48c1-a500-c10210d404cf\"}`,
|
||||||
|
RemoteAddr: "192.168.1.100",
|
||||||
|
ResponseTime: 1,
|
||||||
|
Result: `[]`,
|
||||||
|
StatusCode: 200,
|
||||||
|
Timestamp: 1640995200,
|
||||||
|
TimestampEnd: 1640995201,
|
||||||
|
User: "test@example.com",
|
||||||
|
TTL: "2025-07-31T14:22:57.028000",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Args: "[]",
|
||||||
|
Call: "/restmachine/cloudapi/audit/test",
|
||||||
|
GUID: "550e8400-e29b-41d4-a716-446655440002",
|
||||||
|
CorrelationID: "550e8400-e29b-41d4-a716-446655440002",
|
||||||
|
Kwargs: `{\"audit_guid\":\"dd8623a1-a887-48c1-a500-c10210d404cf\"}`,
|
||||||
|
RemoteAddr: "192.168.1.105",
|
||||||
|
ResponseTime: 5,
|
||||||
|
Result: `[]`,
|
||||||
|
StatusCode: 400,
|
||||||
|
Timestamp: 1640995200,
|
||||||
|
TimestampEnd: 1640995201,
|
||||||
|
User: "test2@example.com",
|
||||||
|
TTL: "2025-07-31T14:22:57.028000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
EntryCount: 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilterByID(t *testing.T) {
|
||||||
|
actual := audits.FilterByID("550e8400-e29b-41d4-a716-446655440002").FindOne()
|
||||||
|
|
||||||
|
if actual.GUID != "550e8400-e29b-41d4-a716-446655440002" {
|
||||||
|
t.Fatal("expected GUID 550e8400-e29b-41d4-a716-446655440002, found: ", actual.GUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
actualEmpty := audits.FilterByID("")
|
||||||
|
|
||||||
|
if len(actualEmpty.Data) != 0 {
|
||||||
|
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilterByCorrelationID(t *testing.T) {
|
||||||
|
actual := audits.FilterByCorrelationID("550e8400-e29b-41d4-a716-446655440002").FindOne()
|
||||||
|
|
||||||
|
if actual.CorrelationID != "550e8400-e29b-41d4-a716-446655440002" {
|
||||||
|
t.Fatal("expected GUID 550e8400-e29b-41d4-a716-446655440002, found: ", actual.CorrelationID)
|
||||||
|
}
|
||||||
|
|
||||||
|
actualEmpty := audits.FilterByCorrelationID("")
|
||||||
|
|
||||||
|
if len(actualEmpty.Data) != 0 {
|
||||||
|
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilterByRemoteAddr(t *testing.T) {
|
||||||
|
actual := audits.FilterByRemoteAddr("192.168.1.100").FindOne()
|
||||||
|
|
||||||
|
if actual.RemoteAddr != "192.168.1.100" {
|
||||||
|
t.Fatal("expected remote address 192.168.1.100, found: ", actual.RemoteAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
actualEmpty := audits.FilterByRemoteAddr("")
|
||||||
|
|
||||||
|
if len(actualEmpty.Data) != 0 {
|
||||||
|
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilterByUser(t *testing.T) {
|
||||||
|
actual := audits.FilterByUser("test@example.com").FindOne()
|
||||||
|
|
||||||
|
if actual.User != "test@example.com" {
|
||||||
|
t.Fatal("expected user test@example.com, found: ", actual.RemoteAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
actualEmpty := audits.FilterByUser("")
|
||||||
|
|
||||||
|
if len(actualEmpty.Data) != 0 {
|
||||||
|
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilterByCall(t *testing.T) {
|
||||||
|
actual := audits.FilterByCall("/restmachine/cloudapi/audit/test").FindOne()
|
||||||
|
|
||||||
|
if actual.Call != "/restmachine/cloudapi/audit/test" {
|
||||||
|
t.Fatal("expected call /restmachine/cloudapi/audit/test, found: ", actual.Call)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilterByStatusCode(t *testing.T) {
|
||||||
|
actual := audits.FilterByStatusCode(200)
|
||||||
|
|
||||||
|
for _, item := range actual.Data {
|
||||||
|
if item.StatusCode != 200 {
|
||||||
|
t.Fatal("expected 200 status code, found: ", item.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,124 @@
|
|||||||
|
package audit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListRequest struct to give list of account audits
|
||||||
|
type ListRequest struct {
|
||||||
|
|
||||||
|
// Find all audits after point in time (unixtime)
|
||||||
|
// Required: false
|
||||||
|
TimestampAt uint64 `url:"timestamp_at,omitempty" json:"timestamp_at,omitempty"`
|
||||||
|
|
||||||
|
// Find all audits before point in time (unixtime)
|
||||||
|
// Required: false
|
||||||
|
TimestampTo uint64 `url:"timestamp_to,omitempty" json:"timestamp_to,omitempty"`
|
||||||
|
|
||||||
|
// Find by user (Mongo RegExp supported)
|
||||||
|
// Required: false
|
||||||
|
User string `url:"user,omitempty" json:"user,omitempty"`
|
||||||
|
|
||||||
|
// Find by api endpoint (Mongo RegExp supported)
|
||||||
|
// Required: false
|
||||||
|
Call string `url:"call,omitempty" json:"call,omitempty"`
|
||||||
|
|
||||||
|
// Find by request id
|
||||||
|
// Required: false
|
||||||
|
RequestID string `url:"request_id,omitempty" json:"request_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by HTTP min status code
|
||||||
|
// Required: false
|
||||||
|
MinStatusCode uint64 `url:"min_status_code,omitempty" json:"min_status_code,omitempty"`
|
||||||
|
|
||||||
|
// Find by HTTP max status code
|
||||||
|
// Required: false
|
||||||
|
MaxStatusCode uint64 `url:"max_status_code,omitempty" json:"max_status_code,omitempty"`
|
||||||
|
|
||||||
|
// Sort by one of supported fields, format +|-(field)
|
||||||
|
// Required: false
|
||||||
|
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty" validate:"omitempty,sortBy"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group id
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"resgroup_id,omitempty" json:"resgroup_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by compute id
|
||||||
|
// Required: false
|
||||||
|
ComputeID uint64 `url:"compute_id,omitempty" json:"compute_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by account id
|
||||||
|
// Required: false
|
||||||
|
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by vins id
|
||||||
|
// Required: false
|
||||||
|
VINSID uint64 `url:"vins_id,omitempty" json:"vins_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by service id
|
||||||
|
// Required: false
|
||||||
|
ServiceID uint64 `url:"service_id,omitempty" json:"service_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by k8s id
|
||||||
|
// Required: false
|
||||||
|
K8SID uint64 `url:"k8s_id,omitempty" json:"k8s_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by flipgroup id
|
||||||
|
// Required: false
|
||||||
|
FLIPGroupID uint64 `url:"flipgroup_id,omitempty" json:"flipgroup_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by load balancer id
|
||||||
|
// Required: false
|
||||||
|
LBID uint64 `url:"lb_id,omitempty" json:"lb_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by sep id
|
||||||
|
// Required: false
|
||||||
|
SEPID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
|
||||||
|
|
||||||
|
// Exclude audit lines from response
|
||||||
|
// Required: false
|
||||||
|
ExcludeAuditLines bool `url:"exclude_audit_lines,omitempty" json:"exclude_audit_lines,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List gets audit records for the specified account object
|
||||||
|
func (a Audit) List(ctx context.Context, req ListRequest) (*ListAudits, error) {
|
||||||
|
|
||||||
|
res, err := a.ListRaw(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListAudits{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &list, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRaw gets list of audit records an array of bytes
|
||||||
|
func (a Audit) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||||
|
|
||||||
|
if err := validators.ValidateRequest(req); err != nil {
|
||||||
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/audit/list"
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package bservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MigrateToZone struct to move basic service to another zone
|
||||||
|
type MigrateToZoneRequest struct {
|
||||||
|
// ID of the BasicService to move
|
||||||
|
// Required: true
|
||||||
|
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the zone to move
|
||||||
|
// Required: true
|
||||||
|
ZoneID uint64 `url:"zoneId" json:"zoneId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MigrateToZone moves basic service instance to new zone
|
||||||
|
func (b BService) MigrateToZone(ctx context.Context, req MigrateToZoneRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/bservice/migrateToZone"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AbortSharedSnapshotMergeRequest struct to abort shared snapshots merge
|
||||||
|
type AbortSharedSnapshotMergeRequest struct {
|
||||||
|
// ID of the compute
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||||
|
|
||||||
|
// Label of the snapshot
|
||||||
|
// Required: true
|
||||||
|
Label string `url:"label" json:"label" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AbortSharedSnapshotMerge shared snapshots merge abort
|
||||||
|
func (c Compute) AbortSharedSnapshotMerge(ctx context.Context, req AbortSharedSnapshotMergeRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/abort_shared_snapshot_merge"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ChangeMTURequest struct to change MTU for a compute
|
||||||
|
type ChangeMTURequest struct {
|
||||||
|
// ID of compute instance
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||||
|
|
||||||
|
// Interface name or MAC address
|
||||||
|
// Required: true
|
||||||
|
Interface string `url:"interface" json:"interface" validate:"required"`
|
||||||
|
|
||||||
|
// Maximum transmission unit
|
||||||
|
// Required: true
|
||||||
|
MTU uint64 `url:"mtu" json:"mtu" validate:"required" validate:"omitempty,mtu"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangeMTU change MTU for compute instance
|
||||||
|
func (c Compute) ChangeMTU(ctx context.Context, req ChangeMTURequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/change_mtu"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ChangeSecGroupsRequest struct to change security groups for compute
|
||||||
|
type ChangeSecGroupsRequest struct {
|
||||||
|
// Identifier compute
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||||
|
|
||||||
|
// Interface name or MAC address
|
||||||
|
// Required: true
|
||||||
|
Interface string `url:"interface" json:"interface" validate:"required"`
|
||||||
|
|
||||||
|
// List of security group IDs to assign to this interface
|
||||||
|
// Required: false
|
||||||
|
SecGroups []uint64 `url:"security_groups,omitempty" json:"security_groups,omitempty"`
|
||||||
|
|
||||||
|
// Flag indicating whether security groups are enabled for this interface
|
||||||
|
// Required: false
|
||||||
|
EnableSecGroups interface{} `url:"enable_secgroups,omitempty" json:"enable_secgroups,omitempty" validate:"omitempty,isBool"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangeSecGroups changes security groups for compute
|
||||||
|
func (c Compute) ChangeSecGroups(ctx context.Context, req ChangeSecGroupsRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/change_security_groups"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CloneAbortRequest struct to abort a compute clone
|
||||||
|
type CloneAbortRequest struct {
|
||||||
|
// ID of compute instance
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloneAbort aborts a compute clone
|
||||||
|
func (c Compute) CloneAbort(ctx context.Context, req CloneAbortRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/clone_abort"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetCloneStatusRequest struct to get information about compute clone status
|
||||||
|
type GetCloneStatusRequest struct {
|
||||||
|
// ID of compute instance
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCloneStatus gets information about compute clone status as a RecordCloneStatus struct
|
||||||
|
func (c Compute) GetCloneStatus(ctx context.Context, req GetCloneStatusRequest) ([]RecordCloneStatus, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/clone_status"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cloneStatus := make([]RecordCloneStatus, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &cloneStatus)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cloneStatus, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GuestAgentExecuteRequest struct to execute command from user to agent
|
||||||
|
type GuestAgentExecuteRequest struct {
|
||||||
|
// ID of compute instance
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||||
|
|
||||||
|
// Custom command from user to agent
|
||||||
|
// Required: true
|
||||||
|
Command string `url:"command" json:"command" validate:"required"`
|
||||||
|
|
||||||
|
// Arguments to command
|
||||||
|
// Required: true
|
||||||
|
Arguments string `url:"arguments" json:"arguments" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute guest agent command
|
||||||
|
func (c Compute) GuestAgentExecuteRequest(ctx context.Context, req GuestAgentExecuteRequest) (map[string]interface{}, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/guest_agent_execute"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result map[string]interface{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GuestAgentFeatureGetRequest struct to feature get guest agent
|
||||||
|
type GuestAgentFeatureGetRequest struct {
|
||||||
|
// ID of compute instance
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of features
|
||||||
|
func (c Compute) GuestAgentFeatureGet(ctx context.Context, req GuestAgentFeatureGetRequest) ([]string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/guest_agent_feature_get"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
features := make([]string, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &features)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return features, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GuestAgentFeatureUpdateRequest struct to feature update guest agent
|
||||||
|
type GuestAgentFeatureUpdateRequest struct {
|
||||||
|
// ID of compute instance
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Feature update guest agent
|
||||||
|
func (c Compute) GuestAgentFeatureUpdate(ctx context.Context, req GuestAgentFeatureUpdateRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/guest_agent_feature_update"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PinToNodeRequest struct to pin compute to node
|
||||||
|
type PinToNodeRequest struct {
|
||||||
|
// ID of the compute instance
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Auto start when node restarted
|
||||||
|
// Required: false
|
||||||
|
// Default: false
|
||||||
|
AutoStart bool `url:"autoStart" json:"autoStart"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PinToNode pin compute to current node
|
||||||
|
func (c Compute) PinToNode(ctx context.Context, req PinToNodeRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/pin_to_node"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -1,38 +0,0 @@
|
|||||||
package compute
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PinToStackRequest struct to pin compute to stack
|
|
||||||
type PinToStackRequest struct {
|
|
||||||
// ID of the compute instance
|
|
||||||
// Required: true
|
|
||||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PinToStack pin compute to current stack
|
|
||||||
func (c Compute) PinToStack(ctx context.Context, req PinToStackRequest) (uint64, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/compute/pinToStack"
|
|
||||||
|
|
||||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SharedSnapshotMergeStatusRequest struct to get shared snapshot merge status
|
||||||
|
type SharedSnapshotMergeStatusRequest struct {
|
||||||
|
// ID of compute instance to get log for
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharedSnapshotMergeStatus shared snapshots merge status
|
||||||
|
// returns a string representing either the current status or the progress percentage
|
||||||
|
func (c Compute) SharedSnapshotMergeStatus(ctx context.Context, req SharedSnapshotMergeStatusRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/shared_snapshot_merge_status"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(res), nil
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package disks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ChangeDiskStoragePolicyRequest struct to change storage policy for disk
|
||||||
|
type ChangeDiskStoragePolicyRequest struct {
|
||||||
|
// ID of the disk
|
||||||
|
// Required: true
|
||||||
|
DiskID uint64 `url:"disk_id" json:"disk_id" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the storage policy to which to connect for disk
|
||||||
|
// Required: true
|
||||||
|
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangeDiskStoragePolicy changes storage policy for disk
|
||||||
|
func (d Disks) ChangeDiskStoragePolicy(ctx context.Context, req ChangeDiskStoragePolicyRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/disks/change_disk_storage_policy"
|
||||||
|
|
||||||
|
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetRequest struct to get information about reserved address or address poll
|
||||||
|
type GetReservedIP struct {
|
||||||
|
// AccountID of the account whose reservation information we want to receive
|
||||||
|
// Required: true
|
||||||
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
|
// Field for specifying the ID of extnet whose reservation information we want to receive
|
||||||
|
// Required: false
|
||||||
|
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetReservedIP gets information about reserved address or address poll as a slice of RecordReservedIP struct
|
||||||
|
func (e ExtNet) GetReservedIP(ctx context.Context, req GetReservedIP) ([]RecordReservedIP, error) {
|
||||||
|
res, err := e.GetReservedIPRaw(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
reservedIP := make([]RecordReservedIP, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &reservedIP)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return reservedIP, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRaw gets detailed information about external network as an array of bytes
|
||||||
|
func (e ExtNet) GetReservedIPRaw(ctx context.Context, req GetReservedIP) ([]byte, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/extnet/getReservedIp"
|
||||||
|
|
||||||
|
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ChangeStoragePolicyRequest struct {
|
||||||
|
// ID of the image to change the storage policy
|
||||||
|
// Required: true
|
||||||
|
ImageID uint64 `url:"image_id" json:"image_id" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the storage policy to move the image to
|
||||||
|
// Required: true
|
||||||
|
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangeStoragePolicy changes the storage policy of the image chosen
|
||||||
|
func (i Image) ChangeStoragePolicy(ctx context.Context, req ChangeStoragePolicyRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/image/change_storage_policy"
|
||||||
|
|
||||||
|
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MigrateToZone struct to move k8s cluster to another zone
|
||||||
|
type MigrateToZoneRequest struct {
|
||||||
|
// Kubernetes cluster ID to move
|
||||||
|
// Required: true
|
||||||
|
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the zone to move
|
||||||
|
// Required: true
|
||||||
|
ZoneID uint64 `url:"zoneId" json:"zoneId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MigrateToZone moves k8s cluster instance to new zone
|
||||||
|
func (k8s K8S) MigrateToZone(ctx context.Context, req MigrateToZoneRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/k8s/migrateToZone"
|
||||||
|
|
||||||
|
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package lb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MigrateToZone struct to move lb to another zone
|
||||||
|
type MigrateToZoneRequest struct {
|
||||||
|
// ID of the load balancer instance to move
|
||||||
|
// Required: true
|
||||||
|
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the zone to move
|
||||||
|
// Required: true
|
||||||
|
ZoneID uint64 `url:"zoneId" json:"zoneId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MigrateToZone moves lb instance to new zone
|
||||||
|
func (l LB) MigrateToZone(ctx context.Context, req MigrateToZoneRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/lb/migrateToZone"
|
||||||
|
|
||||||
|
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue