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,10 @@
package cloudbroker
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/pkg/cloudbroker/account"
)
// Accessing the Account method group
func (cb *CloudBroker) Account() *account.Account {
return account.New(cb.client)
}

View File

@@ -0,0 +1,16 @@
// API Actor API for managing account
package account
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
// Structure for creating request to account
type Account struct {
client interfaces.Caller
}
// Builder for account endpoints
func New(client interfaces.Caller) *Account {
return &Account{
client: client,
}
}

View File

@@ -0,0 +1,49 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AddUserRequest struct for adding permission to access to account for a user
type AddUserRequest struct {
// ID of account to add to
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Name of the user to be given rights
// Required: true
Username string `url:"username" json:"username" validate:"required"`
// Account permission types:
// - 'R' for read only access
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype" json:"accesstype" validate:"accessType"`
}
// AddUser gives a user access rights.
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/addUser"
res, err := a.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,40 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AuditsRequest struct to give list of account audits
type AuditsRequest struct {
// ID of the account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Audits gets audit records for the specified account object
func (a Account) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/audits"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,85 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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"`
// List of strings with pools
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
// Advanced compute features,
// one of: hugepages, numa, cpupin, vfnic
// Required: false
ComputeFeatures []string `url:"computeFeatures,omitempty" json:"computeFeatures,omitempty" validate:"omitempty,computeFeatures"`
}
// 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 := "/cloudbroker/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
}

View File

@@ -0,0 +1,36 @@
package account
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteRequest struct to delete account
type DeleteRequest struct {
// ID of account to delete
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Whether to completely delete the account
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
}
// Delete completes delete an account from the system Returns true if account is deleted or was already deleted or never existed
func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/delete"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

View File

@@ -0,0 +1,36 @@
package account
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteAccountsRequest struct to delete group of accounts
type DeleteAccountsRequest struct {
// IDs of accounts
// Required: true
AccountsIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
// Whether to completely destroy accounts or not
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
}
// DeleteAccounts destroys a group of accounts
func (a Account) DeleteAccounts(ctx context.Context, req DeleteAccountsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/deleteAccounts"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

View File

@@ -0,0 +1,42 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteUserRequest struct to revoke access to account
type DeleteUserRequest struct {
// ID of the account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// ID or emailaddress of the user to remove
// Required: true
UserName string `url:"username" json:"username" validate:"required"`
}
// DeleteUser revokes user access from the account
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/deleteUser"
res, err := a.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,38 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DisableRequest struct to disable account
type DisableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Disable disables an account
func (a Account) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/disable"
res, err := a.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,32 @@
package account
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DisableAccountsRequest struct to disable group of accounts
type DisableAccountsRequest struct {
// IDs of accounts
// Required: true
AccountIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
}
// DisableAccounts disables accounts
func (a Account) DisableAccounts(ctx context.Context, req DisableAccountsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/disableAccounts"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

View File

@@ -0,0 +1,38 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// EnableRequest struct to enable account
type EnableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Enable enables an account
func (a Account) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/enable"
res, err := a.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,32 @@
package account
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// EnableAccountsRequest to enable group of accounts
type EnableAccountsRequest struct {
// IDs od accounts
// Required: true
AccountIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
}
// EnableAccounts enables accounts
func (a Account) EnableAccounts(ctx context.Context, req EnableAccountsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/enableAccounts"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

View File

@@ -0,0 +1,88 @@
package account
// FilterByID returns ListAccounts with specified ID.
func (la ListAccounts) FilterByID(id uint64) ListAccounts {
predicate := func(ia ItemAccount) bool {
return ia.ID == id
}
return la.FilterFunc(predicate)
}
// FilterByName returns ListAccounts with specified Name.
func (la ListAccounts) FilterByName(name string) ListAccounts {
predicate := func(ia ItemAccount) bool {
return ia.Name == name
}
return la.FilterFunc(predicate)
}
// FilterByStatus returns ListAccounts with specified Status.
func (la ListAccounts) FilterByStatus(status string) ListAccounts {
predicate := func(ia ItemAccount) bool {
return ia.Status == status
}
return la.FilterFunc(predicate)
}
// FilterByUserGroupID returns ListAccounts with specified UserGroupID.
func (la ListAccounts) FilterByUserGroupID(userGroupID string) ListAccounts {
predicate := func(ia ItemAccount) bool {
acl := ia.ACL
for _, item := range acl {
if item.UserGroupID == userGroupID {
return true
}
}
return false
}
return la.FilterFunc(predicate)
}
// FilterByCompany returns ListAccounts with specified Company.
func (la ListAccounts) FilterByCompany(company string) ListAccounts {
predicate := func(ia ItemAccount) bool {
return ia.Company == company
}
return la.FilterFunc(predicate)
}
// FilterByCreatedBy returns ListAccounts created by specified user.
func (la ListAccounts) FilterByCreatedBy(createdBy string) ListAccounts {
predicate := func(ia ItemAccount) bool {
return ia.CreatedBy == createdBy
}
return la.FilterFunc(predicate)
}
// FilterFunc allows filtering ListAccounts based on a user-specified predicate.
func (la ListAccounts) FilterFunc(predicate func(ItemAccount) bool) ListAccounts {
var result ListAccounts
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 ItemAccount.
// If none was found, returns an empty struct.
func (la ListAccounts) FindOne() ItemAccount {
if len(la.Data) == 0 {
return ItemAccount{}
}
return la.Data[0]
}

View File

@@ -0,0 +1,158 @@
package account
import (
"testing"
)
var accounts = ListAccounts{
Data: []ItemAccount{
{
Meta: []interface{}{},
InfoAccount: InfoAccount{
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "not_really_timofey_tkachev_1@decs3o",
},
},
CreatedTime: 1676878820,
DeletedTime: 0,
ID: 132847,
Name: "std_2",
Status: "CONFIRMED",
UpdatedTime: 1676645275,
},
},
{
Meta: []interface{}{},
InfoAccount: InfoAccount{
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "timofey_tkachev_1@decs3o",
},
},
CreatedTime: 1676645275,
DeletedTime: 1677723401,
ID: 132846,
Name: "std",
Status: "DELETED",
UpdatedTime: 1676645275,
},
},
{
Meta: []interface{}{},
InfoAccount: InfoAccount{
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "timofey_tkachev_1@decs3o",
},
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "second_account@decs3o",
},
},
CreatedTime: 1676883850,
DeletedTime: 1676883899,
ID: 132848,
Name: "std_broker",
Status: "DELETED",
UpdatedTime: 1676878820,
},
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
actual := accounts.FilterByID(132846).FindOne()
if actual.ID != 132846 {
t.Fatal("actual: ", actual.ID, " > expected: 132846")
}
}
func TestFilterByUserGroupId(t *testing.T) {
actual := accounts.FilterByUserGroupID("second_account@decs3o").FindOne()
for _, item := range actual.ACL {
if item.UserGroupID == "second_account@decs3o" {
return
}
}
t.Fatal("second_account@decs3o has not been found. expected 1 found")
}
func TestFilterByName(t *testing.T) {
actual := accounts.FilterByName("std_broker").FindOne()
if actual.Name != "std_broker" {
t.Fatal("actual: ", actual.Name, " >> expected: std_broker")
}
}
func TestFilterByStatus(t *testing.T) {
actual := accounts.FilterByStatus("DELETED")
if len(actual.Data) != 2 {
t.Fatal("Expected 2 elements in slice, found: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.Status != "DELETED" {
t.Fatal("expected DELETED, found: ", item.Status)
}
}
}
func TestFilterFunc(t *testing.T) {
actual := accounts.FilterFunc(func(ia ItemAccount) bool {
return ia.DeletedTime == 0
})
for _, item := range actual.Data {
if item.DeletedTime != 0 {
t.Fatal("Expected DeletedTime = 0, found: ", item.DeletedTime)
}
}
}
func TestSortingByCreatedTime(t *testing.T) {
actual := accounts.SortByCreatedTime(false)
if actual.Data[0].Name != "std" {
t.Fatal("Expected account std as earliest, found: ", actual.Data[0].Name)
}
actual = accounts.SortByCreatedTime(true)
if actual.Data[0].Name != "std_broker" {
t.Fatal("Expected account std_broker as latest, found: ", actual.Data[0].Name)
}
}
func TestFilterEmpty(t *testing.T) {
actual := accounts.FilterByID(0)
if len(actual.Data) != 0 {
t.Fatal("Expected 0 found, actual: ", len(actual.Data))
}
}

View File

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

View File

@@ -0,0 +1,40 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetResourceConsumptionRequest struct for getting resource consumption
type GetResourceConsumptionRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// GetResourceConsumption shows amount of consumed and reserved resources (cpu, ram, disk) by specific account
func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResourceConsumption, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/getResourceConsumption"
info := RecordResourceConsumption{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,42 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GrantAccessTemplatesRequest struct to share images with account
type GrantAccessTemplatesRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// list of image IDs
// Required: true
ImageIDs []uint64 `url:"imageIds" json:"imageIds" validate:"required"`
}
// GrantAccessTemplates shares specified images with specified account
func (a Account) GrantAccessTemplates(ctx context.Context, req GrantAccessTemplatesRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/grantAccessTemplates"
res, err := a.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,64 @@
package account
// IDs gets array of AccountIDs from ListAccounts struct
func (la ListAccounts) IDs() []uint64 {
res := make([]uint64, 0, len(la.Data))
for _, acc := range la.Data {
res = append(res, acc.ID)
}
return res
}
// IDs gets array of ComputeIDs from ListComputes struct
func (lc ListComputes) IDs() []uint64 {
res := make([]uint64, 0, len(lc.Data))
for _, c := range lc.Data {
res = append(res, c.ID)
}
return res
}
// IDs gets array of DiskIDs from ListDisks struct
func (ld ListDisks) IDs() []uint64 {
res := make([]uint64, 0, len(ld.Data))
for _, d := range ld.Data {
res = append(res, d.ID)
}
return res
}
// IDs gets array of FLIPGroupIDs from ListFLIPGroups struct
func (fg ListFLIPGroups) IDs() []uint64 {
res := make([]uint64, 0, len(fg.Data))
for _, g := range fg.Data {
res = append(res, g.ID)
}
return res
}
// IDs gets array of AccountIDs from ListResourceConsumption struct
func (rc ListResources) IDs() []uint64 {
res := make([]uint64, 0, len(rc.Data))
for _, r := range rc.Data {
res = append(res, r.AccountID)
}
return res
}
// IDs gets array of RGIDs from ListRG struct
func (rg ListRG) IDs() []uint64 {
res := make([]uint64, 0, len(rg.Data))
for _, g := range rg.Data {
res = append(res, g.ID)
}
return res
}
// IDs gets array of VINSIDs from ListVINS struct
func (lv ListVINS) IDs() []uint64 {
res := make([]uint64, 0, len(lv.Data))
for _, v := range lv.Data {
res = append(res, v.ID)
}
return res
}

View File

@@ -0,0 +1,71 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListRequest struct to get list of accounts
type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by access control list
// Required: false
ACL string `url:"acl,omitempty" json:"acl,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,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 accounts the user has access to as a ListAccounts struct
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
res, err := a.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListAccounts{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of all accounts the user has access to as an array of bytes
func (a Account) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,41 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListAvailableTemplatesRequest struct to list templates who sharedWith include accountId
type ListAvailableTemplatesRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// ListAvailableTemplates lists templates who sharedWith include accountId
func (a Account) ListAvailableTemplates(ctx context.Context, req ListAvailableTemplatesRequest) ([]uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/listAvailableTemplates"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := make([]uint64, 0)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,85 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListComputesRequest struct to a get list of compute instances
type ListComputesRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Find by compute id
// Required: false
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by resource group name
// Required: false
RGName string `url:"rgName,omitempty" json:"rgName,omitempty"`
// Find by resource group id
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by tech status
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Find by ip address
// Required: false
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
// Find by external network name
// Required: false
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
// Find by external network id
// Required: false
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,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"`
}
// ListComputes gets list of all compute instances under specified account, accessible by the user
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/listComputes"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListComputes{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,60 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListDeletedRequest struct to get list of deleted accounts
type ListDeletedRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by access control list
// Required: false
ACL string `url:"acl,omitempty" json:"acl,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"`
}
// ListDeleted gets list all deleted accounts the user has access to
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAccounts, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/listDeleted"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListAccounts{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,69 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListDisksRequest struct to get list of deleted disks
type ListDisksRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Find by disk id
// Required: false
DiskID uint64 `url:"diskId,omitempty" json:"diskId,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by max size disk
// Required: false
DiskMaxSize uint64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
// Type of the disks
// Required: false
Type string `url:"type,omitempty" json:"type,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"`
}
// ListDisks gets list of all currently unattached disks under specified account
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (*ListDisks, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/listDisks"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListDisks{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,77 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListFLIPGroupsRequest struct to get list of FLIPGroups
type ListFLIPGroupsRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by vinsId
// Required: false
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
// Find by VINS name
// Required: false
VINSName string `url:"vinsName,omitempty" json:"vinsName,omitempty"`
// Find by external network id
// Required: false
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
// Find by IP
// Required: false
ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"`
// Find by flipGroup Id
// Required: false
FLIPGroupID uint64 `url:"flipGroupId,omitempty" json:"flipGroupId,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"`
}
// ListFLIPGroups gets list of all FLIPGroups under specified account, accessible by the user
func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (*ListFLIPGroups, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/listFlipGroups"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListFLIPGroups{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,26 @@
package account
import (
"context"
"encoding/json"
"net/http"
)
// ListResourceConsumption show data list amount of consumed and reserved resources (cpu, ram, disk) by specific accounts
func (a Account) ListResourceConsumption(ctx context.Context) (*ListResources, error) {
url := "/cloudbroker/account/listResourceConsumption"
info := ListResources{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,73 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListRGRequest struct to get list of resource groups
type ListRGRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// 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:"rgId,omitempty" json:"rgId,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by vinsId
// Required: false
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
// Find by VM ID
// Required: false
VMID uint64 `url:"vmId,omitempty" json:"vmId,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
}
// ListRG gets list of all resource groups under specified account, accessible by the user
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (*ListRG, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/listRG"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListRG{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,69 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListVINSRequest struct to get list of VINS
type ListVINSRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Find by VINS ID
// Required: false
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by resource group id
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by external network ip
// Required: false
ExtIP string `url:"extIp,omitempty" json:"extIp,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"`
}
// ListVINS gets list of all ViNSes under specified account, accessible by the user
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/listVins"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListVINS{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,577 @@
package account
// Main info about audit
type ItemAudit struct {
// Call
Call string `json:"call"`
// Response time
ResponseTime float64 `json:"responsetime"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// User
User string `json:"user"`
}
// List of audits
type ListAudits []ItemAudit
type RecordResourceConsumption struct {
ItemResourceConsumption
ResourceLimits ResourceLimits `json:"resourceLimits"`
}
type ItemResourceConsumption struct {
// Current information about resources
Consumed Resource `json:"consumed"`
// Reserved information about resources
Reserved Resource `json:"reserved"`
// ID of account
AccountID uint64 `json:"id"`
}
type ListResources struct {
// Data
Data []ItemResourceConsumption `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
type Resource struct {
// Number of cores
CPU int64 `json:"cpu"`
// Disk size
DiskSize float64 `json:"disksize"`
// Disk size max
DiskSizeMax float64 `json:"disksizemax"`
// Number of External IPs
ExtIPs int64 `json:"extips"`
// External traffic
ExtTraffic int64 `json:"exttraffic"`
// Number of grafic cores
GPU int64 `json:"gpu"`
// Number of RAM
RAM int64 `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"`
}
// Access Control List
type ACL struct {
// Whether access is explicitly specified
Explicit bool `json:"explicit"`
// GUID
GUID string `json:"guid"`
// Access rights
Right string `json:"right"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// User group ID
UserGroupID string `json:"userGroupId"`
}
// Resource limits
type ResourceLimits struct {
// CuC
CuC float64 `json:"CU_C"`
// CuD
CuD float64 `json:"CU_D"`
// CuDM
CuDM float64 `json:"CU_DM"`
// CuI
CuI float64 `json:"CU_I"`
// CuM
CuM float64 `json:"CU_M"`
// CuNP
CuNP float64 `json:"CU_NP"`
// GPUUnits
GPUUnits float64 `json:"gpu_units"`
}
// Main information about account
type InfoAccount struct {
// DCLocation
DCLocation string `json:"DCLocation"`
// CKey
CKey string `json:"_ckey"`
// Access Control List
ACL []ACL `json:"acl"`
// Company
Company string `json:"company"`
// Company URL
CompanyURL string `json:"companyurl"`
// Compute Features
ComputeFeatures []string `json:"computeFeatures"`
// CPU allocation parameter
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
// CPU allocation ratio
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deactivation time
DeactivationTime float64 `json:"deactivationTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Display name
DisplayName string `json:"displayname"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Resource limits
ResourceLimits ResourceLimits `json:"resourceLimits"`
// Resource types
ResTypes []string `json:"resourceTypes"`
// Send access emails
SendAccessEmails bool `json:"sendAccessEmails"`
// Status
Status string `json:"status"`
// UniqPools
UniqPools []string `json:"uniqPools"`
// UpdatedTime
UpdatedTime uint64 `json:"updatedTime"`
// Version
Version uint64 `json:"version"`
// List of VINS IDs
VINS []uint64 `json:"vins"`
}
// Deatailed information about account
type RecordAccount struct {
// Main information about account
InfoAccount
}
// More information about account
type ItemAccount struct {
// Meta
Meta []interface{} `json:"_meta"`
// Main information about account
InfoAccount
}
// List of accounts
type ListAccounts struct {
// Data
Data []ItemAccount `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// List of computes
type ListComputes struct {
// Data
Data []ItemCompute `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about compute
type ItemCompute struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Number of CPU
CPUs uint64 `json:"cpus"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Number of RAM
RAM uint64 `json:"ram"`
// Registered
Registered bool `json:"registered"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RgName string `json:"rgName"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Total disks size
TotalDisksSize uint64 `json:"totalDisksSize"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// User managed
UserManaged bool `json:"userManaged"`
// VINS Connected
VINSConnected uint64 `json:"vinsConnected"`
}
// List of disks
type ListDisks struct {
// Data
Data []ItemDisk `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about disks
type ItemDisk struct {
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Pool
Pool string `json:"pool"`
// SepID
SepID uint64 `json:"sepId"`
// Shareable
Shareable bool `json:"shareable"`
// Size max
SizeMax uint64 `json:"sizeMax"`
// Type
Type string `json:"type"`
}
// List of FLIPGroups
type ListFLIPGroups struct {
// Data
Data []ItemFLIPGroup `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about FLIPGroup
type ItemFLIPGroup struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Client type
ClientType string `json:"clientType"`
// Connection type
ConnType string `json:"connType"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Default GW
DefaultGW string `json:"defaultGW"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// IP
IP string `json:"ip"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Network ID
NetID uint64 `json:"netId"`
// Network type
NetType string `json:"netType"`
// Network mask
Netmask uint64 `json:"netmask"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
// Computes info
type Computes struct {
// Started
Started uint64 `json:"Started"`
// Stopped
Stopped uint64 `json:"Stopped"`
}
// Limits
type Limits struct {
// Number of CPU
CPU int64 `json:"cpu"`
// Disk size
DiskSize int64 `json:"disksize"`
// Disk size max
DiskSizeMax int64 `json:"disksizemax"`
// External IPs
ExtIPs int64 `json:"extips"`
// External traffic
ExtTraffic int64 `json:"exttraffic"`
// Number of GPU
GPU int64 `json:"gpu"`
// Number of RAM
RAM int64 `json:"ram"`
// SEPs number
SEPs uint64 `json:"seps"`
}
// Resources of resource group
type RGResuorces struct {
// Consumed
Consumed Resource `json:"Consumed"`
// Limits
Limits Limits `json:"Limits"`
// Reserved
Reserved Resource `json:"Reserved"`
}
// Main information about Resource group
type ItemRG struct {
// Compute
Computes Computes `json:"Computes"`
// Resources of resource group
Resources RGResuorces `json:"Resources"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// ID
ID uint64 `json:"id"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Number of VINSes
VINSes uint64 `json:"vinses"`
}
// List of resource groups
type ListRG struct {
// Data
Data []ItemRG `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about VINS
type ItemVINS struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Computes
Computes uint64 `json:"computes"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// External IP
ExternalIP string `json:"externalIP"`
// Extnet ID
ExtnetId uint64 `json:"extnetId"`
// Free IPs
FreeIPs int64 `json:"freeIPs"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Network
Network string `json:"network"`
// PriVNFDevID
PriVNFDevID uint64 `json:"priVnfDevId"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RGName string `json:"rgName"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
// List of VINSes
type ListVINS struct {
//Data
Data []ItemVINS `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -0,0 +1,32 @@
package account
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// RestoreRequest struct to restore a deleted account
type RestoreRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Restore restores a deleted account
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/restore"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

View File

@@ -0,0 +1,42 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// RevokeAccessTemplatesRequest struct to unshare images with account
type RevokeAccessTemplatesRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// list of image IDs
// Required: true
ImageIDs []uint64 `url:"imageIds" json:"imageIds" validate:"required"`
}
// RevokeAccessTemplates unshares specified images with specified account
func (a Account) RevokeAccessTemplates(ctx context.Context, req RevokeAccessTemplatesRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/revokeAccessTemplates"
res, err := a.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 account
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 (la ListAccounts) Serialize(params ...string) (serialization.Serialized, error) {
if la.EntryCount == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(la, prefix, indent)
}
return json.Marshal(la)
}
// 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 (ia ItemAccount) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(ia, prefix, indent)
}
return json.Marshal(ia)
}

View File

@@ -0,0 +1,44 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SetCPUAllocationParameterRequest struct for setting CPU allocation parameter
type SetCPUAllocationParameterRequest struct {
// Account ID
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" 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 (a Account) SetCPUAllocationParameter(ctx context.Context, req SetCPUAllocationParameterRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/setCpuAllocationParameter"
res, err := a.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 account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SetCPUAllocationRatioRequest struct for setting CPU allocation ratio
type SetCPUAllocationRatioRequest struct {
// Account ID
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// CPU allocation ratio, i.e. one pCPU = ratio*vCPU
// Required: true
Ratio float64 `url:"ratio" json:"ratio" validate:"required"`
}
// SetCPUAllocationRatio sets CPU allocation ratio
func (a Account) SetCPUAllocationRatio(ctx context.Context, req SetCPUAllocationRatioRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/setCpuAllocationRatio"
res, err := a.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,60 @@
package account
import "sort"
// SortByCreatedTime sorts ListAccounts by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts {
if len(la.Data) < 2 {
return la
}
sort.Slice(la.Data, func(i, j int) bool {
if inverse {
return la.Data[i].CreatedTime > la.Data[j].CreatedTime
}
return la.Data[i].CreatedTime < la.Data[j].CreatedTime
})
return la
}
// SortByUpdatedTime sorts ListAccounts by the UpdatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts {
if len(la.Data) < 2 {
return la
}
sort.Slice(la.Data, func(i, j int) bool {
if inverse {
return la.Data[i].UpdatedTime > la.Data[j].UpdatedTime
}
return la.Data[i].UpdatedTime < la.Data[j].UpdatedTime
})
return la
}
// SortByDeletedTime sorts LisAccounts by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (la ListAccounts) SortByDeletedTime(inverse bool) ListAccounts {
if len(la.Data) < 2 {
return la
}
sort.Slice(la.Data, func(i, j int) bool {
if inverse {
return la.Data[i].DeletedTime > la.Data[j].DeletedTime
}
return la.Data[i].DeletedTime < la.Data[j].DeletedTime
})
return la
}

View File

@@ -0,0 +1,80 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UpdateRequest struct to update account
type UpdateRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Name of the account
// Required: false
Name string `url:"name" json:"name"`
// 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"`
// List of strings with pools
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
// if True the field will be cleared
// Default: false
// Required: false
ClearUniqPools bool `url:"clearUniqPools" json:"clearUniqPools"`
}
// Update updates an account name and resource types and limits
func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/update"
res, err := a.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 account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UpdateComputeFeaturesRequest struct to update advanced compute features
type UpdateComputeFeaturesRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Advanced compute features,
// one of: hugepages, numa, cpupin, vfnic
// Required: false
ComputeFeatures []string `url:"computeFeatures,omitempty" json:"computeFeatures,omitempty" validate:"omitempty,computeFeatures"`
}
// UpdateComputeFeatures updates advanced compute features
func (a Account) UpdateComputeFeatures(ctx context.Context, req UpdateComputeFeaturesRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/updateComputeFeatures"
res, err := a.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,48 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UpdateResourceTypesRequest struct to update resource types in account
type UpdateResourceTypesRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Resource types available to create in this account
// Each element in a resource type slice must be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: true
ResTypes []string `url:"resourceTypes" json:"resourceTypes" validate:"min=1,resTypes"`
}
func (a Account) UpdateResourceTypes(ctx context.Context, req UpdateResourceTypesRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/updateResourceTypes"
res, err := a.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,49 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UpdateUserRequest struct to update user access rights
type UpdateUserRequest struct {
// ID of the account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Userid/Email for registered users or emailaddress for unregistered users
// Required: true
UserID string `url:"userId" json:"userId" validate:"required"`
// Account permission types:
// - 'R' for read only access
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype" json:"accesstype" validate:"accessType"`
}
// UpdateUser updates user access rights
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/updateUser"
res, err := a.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,8 @@
package cloudbroker
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/pkg/cloudbroker/apiaccess"
// Accessing the APIAccess method group
func (cb *CloudBroker) APIAccess() *apiaccess.APIAccess {
return apiaccess.New(cb.client)
}

View File

@@ -0,0 +1,41 @@
package apiaccess
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// APIFindRequest struct for finding apiaccess groups.
type APIFindRequest struct {
// API function to find
// Example: cloudbroker/k8s/create
// Required: true
APIName string `url:"apiName" json:"apiName" validate:"required"`
}
// APIFind outputs a list of apiaccess groups that mention the specified API function.
func (a APIAccess) APIFind(ctx context.Context, req APIFindRequest) ([]uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/apiFind"
list := make([]uint64, 0)
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,15 @@
package apiaccess
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
// Structure for creating request to APIAccess
type APIAccess struct {
client interfaces.Caller
}
// Builder for APIAccess endpoints
func New(client interfaces.Caller) *APIAccess {
return &APIAccess{
client: client,
}
}

View File

@@ -0,0 +1,69 @@
package apiaccess
import (
"context"
"encoding/json"
"fmt"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
type APIString string
// APIsExcludeRequest struct for removing api from access group.
type APIsExcludeRequest struct {
// APIAccess group ID
// Required: true
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
// APIs to remove from APIAccess group
// Required: true
APIs APIString `url:"-" json:"apis" validate:"required"`
}
type wrapperAPIsExcludeRequest struct {
APIsExcludeRequest
APIString string `url:"apis"`
}
// APIsExclude removes the listed API functions from the specified apiaccess group.
func (a APIAccess) APIsExclude(ctx context.Context, req APIsExcludeRequest) (*APIsEndpoints, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/apisExclude"
info := APIsEndpoints{}
apiJSON, err := json.Marshal(&req.APIs)
if err != nil {
return nil, err
}
apiJSONPretty, err := json.MarshalIndent(&req.APIs, "", " ")
if err != nil {
return nil, err
}
fmt.Println(string(apiJSONPretty))
reqWrapped := wrapperAPIsExcludeRequest{
APIsExcludeRequest: req,
APIString: string(apiJSON),
}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,60 @@
package apiaccess
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// APIsIncludeRequest struct for adding api to access group.
type APIsIncludeRequest struct {
// APIAccess group ID.
// Required: true
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
// APIs to add to APIAccess group.
// Required: true
APIs APIString `url:"-" json:"apis" validate:"required"`
}
type wrapperAPIsIncludeRequest struct {
APIsIncludeRequest
APIString string `url:"apis"`
}
// APIsInclude adds the listed API functions to the specified apiaccess group.
func (a APIAccess) APIsInclude(ctx context.Context, req APIsIncludeRequest) (*APIsEndpoints, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/apisInclude"
info := APIsEndpoints{}
apiJSON, err := json.Marshal(&req.APIs)
if err != nil {
return nil, err
}
reqWrapped := wrapperAPIsIncludeRequest{
APIsIncludeRequest: req,
APIString: string(apiJSON),
}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,42 @@
package apiaccess
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CopyRequest Request for copying apiaccess group.
type CopyRequest struct {
// ID of the API access group to make copy from
// Required: true
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
// Name of the target API access group, which will be created on successful copy
// Required: true
Name string `url:"name" json:"name" validate:"required"`
}
// Copy creates a copy of the specified apiaccess group with a new name (and a new unique ID).
func (a APIAccess) Copy(ctx context.Context, req CopyRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/copy"
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
}

View File

@@ -0,0 +1,42 @@
package apiaccess
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CreateRequest struct for creating apiaccess group.
type CreateRequest struct {
// Name of this apiaccess group.
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Description of this apiaccess group.
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
}
// Create creates apiaccess group.
func (a APIAccess) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/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
}

View File

@@ -0,0 +1,42 @@
package apiaccess
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteRequest struct for deleting apiaccess group.
type DeleteRequest struct {
// APIAccess group ID.
// Required: true
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
// Set True to delete apiaccess group with attached users.
// Required: false
Force bool `url:"force,omitempty" json:"force,omitempty"`
}
// Delete deletes apiaccess group
func (a APIAccess) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/delete"
res, err := a.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 apiaccess
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DescUpdateRequest struct for updating apiaccess group description.
type DescUpdateRequest struct {
// APIAccess group ID.
// Required: true
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
// New description to set for the apiaccess group.
// Required: true
Description string `url:"desc" json:"desc" validate:"required"`
}
// DescUpdate sets a new text description of the apiaccess group.
func (a APIAccess) DescUpdate(ctx context.Context, req DescUpdateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/descUpdate"
res, err := a.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 apiaccess
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetRequest struct to get apiaccess group.
type GetRequest struct {
// APIAccess group ID.
// Required: true
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
}
// Get gets apiaccess group as an ItemAPIAccess struct
func (a APIAccess) Get(ctx context.Context, req GetRequest) (*ItemAPIAccess, error) {
res, err := a.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := ItemAPIAccess{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets apiaccess group as an array of bytes
func (a APIAccess) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/get"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,26 @@
package apiaccess
import (
"context"
"encoding/json"
"net/http"
)
// GetFull gets full current endpoints dictionary
func (a APIAccess) GetFull(ctx context.Context) (*APIsEndpoints, error) {
url := "/cloudbroker/apiaccess/getFull"
info := APIsEndpoints{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,26 @@
package apiaccess
import (
"context"
"encoding/json"
"net/http"
)
// GetPreGroups gets list of pre default groups from spec
func (a APIAccess) GetPreGroups(ctx context.Context) (map[string]APIsEndpoints, error) {
url := "/cloudbroker/apiaccess/getPreGroups"
info := make(map[string]APIsEndpoints)
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return info, nil
}

View File

@@ -0,0 +1,10 @@
package apiaccess
// IDs gets array of APIAccessId from ListAPIAccess struct
func (laa ListAPIAccess) IDs() []uint64 {
res := make([]uint64, 0, len(laa.Data))
for _, apiaccess := range laa.Data {
res = append(res, apiaccess.ID)
}
return res
}

View File

@@ -0,0 +1,79 @@
package apiaccess
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListRequest struct to get list of all non deleted apiaccess instances.
type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name apiaccess
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by status apiaccess
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by created actor
// Required: false
CreatedBy string `url:"createdBy,omitempty" json:"createdBy,omitempty"`
// Find by created after time (unix timestamp)
// Required: false
CreatedAfter uint64 `url:"createdAfter,omitempty" json:"createdAfter,omitempty"`
// Find by created before time (unix timestamp)
// Required: false
CreatedBefore uint64 `url:"createdBefore,omitempty" json:"createdBefore,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, maximum - 100
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of all non deleted apiaccess instances as a ListAPIAccess struct
func (a APIAccess) List(ctx context.Context, req ListRequest) (*ListAPIAccess, error) {
res, err := a.ListRaw(ctx, req)
if err != nil {
return nil, err
}
info := ListAPIAccess{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// ListRaw gets list of all non deleted apiaccess instances as an array of bytes
func (a APIAccess) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,48 @@
package apiaccess
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListDeletedRequest struct for getting list of all deleted apiaccess instances.
type ListDeletedRequest struct {
// 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"`
}
// ListDeleted gets list of all deleted apiaccess instances.
func (a APIAccess) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAPIAccess, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/listDeleted"
info := ListAPIAccess{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,180 @@
package apiaccess
type ItemAPIAccess struct {
// APIs
APIs APIsEndpoints `json:"apis"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Is default
Default bool `json:"default"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"decs"`
// GID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Is protected
Protected bool `json:"protected"`
// Status
Status string `json:"status"`
//Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
type ListAPIAccess struct {
Data []ItemAPIAccess `json:"data"`
EntryCount uint64 `json:"entryCount"`
}
type APIsEndpoints struct {
// CloudAPI endpoints
CloudAPI CloudAPIEndpoints `json:"cloudapi,omitempty"`
// CloudBroker endpoints
CloudBroker CloudBrokerEndpoints `json:"cloudbroker,omitempty"`
// LibCloud endpoints
LibCloud LibCloudEndpoints `json:"libcloud,omitempty"`
// System endpoints
System SystemEndpoints `json:"system,omitempty"`
}
type CloudAPIEndpoints struct {
Account []string `json:"account,omitempty"`
BService []string `json:"bservice,omitempty"`
CloudSpace []string `json:"cloudspace,omitempty"`
Compute []string `json:"compute,omitempty"`
ComputeCI []string `json:"computeci,omitempty"`
Disks []string `json:"disks,omitempty"`
ExtNet []string `json:"extnet,omitempty"`
FLIPGroup []string `json:"flipgroup,omitempty"`
GPU []string `json:"gpu,omitempty"`
Image []string `json:"image,omitempty"`
K8CI []string `json:"k8ci,omitempty"`
K8S []string `json:"k8s,omitempty"`
KVMX86 []string `json:"kvmx86,omitempty"`
LB []string `json:"lb,omitempty"`
Loactions []string `json:"locations,omitempty"`
Machine []string `json:"machine,omitempty"`
Openshift []string `json:"openshift,omitempty"`
OpenshiftCI []string `json:"openshiftci,omitempty"`
PCIDevice []string `json:"pcidevice,omitempty"`
PortForwarding []string `json:"portforwarding,omitempty"`
Prometheus []string `json:"prometheus,omitempty"`
RG []string `json:"rg,omitempty"`
Sizes []string `json:"sizes,omitempty"`
Tasks []string `json:"tasks,omitempty"`
User []string `json:"user,omitempty"`
VGPU []string `json:"vgpu,omitempty"`
VINS []string `json:"vins,omitempty"`
All bool `json:"ALL,omitempty"`
}
type CloudBrokerEndpoints struct {
Account []string `json:"account,omitempty"`
APIAccess []string `json:"apiaccess,omitempty"`
Audit interface{} `json:"audit,omitempty"`
AuditBeat []string `json:"auditbeat,omitempty"`
AuditCollector []string `json:"auditcollector,omitempty"`
BackupCreator []string `json:"backupcreator,omitempty"`
BService []string `json:"bservice,omitempty"`
CloudSpace []string `json:"cloudspace,omitempty"`
Compute []string `json:"compute,omitempty"`
ComputeCI []string `json:"computeci,omitempty"`
Desnode []string `json:"desnode,omitempty"`
Diagnostics []string `json:"diagnostics,omitempty"`
Disks []string `json:"disks,omitempty"`
Eco []string `json:"eco,omitempty"`
ExtNet []string `json:"extnet,omitempty"`
FlIPgroup []string `json:"flipgroup,omitempty"`
Grid []string `json:"grid,omitempty"`
Group []string `json:"group,omitempty"`
Health []string `json:"health,omitempty"`
IaaS []string `json:"iaas,omitempty"`
Image []string `json:"image,omitempty"`
Job interface{} `json:"job,omitempty"`
K8CI []string `json:"k8ci,omitempty"`
K8S []string `json:"k8s,omitempty"`
KVMX86 []string `json:"kvmx86,omitempty"`
LB []string `json:"lb,omitempty"`
Machine []string `json:"machine,omitempty"`
Metering []string `json:"metering,omitempty"`
Milestones []string `json:"milestones,omitempty"`
Node []string `json:"node,omitempty"`
Openshift []string `json:"openshift,omitempty"`
OpenshiftCI []string `json:"openshiftci,omitempty"`
Ovsnode []string `json:"ovsnode,omitempty"`
PCIDevice []string `json:"pcidevice,omitempty"`
PGPU []string `json:"pgpu,omitempty"`
Prometheus []string `json:"prometheus,omitempty"`
QOS []string `json:"qos,omitempty"`
Resmon interface{} `json:"resmon,omitempty"`
RG []string `json:"rg,omitempty"`
Sep []string `json:"sep,omitempty"`
Stack []string `json:"stack,omitempty"`
Tasks []string `json:"tasks,omitempty"`
TLock []string `json:"tlock,omitempty"`
User []string `json:"user,omitempty"`
VGPU []string `json:"vgpu,omitempty"`
VINS []string `json:"vins,omitempty"`
VNFDev []string `json:"vnfdev,omitempty"`
ZeroAccess []string `json:"zeroaccess,omitempty"`
All bool `json:"ALL,omitempty"`
}
type LibCloudEndpoints struct {
Libvirt []string `json:"libvirt,omitempty"`
All bool `json:"ALL,omitempty"`
}
type SystemEndpoints struct {
AgentController []string `json:"agentcontroller,omitempty"`
Alerts []string `json:"alerts,omitempty"`
Audits []string `json:"audits,omitempty"`
ContentManager []string `json:"contentmanager,omitempty"`
DocGenerator []string `json:"docgenerator,omitempty"`
EmailSender []string `json:"emailsender,omitempty"`
ErrorConditionHandler []string `json:"errorconditionhandler,omitempty"`
GridManager []string `json:"gridmanager,omitempty"`
Health []string `json:"health,omitempty"`
Info []string `json:"info,omitempty"`
InfoMGR []string `json:"infomgr,omitempty"`
Job []string `json:"job,omitempty"`
Log []string `json:"log,omitempty"`
Logo []string `json:"logo,omitempty"`
Oauth []string `json:"oauth,omitempty"`
Task []string `json:"task,omitempty"`
UserManager []string `json:"usermanager,omitempty"`
All bool `json:"ALL,omitempty"`
}

View File

@@ -0,0 +1,38 @@
package apiaccess
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SetDefaultRequest struct for setting default apiaccess group.
type SetDefaultRequest struct {
// APIAccess group ID
// Required: true
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
}
// SetDefault sets current apiaccess group default.
func (a APIAccess) SetDefault(ctx context.Context, req SetDefaultRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/setDefault"
res, err := a.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 apiaccess
import (
"encoding/json"
"net/http"
"context"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SubtractRequest struct for subtracting.
type SubtractRequest struct {
// ID of the API access group to subtract from. This group will contain the difference.
MinuendID uint64 `url:"minuendId" json:"minuendId" validate:"required"`
// ID of the API access group which is subtracted. This group is unchanged.
SubtrahendID uint64 `url:"subtrahendId" json:"subtrahendId" validate:"required"`
}
// Subtract removes such APIs from MinuendID that match APIs from SubtrahendID.
func (a APIAccess) Subtruct(ctx context.Context, req SubtractRequest) (*APIsEndpoints, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/subtract"
info := APIsEndpoints{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,45 @@
package apiaccess
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UnionRequest struct for union.
type UnionRequest struct {
// Recipient apiaccess group ID
// Required: true
RecipientID uint64 `url:"recipientId" json:"recipientId" validate:"required"`
// Donor apiaccess group ID
// Required: true
DonorID uint64 `url:"donorId" json:"donorId" validate:"required"`
}
// Union combines the API list of group #1 ("recipient") and group #2 ("donor"),
// writing the result to group #1 and avoiding duplicates in the list
func (a APIAccess) Union(ctx context.Context, req UnionRequest) (*APIsEndpoints, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/union"
info := APIsEndpoints{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,60 @@
package apiaccess
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UpdateRequest struct for updating apis of apiaccess group.
type UpdateRequest struct {
// APIAccess group ID
// Required: true
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
// APIs to remove from APIAccess group
// Required: false
APIs APIsEndpoints `url:"-" json:"-"`
}
type wrapperUpdateRequest struct {
UpdateRequest
APIString string `url:"apis"`
}
// Update updates apis of apiaccess group.
func (a APIAccess) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/update"
reqWrapped := wrapperUpdateRequest{
UpdateRequest: req,
}
apiJSON, err := json.Marshal(&req.APIs)
if err != nil {
return false, err
}
reqWrapped.APIString = string(apiJSON)
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
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,48 @@
package apiaccess
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UserListRequest struct for getting a list of users currently included in the specified group.
type UserListRequest struct {
// APIAccess group ID
// Required: true
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// UserList gets a list of users currently included in the specified group.
func (a APIAccess) UserList(ctx context.Context, req UserListRequest) ([]string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/apiaccess/userList"
list := make([]string, 0)
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

10
pkg/cloudbroker/audit.go Normal file
View File

@@ -0,0 +1,10 @@
package cloudbroker
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/pkg/cloudbroker/audit"
)
// Accessing the Stack method group
func (cb *CloudBroker) Audit() *audit.Audit {
return audit.New(cb.client)
}

View File

@@ -0,0 +1,15 @@
package audit
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
// Structure for creating request to audit
type Audit struct {
client interfaces.Caller
}
// Builder for audit endpoint
func New(client interfaces.Caller) *Audit {
return &Audit{
client: client,
}
}

View File

@@ -0,0 +1,18 @@
package audit
import (
"context"
"net/http"
)
// ExportAuditsToFile Get audits in csv file, return []byte which should be written to a file *tar.gz
func (a Audit) ExportAuditsToFile(ctx context.Context) ([]byte, error) {
url := "/cloudbroker/audit/exportAuditsToFile"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, nil)
if err != nil {
return nil, err
}
return res, nil
}

View File

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

View File

@@ -0,0 +1,46 @@
package audit
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// LinkedJobsRequest struct to get information about jobs linked with Audit
type LinkedJobsRequest struct {
// Audit GUID
// Required: true
AuditGuid string `url:"auditGuid" json:"auditGuid" validate:"required"`
}
// LinkedJobs gets information about Linked Jobs as a ListLinkedJobs struct
func (a Audit) LinkedJobs(ctx context.Context, req LinkedJobsRequest) (*ListLinkedJobs, error) {
res, err := a.GetRawLinkedJobs(ctx, req)
if err != nil {
return nil, err
}
info := ListLinkedJobs{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRawLinkedJobs gets information about Linked Jobs as an array of bytes
func (a Audit) GetRawLinkedJobs(ctx context.Context, req LinkedJobsRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/audit/linkedJobs"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,80 @@
package audit
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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:"timestampAt,omitempty" json:"timestampAt,omitempty"`
// Find all audits before point in time (unixtime)
// Required: false
TimestampTo uint64 `url:"timestampTo,omitempty" json:"timestampTo,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 HTTP min status code
// Required: false
MinStatusCode uint64 `url:"minStatusCode,omitempty" json:"minStatusCode,omitempty"`
// Find by HTTP max status code
// Required: false
MaxStatusCode uint64 `url:"maxStatusCode,omitempty" json:"maxStatusCode,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 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 := "/cloudbroker/audit/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,102 @@
package audit
// Main info about audit
type ItemAudit struct {
// Call
Call string `json:"call"`
// GUID
GUID string `json:"guid"`
// Response time
ResponseTime float64 `json:"responsetime"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// User
User string `json:"user"`
}
// List of audits
type ListAudits struct {
// Data
Data []ItemAudit `json:"data"`
// EntryCount
EntryCount uint64 `json:"entryCount"`
}
// Main info about audit
type RecordAudit struct {
// Arguments
Arguments string `json:"args"`
// Call
Call string `json:"call"`
// GUID
GUID string `json:"guid"`
// Kwargs
Kwargs string `json:"kwargs"`
// RemoteAddr
RemoteAddr string `json:"remote_addr"`
// Response time
ResponseTime float64 `json:"responsetime"`
// Result
Result string `json:"result"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Tags
Tags string `json:"tags"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// TimestampEnd
TimestampEnd float64 `json:"timestampEnd"`
// User
User string `json:"user"`
}
// List of Linked Jobs
type ListLinkedJobs []ItemLinkedJobs
// Main info about Linked Jobs
type ItemLinkedJobs struct {
// CMD
CMD string `json:"cmd"`
// GUID
GUID string `json:"guid"`
// NID
NID uint64 `json:"nid"`
// state
State string `json:"state"`
// TimeCreate
TimeCreate uint64 `json:"timeCreate"`
// TimeStart
TimeStart uint64 `json:"timeStart"`
// TimeStop
TimeStop uint64 `json:"timeStop"`
// Timeout
Timeout uint64 `json:"timeout"`
}

View File

@@ -0,0 +1,8 @@
package cloudbroker
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/pkg/cloudbroker/backup"
// Accessing the Backup method group
func (cb *CloudBroker) Backup() *backup.Backup {
return backup.New(cb.client)
}

View File

@@ -0,0 +1,17 @@
package backup
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
)
// Structure for creating request to backup
type Backup struct {
client interfaces.Caller
}
// Builder for backup endpoints
func New(client interfaces.Caller) *Backup {
return &Backup{
client: client,
}
}

View File

@@ -0,0 +1,84 @@
package backup
import (
"context"
"encoding/json"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CreateDiskBackupRequest struct for creating disk backup
type CreateDiskBackupRequest struct {
// Compute ID
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Disk ID
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Backup path
// Required: true
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
}
type wrapperCreateDiskBackupRequest struct {
CreateDiskBackupRequest
AsyncMode bool `url:"asyncMode"`
}
// CreateDiskBackup creates disk backup
func (b Backup) CreateDiskBackup(ctx context.Context, req CreateDiskBackupRequest) (ListInfoBackup, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperCreateDiskBackupRequest{
CreateDiskBackupRequest: req,
AsyncMode: false,
}
url := "/cloudbroker/backup/createDiskBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return nil, err
}
result := make(ListInfoBackup, 0)
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return result, nil
}
// CreateDiskBackupAsync creates disk backup
func (b Backup) CreateDiskBackupAsync(ctx context.Context, req CreateDiskBackupRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperCreateDiskBackupRequest{
CreateDiskBackupRequest: req,
AsyncMode: true,
}
url := "/cloudbroker/backup/createDiskBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,86 @@
package backup
import (
"context"
"encoding/json"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
type Disk struct {
// Disk ID
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Backup path
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
}
// CreateDisksBackupRequest struct for creating disks backup
type CreateDisksBackupRequest struct {
// Compute ID
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Disks
Disks []Disk `url:"disks" json:"disks" validate:"required,dive"`
}
type wrapperCreateDisksBackupRequest struct {
CreateDisksBackupRequest
AsyncMode bool `url:"asyncMode"`
}
// CreateDisksBackup creates disks backup
func (b Backup) CreateDisksBackup(ctx context.Context, req CreateDisksBackupRequest) (ListInfoBackup, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperCreateDisksBackupRequest{
CreateDisksBackupRequest: req,
AsyncMode: false,
}
url := "/cloudbroker/backup/createDisksBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return nil, err
}
result := make(ListInfoBackup, 0)
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return result, nil
}
// CreateDisksBackupAsync creates disks backup
func (b Backup) CreateDisksBackupAsync(ctx context.Context, req CreateDisksBackupRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperCreateDisksBackupRequest{
CreateDisksBackupRequest: req,
AsyncMode: true,
}
url := "/cloudbroker/backup/createDisksBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,76 @@
package backup
import (
"context"
"net/http"
"strconv"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteDiskBackupRequest struct for deleting disk backup
type DeleteDiskBackupRequest struct {
// Backup path
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
// Backup file
BackupFile string `url:"backupFile" json:"backupFile" validate:"required"`
}
type wrapperDeleteDiskBackupRequest struct {
DeleteDiskBackupRequest
AsyncMode bool `url:"asyncMode"`
}
// DeleteDiskBackup deletes disk backup
func (b Backup) DeleteDiskBackup(ctx context.Context, req DeleteDiskBackupRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperDeleteDiskBackupRequest{
DeleteDiskBackupRequest: req,
AsyncMode: false,
}
url := "/cloudbroker/backup/deleteDiskBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
// DeleteDiskBackupAsync deletes disk backup
func (b Backup) DeleteDiskBackupAsync(ctx context.Context, req DeleteDiskBackupRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperDeleteDiskBackupRequest{
DeleteDiskBackupRequest: req,
AsyncMode: true,
}
url := "/cloudbroker/backup/deleteDiskBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,40 @@
package backup
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListBackupPathsRequest struct for getting list of backup paths
type ListBackupPathsRequest struct {
// Grid ID
GID uint64 `url:"gridId" json:"gridId" validate:"required"`
}
// ListBackupPaths gets list of backup paths
func (b Backup) ListBackupPaths(ctx context.Context, req ListBackupPathsRequest) ([]string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/backup/listBackupPaths"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := make([]string, 0)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,31 @@
package backup
// Main info about backup
type InfoBackup struct {
// Compute ID
ComputeID uint64 `json:"computeId"`
// Disk ID
DiskID uint64 `json:"diskId"`
// Backup path
BackupPath string `json:"backupPath"`
// Possible error
Error string `json:"error"`
}
// CreateDisksBackup response
type ListInfoBackup []InfoBackup
// RestoreDiskFromFile response
type InfoRestoredDisk struct {
// Compute ID
ComputeID uint64 `json:"computeId"`
// Disk ID
DiskID uint64 `json:"diskId"`
}
// RestoreDisksFromFile response
type ListInfoRestoredDisk []InfoRestoredDisk

View File

@@ -0,0 +1,84 @@
package backup
import (
"context"
"encoding/json"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// RestoreDiskFromBackupRequest struct for restoring disk from backup
type RestoreDiskFromBackupRequest struct {
// Compute ID
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Disk ID
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Backup path
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
// Backup file
BackupFile string `url:"backupFile" json:"backupFile" validate:"required"`
}
type wrapperRestoreDiskFromBackupRequest struct {
RestoreDiskFromBackupRequest
AsyncMode bool `url:"asyncMode"`
}
// RestoreDiskFromBackup restores disk from backup
func (b Backup) RestoreDiskFromBackup(ctx context.Context, req RestoreDiskFromBackupRequest) (ListInfoRestoredDisk, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperRestoreDiskFromBackupRequest{
RestoreDiskFromBackupRequest: req,
AsyncMode: false,
}
url := "/cloudbroker/backup/restoreDiskFromBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return nil, err
}
result := make(ListInfoRestoredDisk, 0)
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return result, nil
}
// RestoreDiskFromBackupAsync restores disk from backup
func (b Backup) RestoreDiskFromBackupAsync(ctx context.Context, req RestoreDiskFromBackupRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperRestoreDiskFromBackupRequest{
RestoreDiskFromBackupRequest: req,
AsyncMode: true,
}
url := "/cloudbroker/backup/restoreDiskFromBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,89 @@
package backup
import (
"context"
"encoding/json"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
type BackupFile struct {
// Disk ID
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Backup path
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
// Backup file
BackupFile string `url:"backupFile" json:"backupFile" validate:"required"`
}
// RestoreDisksFromBackupRequest struct for restoring disks from backup
type RestoreDisksFromBackupRequest struct {
// Compute ID
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
//Backup files
BackupFiles []BackupFile `url:"disks" json:"disks" validate:"required,dive"`
}
type wrapperRestoreDisksFromBackupRequest struct {
RestoreDisksFromBackupRequest
AsyncMode bool `url:"asyncMode"`
}
// RestoreDisksFromBackup restores disks from backup
func (b Backup) RestoreDisksFromBackup(ctx context.Context, req RestoreDisksFromBackupRequest) (ListInfoRestoredDisk, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperRestoreDisksFromBackupRequest{
RestoreDisksFromBackupRequest: req,
AsyncMode: false,
}
url := "/cloudbroker/backup/restoreDisksFromBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return nil, err
}
result := make(ListInfoRestoredDisk, 0)
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return result, nil
}
// RestoreDisksFromBackupAsync restores disks from backup
func (b Backup) RestoreDisksFromBackupAsync(ctx context.Context, req RestoreDisksFromBackupRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperRestoreDisksFromBackupRequest{
RestoreDisksFromBackupRequest: req,
AsyncMode: true,
}
url := "/cloudbroker/backup/restoreDisksFromBackup"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,16 @@
// List of method groups for the admin
package cloudbroker
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
// Structure for creating request to CloudBroker groups
type CloudBroker struct {
client interfaces.Caller
}
// Builder to get access to CloudBroker
func New(client interfaces.Caller) *CloudBroker {
return &CloudBroker{
client: client,
}
}

View File

@@ -0,0 +1,10 @@
package cloudbroker
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/pkg/cloudbroker/compute"
)
// Accessing the Compute method group
func (cb *CloudBroker) Compute() *compute.Compute {
return compute.New(cb.client)
}

View File

@@ -0,0 +1,36 @@
package compute
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AffinityGroupCheckStartRequest struct to check all computes with current affinity label can start
type AffinityGroupCheckStartRequest struct {
// ID of the resource group
// Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Affinity group label
// Required: true
AffinityLabel string `url:"affinityLabel" json:"affinityLabel" validate:"required"`
}
// AffinityGroupCheckStart check all computes with current affinity label can start
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/affinityGroupCheckStart"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,38 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AffinityLabelRemoveRequest struct for clear affinity label for compute
type AffinityLabelRemoveRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
}
// AffinityLabelRemove clear affinity label for compute
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/affinityLabelRemove"
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
}

View File

@@ -0,0 +1,41 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AffinityLabelSetRequest struct to set affinity label for compute
type AffinityLabelSetRequest struct {
// IDs of the compute instances
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
// Affinity group label
// Required: true
AffinityLabel string `url:"affinityLabel" json:"affinityLabel" validate:"required"`
}
// AffinityLabelSet sets affinity label for compute
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/affinityLabelSet"
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
}

View File

@@ -0,0 +1,40 @@
package compute
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AffinityRelationsRequest struct to get dict of computes
type AffinityRelationsRequest struct {
// ID of the compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// AffinityRelations gets dict of computes divided by affinity and anti affinity rules
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*RecordAffinityRelations, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/affinityRelations"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := RecordAffinityRelations{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,68 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AffinityRuleAddRequest struct to add affinity rule
type AffinityRuleAddRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
// Should be one of:
// - node
// - compute
// Required: true
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: false
// Not required on purpose: despite required tag on platform, empty string is allowed
Value string `url:"value" json:"value"`
}
// AffinityRuleAdd adds affinity rule
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/affinityRuleAdd"
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
}

View File

@@ -0,0 +1,66 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AffinityRuleRemoveRequest struct to remove affinity rule
type AffinityRuleRemoveRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: false
// Not required on purpose: despite required tag on platform, empty string is allowed
Value string `url:"value" json:"value"`
}
// AffinityRuleRemove remove affinity rule
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/affinityRuleRemove"
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
}

View File

@@ -0,0 +1,38 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AffinityRulesClearRequest struct to clear affinity rules
type AffinityRulesClearRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
}
// AffinityRulesClear clears affinity rules
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/affinityRulesClear"
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
}

View File

@@ -0,0 +1,66 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AntiAffinityRuleAddRequest struct to add anti affinity rule
type AntiAffinityRuleAddRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: false
// Not required on purpose: despite required tag on platform, empty string is allowed
Value string `url:"value" json:"value"`
}
// AntiAffinityRuleAdd adds anti affinity rule
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/antiAffinityRuleAdd"
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
}

View File

@@ -0,0 +1,38 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AntiAffinityRulesClearRequest struct to clear anti affinity rules
type AntiAffinityRulesClearRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
}
// AntiAffinityRulesClear clear anti affinity rules
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/antiAffinityRulesClear"
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
}

View File

@@ -0,0 +1,66 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AntiAffinityRuleRemoveRequest struct to remove anti affinity rule
type AntiAffinityRuleRemoveRequest struct {
// IDs of the compute instances
// Required: true
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
// Compute or node, for whom rule applies
// Required: true
Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule
// Should be one of:
// - RECOMMENDED
// - REQUIRED
// Required: true
Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key'
// Should be one of:
// - EQ
// - EN
// - ANY
// Required: true
Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified
// Required: true
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: false
// Not required on purpose: despite required tag on platform, empty string is allowed
Value string `url:"value" json:"value"`
}
// AntiAffinityRuleRemove removes anti affinity rule
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/antiAffinityRuleRemove"
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
}

View File

@@ -0,0 +1,42 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AttachGPURequest struct to attach GPU for compute
type AttachGPURequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Identifier vGPU
// Required: true
VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
}
// AttachGPU attaches GPU for compute, returns vGPU ID on success
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/attachGpu"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,42 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AttachPCIDeviceRequest struct to attach PCI device
type AttachPCIDeviceRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// PCI device ID
// Required: true
DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
}
// AttachPCIDevice attaches PCI device
func (c Compute) AttachPCIDevice(ctx context.Context, req AttachPCIDeviceRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/attachPciDevice"
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
}

View File

@@ -0,0 +1,40 @@
package compute
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AuditsRequest struct to get audit records
type AuditsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Audits gets audit records for the specified compute object
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListDetailedAudits, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/audits"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListDetailedAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,42 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// BootDiskSetRequest struct to set boot disk for compute
type BootDiskSetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to set as boot
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// BootDiskSet sets boot disk for compute
func (c Compute) BootDiskSet(ctx context.Context, req BootDiskSetRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/bootDiskSet"
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
}

View File

@@ -0,0 +1,40 @@
package compute
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// BootOrderGetRequest struct to get boot order
type BootOrderGetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// BootOrderGet gets actual compute boot order information
func (c Compute) BootOrderGet(ctx context.Context, req BootOrderGetRequest) ([]string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/bootOrderGet"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
orders := make([]string, 0)
err = json.Unmarshal(res, &orders)
if err != nil {
return nil, err
}
return orders, nil
}

View File

@@ -0,0 +1,48 @@
package compute
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// BootOrderSetRequest struct to set boot order
type BootOrderSetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// List of boot devices
// Should be one of:
// - cdrom
// - network
// - hd
// Required: true
Order []string `url:"order" json:"order" validate:"min=1,computeOrder"`
}
// BootOrderSet sets compute boot order
func (c Compute) BootOrderSet(ctx context.Context, req BootOrderSetRequest) ([]string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/bootOrderSet"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
orders := make([]string, 0)
err = json.Unmarshal(res, &orders)
if err != nil {
return nil, err
}
return orders, nil
}

View File

@@ -0,0 +1,38 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CDEjectRequest struct to eject CD image
type CDEjectRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// CDEject ejects CD image to compute's CD-ROM
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/cdEject"
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, err
}

View File

@@ -0,0 +1,36 @@
package compute
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CDInsertRequest struct to insert new CD image
type CDInsertRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of CD-ROM image
// Required: true
CDROMID uint64 `url:"cdromId" json:"cdromId" validate:"required"`
}
// CDInsert inserts new CD image to compute's CD-ROM
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/cdInsert"
_, err = c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
return true, nil
}

View File

@@ -0,0 +1,54 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ChangeIPRequest struct to change IP for network
type ChangeIPRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Network type
// 'EXTNET' for connect to external network directly
// 'VINS' for connect to ViNS
// Required: true
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
// Network ID for connect to
// For EXTNET - external network ID
// For VINS - VINS ID
// Required: true
NetID uint64 `url:"netId" json:"netId" validate:"required"`
// IP address to which we will change the existing one, it must be from the same subnet
// Required: true
IPAddr string `url:"ipAddr" json:"ipAddr" validate:"required"`
}
// ChangeIP change reserved IP for compute instance
func (c Compute) ChangeIP(ctx context.Context, req ChangeIPRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/changeIp"
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
}

View File

@@ -0,0 +1,46 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ChangeLinkStateRequest struct for changing link state
type ChangeLinkStateRequest struct {
// Compute ID
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Interface name or MAC address
// Required: true
Interface string `url:"interface" json:"interface" validate:"required"`
// Interface state
// Must be either "on" or "off"
// Required: true
State string `url:"state" json:"state" validate:"required,interfaceState"`
}
// ChangeLinkState changes the status link virtual of compute
func (c Compute) ChangeLinkState(ctx context.Context, req ChangeLinkStateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/changeLinkState"
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
}

View File

@@ -0,0 +1,55 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CloneRequest struct to clone compute instance
type CloneRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name of the clone
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Timestamp of the parent's snapshot to create clone from
// Required: false
SnapshotTimestamp uint64 `url:"snapshotTimestamp" json:"snapshotTimestamp"`
// Name of the parent's snapshot to create clone from
// Required: false
SnapshotName string `url:"snapshotName" json:"snapshotName"`
// true ignore that the compute is running
// Default: false
// Required: false
Force bool `url:"force" json:"force"`
}
// Clone clones compute instance
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/clone"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,16 @@
// API Actor for managing Compute. This actor is a final API for admin to manage Compute
package compute
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
// Structure for creating request to compute
type Compute struct {
client interfaces.Caller
}
// Builder for compute endpoints
func New(client interfaces.Caller) *Compute {
return &Compute{
client: client,
}
}

View File

@@ -0,0 +1,42 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ComputeCISetRequest struct to set compute CI
type ComputeCISetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the Compute CI
// Required: true
ComputeCIID uint64 `url:"computeciId" json:"computeciId" validate:"required"`
}
// ComputeCISet sets compute CI ID for compute
func (c Compute) ComputeCISet(ctx context.Context, req ComputeCISetRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/computeciSet"
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
}

Some files were not shown because too many files have changed in this diff Show More