v1.0.0
This commit is contained in:
59
pkg/cloudbroker/grid/add.go
Normal file
59
pkg/cloudbroker/grid/add.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for location code
|
||||
type AddRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
|
||||
// Name of the location
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// Location code typicly used in dns names
|
||||
// Required: true
|
||||
LocationCode string `url:"locationcode"`
|
||||
}
|
||||
|
||||
func (grq AddRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if grq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if grq.LocationCode == "" {
|
||||
return errors.New("validation-error: field LocationCode must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Add location code (e.g. DNS name of this grid)
|
||||
func (g Grid) Add(ctx context.Context, req AddRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/grid/change_settings.go
Normal file
52
pkg/cloudbroker/grid/change_settings.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for change grid settings
|
||||
type ChangeSettingsRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"id"`
|
||||
|
||||
// Json data of the new settings will override old data
|
||||
// Required: true
|
||||
Settings string `url:"settings"`
|
||||
}
|
||||
|
||||
func (grq ChangeSettingsRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if grq.Settings == "" {
|
||||
return errors.New("validation-error: field Settings must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChangeSettings changes grid settings
|
||||
func (g Grid) ChangeSettings(ctx context.Context, req ChangeSettingsRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
45
pkg/cloudbroker/grid/check_vms.go
Normal file
45
pkg/cloudbroker/grid/check_vms.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for check virtual machine
|
||||
type CheckVMsRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
}
|
||||
|
||||
func (grq CheckVMsRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckVMs run checkvms jumpscript
|
||||
func (g Grid) CheckVMs(ctx context.Context, req CheckVMsRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/grid/checkVMs"
|
||||
|
||||
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
|
||||
}
|
||||
79
pkg/cloudbroker/grid/create_system_space.go
Normal file
79
pkg/cloudbroker/grid/create_system_space.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for create system space
|
||||
type CreateSystemSpaceRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"id"`
|
||||
|
||||
// Name of the account/cloudspace to be created for the system
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// ID of the specific image
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId"`
|
||||
|
||||
// Size of base volume
|
||||
// Required: true
|
||||
BootSize uint64 `url:"bootsize"`
|
||||
|
||||
// Data disk size in gigabytes
|
||||
// Required: true
|
||||
DataDiskSize uint64 `url:"dataDiskSize"`
|
||||
|
||||
// ID of the specific size
|
||||
// Required: false
|
||||
SizeID uint64 `url:"sizeId,omitempty"`
|
||||
|
||||
// Number of vcpus to provide
|
||||
// Required: false
|
||||
VCPUS uint64 `url:"vcpus,omitempty"`
|
||||
|
||||
// Amount of memory to provide
|
||||
// Required: false
|
||||
Memory uint64 `url:"memory,omitempty"`
|
||||
}
|
||||
|
||||
func (grq CreateSystemSpaceRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if grq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if grq.BootSize == 0 {
|
||||
return errors.New("validation-error: field BootSize must be set")
|
||||
}
|
||||
if grq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID must be set")
|
||||
}
|
||||
if grq.DataDiskSize == 0 {
|
||||
return errors.New("validation-error: field DataDiskSize must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateSystemSpace creates system space
|
||||
func (g Grid) CreateSystemSpace(ctx context.Context, req CreateSystemSpaceRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/grid/createSystemSpace"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
59
pkg/cloudbroker/grid/execute_maintenance_script.go
Normal file
59
pkg/cloudbroker/grid/execute_maintenance_script.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for execute script
|
||||
type ExecuteMaintenanceScriptRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID string `url:"gid"`
|
||||
|
||||
// Type of nodes you want to apply the action on
|
||||
// Required: true
|
||||
NodesType string `url:"nodestype"`
|
||||
|
||||
// The script you want to run
|
||||
// Required: true
|
||||
Script string `url:"script"`
|
||||
}
|
||||
|
||||
func (grq ExecuteMaintenanceScriptRequest) validate() error {
|
||||
if grq.GID == "" {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if grq.NodesType == "" {
|
||||
return errors.New("validation-error: field NodesType must be set")
|
||||
}
|
||||
if grq.Script == "" {
|
||||
return errors.New("validation-error: field Script must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExecuteMaintenanceScript executes maintenance script
|
||||
func (g Grid) ExecuteMaintenanceScript(ctx context.Context, req ExecuteMaintenanceScriptRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
47
pkg/cloudbroker/grid/get.go
Normal file
47
pkg/cloudbroker/grid/get.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get grid details
|
||||
type GetRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gridId"`
|
||||
}
|
||||
|
||||
func (grq GetRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get gets information about grid by ID
|
||||
func (g Grid) Get(ctx context.Context, req GetRequest) (*RecordGrid, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/grid/get"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordGrid{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
56
pkg/cloudbroker/grid/get_backup.go
Normal file
56
pkg/cloudbroker/grid/get_backup.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get backup
|
||||
type GetBackupRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
}
|
||||
|
||||
func (grq GetBackupRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBackup gets platform backup
|
||||
func (g Grid) GetBackup(ctx context.Context, req GetBackupRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", 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 := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/grid/getBackup"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
56
pkg/cloudbroker/grid/get_diagnosis.go
Normal file
56
pkg/cloudbroker/grid/get_diagnosis.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get platform snapshot with additional diagnosis
|
||||
type GetDiagnosisRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
}
|
||||
|
||||
func (grq GetDiagnosisRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDiagnosis get platform snapshot with additional diagnosis info like a logs, etc
|
||||
func (g Grid) GetDiagnosis(ctx context.Context, req GetDiagnosisRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", 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 get platform snapshot with additional diagnosis info like a logs, etc
|
||||
func (g Grid) GetDiagnosisGET(ctx context.Context, req GetDiagnosisRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/grid/getDiagnosis"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
18
pkg/cloudbroker/grid/grid.go
Normal file
18
pkg/cloudbroker/grid/grid.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Operator actions for handling interventions on a grid
|
||||
package grid
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/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,
|
||||
}
|
||||
}
|
||||
37
pkg/cloudbroker/grid/list.go
Normal file
37
pkg/cloudbroker/grid/list.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list locations
|
||||
type ListRequest struct {
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list all locations
|
||||
func (g Grid) List(ctx context.Context, req ListRequest) (ListGrids, error) {
|
||||
url := "/cloudbroker/grid/list"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListGrids{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
26
pkg/cloudbroker/grid/list_emails.go
Normal file
26
pkg/cloudbroker/grid/list_emails.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ListEmails returns list of email addresses of users
|
||||
func (g Grid) ListEmails(ctx context.Context) ([]string, error) {
|
||||
url := "/cloudbroker/grid/listEmails"
|
||||
|
||||
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]string, 0)
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
58
pkg/cloudbroker/grid/models.go
Normal file
58
pkg/cloudbroker/grid/models.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package grid
|
||||
|
||||
// Resource information
|
||||
type Resources struct {
|
||||
// Current resources
|
||||
Current RecordResource `json:"Current"`
|
||||
|
||||
// Reserved resources
|
||||
Reserved RecordResource `json:"Reserved"`
|
||||
}
|
||||
|
||||
// Resource details
|
||||
type RecordResource struct {
|
||||
// Number of CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// Disk size
|
||||
DiskSize uint64 `json:"disksize"`
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// Detailed information about grid
|
||||
type RecordGrid struct {
|
||||
// Resource information
|
||||
Resources Resources `json:"Resources"`
|
||||
|
||||
// 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 []RecordGrid
|
||||
53
pkg/cloudbroker/grid/purge_logs.go
Normal file
53
pkg/cloudbroker/grid/purge_logs.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for purge logs
|
||||
type PurgeLogsRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
func (grq PurgeLogsRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if grq.Age == "" {
|
||||
return errors.New("validation-error: field Age must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/grid/rename.go
Normal file
52
pkg/cloudbroker/grid/rename.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for rename grid
|
||||
type RenameRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
|
||||
// New name
|
||||
// Required: true
|
||||
Name string `url:"Name"`
|
||||
}
|
||||
|
||||
func (grq RenameRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if grq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Rename renames a grid
|
||||
func (g Grid) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/grid/services_restart.go
Normal file
52
pkg/cloudbroker/grid/services_restart.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for restart services
|
||||
type ServicesRestartRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
|
||||
// Node ID
|
||||
// Required: true
|
||||
NID uint64 `url:"nid"`
|
||||
}
|
||||
|
||||
func (grq ServicesRestartRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if grq.NID == 0 {
|
||||
return errors.New("validation-error: field NID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ServicesRestart restarts decort services on the node
|
||||
func (g Grid) ServicesRestart(ctx context.Context, req ServicesRestartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/grid/set_cpu_allocation_ratio.go
Normal file
52
pkg/cloudbroker/grid/set_cpu_allocation_ratio.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for set allocation
|
||||
type SetCPUAllocationRatioRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gridId"`
|
||||
|
||||
// Allocation ratio
|
||||
// Required: true
|
||||
Ratio float64 `url:"ratio"`
|
||||
}
|
||||
|
||||
func (grq SetCPUAllocationRatioRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if grq.Ratio == 0.0 {
|
||||
return errors.New("validation-error: field Ratio must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetCPUAllocationRatio sets CPU allocation ratio
|
||||
func (g Grid) SetCPUAllocationRatio(ctx context.Context, req SetCPUAllocationRatioRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
52
pkg/cloudbroker/grid/set_mem_allocation_ratio.go
Normal file
52
pkg/cloudbroker/grid/set_mem_allocation_ratio.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for set memory allocation
|
||||
type SetMemAllocationRatioRequest struct {
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gridId"`
|
||||
|
||||
// Allocation ratio
|
||||
// Required: true
|
||||
Ratio float64 `url:"ratio"`
|
||||
}
|
||||
|
||||
func (grq SetMemAllocationRatioRequest) validate() error {
|
||||
if grq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if grq.Ratio == 0.0 {
|
||||
return errors.New("validation-error: field Ratio must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetMemAllocationRatio sets memory allocation ratio
|
||||
func (g Grid) SetMemAllocationRatio(ctx context.Context, req SetMemAllocationRatioRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, 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
|
||||
}
|
||||
41
pkg/cloudbroker/grid/status.go
Normal file
41
pkg/cloudbroker/grid/status.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user