This commit is contained in:
asteam
2025-09-23 14:34:24 +03:00
parent b924e85e49
commit f1ffb4c0fd
1108 changed files with 72020 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AddRequest struct for location code
type AddRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// Name of the location
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Location code typicly used in dns names
// Required: true
LocationCode string `url:"locationcode" json:"locationcode" validate:"required"`
}
// Add location code (e.g. DNS name of this grid)
func (g Grid) Add(ctx context.Context, req AddRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/add"
res, err := g.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
}

View File

@@ -0,0 +1,42 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AddCustomBackupPathRequest struct to add new path to the list of custom backup paths
type AddCustomBackupPathRequest struct {
// ID of the grid
// Required: true
GID uint64 `url:"gridId" json:"gridId" validate:"required"`
// Absolute path
// Required: true
Path string `url:"path" json:"path" validate:"required"`
}
// AddCustomBackupPath add new path to the list of custom backup paths
func (g Grid) AddCustomBackupPath(ctx context.Context, req AddCustomBackupPathRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/addCustomBackupPath"
res, err := g.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
}

View File

@@ -0,0 +1,42 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ChangeSettingsRequest struct to change grid settings
type ChangeSettingsRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"id" json:"id" validate:"required"`
// Json data of the new settings will override old data
// Required: true
Settings string `url:"settings" json:"settings" validate:"required"`
}
// ChangeSettings changes grid settings
func (g Grid) ChangeSettings(ctx context.Context, req ChangeSettingsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/changeSettings"
res, err := g.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
}

View File

@@ -0,0 +1,46 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ExecuteMaintenanceScriptRequest struct to execute script
type ExecuteMaintenanceScriptRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// Type of nodes you want to apply the action on
// Required: true
NodesType string `url:"nodestype" json:"nodestype" validate:"required"`
// The script you want to run
// Required: true
Script string `url:"script" json:"script" validate:"required"`
}
// ExecuteMaintenanceScript executes maintenance script
func (g Grid) ExecuteMaintenanceScript(ctx context.Context, req ExecuteMaintenanceScriptRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/executeMaintenanceScript"
res, err := g.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
}

View File

@@ -0,0 +1,62 @@
package grid
// FilterByID returns ListGrids with specified ID.
func (lg ListGrids) FilterByID(id uint64) ListGrids {
predicate := func(rg ItemGridList) bool {
return rg.ID == id
}
return lg.FilterFunc(predicate)
}
// FilterByGID returns ListGrids with specified GID.
func (lg ListGrids) FilterByGID(gid uint64) ListGrids {
predicate := func(rg ItemGridList) bool {
return rg.GID == gid
}
return lg.FilterFunc(predicate)
}
// FilterByName returns ListGrids with specified Name.
func (lg ListGrids) FilterByName(name string) ListGrids {
predicate := func(rg ItemGridList) bool {
return rg.Name == name
}
return lg.FilterFunc(predicate)
}
// FilterByLocationCode returns ListGrids with specified LocationCode.
func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids {
predicate := func(rg ItemGridList) bool {
return rg.LocationCode == locationCode
}
return lg.FilterFunc(predicate)
}
// FilterFunc allows filtering ListGrids based on a user-specified predicate.
func (lg ListGrids) FilterFunc(predicate func(ItemGridList) bool) ListGrids {
var result ListGrids
for _, item := range lg.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found RecordGrid.
// If none was found, returns an empty struct.
func (lg ListGrids) FindOne() ItemGridList {
if len(lg.Data) == 0 {
return ItemGridList{}
}
return lg.Data[0]
}

View File

@@ -0,0 +1,142 @@
package grid
import "testing"
var grids = ListGrids{
Data: []ItemGridList{
{
Resources: Resources{
Current: RecordResource{
CPU: 84,
DiskSize: 976,
DiskSizeMax: 1200,
ExtIPs: 132,
ExtTraffic: 0,
GPU: 79500,
RAM: 0,
SEPs: map[string]map[string]DiskUsage{},
},
Reserved: RecordResource{
CPU: 123,
DiskSize: 976,
DiskSizeMax: 1200,
ExtIPs: 132,
ExtTraffic: 0,
GPU: 0,
RAM: 152600,
SEPs: map[string]map[string]DiskUsage{},
},
},
Flag: "",
GID: 212,
GUID: 1,
ID: 1,
LocationCode: "alfa",
Name: "alfa",
},
{
Resources: Resources{
Current: RecordResource{
CPU: 84,
DiskSize: 976,
DiskSizeMax: 1200,
ExtIPs: 132,
ExtTraffic: 0,
GPU: 79500,
RAM: 0,
SEPs: map[string]map[string]DiskUsage{},
},
Reserved: RecordResource{
CPU: 123,
DiskSize: 976,
DiskSizeMax: 1200,
ExtIPs: 132,
ExtTraffic: 0,
GPU: 0,
RAM: 152600,
SEPs: map[string]map[string]DiskUsage{},
},
},
Flag: "",
GID: 666,
GUID: 2,
ID: 2,
LocationCode: "beta",
Name: "beta",
},
{
Resources: Resources{
Current: RecordResource{
CPU: 84,
DiskSize: 976,
DiskSizeMax: 1200,
ExtIPs: 132,
ExtTraffic: 0,
GPU: 79500,
RAM: 0,
SEPs: map[string]map[string]DiskUsage{},
},
Reserved: RecordResource{
CPU: 123,
DiskSize: 976,
DiskSizeMax: 1200,
ExtIPs: 132,
ExtTraffic: 0,
GPU: 0,
RAM: 152600,
SEPs: map[string]map[string]DiskUsage{},
},
},
Flag: "",
GID: 777,
GUID: 3,
ID: 3,
LocationCode: "gamma",
Name: "gamma",
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
actual := grids.FilterByID(2).FindOne()
if actual.ID != 2 {
t.Fatal("expected ID 2, found: ", actual.ID)
}
}
func TestFilterByGID(t *testing.T) {
actual := grids.FilterByGID(777).FindOne()
if actual.GID != 777 {
t.Fatal("expected ID 777, found: ", actual.GID)
}
}
func TestFilterByName(t *testing.T) {
actual := grids.FilterByName("gamma").FindOne()
if actual.Name != "gamma" {
t.Fatal("expected Name 'gamma', found: ", actual.Name)
}
}
func TestFilterByLocationCode(t *testing.T) {
actual := grids.FilterByLocationCode("alfa").FindOne()
if actual.LocationCode != "alfa" {
t.Fatal("expected LocationCode 'alfa', found: ", actual.LocationCode)
}
}
func TestFilterFunc(t *testing.T) {
actual := grids.FilterFunc(func(rg ItemGridList) bool {
return rg.GID == 777
}).
FindOne()
if actual.GID != 777 {
t.Fatal("expected GID 777, found: ", actual.GID)
}
}

View File

@@ -0,0 +1,46 @@
package grid
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetRequest struct to get grid details
type GetRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gridId" json:"gridId" validate:"required"`
}
// Get gets information about grid by ID as a RecordGrid struct
func (g Grid) Get(ctx context.Context, req GetRequest) (*RecordGrid, error) {
res, err := g.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordGrid{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets information about grid by ID as an array of bytes
func (g Grid) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/get"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,49 @@
package grid
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetBackupRequest struct to get backup
type GetBackupRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
}
// GetBackup gets platform backup
func (g Grid) GetBackup(ctx context.Context, req GetBackupRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/getBackup"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}
// GetBackupGET gets platform backup
func (g Grid) GetBackupGET(ctx context.Context, req GetBackupRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/getBackup"
res, err := g.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,50 @@
package grid
import (
"context"
"fmt"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetDiagnosisRequest struct to get platform snapshot with additional diagnosis
type GetDiagnosisRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
}
// GetDiagnosis gets platform snapshot with additional diagnosis info like a logs, etc
func (g Grid) GetDiagnosis(ctx context.Context, req GetDiagnosisRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/getDiagnosis"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}
// GetDiagnosisGET gets platform snapshot with additional diagnosis info like a logs, etc
func (g Grid) GetDiagnosisGET(ctx context.Context, req GetDiagnosisRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := fmt.Sprintf("/cloudbroker/grid/getDiagnosis/?gid=%d", req.GID)
res, err := g.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,40 @@
package grid
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetResourceConsumptionRequest struct to get resource consumption
type GetResourceConsumptionRequest struct {
// ID of the grid
// Required: true
GridID uint64 `url:"gridId" json:"gridId" validate:"required"`
}
// GetResourceConsumption gets resource consumption
func (g Grid) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResourcesConsumption, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/getResourceConsumption"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
result := RecordResourcesConsumption{}
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return &result, nil
}

View File

@@ -0,0 +1,46 @@
package grid
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetSettingsRequest struct to get grid settings
type GetSettingsRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"grid_id" json:"grid_id" validate:"required"`
}
// GetSettings gets settings grid by ID as a RecordSettingsGrid struct
func (g Grid) GetSettings(ctx context.Context, req GetSettingsRequest) (*RecordSettingsGrid, error) {
res, err := g.GetSettingsRaw(ctx, req)
if err != nil {
return nil, err
}
settings := RecordSettingsGrid{}
err = json.Unmarshal(res, &settings)
if err != nil {
return nil, err
}
return &settings, nil
}
// GetSettingsRaw gets settings grid by ID as an array of bytes
func (g Grid) GetSettingsRaw(ctx context.Context, req GetSettingsRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/getSettings"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,18 @@
// Operator actions for handling interventions on a grid
package grid
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
)
// Structure for creating request to grid
type Grid struct {
client interfaces.Caller
}
// Builder for grid endpoints
func New(client interfaces.Caller) *Grid {
return &Grid{
client: client,
}
}

View File

@@ -0,0 +1,19 @@
package grid
// IDs gets array of GRIDID from ListGrids struct
func (lg ListGrids) IDs() []uint64 {
res := make([]uint64, 0, len(lg.Data))
for _, e := range lg.Data {
res = append(res, e.GID)
}
return res
}
// IDs gets array of GRIDID from ListResourceConsumption struct
func (lg ListResourceConsumption) IDs() []uint64 {
res := make([]uint64, 0, len(lg.Data))
for _, e := range lg.Data {
res = append(res, e.GID)
}
return res
}

View File

@@ -0,0 +1,63 @@
package grid
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListRequest struct to get list of locations
type ListRequest struct {
// Find by id grid
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name grid
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of all locations as a ListGrids struct
func (g Grid) List(ctx context.Context, req ListRequest) (*ListGrids, error) {
res, err := g.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListGrids{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of all locations as an array of bytes
func (g Grid) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/list"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,37 @@
package grid
import (
"context"
"encoding/json"
"net/http"
)
// ListEmailsRequest struct for getting list of email addresses of users
type ListEmailsRequest 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"`
}
// ListEmails returns list of email addresses of users
func (g Grid) ListEmails(ctx context.Context, req ListEmailsRequest) (*ListEmails, error) {
url := "/cloudbroker/grid/listEmails"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListEmails{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,25 @@
package grid
import (
"context"
"encoding/json"
"net/http"
)
func (g Grid) ListResourceConsumption(ctx context.Context) (*ListResourceConsumption, error) {
url := "/cloudbroker/grid/listResourceConsumption"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, nil)
if err != nil {
return nil, err
}
result := ListResourceConsumption{}
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return &result, nil
}

View File

@@ -0,0 +1,239 @@
package grid
// Resource information
type Resources struct {
// Current resources
Current RecordResource `json:"Current"`
// Reserved resources
Reserved RecordResource `json:"Reserved"`
}
// Resource consumption information
type RecordResourcesConsumption struct {
// Current resources
Consumed RecordResource `json:"Consumed"`
// Reserved resources
Reserved RecordResource `json:"Reserved"`
// GID
GID uint64 `json:"id"`
}
type ListResourceConsumption struct {
// Data
Data []RecordResourcesConsumption `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Resource details
type RecordResource struct {
// Number of CPU
CPU uint64 `json:"cpu"`
// Disk size
DiskSize float64 `json:"disksize"`
// Disk size max
DiskSizeMax int64 `json:"disksizemax"`
// External IPs
ExtIPs uint64 `json:"extips"`
// External traffic
ExtTraffic uint64 `json:"exttraffic"`
// Number of GPU
GPU uint64 `json:"gpu"`
// Number of RAM
RAM uint64 `json:"ram"`
// SEPs
SEPs map[string]map[string]DiskUsage `json:"seps"`
}
// Disk usage
type DiskUsage struct {
// Disk size
DiskSize float64 `json:"disksize"`
// Disk size max
DiskSizeMax float64 `json:"disksizemax"`
}
// Detailed information about grid
type RecordGrid struct {
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// AuthBroker
AuthBroker []interface{} `json:"authBroker"`
// Flag
Flag string `json:"flag"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Location code
LocationCode string `json:"locationCode"`
// Name
Name string `json:"name"`
}
// Information about grid
type ItemGridList struct {
// Resource information
Resources Resources `json:"Resources"`
// AuthBroker
AuthBroker []interface{} `json:"authBroker"`
// Flag
Flag string `json:"flag"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Location code
LocationCode string `json:"locationCode"`
// Name
Name string `json:"name"`
}
// List Grids
type ListGrids struct {
//Data
Data []ItemGridList `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// List emails
type ListEmails struct {
//Data
Data []string `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Detailed information about grid settings
type RecordSettingsGrid struct {
//Allowed ports
Allowedports []int `json:"allowedports"`
//Cleanup retention period
CleanupRetentionPeriod uint64 `json:"cleanupRetentionPeriod"`
//Docker registry
DockerRegistry DockerRegistry `json:"docker_registry"`
//Enable uptime monitor
EnableUptimeMonitor bool `json:"enableUptimeMonitor"`
//Extnet max prereservation num
ExtnetMaxPreReservationsNum int `json:"extnetMaxPreReservationsNum"`
//Healthcheck notifications
HealthcheckNotifications HealthcheckNotifications `json:"healthcheck_notifications"`
//k8s cleanup enabled
K8sCleanupEnabled bool `json:"k8s_cleanup_enabled"`
//Limits
Limits interface{} `json:"limits"`
//Location url
LocationURL string `json:"location_url"`
//Net QOS
NetQOS NetQOS `json:"net_qos"`
//Networks
Networks string `json:"networks"`
//Prometheus
Prometheus Prometheus `json:"prometheus"`
//Vins max prereservation num
VinsMaxPreReservationsNum int `json:"vinsMaxPreReservationsNum"`
//Vnfdev mgmt net range
VnfdevMgmtNetRange string `json:"vnfdev_mgmt_net_range"`
}
// DockerRegistry in grid settings
type DockerRegistry struct {
//Password
Password string `json:"password"`
//Server
Server string `json:"server"`
//Username
Username string `json:"username"`
}
// NetQOS in grid settings
type NetQOS struct {
// ExtNet Net QOS settings
ExtNet SettingsNetQOS `json:"ext_net"`
// VINS Net QOS settings
VINS SettingsNetQOS `json:"vins"`
}
// SettingsNetQOS in grid settings
type SettingsNetQOS struct {
//ERate
ERate uint64 `json:"eRate"`
//InBurst
InBurst uint64 `json:"inBurst"`
//InRate
InRate uint64 `json:"inRate"`
}
// HealthcheckNotifications settings in grid
type HealthcheckNotifications struct {
//Emails
Emails []Emails `json:"emails"`
}
type Emails struct {
//Address
Address string `json:"address"`
//Enabled
Enabled bool `json:"enabled"`
}
// Prometheus setting in grid
type Prometheus struct {
//ScrapeInterval
ScrapeInterval int `json:"scrapeInterval"`
}

View File

@@ -0,0 +1,43 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// PurgeLogsRequest struct to purge logs
type PurgeLogsRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// Age of the records to remove, e.g. -1h for records older than 1 hour, -1w - one week, etc
// Required: true
Age string `url:"age" json:"age" validate:"required"`
}
// PurgeLogs clear Log and ECO records that are older than the specified age.
// By default, records older than one week are removed
func (g Grid) PurgeLogs(ctx context.Context, req PurgeLogsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/purgeLogs"
res, err := g.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
}

View File

@@ -0,0 +1,42 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// RemoveCustomBackupPathRequest struct to remove path from the list of custom backup paths
type RemoveCustomBackupPathRequest struct {
// ID of the grid
// Required: true
GID uint64 `url:"gridId" json:"gridId" validate:"required"`
// Absolute path
// Required: true
Path string `url:"path" json:"path" validate:"required"`
}
// RemoveCustomBackupPath remove path from the list of custom backup paths
func (g Grid) RemoveCustomBackupPath(ctx context.Context, req RemoveCustomBackupPathRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/removeCustomBackupPath"
res, err := g.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
}

View File

@@ -0,0 +1,42 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// RenameRequest struct to rename grid
type RenameRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// New name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
}
// Rename renames a grid
func (g Grid) Rename(ctx context.Context, req RenameRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/rename"
res, err := g.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
}

View File

@@ -0,0 +1,43 @@
package grid
import (
"encoding/json"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (lg ListGrids) Serialize(params ...string) (serialization.Serialized, error) {
if len(lg.Data) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(lg, prefix, indent)
}
return json.Marshal(lg)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (rg RecordGrid) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(rg, prefix, indent)
}
return json.Marshal(rg)
}

View File

@@ -0,0 +1,42 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ServicesRestartRequest struct to restart services
type ServicesRestartRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// Node ID
// Required: true
NID uint64 `url:"nid" json:"nid" validate:"required"`
}
// ServicesRestart restarts decort services on the node
func (g Grid) ServicesRestart(ctx context.Context, req ServicesRestartRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/servicesRestart"
res, err := g.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
}

View File

@@ -0,0 +1,44 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SetCPUAllocationParameterRequest for setting CPU allocation parameter
type SetCPUAllocationParameterRequest struct {
// Grid ID
// Required: true
GridID uint64 `url:"gridId" json:"gridId" validate:"required"`
// CPU allocation parameter.
// If "strict" VM can't be run if not enough CPU resources.
// "loose" allow running VM if not enough resources.
// Required: true
StrictLoose string `url:"strict_loose" json:"strict_loose" validate:"required,strict_loose"`
}
// SetCPUAllocationParameter sets CPU allocation parameter
func (g Grid) SetCPUAllocationParameter(ctx context.Context, req SetCPUAllocationParameterRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/setCpuAllocationParameter"
res, err := g.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
}

View File

@@ -0,0 +1,42 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SetCPUAllocationRatioRequest struct to set allocation
type SetCPUAllocationRatioRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gridId" json:"gridId" validate:"required"`
// Allocation ratio
// Required: true
Ratio float64 `url:"ratio" json:"ratio" validate:"required"`
}
// SetCPUAllocationRatio sets CPU allocation ratio
func (g Grid) SetCPUAllocationRatio(ctx context.Context, req SetCPUAllocationRatioRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/setCpuAllocationRatio"
res, err := g.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
}

View File

@@ -0,0 +1,42 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SetCPUAllocationRatioForVMRequest for setting CPU allocation ratio for computes
type SetCPUAllocationRatioForVMRequest struct {
// Grid ID
// Required: true
GridID uint64 `url:"gridId" json:"gridId" validate:"required"`
// Default CPU allocation ratio for computes
// Required: true
Ratio float64 `url:"ratio" json:"ratio" validate:"required"`
}
// SetCPUAllocationRatioForVM sets CPU allocation ratio for computes
func (g Grid) SetCPUAllocationRatioForVM(ctx context.Context, req SetCPUAllocationRatioForVMRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/setCpuAllocationRatioForVM"
res, err := g.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
}

View File

@@ -0,0 +1,42 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SetMemAllocationRatioRequest struct to set memory allocation
type SetMemAllocationRatioRequest struct {
// Grid (platform) ID
// Required: true
GID uint64 `url:"gridId" json:"gridId" validate:"required"`
// Allocation ratio
// Required: true
Ratio float64 `url:"ratio" json:"ratio" validate:"required"`
}
// SetMemAllocationRatio sets memory allocation ratio
func (g Grid) SetMemAllocationRatio(ctx context.Context, req SetMemAllocationRatioRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/setMemAllocationRatio"
res, err := g.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
}

View File

@@ -0,0 +1,70 @@
package grid
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SetPasswordPolicyRequest struct to set password policy for a grid
type SetPasswordPolicyRequest struct {
// ID of the grid
// Required: true
GID uint64 `url:"gridId" json:"gridId" validate:"required"`
// Available numbers in the password
// Default value : true
// Required: true
Digits interface{} `url:"digits" json:"digits" validate:"isBool"`
// Available special characters in the password
// Default value : false
// Required: true
SpecialSymbols bool `url:"specialSymbols" json:"specialSymbols"`
// Number of characters in the password
// Default value : 9
// Required: true
PasswordLength uint64 `url:"passwordLength" json:"passwordLength"`
// Capital letters in the password are available
// Default value : true
// Required: true
Uppercase interface{} `url:"uppercase" json:"uppercase" validate:"isBool"`
}
// RemoveCustomBackupPath set set password policy for a grid
func (g Grid) SetPasswordPolicy(ctx context.Context, req SetPasswordPolicyRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
if req.PasswordLength == 0 {
req.PasswordLength = 9
}
if req.Digits == nil {
req.Digits = true
}
if req.Uppercase == nil {
req.Uppercase = true
}
url := "/cloudbroker/grid/setPasswordPolicy"
res, err := g.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
}

View File

@@ -0,0 +1,41 @@
package grid
import (
"context"
"net/http"
"strconv"
)
// Status check if current environment is active
func (g Grid) Status(ctx context.Context) (bool, error) {
url := "/cloudbroker/grid/status"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, nil)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
// StatusGET check if current environment is active
func (g Grid) StatusGET(ctx context.Context) (bool, error) {
url := "/cloudbroker/grid/status"
res, err := g.client.DecortApiCall(ctx, http.MethodGet, url, nil)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}