Compare commits
19 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
562b6019d0 | 3 weeks ago |
|
|
bf5c01b40b | 4 weeks ago |
|
|
095a18f27a | 1 month ago |
|
|
84a090f9e8 | 1 month ago |
|
|
befff7acd9 | 2 months ago |
|
|
abd35f858c | 2 months ago |
|
|
825b1a0a00 | 2 months ago |
|
|
e10ee7f801 | 3 months ago |
|
|
7dacf35cd6 | 4 months ago |
|
|
1f8637400f | 4 months ago |
|
|
89831894df | 4 months ago |
|
|
92431c5c65 | 6 months ago |
|
|
c7a2c4ed5a | 6 months ago |
|
|
0c44daa241 | 7 months ago |
|
|
650b1c158b | 7 months ago |
|
|
8a101c6fcb | 7 months ago |
|
|
3f21a89e80 | 8 months ago |
|
|
cbce7f434f | 9 months ago |
|
|
e04dc42d2b | 10 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))
|
||||
}
|
||||
@ -1,21 +1,21 @@
|
||||
module repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
|
||||
go 1.20
|
||||
go 1.24.0
|
||||
|
||||
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/joho/godotenv v1.5.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
golang.org/x/crypto v0.15.0 // indirect
|
||||
golang.org/x/sys v0.14.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
golang.org/x/crypto v0.42.0 // indirect
|
||||
golang.org/x/sys v0.36.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,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
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package locations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListGetRequest struct to get list of locations
|
||||
type ListGetRequest struct {
|
||||
// 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 flag
|
||||
// Required: false
|
||||
Flag string `url:"flag,omitempty" json:"flag,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by code location
|
||||
// Required: false
|
||||
LocationCode string `url:"locationCode,omitempty" json:"locationCode,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
}
|
||||
|
||||
// ListGet gets list of all locations as a ListLocations struct
|
||||
func (l Locations) ListGet(ctx context.Context, req ListGetRequest) (*ListLocations, error) {
|
||||
|
||||
res, err := l.ListGetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListLocations{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListGetRaw gets list of all locations as an array of bytes
|
||||
func (l Locations) ListGetRaw(ctx context.Context, req ListGetRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/locations/list"
|
||||
|
||||
res, err := l.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package cloudapi
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/prometheus"
|
||||
|
||||
// Accessing the Resmon method group
|
||||
func (ca *CloudAPI) Prometheus() *prometheus.Prometheus {
|
||||
return prometheus.New(ca.client)
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type ComputeCPULoadRequest struct {
|
||||
// Compute ID
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Time to loads of statistic in seconds
|
||||
// Required: false
|
||||
ForLast uint64 `url:"forLast,omitempty" json:"forLast,omitempty"`
|
||||
|
||||
// The reading interval in seconds
|
||||
// Required: false
|
||||
Step uint64 `url:"step,omitempty" json:"step,omitempty"`
|
||||
|
||||
// Number of zeros after the decimal point
|
||||
// Required: false
|
||||
DecimalPlaces uint64 `url:"decimalPlaces,omitempty" json:"decimalPlaces,omitempty"`
|
||||
}
|
||||
|
||||
// Per-second CPU time consumed by Compute in percent, average over the time step specified
|
||||
func (p Prometheus) ComputeCPULoad(ctx context.Context, req ComputeCPULoadRequest) (*PrometheusData, error) {
|
||||
res, err := p.ComputeCPULoadRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := PrometheusData{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets information about compute as an array of bytes
|
||||
func (p Prometheus) ComputeCPULoadRaw(ctx context.Context, req ComputeCPULoadRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/prometheus/computeCPUload"
|
||||
|
||||
res, err := p.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type ComputeMemoryAvailableRequest struct {
|
||||
// Compute ID
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Time to loads of statistic in seconds
|
||||
// Required: false
|
||||
ForLast uint64 `url:"forLast,omitempty" json:"forLast,omitempty"`
|
||||
|
||||
// The reading interval in seconds
|
||||
// Required: false
|
||||
Step uint64 `url:"step,omitempty" json:"step,omitempty"`
|
||||
}
|
||||
|
||||
// Available Memory
|
||||
func (p Prometheus) ComputeMemoryAvailable(ctx context.Context, req ComputeMemoryAvailableRequest) (*PrometheusData, error) {
|
||||
res, err := p.ComputeMemoryAvailableRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := PrometheusData{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets information about compute as an array of bytes
|
||||
func (p Prometheus) ComputeMemoryAvailableRaw(ctx context.Context, req ComputeMemoryAvailableRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/prometheus/computeMemoryAvailable"
|
||||
|
||||
res, err := p.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue