Compare commits

...

5 Commits

Author SHA1 Message Date
dayterr
095a18f27a v1.12.6 2025-10-02 12:36:47 +03:00
asteam
84a090f9e8 v1.12.5 2025-09-26 12:21:29 +03:00
befff7acd9 V1.12.4 2025-09-19 13:45:58 +03:00
dayterr
abd35f858c v1.12.3 2025-09-11 15:56:44 +03:00
asteam
825b1a0a00 v1.12.2 2025-08-29 12:51:25 +03:00
216 changed files with 6736 additions and 680 deletions

View File

@@ -1,27 +1,32 @@
## Version 1.12.1
## Version 1.12.6
Методы `Audits` в cloudapi/compute, cloudbroker/compute, cloudapi/account, cloudbroker/account, cloudapi/vins, cloudbroker/vins, cloudapi/rg и cloudbroker/rg стали deprecated и в следующих версиях будут удалены, вместо них необходимо использовать метод `List` в cloudapi/audit и cloudbroker/audit с соответствующими фильтрами
Метод `ListStacks` в cloudbroker/image стал deprecated и в следующих версиях будет удалён
Методы `AccessGrant`, `AccessGrantToPool`, `AccessRevoke`, `AccessRevokeToPool` в cloudbroker/sep стали deprecated и в следующих версиях будут удалены
### Добавлено
#### account
#### общее
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-559 | В структуру ответа `RecordACL` добавлено поле `Emails` в cloudapi/account |
#### compute
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-566 | Поле `TrunkTags` в структуру `ItemVNFInterface` в структуре ответа `RecordCompute` в cloudapi/compute и в структуру `ItemInterface` в структуре ответа `RecordCompute` в cloudbroker/compute |
| BGOS-492 | Метод `MigrateAbort` и структура запроса `MigrateAbortRequest` в cloudbroker/compute |
### Исправлено
#### accounts
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-559 | Структура ответа `ItemAccount` использует структуру `ListRecordACL` в поле `ACL` в cloudapi/account |
| BGOS-638 | Добавлена поддержка версий 4.1.0 и 4.2.0 в функцию check |
#### image
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-564 | Загрузка образов в cloudbroker/image |
| BGOS-481 | Метод `AsyncCreateCDROMImage` в cloudbroker/image |
#### node
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-634 | Метод `UpdateDescription` и структура запроса `UpdateDescriptionRequest` в cloudbroker/node |
#### stpolicy
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-636 | Вычисляемое поле `StoragePolicyID` в структуры ответа `InfoStoragePolicy` и `ItemStoragePolicy` в `cloudapi/stpolicy` и в cloudbroker/stpolicy |
#### vins
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-637 | Вычисляемое поле `LiveMigrationJobID` в структуры ответа `RecordVNFDev` в cloudapi/vins и в `VNFDev` cloudbroker/vins |

View File

@@ -1,6 +1,3 @@
# Внимание
Данная версия предназначена только для версии платформы 4.4.0 build 963!
# Decort SDK
Decort SDK - это библиотека, написанная на языке GO, позволяющая взаимодействовать с API облачной платформы **DECORT**. Библиотека содержит в себе структуры и методы, необходимые для отправки запросов. Decort SDK имеет встроенный http-клиент и поддерживает разные способы авторизации на платформе. Библиотека так же содержит в себе модели ответов от платформы.
@@ -100,6 +97,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
- `cloudapi` - пользовательская группа, которая позволяет воспользоваться всем стардартным функционалом платформы;
- `cloudbroker` - административная группа, которая позволяет воспользоваться всем стандартным функционалом платформы и расширенными возможностями, включающими в себя управление пользователями, ресурсами, платформами размещения ресурсов и т.д.
- `sdn` - группа для работы с SDN;
### Cloudapi
@@ -122,8 +120,10 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
- `Locations` - получение информации о grid площадки;
- `Prometheus` - получение статистики prometheus;
- `RG` - управление ресурсными группами аккаунта;
- `Security group` управление группами безопасности;
- `SEP` - управление storage endpoint (sep);
- `Stack` - получение информации о вычислительных узлах;
- `Storage policy` получение информации о политиках хранения;
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
- `Trunk` - получение информации о транковых портах;
- `VFPool` - управление пулом виртуальных сетевых функций;
@@ -157,8 +157,10 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
- `Prometheus` - получение статистики prometheus;
- `Resmon` - получение статистики resource monitoring;
- `RG` - управление ресурсными группами аккаунта;
- `Security group` управление группами безопасности;
- `SEP` - управление storage endpoint (sep);
- `Stack` - получение информации о вычислительных узлах;
- `Storage policy` управление политиками хранения;
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
- `Trunk` - управление транковыми портами;
- `User` - управление пользователями (индивидуально);
@@ -167,6 +169,13 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
- `VINS` - управление виртуальными изолированными сетями.
- `Zone` - управление зонами.
### SDN
`SDN` позволяет выполнять запросы к группе пользовательских конечных точек
Данная группа ручек позволяет выполнять следующие операции в платформе:
- `AccessGroup` - управление группами доступа
## Работа с библиотекой
Алгоритм работы с библиотекой выглядит следующим образом:
@@ -293,6 +302,7 @@ func main() {
- `pkg/cloudapi` - для `cloudapi`
- `pkg/cloudbroker` - для `cloudbroker`
- `pkg/sdn` - для `sdn`
В каждом пакете находятся пакеты групп API:
@@ -313,8 +323,10 @@ func main() {
- `pkg/cloudapi/locations` - для `Locations`
- `pkg/cloudapi/prometheus` - для `Prometheus`
- `pkg/cloudapi/rg` - для `RG`
- `pkg/cloudapi/secgroup` - для `Security group`
- `pkg/cloudapi/sep` - для `SEP`
- `pkg/cloudapi/stack` - для `Stack`
- `pkg/cloudapi/stpolicy` - для `Storage policy`
- `pkg/cloudapi/tasks` - для `Tasks`
- `pkg/cloudapi/trunk` - для `Trunk`
- `pkg/cloudapi/vfpool` - для `VFPool`
@@ -343,8 +355,10 @@ func main() {
- `pkg/cloudbroker/prometheus` - для `Prometheus`
- `pkg/cloudbroker/resmon` - для `Resmon`
- `pkg/cloudbroker/rg` - для `RG`
- `pkg/cloudbroker/secgroup` - для `Security group`
- `pkg/cloudbroker/sep` - для `SEP`
- `pkg/cloudbroker/stack` - для `Stack`
- `pkg/cloudbroker/stpolicy` - для `Storage policy`
- `pkg/cloudbroker/tasks` - для `Tasks`
- `pkg/cloudbroker/trunk` - для `Trunk`
- `pkg/cloudbroker/user` - для `User`
@@ -352,6 +366,8 @@ func main() {
- `pkg/cloudbroker/vfpool` - для `VFPool`
- `pkg/cloudbroker/vins` - для `VINS`
- `pkg/cloudbroker/zone` - для `Zone`
- **sdn**:
- `pkg/sdn/access_groups` - для `AccessGroups`
Все поля структуры имеют описание, в которых содержится:
@@ -485,7 +501,7 @@ func main() {
Чтобы выполнить запрос, необходимо:
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно совершать запросы.
1. Вызвать у клиента метод, отвечающий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, `.CloudBroker()` или `.SDN()`. Данные методы возвращают соответствующие структуры, с помощью которых можно совершать запросы.
2. Вызвать у возвращенной структуры метод, определяющий группу ручек для взаимодействия.
Доступные методы для `.CloudAPI()`:
@@ -506,8 +522,10 @@ func main() {
- `.Locations()` - для работы с `Locations`
- `.Prometheus()` - для работы с `Prometheus`
- `.RG()` - для работы с `RG`
- `.SecurityGroup()` - для работы с `Security Group`
- `.SEP()` - для работы с `SEP`
- `.Stack()` - для работы с `Stack`
- `.StPolicy()` - для работы с `Storage Policy`
- `.Tasks()` - для работы с `Tasks`
- `.Trunk()` - для работы с `Trunk`
- `.VFPool()` - для работы с `VFPool`
@@ -538,8 +556,10 @@ func main() {
- `.Prometheus()` - для работы с `Prometheus`
- `.Resmon()` - для работы с `Resmon`
- `.RG()` - для работы с `RG`
- `.SecurityGroup()` - для работы с `Security Group`
- `.SEP()` - для работы с `SEP`
- `.Stack()` - для работы с `Stack`
- `.StPolicy()` - для работы с `Storage Policy`
- `.Tasks()` - для работы с `Tasks`
- `.Trunk()` - для работы с `Trunk`
- `.User()` - для работы с `User`
@@ -548,6 +568,10 @@ func main() {
- `.VINS()` - для работы с `VINS`
- `.Zone()` - для работы с `Zone`
Доступные методы для `.SDN()`:
- `.AccessGroup()` - для работы с `AccessGroup`
3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
- контекст;

View File

@@ -28,7 +28,13 @@ func (de DecortClient) Check() (*CheckInfo, error) {
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
if err != nil {
return nil, err
var v string
json.Unmarshal([]byte(res), &v)
if _, exists := constants.VersionMap[v]; exists {
info.Version = v
} else {
return nil, fmt.Errorf("platform version isn't supported")
}
}
if v, ok := constants.VersionMap[info.Version]; ok {
@@ -51,7 +57,13 @@ func (bvs BVSDecortClient) Check() (*CheckInfo, error) {
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
if err != nil {
return nil, err
var v string
json.Unmarshal([]byte(res), &v)
if _, exists := constants.VersionMap[v]; exists {
info.Version = v
} else {
return nil, fmt.Errorf("platform version isn't supported")
}
}
if v, ok := constants.VersionMap[info.Version]; ok {
@@ -74,7 +86,13 @@ func (ldc LegacyDecortClient) Check() (*CheckInfo, error) {
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
if err != nil {
return nil, err
var v string
json.Unmarshal([]byte(res), &v)
if _, exists := constants.VersionMap[v]; exists {
info.Version = v
} else {
return nil, fmt.Errorf("platform version isn't supported")
}
}
if v, ok := constants.VersionMap[info.Version]; ok {

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
"io"
@@ -21,6 +22,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn"
)
// DecortClient is HTTP-client for platform
@@ -38,12 +40,6 @@ func New(cfg config.Config) *DecortClient {
cfg.Retries = 5
}
var expiryTime time.Time
if cfg.Token != "" {
expiryTime = time.Now().AddDate(0, 0, 1)
}
return &DecortClient{
decortURL: cfg.DecortURL,
client: &http.Client{
@@ -54,9 +50,8 @@ func New(cfg config.Config) *DecortClient {
},
},
},
cfg: trimConfig(&cfg),
expiryTime: expiryTime,
mutex: &sync.Mutex{},
cfg: trimConfig(&cfg),
mutex: &sync.Mutex{},
}
}
@@ -70,6 +65,11 @@ func (dc *DecortClient) CloudBroker() *cloudbroker.CloudBroker {
return cloudbroker.New(dc)
}
// SDN builder
func (dc *DecortClient) SDN() *sdn.SDN {
return sdn.New(dc)
}
// DecortApiCall method for sending requests to the platform
func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
@@ -107,6 +107,47 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
return respBytes, err
}
// DecortApiCallCtype method for sending requests to the platform with content type
func (dc *DecortClient) DecortApiCallCtype(ctx context.Context, method, url, ctype string, params interface{}) ([]byte, error) {
var body *bytes.Buffer
switch ctype {
case constants.MIMESTREAM:
body = bytes.NewBuffer(params.([]byte))
case constants.MIMEJSON:
jsonBody, err := json.Marshal(params)
if err != nil {
return nil, err
}
body = bytes.NewBuffer(jsonBody)
default:
ctype = constants.MIMEPOSTForm
values, err := query.Values(params)
if err != nil {
return nil, err
}
body = bytes.NewBufferString(values.Encode())
}
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+constants.RESTMACHINE+url, body)
if err != nil {
return nil, err
}
// get token
if err = dc.getToken(ctx); err != nil {
return nil, err
}
// perform request
respBytes, err := dc.do(req, ctype)
if err != nil {
return nil, err
}
return respBytes, err
}
// DecortApiCallMP method for sending requests to the platform
func (dc *DecortClient) DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
body, ctype, err := multiPartReq(params)
@@ -170,8 +211,13 @@ func (dc *DecortClient) getToken(ctx context.Context) error {
// save token in config
token := string(tokenBytes)
expiryTime, err := getTokenExp(token)
if err != nil {
return fmt.Errorf("cannot get expiry time: %w", err)
}
dc.cfg.Token = token
dc.expiryTime = time.Now().AddDate(0, 0, 1)
dc.expiryTime = expiryTime
return nil
}
@@ -375,3 +421,29 @@ func trimConfig(cfg *config.Config) config.Config {
cfg.DecortURL = strings.TrimSuffix(cfg.DecortURL, "/")
return *cfg
}
func getTokenExp(token string) (time.Time, error) {
parts := strings.Split(token, ".")
if len(parts) != 3 {
return time.Time{}, fmt.Errorf("invalid token format")
}
payload, err := base64.RawURLEncoding.DecodeString(parts[1])
if err != nil {
return time.Time{}, fmt.Errorf("error decode payload from token: %w", err)
}
var claims map[string]interface{}
if err := json.Unmarshal(payload, &claims); err != nil {
return time.Time{}, err
}
exp, ok := claims["exp"]
if !ok {
return time.Time{}, fmt.Errorf("exp time bot found")
}
expTime := time.Unix(int64(exp.(float64)), 0)
return expTime, nil
}

View File

@@ -131,6 +131,72 @@ func (bdc *BVSDecortClient) DecortApiCall(ctx context.Context, method, url strin
return respBytes, err
}
// DecortApiCallCtype method for sending requests to the platform with content type
func (bdc *BVSDecortClient) DecortApiCallCtype(ctx context.Context, method, url, ctype string, params interface{}) ([]byte, error) {
var body *bytes.Buffer
switch ctype {
case constants.MIMESTREAM:
body = bytes.NewBuffer(params.([]byte))
case constants.MIMEJSON:
jsonBody, err := json.Marshal(params)
if err != nil {
return nil, err
}
body = bytes.NewBuffer(jsonBody)
default:
ctype = constants.MIMEPOSTForm
values, err := query.Values(params)
if err != nil {
return nil, err
}
body = bytes.NewBufferString(values.Encode())
}
req, err := http.NewRequestWithContext(ctx, method, bdc.decortURL+constants.RESTMACHINE+url, body)
if err != nil {
return nil, err
}
// get token
if bdc.cfg.Token.AccessToken == "" {
if _, err = bdc.GetToken(ctx); err != nil {
return nil, err
}
}
// refresh token
if bdc.cfg.Token.RefreshToken != "" && bdc.cfg.Token.Expiry.Add(-time.Duration(bdc.cfg.TimeToRefresh)*time.Minute).Before(time.Now()) {
if _, err := bdc.RefreshToken(ctx); err != nil {
if _, err = bdc.GetToken(ctx); err != nil {
return nil, err
}
}
}
// perform request
reqCopy := req.Clone(ctx)
respBytes, err := bdc.do(req, ctype)
if err == nil {
return respBytes, nil
}
// get token and retry in case of access denied
if err.Error() == "access is denied" {
_, err = bdc.GetToken(ctx)
if err != nil {
return nil, err
}
respBytes, err = bdc.do(reqCopy, "")
if err != nil {
return nil, err
}
}
return respBytes, err
}
func (bdc *BVSDecortClient) DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
body, ctype, err := multiPartReq(params)
if err != nil {

View File

@@ -7,6 +7,9 @@ type Caller interface {
// DecortApiCall method for sending requests to the platform
DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error)
// DecortApiCallCtype method for sending requests to the platform
DecortApiCallCtype(ctx context.Context, method, url, ctype string, params interface{}) ([]byte, error)
// DecortApiCallMP method for sending requests to the platform
DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error)
}

View File

@@ -2,9 +2,23 @@ package constants
const (
RESTMACHINE = "/restmachine"
)
// RAM_DIVISIBILITY sets divisibility of RAM value
RAM_DIVISIBILITY uint64 = 128
const (
MIMEJSON = "application/json"
MIMEHTML = "text/html"
MIMEXML = "application/xml"
MIMEXML2 = "text/xml"
MIMEPlain = "text/plain"
MIMEPOSTForm = "application/x-www-form-urlencoded"
MIMEMultipartPOSTForm = "multipart/form-data"
MIMEPROTOBUF = "application/x-protobuf"
MIMEMSGPACK = "application/x-msgpack"
MIMEMSGPACK2 = "application/msgpack"
MIMEYAML = "application/x-yaml"
MIMEYAML2 = "application/yaml"
MIMETOML = "application/toml"
MIMESTREAM = "application/octet-stream"
)
var FileName = map[string]string{
@@ -14,5 +28,9 @@ var FileName = map[string]string{
var K8sValues = []string{"labels", "taints", "annotations, additionalSANs"}
var VersionMap = map[string]string{
"4.4.0": "-",
"4.3.0": "-",
"4.2.0": "-",
"4.1.1": "-",
"4.1.0": "-",
}

View File

@@ -14,13 +14,6 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/multierror"
)
// computeDriverValidator is used to validate Driver field in kvmx86 create.
func computeDriverValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, computeDriverValues)
}
// protoValidator is used to validate Proto fields.
func protoValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
@@ -58,13 +51,6 @@ func resTypesValidator(fe validator.FieldLevel) bool {
return true
}
// driverValidator is used to validate Driver fields.
func driverValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, driverValues)
}
// accountCUTypeValidator is used to validate CUType field.
func accountCUTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
@@ -121,6 +107,27 @@ func computex86NetTypeValidator(fe validator.FieldLevel) bool {
return IsInSlice(fieldValue, computex86NetTypeValues)
}
// securityGroupDirectionValidator is used to validate Direction field
func securityGroupDirectionValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, securityGroupDirectionValues)
}
// securityGroupEthertypeValidator is used to validate Ethertype field
func securityGroupEthertypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, securityGroupEthertypeValues)
}
// securityGroupProtocolValidator is used to validate Protocol field
func securityGroupProtocolValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, securityGroupProtocolValues)
}
// computeOrderValidator is used to validate Order field.
func computeOrderValidator(fe validator.FieldLevel) bool {
fieldSlice, ok := fe.Field().Interface().([]string)
@@ -207,22 +214,6 @@ func imageTypeValidator(fe validator.FieldLevel) bool {
return IsInSlice(fieldValue, imageTypeValues)
}
// imageDriversValidator is used to validate Drivers field.
func imageDriversValidator(fe validator.FieldLevel) bool {
fieldSlice, ok := fe.Field().Interface().([]string)
if !ok {
return false
}
for _, item := range fieldSlice {
if !IsInSlice(item, imageDriversValues) {
return false
}
}
return true
}
// imageArchitectureValidator is used to validate Architecture field.
func imageArchitectureValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()

View File

@@ -28,12 +28,6 @@ func errorMessage(fe validator.FieldError) string {
case "isBool":
return fmt.Sprintf("%s %s: must be bool type", prefix, fe.Field())
case "driver":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(driverValues))
case "accessType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
@@ -128,12 +122,6 @@ func errorMessage(fe validator.FieldError) string {
fe.Field(),
joinValues(computeDataDisksValues))
case "computeDriver":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeDriverValues))
// Disk Validators
case "diskType":
return fmt.Sprintf("%s %s must be one of the following: %s",
@@ -201,12 +189,6 @@ func errorMessage(fe validator.FieldError) string {
fe.Field(),
joinValues(imageTypeValues))
case "imageDrivers":
return fmt.Sprintf("%s %s must contain only the following: %s",
prefix,
fe.Field(),
joinValues(imageDriversValues))
case "imageArchitecture":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
@@ -341,6 +323,25 @@ func errorMessage(fe validator.FieldError) string {
fe.Field(),
joinValues(userProviders))
// security group validators
case "securityGroupDirection":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(securityGroupDirectionValues))
case "securityGroupEthertype":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(securityGroupEthertypeValues))
case "securityGroupProtocol":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(securityGroupProtocolValues))
// trunk tags validator
case "trunkTags":
return fmt.Sprintf("%s %s must be in range from 1 to 4095",

View File

@@ -31,11 +31,6 @@ func registerAllValidators(validate *validator.Validate) error {
return err
}
err = validate.RegisterValidation("computeDriver", computeDriverValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("apiGroup", apiGroupValidator)
if err != nil {
return err
@@ -51,11 +46,6 @@ func registerAllValidators(validate *validator.Validate) error {
return err
}
err = validate.RegisterValidation("driver", driverValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("imageBootType", imageBootTypeValidator)
if err != nil {
return err
@@ -66,11 +56,6 @@ func registerAllValidators(validate *validator.Validate) error {
return err
}
err = validate.RegisterValidation("imageDrivers", imageDriversValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("imageArchitecture", imageArchitectureValidator)
if err != nil {
return err
@@ -301,5 +286,20 @@ func registerAllValidators(validate *validator.Validate) error {
return err
}
err = validate.RegisterValidation("securityGroupDirection", securityGroupDirectionValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("securityGroupEthertype", securityGroupEthertypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("securityGroupProtocol", securityGroupProtocolValidator)
if err != nil {
return err
}
return nil
}

View File

@@ -3,7 +3,6 @@ package validators
var (
apiGroupValues = []string{"cloudapi", "cloudbroker", "system"}
driverValues = []string{"KVM_X86"}
accessTypeValues = []string{"R", "RCX", "ARCXDU"}
resTypesValues = []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}
protoValues = []string{"tcp", "udp"}
@@ -20,7 +19,6 @@ var (
computex86NetTypeValues = []string{"EXTNET", "VINS", "VFNIC", "DPDK", "SDN", "EMPTY", "TRUNK"}
computeOrderValues = []string{"cdrom", "network", "hd"}
computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"}
computeDriverValues = []string{"KVM_X86"}
diskTypeValues = []string{"B", "T", "D"}
@@ -38,7 +36,6 @@ var (
imageBootTypeValues = []string{"uefi", "bios"}
imageTypeValues = []string{"windows", "linux", "unknown"}
imageDriversValues = []string{"KVM_X86"}
imageArchitectureValues = []string{"X86_64"}
sepFieldTypeValues = []string{"int", "str", "bool", "list", "dict"}
@@ -76,6 +73,10 @@ var (
userProviders = []string{"bvs", "decs3o"}
deviceValues = []string{"primary", "secondary"}
securityGroupDirectionValues = []string{"inbound", "outbound"}
securityGroupEthertypeValues = []string{"IPv4", "IPv6"}
securityGroupProtocolValues = []string{"icmp", "tcp", "udp"}
)
const (

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io"
"net/http"
@@ -102,6 +103,47 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st
return respBytes, err
}
// DecortApiCallCtype method for sending requests to the platform with content type
func (ldc *LegacyDecortClient) DecortApiCallCtype(ctx context.Context, method, url, ctype string, params interface{}) ([]byte, error) {
// get token
if err := ldc.getToken(ctx); err != nil {
return nil, err
}
var body *bytes.Buffer
switch ctype {
case constants.MIMESTREAM:
body = bytes.NewBuffer(params.([]byte))
case constants.MIMEJSON:
jsonBody, err := json.Marshal(params)
if err != nil {
return nil, err
}
body = bytes.NewBuffer(jsonBody)
default:
ctype = constants.MIMEPOSTForm
values, err := query.Values(params)
if err != nil {
return nil, err
}
body = bytes.NewBufferString(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token))
}
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+constants.RESTMACHINE+url, body)
if err != nil {
return nil, err
}
// perform request
respBytes, err := ldc.do(req, ctype)
if err != nil {
return nil, err
}
return respBytes, err
}
func (ldc *LegacyDecortClient) DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
body, ctype, err := multiPartReq(params)
if err != nil {

View File

@@ -30,6 +30,11 @@ type ListRequest struct {
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -73,6 +73,15 @@ type ResourceLimits struct {
// Number of graphics cores
GPUUnits float64 `json:"gpu_units"`
// Storage policy
StoragePolicy []StoragePolicyItem `json:"storage_policy"`
}
type StoragePolicyItem struct {
ID uint64 `json:"id"`
Limit int `json:"limit"`
}
// Main information in one of if the list of accounts
@@ -103,6 +112,9 @@ type ItemAccount struct {
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Zones
ZoneIDs []uint64 `json:"zoneIds"`
}
// List of accounts
@@ -112,6 +124,18 @@ type ListAccounts struct {
EntryCount uint64 `json:"entryCount"`
}
// Policy
type Policy struct {
// Size of the disk
DiskSize float64 `json:"disksize"`
// Max size of the disk
DiskSizeMax float64 `json:"disksizemax"`
// SEPs used
SEPs map[string]map[string]DiskUsage `json:"seps"`
}
// Resources used
type Resource struct {
// Number of cores
@@ -132,6 +156,9 @@ type Resource struct {
// Number of grafic cores
GPU int64 `json:"gpu"`
// Policies
Policies map[string]Policy `json:"policies"`
// Number of RAM
RAM int64 `json:"ram"`
@@ -206,9 +233,6 @@ type RecordAccount struct {
// DCLocation
DCLocation string `json:"DCLocation"`
// CKey
CKey string `json:"_ckey"`
// Access control list
ACL []RecordACL `json:"acl"`
@@ -275,6 +299,9 @@ type RecordAccount struct {
// Status
Status string `json:"status"`
// Storage policy ids
StoragePolicyIDs []uint64 `json:"storage_policy_ids"`
// UniqPools
UniqPools []interface{} `json:"uniqPools"`
@@ -291,7 +318,7 @@ type RecordAccount struct {
VINSes uint64 `json:"vinses"`
// Zone
ZoneIDs []ZoneID
ZoneIDs []ZoneID `json:"zoneIds"`
// Zones
DefaultZoneID uint64 `json:"defaultZoneId"`

View File

@@ -0,0 +1,81 @@
package audit
// FilterByID returns ListAudits with specified ID.
func (la ListAudits) FilterByID(guid string) ListAudits {
predicate := func(ia ItemAudit) bool {
return ia.GUID == guid
}
return la.FilterFunc(predicate)
}
// FilterByCall returns ListAudits with specified call.
func (la ListAudits) FilterByCall(call string) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.Call == call
}
return la.FilterFunc(predicate)
}
// FilterByCorrelationID returns ListAudits with specified correlation id.
func (la ListAudits) FilterByCorrelationID(correlationID string) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.CorrelationID == correlationID
}
return la.FilterFunc(predicate)
}
// FilterByRemoteAddr returns ListAudits with specified remote address.
func (la ListAudits) FilterByRemoteAddr(remoteAddr string) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.RemoteAddr == remoteAddr
}
return la.FilterFunc(predicate)
}
// FilterByUser returns ListAudits with specified user name.
func (la ListAudits) FilterByUser(user string) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.User == user
}
return la.FilterFunc(predicate)
}
// FilterByStatusCode return ListAudits with specified status code.
func (la ListAudits) FilterByStatusCode(statusCode uint64) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.StatusCode == statusCode
}
return la.FilterFunc(predicate)
}
// FilterFunc allows filtering ListAudits based on a user-specified predicate.
func (la ListAudits) FilterFunc(predicate func(ItemAudit) bool) ListAudits {
var result ListAudits
for _, item := range la.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemAudit
// If none was found, returns an empty struct.
func (la ListAudits) FindOne() ItemAudit {
if len(la.Data) == 0 {
return ItemAudit{}
}
return la.Data[0]
}

View File

@@ -0,0 +1,115 @@
package audit
import (
"testing"
)
var audits = ListAudits{
Data: []ItemAudit{
{
Args: "[]",
Call: "/restmachine/cloudapi/audit/linkedJobs",
GUID: "550e8400-e29b-41d4-a716-446655440001",
CorrelationID: "550e8400-e29b-41d4-a716-446655440001",
Kwargs: `{\"audit_guid\":\"dd8623a1-a887-48c1-a500-c10210d404cf\"}`,
RemoteAddr: "192.168.1.100",
ResponseTime: 1,
Result: `[]`,
StatusCode: 200,
Timestamp: 1640995200,
TimestampEnd: 1640995201,
User: "test@example.com",
TTL: "2025-07-31T14:22:57.028000",
},
{
Args: "[]",
Call: "/restmachine/cloudapi/audit/test",
GUID: "550e8400-e29b-41d4-a716-446655440002",
CorrelationID: "550e8400-e29b-41d4-a716-446655440002",
Kwargs: `{\"audit_guid\":\"dd8623a1-a887-48c1-a500-c10210d404cf\"}`,
RemoteAddr: "192.168.1.105",
ResponseTime: 5,
Result: `[]`,
StatusCode: 400,
Timestamp: 1640995200,
TimestampEnd: 1640995201,
User: "test2@example.com",
TTL: "2025-07-31T14:22:57.028000",
},
},
EntryCount: 2,
}
func TestFilterByID(t *testing.T) {
actual := audits.FilterByID("550e8400-e29b-41d4-a716-446655440002").FindOne()
if actual.GUID != "550e8400-e29b-41d4-a716-446655440002" {
t.Fatal("expected GUID 550e8400-e29b-41d4-a716-446655440002, found: ", actual.GUID)
}
actualEmpty := audits.FilterByID("")
if len(actualEmpty.Data) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
}
}
func TestFilterByCorrelationID(t *testing.T) {
actual := audits.FilterByCorrelationID("550e8400-e29b-41d4-a716-446655440002").FindOne()
if actual.CorrelationID != "550e8400-e29b-41d4-a716-446655440002" {
t.Fatal("expected GUID 550e8400-e29b-41d4-a716-446655440002, found: ", actual.CorrelationID)
}
actualEmpty := audits.FilterByCorrelationID("")
if len(actualEmpty.Data) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
}
}
func TestFilterByRemoteAddr(t *testing.T) {
actual := audits.FilterByRemoteAddr("192.168.1.100").FindOne()
if actual.RemoteAddr != "192.168.1.100" {
t.Fatal("expected remote address 192.168.1.100, found: ", actual.RemoteAddr)
}
actualEmpty := audits.FilterByRemoteAddr("")
if len(actualEmpty.Data) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
}
}
func TestFilterByUser(t *testing.T) {
actual := audits.FilterByUser("test@example.com").FindOne()
if actual.User != "test@example.com" {
t.Fatal("expected user test@example.com, found: ", actual.RemoteAddr)
}
actualEmpty := audits.FilterByUser("")
if len(actualEmpty.Data) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
}
}
func TestFilterByCall(t *testing.T) {
actual := audits.FilterByCall("/restmachine/cloudapi/audit/test").FindOne()
if actual.Call != "/restmachine/cloudapi/audit/test" {
t.Fatal("expected call /restmachine/cloudapi/audit/test, found: ", actual.Call)
}
}
func TestFilterByStatusCode(t *testing.T) {
actual := audits.FilterByStatusCode(200)
for _, item := range actual.Data {
if item.StatusCode != 200 {
t.Fatal("expected 200 status code, found: ", item.StatusCode)
}
}
}

124
pkg/cloudapi/audit/list.go Normal file
View File

@@ -0,0 +1,124 @@
package audit
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListRequest struct to give list of account audits
type ListRequest struct {
// Find all audits after point in time (unixtime)
// Required: false
TimestampAt uint64 `url:"timestamp_at,omitempty" json:"timestamp_at,omitempty"`
// Find all audits before point in time (unixtime)
// Required: false
TimestampTo uint64 `url:"timestamp_to,omitempty" json:"timestamp_to,omitempty"`
// Find by user (Mongo RegExp supported)
// Required: false
User string `url:"user,omitempty" json:"user,omitempty"`
// Find by api endpoint (Mongo RegExp supported)
// Required: false
Call string `url:"call,omitempty" json:"call,omitempty"`
// Find by request id
// Required: false
RequestID string `url:"request_id,omitempty" json:"request_id,omitempty"`
// Find by HTTP min status code
// Required: false
MinStatusCode uint64 `url:"min_status_code,omitempty" json:"min_status_code,omitempty"`
// Find by HTTP max status code
// Required: false
MaxStatusCode uint64 `url:"max_status_code,omitempty" json:"max_status_code,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Find by resource group id
// Required: false
RGID uint64 `url:"resgroup_id,omitempty" json:"resgroup_id,omitempty"`
// Find by compute id
// Required: false
ComputeID uint64 `url:"compute_id,omitempty" json:"compute_id,omitempty"`
// Find by account id
// Required: false
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
// Find by vins id
// Required: false
VINSID uint64 `url:"vins_id,omitempty" json:"vins_id,omitempty"`
// Find by service id
// Required: false
ServiceID uint64 `url:"service_id,omitempty" json:"service_id,omitempty"`
// Find by k8s id
// Required: false
K8SID uint64 `url:"k8s_id,omitempty" json:"k8s_id,omitempty"`
// Find by flipgroup id
// Required: false
FLIPGroupID uint64 `url:"flipgroup_id,omitempty" json:"flipgroup_id,omitempty"`
// Find by load balancer id
// Required: false
LBID uint64 `url:"lb_id,omitempty" json:"lb_id,omitempty"`
// Find by sep id
// Required: false
SEPID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
// Exclude audit lines from response
// Required: false
ExcludeAuditLines bool `url:"exclude_audit_lines,omitempty" json:"exclude_audit_lines,omitempty"`
}
// List gets audit records for the specified account object
func (a Audit) List(ctx context.Context, req ListRequest) (*ListAudits, error) {
res, err := a.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of audit records an array of bytes
func (a Audit) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/audit/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -12,6 +12,9 @@ type RecordAudit struct {
// GUID
GUID string `json:"guid"`
// Correlation ID
CorrelationID string `json:"correlation_id"`
// Kwargs
Kwargs string `json:"kwargs"`
@@ -39,3 +42,54 @@ type RecordAudit struct {
// User
User string `json:"user"`
}
// Main info about audit
type ItemAudit struct {
// Args
Args string `json:"args"`
// Call
Call string `json:"call"`
// GUID
GUID string `json:"guid"`
// Correlation ID
CorrelationID string `json:"correlation_id"`
// 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"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// Timestamp End
TimestampEnd float64 `json:"timestampEnd"`
// User
User string `json:"user"`
// TTL
TTL string `json:"_ttl"`
}
// List of audits
type ListAudits struct {
// Data
Data []ItemAudit `json:"data"`
// EntryCount
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -38,11 +38,9 @@ type GroupAddRequest struct {
// Required: true
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
// Compute driver
// should be one of:
// - KVM_X86
// Compute driver like a KVM_X86, etc.
// Required: true
Driver string `url:"driver" json:"driver" validate:"driver"`
Driver string `url:"driver" json:"driver" validate:"required"`
// Storage endpoint provider ID
// Required: false
@@ -75,6 +73,10 @@ type GroupAddRequest struct {
//Chipset "i440fx" or "Q35
//Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"chipset,omitempty"`
// ID of the chosen storage policy
// Required: false
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
}
// GetRAM returns RAM field values

View File

@@ -46,6 +46,11 @@ type ListRequest struct {
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -12,11 +12,47 @@ import (
type AuditsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
// Find all audits after point in time
// Required: false
TimestampAT uint64 `url:"timestamp_at,omitempty" json:"timestamp_at,omitempty"`
// Find all audits before point in time
// Required: false
TimestampTO uint64 `url:"timestamp_to,omitempty" json:"timestamp_to,omitempty"`
// Find by user
// Required: false
User string `url:"user,omitempty" json:"user,omitempty"`
// Find by api endpoints
// Required: false
Call string `url:"call,omitempty" json:"call,omitempty"`
// Sort by one of supported fields, format ±<field>
// Required: false
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
// 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 HTTP min status code
// Required: false
MinStatusCode uint64 `url:"min_status_code,omitempty" json:"min_status_code,omitempty"`
// Find by HTTP max status code
// Required: false
MaxStatusCode uint64 `url:"max_status_code,omitempty" json:"max_status_code,omitempty"`
}
// Audits gets audit records for the specified compute object
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (*ListAudits, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
@@ -24,7 +60,7 @@ func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListAudits, err
url := "/cloudapi/compute/audits"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return nil, err
}
@@ -36,5 +72,5 @@ func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListAudits, err
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ChangeSecGroupsRequest struct to change security groups for compute
type ChangeSecGroupsRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
// Interface name or MAC address
// Required: true
Interface string `url:"interface" json:"interface" validate:"required"`
// List of security group IDs to assign to this interface
// Required: false
SecGroups []uint64 `url:"security_groups,omitempty" json:"security_groups,omitempty"`
// Flag indicating whether security groups are enabled for this interface
// Required: false
EnableSecGroups interface{} `url:"enable_secgroups,omitempty" json:"enable_secgroups,omitempty" validate:"omitempty,isBool"`
}
// ChangeSecGroups changes security groups for compute
func (c Compute) ChangeSecGroups(ctx context.Context, req ChangeSecGroupsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/change_security_groups"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -3,8 +3,8 @@ package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
@@ -18,6 +18,10 @@ type CloneRequest struct {
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// ID of the Storage Policy
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// Timestamp of the parent's snapshot to create clone from
// Required: false
SnapshotTimestamp uint64 `url:"snapshotTimestamp,omitempty" json:"snapshotTimestamp,omitempty"`
@@ -30,26 +34,29 @@ type CloneRequest struct {
// Default: false
// Required: false
Force bool `url:"force" json:"force"`
// The name of the pool to migrate disks to
// Required: false
PoolName string `url:"pool_name" json:"pool_name"`
// The ID of the SEP to migrate disks to
// Required: false
SEPID uint64 `url:"sep_id" json:"sep_id"`
}
// Clone clones compute instance
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
func (c Compute) Clone(ctx context.Context, req CloneRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/clone"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := c.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return 0, err
return "", err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
return string(res), nil
}

View File

@@ -0,0 +1,39 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CloneAbortRequest struct to abort a compute clone
type CloneAbortRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
}
// CloneAbort aborts a compute clone
func (c Compute) CloneAbort(ctx context.Context, req CloneAbortRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/clone_abort"
res, err := c.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,40 @@
package compute
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetCloneStatusRequest struct to get information about compute clone status
type GetCloneStatusRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
}
// GetCloneStatus gets information about compute clone status as a RecordCloneStatus struct
func (c Compute) GetCloneStatus(ctx context.Context, req GetCloneStatusRequest) ([]RecordCloneStatus, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/clone_status"
res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return nil, err
}
cloneStatus := make([]RecordCloneStatus, 0)
err = json.Unmarshal(res, &cloneStatus)
if err != nil {
return nil, err
}
return cloneStatus, nil
}

View File

@@ -3,7 +3,6 @@ package compute
import (
"context"
"net/http"
"strconv"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
@@ -27,47 +26,15 @@ type wrapperCreateTemplateRequest struct {
}
// CreateTemplate create template from compute instance
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperCreateTemplateRequest{
CreateTemplateRequest: req,
AsyncMode: false,
}
url := "/cloudapi/compute/createTemplate"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}
// CreateTemplateAsync create template from compute instance
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) {
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperCreateTemplateRequest{
CreateTemplateRequest: req,
AsyncMode: true,
}
url := "/cloudapi/compute/createTemplate"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}

View File

@@ -27,6 +27,10 @@ type CreateTemplateFromBlankRequest struct {
// Required: true
ImageType string `url:"imagetype" json:"imagetype" validate:"imageType"`
// Storage policy id of disk. The rules of the specified storage policy will be used.
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// Username for the image
// Required: false
Username string `url:"username,omitempty" json:"username,omitempty"`

View File

@@ -22,6 +22,10 @@ type DiskAddRequest struct {
// Required: true
Size uint64 `url:"size" json:"size" validate:"required"`
// Storage policy id of disk. The rules of the specified storage policy will be used.
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// Type of the disk
// Should be one of:
// - D
@@ -46,6 +50,14 @@ type DiskAddRequest struct {
// Specify image id for create disk from template
// Required: false
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
// Desired PCI slot (hex string, e.g. "0x1A")
// Required: false
PCISlot string `url:"pci_slot,omitempty" json:"pci_slot,omitempty"`
// Desired bus number (hex string, e.g. "0x03")
// Required: false
BusNumber string `url:"bus_number,omitempty" json:"bus_number,omitempty"`
}
// DiskAdd creates new disk and attach to compute

View File

@@ -21,6 +21,14 @@ type DiskAttachRequest struct {
// Type of the disk B;D
// Required: false
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
// Desired PCI slot (hex string, e.g. "0x1A")
// Required: false
PCISlot string `url:"pci_slot,omitempty" json:"pci_slot,omitempty"`
// Desired bus number (hex string, e.g. "0x03")
// Required: false
BusNumber string `url:"bus_number,omitempty" json:"bus_number,omitempty"`
}
// DiskAttach attach disk to compute

View File

@@ -55,7 +55,6 @@ var computes = ListComputes{
GID: 212,
GUID: 48500,
ID: 48500,
ImageID: 9884,
Interfaces: []ItemVNFInterface{},
LockStatus: "UNLOCKED",
ManagerID: 0,
@@ -82,7 +81,7 @@ var computes = ListComputes{
UserManaged: true,
VGPUs: []uint64{},
VINSConnected: 0,
VirtualImageID: 0,
ZoneID: 1,
},
{
ACL: ListACL{},
@@ -117,7 +116,6 @@ var computes = ListComputes{
GID: 212,
GUID: 48556,
ID: 48556,
ImageID: 9884,
Interfaces: []ItemVNFInterface{},
LockStatus: "UNLOCKED",
ManagerID: 0,
@@ -144,7 +142,7 @@ var computes = ListComputes{
UserManaged: true,
VGPUs: []uint64{},
VINSConnected: 0,
VirtualImageID: 0,
ZoneID: 5,
},
},
EntryCount: 2,

View File

@@ -58,6 +58,11 @@ type ListRequest struct {
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -238,7 +238,13 @@ type ItemAudit struct {
}
// List Detailed audits
type ListAudits []ItemAudit
type ListAudits struct {
// Data
Data []ItemAudit `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Short information about audit
type ItemShortAudit struct {
@@ -305,6 +311,9 @@ type RecordCompute struct {
// Architecture
Architecture string `json:"arch"`
// Boot image ID
BootImageID uint64 `json:"boot_image_id"`
// Boot order
BootOrder []string `json:"bootOrder"`
@@ -386,6 +395,9 @@ type RecordCompute struct {
// List interfaces
Interfaces ListInterfaces `json:"interfaces"`
// Loader meta iso information
LoaderMetaIso LoaderMetaIso `json:"loaderMetaIso"`
// Live migration job ID
LiveMigrationJobID uint64 `json:"live_migration_job_id"`
@@ -437,6 +449,9 @@ type RecordCompute struct {
// Natable VINS network name
NatableVINSNetworkName string `json:"natableVinsNetworkName"`
// Name of OS
OSVersion string `json:"os_version"`
// List OS Users
OSUsers ListOSUser `json:"osUsers"`
@@ -503,12 +518,6 @@ type RecordCompute struct {
// vGPUs list
VGPUs []VGPUItem `json:"vgpus"`
// Virtual image ID
VirtualImageID uint64 `json:"virtualImageId"`
// Virtual image name
VirtualImageName string `json:"virtualImageName"`
// VNC password
VNCPassword string `json:"vncPasswd"`
@@ -516,6 +525,13 @@ type RecordCompute struct {
// Required: false
ZoneID uint64 `json:"zoneId"`
}
type LoaderMetaIso struct {
// Name
DeviceName string `json:"devicename"`
// Path
Path string `json:"path"`
}
type QemuQuest struct {
Enabled bool `json:"enabled"`
@@ -661,6 +677,9 @@ type ItemVNFInterface struct {
// Enabled
Enabled bool `json:"enabled"`
// Enable security groups
EnableSecGroups bool `json:"enable_secgroups"`
// FLIPGroup ID
FLIPGroupID uint64 `json:"flipgroupId"`
@@ -703,6 +722,9 @@ type ItemVNFInterface struct {
// QOS
QOS QOS `json:"qos"`
// List of security groups
SecGroups []uint64 `json:"security_groups"`
// SDN interface ID
SDNInterfaceID string `json:"sdn_interface_id"`
@@ -749,9 +771,18 @@ type ItemComputeDisk struct {
// Bus number
BusNumber uint64 `json:"bus_number"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Device name
DeviceName string `json:"devicename"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
@@ -848,17 +879,23 @@ type ItemComputeDisk struct {
// Status
Status string `json:"status"`
// Storage policy id of compute.
StoragePolicyID uint64 `json:"storage_policy_id"`
// Tech status
TechStatus string `json:"techStatus"`
// Need to clean before destroy
ToClean bool `json:"to_clean"`
// Type
Type string `json:"type"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Zone ID
ZoneID uint64 `json:"zoneId"`
// UpdatedTime
UpdatedTime uint64 `json:"updatedTime"`
}
type ItemReplication struct {
@@ -979,6 +1016,9 @@ type ItemCompute struct {
// Architecture
Architecture string `json:"arch"`
// Boot image ID
BootImageID uint64 `json:"boot_image_id"`
// Boot order
BootOrder []string `json:"bootOrder"`
@@ -1051,9 +1091,6 @@ type ItemCompute struct {
// ID
ID uint64 `json:"id"`
// Image ID
ImageID uint64 `json:"imageId"`
// List interfaces
Interfaces ListInterfaces `json:"interfaces"`
@@ -1102,6 +1139,9 @@ type ItemCompute struct {
// Number of RAM
RAM uint64 `json:"ram"`
// Name of OS
OSVersion string `json:"os_version"`
// Qemu_quest
QemuQuest QemuQuest `json:"qemu_guest"`
@@ -1159,8 +1199,8 @@ type ItemCompute struct {
// VINS connected
VINSConnected uint64 `json:"vinsConnected"`
// Virtual image ID
VirtualImageID uint64 `json:"virtualImageId"`
// Zone ID
ZoneID uint64 `json:"zoneId"`
}
// ListInfoDisks
@@ -1288,3 +1328,31 @@ type ListPCIDevices struct {
// Entry count
EntryCount uint64 `json:"entryCount"`
}
type RecordCloneStatus struct {
// Disk ID
DiskID int `json:"disk_id"`
// Clone Status
Status CloneStatus `json:"status"`
}
type CloneStatus struct {
// Type
Type int `json:"type"`
// Copy speed
Bandwidth int `json:"bandwidth"`
// Current progress
Cur int `json:"cur"`
// Total size
End int `json:"end"`
// Operation status
Ready bool `json:"ready"`
// Progress percent
ProgressPercent int `json:"progress_percent"`
}

View File

@@ -42,12 +42,24 @@ type NetAttachRequest struct {
// Used only for EXTNET and DPDK
// For DPDK must be 1-9216
// For EXTNET must be 1500-9216
// Required: false
// Required: false
MTU uint64 `url:"mtu,omitempty" json:"mtu,omitempty" validate:"omitempty,mtu"`
// Unique identifier of logical port on SDN side
// Required: false
SDNInterfaceID string `url:"sdn_interface_id,omitempty" json:"sdn_interface_id,omitempty" validate:"omitempty"`
// List of security group IDs to assign to this interface
// Required: false
SecGroups []uint64 `url:"security_groups,omitempty" json:"security_groups,omitempty"`
// Flag indicating whether security groups are enabled for this interface
// Required: false
EnableSecGroups bool `url:"enable_secgroups,omitempty" json:"enable_secgroups,omitempty"`
// Flag indicating whether this interface is enabled (only for VINS, EXTNET, DPDK, SDN, TRUNK)
// Required: false
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
}
// NetAttach attaches network to compute and gets info about network

View File

@@ -14,9 +14,17 @@ type RedeployRequest struct {
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Storage policy id of compute. The rules of the specified storage policy will be used.
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// ID of the new OS image, if image change is required
// Required: false
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
// The OS version that will be installed on the virtual machine
// Required: false
OSVersion string `url:"os_version,omitempty" json:"os_version,omitempty"`
// new size for the boot disk in GB, if boot disk size change is required
// Required: false

View File

@@ -65,6 +65,10 @@ type UpdateRequest struct {
// Does this machine supports hot resize, true or false
// Required: false
HotResize interface{} `url:"hotResize,omitempty" json:"hotResize,omitempty" validate:"omitempty,isBool"`
// The OS version that will be installed on the virtual machine
// Required: false
OSVersion string `url:"os_version,omitempty" json:"os_version,omitempty"`
}
// Update updates some properties of the compute

View File

@@ -0,0 +1,42 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ChangeDiskStoragePolicyRequest struct to change storage policy for disk
type ChangeDiskStoragePolicyRequest struct {
// ID of the disk
// Required: true
DiskID uint64 `url:"disk_id" json:"disk_id" validate:"required"`
// ID of the storage policy to which to connect for disk
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
}
// ChangeDiskStoragePolicy changes storage policy for disk
func (d Disks) ChangeDiskStoragePolicy(ctx context.Context, req ChangeDiskStoragePolicyRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/change_disk_storage_policy"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -18,6 +18,10 @@ type CreateRequest struct {
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// ID of the storage policy under the disk will be created
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// Description of disk
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
@@ -26,10 +30,6 @@ type CreateRequest struct {
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Max IOPS disk can perform defaults to 2000
// Required: false
IOPS uint64 `url:"iops,omitempty" json:"iops,omitempty"`
// Storage endpoint provider ID to create disk
// Required: false
SEPID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`

View File

@@ -43,11 +43,6 @@ type FromPlatformDiskRequest struct {
// Required: false
PoolName string `url:"poolName,omitempty" json:"poolName,omitempty"`
// List of types of compute suitable for image
// Example: [ "KVM_X86" ]
// Required: true
Drivers []string `url:"drivers" json:"drivers" validate:"required"`
// Does this machine supports hot resize
// Required: false
HotResize bool `url:"hotresize" json:"hotresize"`

View File

@@ -46,6 +46,10 @@ type ListRequest struct {
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by storage policy id
// Required: false
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`

View File

@@ -38,6 +38,10 @@ type ListUnattachedRequest struct {
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by storage policy id
// Required: false
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`

View File

@@ -119,9 +119,15 @@ type ItemDisk struct {
// Status
Status string `json:"status"`
// Storage policy ID
StoragePolicyID uint64 `json:"storage_policy_id"`
// Tech status
TechStatus string `json:"techStatus"`
// Need to clean before destroy
ToClean bool `json:"to_clean"`
// Type
Type string `json:"type"`
@@ -477,9 +483,15 @@ type RecordDisk struct {
// Status
Status string `json:"status"`
// Storage policy ID
StoragePolicyID uint64 `json:"storage_policy_id"`
// Tech status
TechStatus string `json:"techStatus"`
// Need to clean before destroy
ToClean bool `json:"to_clean"`
// Type
Type string `json:"type"`

View File

@@ -25,9 +25,13 @@ type ReplicateRequest struct {
// Pool name to create slave disk in
// Required: true
PoolName string `url:"poolName" json:"poolName" validate:"required"`
// ID of the storage policy under the disk will be created
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
}
// Create an empty disk in chosen SEP and pool combination.
// Replicate create an empty disk in chosen SEP and pool combination.
// Starts replication between chosen disk and newly created disk
// Note: only TATLIN type SEP are supported for replications between
func (d Disks) Replicate(ctx context.Context, req ReplicateRequest) (uint64, error) {

View File

@@ -14,6 +14,9 @@ type RecordDPDKNet struct {
// Description
Description string `json:"description"`
// Enable Security Groups
EnableSecGroups bool `json:"enable_secgroups"`
// Grid ID
GID uint64 `json:"gid"`
@@ -63,6 +66,9 @@ type ItemDPDKNet struct {
// Description
Description string `json:"description"`
// Enable Security Groups
EnableSecGroups bool `json:"enable_secgroups"`
// Grid ID
GID uint64 `json:"gid"`

View File

@@ -42,6 +42,11 @@ type ListRequest struct {
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -172,6 +172,9 @@ type RecordExtNet struct {
// Excluded
Excluded []Excluded `json:"excluded"`
// Enable Security Groups
EnableSecGroups bool `json:"enable_secgroups"`
// Free IPs
FreeIPs int64 `json:"free_ips"`

View File

@@ -0,0 +1,41 @@
package image
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type ChangeStoragePolicyRequest struct {
// ID of the image to change the storage policy
// Required: true
ImageID uint64 `url:"image_id" json:"image_id" validate:"required"`
// ID of the storage policy to move the image to
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
}
// ChangeStoragePolicy changes the storage policy of the image chosen
func (i Image) ChangeStoragePolicy(ctx context.Context, req ChangeStoragePolicyRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/image/change_storage_policy"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -35,6 +35,10 @@ type CreateRequest struct {
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// ID of the chosen storage policy
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming
// Should be:
// - eth
@@ -69,11 +73,6 @@ type CreateRequest struct {
// Pool for image create
// Required: false
Pool string `url:"poolName,omitempty" json:"poolName,omitempty"`
// List of types of compute suitable for image
// Example: [ "KVM_X86" ]
// Required: true
Drivers []string `url:"drivers" json:"drivers" validate:"min=1,max=2,imageDrivers"`
}
type asyncWrapperCreateRequest struct {

View File

@@ -17,6 +17,11 @@ type CreateVirtualRequest struct {
// ID of real image to link this virtual image to upon creation
// Required: true
TargetID uint64 `url:"targetId" json:"targetId" validate:"required"`
// AccountID to make the virtual image exclusive
// Required: false
// Default: 0
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
}
// CreateVirtual creates virtual image

View File

@@ -69,6 +69,10 @@ type ListRequest struct {
// Find by enabled True or False
// Required: false
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
// Find by storage policy id
// Required: false
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
}
// List gets list of available images as a ListImages struct, optionally filtering by account ID

View File

@@ -50,6 +50,9 @@ type ItemImage struct {
// Status
Status string `json:"status"`
// Storage policy ID
StoragePolicyID uint64 `json:"storage_policy_id"`
// Type
Type string `json:"type"`
@@ -191,6 +194,9 @@ type RecordImage struct {
// Status
Status string `json:"status"`
// Storage policy ID
StoragePolicyID uint64 `json:"storage_policy_id"`
// Tech status
TechStatus string `json:"techStatus"`

View File

@@ -22,14 +22,6 @@ type ListRequest struct {
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by worker driver
// Required: false
WorkerDriver string `url:"workerDriver,omitempty" json:"workerDriver,omitempty"`
// Find by master driver
// Required: false
MasterDriver string `url:"masterDriver,omitempty" json:"masterDriver,omitempty"`
// Find by network plugin
// Required: false
NetworkPlugins string `url:"netPlugins,omitempty" json:"netPlugins,omitempty"`

View File

@@ -18,14 +18,6 @@ type ListDeletedRequest struct {
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by worker driver
// Required: false
WorkerDriver string `url:"workerDriver,omitempty" json:"workerDriver,omitempty"`
// Find by master driver
// Required: false
MasterDriver string `url:"masterDriver,omitempty" json:"masterDriver,omitempty"`
// Find by network plugin
// Required: false
NetworkPlugins string `url:"netPlugins,omitempty" json:"netPlugins,omitempty"`

View File

@@ -31,6 +31,10 @@ type CreateRequest struct {
// Required: true
NetworkPlugin string `url:"networkPlugin" json:"networkPlugin" validate:"required,networkPlugin"`
// ID of the chosen storage policy
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// ID of SEP to create boot disks for master nodes. Uses images SEP ID if not set
// Required: false
MasterSEPID uint64 `url:"masterSepId,omitempty" json:"masterSepId,omitempty"`

View File

@@ -46,6 +46,11 @@ type ListRequest struct {
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`

View File

@@ -17,6 +17,10 @@ type WorkersGroupAddRequest struct {
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// ID of the chosen storage policy
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// ID of SEP to create boot disks for default worker nodes group. Uses images SEP ID if not set
// Required: false
WorkerSEPID uint64 `url:"workerSepId,omitempty" json:"workerSepId,omitempty"`

View File

@@ -42,6 +42,18 @@ type Interface struct {
// SDN interface id
// Required: false
SDNInterfaceID string `url:"sdn_interface_id,omitempty" json:"sdn_interface_id,omitempty"`
// List of security group IDs to assign to this interface
// Required: false
SecGroups []uint64 `url:"security_groups,omitempty" json:"security_groups,omitempty"`
// Flag indicating whether security groups are enabled for this interface
// Required: false
EnableSecGroups bool `url:"enable_secgroups,omitempty" json:"enable_secgroups,omitempty"`
// Flag indicating whether this interface is enabled (only for VINS, EXTNET, DPDK, SDN, TRUNK)
// Required: false
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
}
// DataDisk detailed struct for DataDisks field in CreateRequest and CreateBlankRequest
@@ -54,6 +66,10 @@ type DataDisk struct {
// Required: true
Size uint64 `url:"size" json:"size" validate:"required"`
// Storage policy id of disk. The rules of the specified storage policy will be used.
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// Storage endpoint provider ID
// By default the same with boot disk
// Required: false
@@ -92,6 +108,10 @@ type CreateRequest struct {
// Required: true
RAM uint64 `url:"ram" json:"ram" validate:"required"`
// Storage policy id of сompute. The rules of the specified storage policy will be used.
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// If True, the imageId, bootDisk, sepId, pool parameters are ignored and the compute is created without a boot disk in the stopped state
// Required: false
WithoutBootDisk bool `url:"withoutBootDisk" json:"withoutBootDisk"`
@@ -101,6 +121,10 @@ type CreateRequest struct {
// Required: false
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
// The OS version that will be installed on the virtual machine
// Required: false
OSVersion string `url:"os_version,omitempty" json:"os_version,omitempty"`
// Size of the boot disk in GB
// Required: false
BootDisk uint64 `url:"bootDisk,omitempty" json:"bootDisk,omitempty"`
@@ -150,10 +174,6 @@ type CreateRequest struct {
// Required: false
CustomFields string `url:"customFields,omitempty" json:"customFields,omitempty"`
// Type of compute Stateful (KVM_X86)
// Required: false
Driver string `url:"driver,omitempty" json:"driver,omitempty" validate:"omitempty,computeDriver"`
// Rule for VM placement with NUMA affinity.
// Possible values - none (placement without NUMA affinity),
// strict (strictly with NUMA affinity, if not possible - do not start VM),

View File

@@ -28,6 +28,10 @@ type CreateBlankRequest struct {
// Required: true
RAM uint64 `url:"ram" json:"ram" validate:"required"`
// Storage policy id of compute. The rules of the specified storage policy will be used.
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// If True, the imageId, bootDisk, sepId, pool parameters are ignored and the compute is created without a boot disk in the stopped state
// Required: false
WithoutBootDisk bool `url:"withoutBootDisk" json:"withoutBootDisk"`
@@ -57,10 +61,6 @@ type CreateBlankRequest struct {
// Required: false
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Type of compute Stateful (KVM_X86)
// Required: false
Driver string `url:"driver,omitempty" json:"driver,omitempty" validate:"omitempty,computeDriver"`
// Type of the emulated system, Q35 or i440fx
// Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"omitempty,chipset"`
@@ -92,6 +92,10 @@ type CreateBlankRequest struct {
// Zone ID
// Required: false
ZoneID uint64 `url:"zoneId,omitempty" json:"zoneId,omitempty"`
// The OS version that will be installed on the virtual machine
// Required: false
OSVersion string `url:"os_version,omitempty" json:"os_version,omitempty"`
}
// GetRAM returns RAM field values

View File

@@ -50,6 +50,11 @@ type ListRequest struct {
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
@@ -22,6 +23,10 @@ type CreateRequest struct {
// Required: true
Name string `url:"name" json:"name" validate:"required,min=2"`
// Storage policies
// Required: false
StoragePolicies []StoragePolicy `url:"storage_policies" json:"storage_policies"`
// Max size of memory in MB
// Required: false
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
@@ -77,6 +82,11 @@ type CreateRequest struct {
SDNAccessGroupID string `url:"sdn_access_group_id,omitempty" json:"sdn_access_group_id,omitempty"`
}
type StoragePolicy struct {
ID uint64 `url:"id" json:"id"`
Limit int `url:"limit" json:"limit"`
}
// Create creates resource group
func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
@@ -86,7 +96,7 @@ func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) {
url := "/cloudapi/rg/create"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return 0, err
}

View File

@@ -134,6 +134,9 @@ type RecordResourceGroup struct {
// List of resource types
ResTypes []string `json:"resourceTypes"`
// Storage policy ids
StoragePolicyIDs []uint64 `json:"storage_policy_ids"`
// SDN access group id
SDNAccessGroupID string `json:"sdn_access_group_id"`
@@ -233,6 +236,9 @@ type ItemResourceGroup struct {
// SDN access group id
SDNAccessGroupID string `json:"sdn_access_group_id"`
// Storage policy ids
StoragePolicyIDs []uint64 `json:"storage_policy_ids"`
// Secret
Secret string `json:"secret"`
@@ -308,6 +314,9 @@ type ResourceLimits struct {
// GPU units
GPUUnits float64 `json:"gpu_units"`
// Storage policies
StoragePolicies []StoragePolicy `json:"storage_policy"`
}
// Main information about affinity group

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
@@ -50,6 +51,10 @@ type UpdateRequest struct {
// Default: false
// Required: false
ClearUniqPools bool `url:"clearUniqPools" json:"clearUniqPools"`
// Storage policies
// Required: false
StoragePolicies []StoragePolicy `url:"-" json:"storage_policies,omitempty"`
}
// Update updates resource group
@@ -61,7 +66,7 @@ func (r RG) Update(ctx context.Context, req UpdateRequest) (bool, error) {
url := "/cloudapi/rg/update"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return false, err
}

View File

@@ -0,0 +1,46 @@
package secgroup
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type CreateRequest struct {
// Account ID that owns security group
// Required: true
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
// Security group name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Security group description
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
}
func (sg SecurityGroup) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/security_group/create"
res, err := sg.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, 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,63 @@
package secgroup
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type CreateRuleRequest struct {
// Security group ID
// Required: true
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
// Traffic direction (inbound/outbound)
// Required: true
Direction string `url:"direction" json:"direction" validate:"required,securityGroupDirection"`
// IP protocol version
// Default: IPv4
// Required: false
Ethertype string `url:"ethertype,omitempty" json:"ethertype,omitempty" validate:"omitempty,securityGroupEthertype"`
// Network protocol, available values : icmp, tcp, udp
// Required: false
Protocol string `url:"protocol,omitempty" json:"protocol,omitempty" validate:"omitempty,securityGroupProtocol"`
// Start port number (for TCP/UDP)
// Required: false
PortRangeMin uint64 `url:"port_range_min,omitempty" json:"port_range_min,omitempty"`
// End port number (for TCP/UDP)
// Required: false
PortRangeMax uint64 `url:"port_range_max,omitempty" json:"port_range_max,omitempty"`
// Remote IP prefix in CIDR notation
// Required: false
RemoteIPPrefix string `url:"remote_ip_prefix,omitempty" json:"remote_ip_prefix,omitempty"`
}
func (sg SecurityGroup) CreateRule(ctx context.Context, req CreateRuleRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/security_group/create_rule"
res, err := sg.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, 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 secgroup
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type DeleteRequest struct {
// Security group ID
// Required: true
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
}
func (sg SecurityGroup) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/security_group/delete"
res, err := sg.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 secgroup
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type DeleteRuleRequest struct {
// Security group ID
// Required: true
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
// Rule ID
// Required: true
RuleID uint64 `url:"rule_id" json:"rule_id" validate:"required"`
}
func (sg SecurityGroup) DeleteRule(ctx context.Context, req DeleteRuleRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/security_group/delete_rule"
res, err := sg.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,80 @@
package secgroup
// FilterByID returns ListSecurityGroups with specified ID.
func (lsg ListSecurityGroups) FilterByID(id uint64) ListSecurityGroups {
predicate := func(isg ItemSecurityGroup) bool {
return isg.ID == id
}
return lsg.FilterFunc(predicate)
}
// FilterByID returns ListSecurityGroups with specified Name.
func (lsg ListSecurityGroups) FilterByName(name string) ListSecurityGroups {
predicate := func(isg ItemSecurityGroup) bool {
return isg.Name == name
}
return lsg.FilterFunc(predicate)
}
// FilterByCreatedBy returns ListSecurityGroups with specified CreatedBy.
func (lsg ListSecurityGroups) FilterByCreatedBy(createdBy string) ListSecurityGroups {
predicate := func(isg ItemSecurityGroup) bool {
return isg.CreatedBy == createdBy
}
return lsg.FilterFunc(predicate)
}
// FilterByDescription returns ListSecurityGroups with specified Description.
func (lsg ListSecurityGroups) FilterByDescription(description string) ListSecurityGroups {
predicate := func(isg ItemSecurityGroup) bool {
return isg.Description == description
}
return lsg.FilterFunc(predicate)
}
// FilterByUpdatedBy returns ListSecurityGroups with specified UpdatedBy.
func (lsg ListSecurityGroups) FilterByUpdatedBy(updatedBy string) ListSecurityGroups {
predicate := func(isg ItemSecurityGroup) bool {
return isg.UpdatedBy == updatedBy
}
return lsg.FilterFunc(predicate)
}
// FilterByAccountID returns ListSecurityGroups with specified AccountID.
func (lsg ListSecurityGroups) FilterByAccountID(accountID uint64) ListSecurityGroups {
predicate := func(isg ItemSecurityGroup) bool {
return isg.AccountID == accountID
}
return lsg.FilterFunc(predicate)
}
// FilterFunc allows filtering ListSecurityGroups based on a user-specified predicate.
func (lsg ListSecurityGroups) FilterFunc(predicate func(ItemSecurityGroup) bool) ListSecurityGroups {
var result ListSecurityGroups
for _, item := range lsg.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemSecurityGroup
// If none was found, returns an empty struct.
func (lsg ListSecurityGroups) FindOne() ItemSecurityGroup {
if len(lsg.Data) == 0 {
return ItemSecurityGroup{}
}
return lsg.Data[0]
}

View File

@@ -0,0 +1,87 @@
package secgroup
import "testing"
var securityGroups = ListSecurityGroups{
Data: []ItemSecurityGroup{
{
ID: 1,
AccountID: 1,
Name: "sg1",
Description: "some desc",
CreatedBy: "user",
},
{
ID: 3,
AccountID: 3,
Name: "sg3",
Description: "some desc",
CreatedBy: "anotheruser",
},
{
ID: 5,
AccountID: 3,
Name: "sg5",
Description: "some other desc",
CreatedBy: "anotheruser",
UpdatedBy: "user",
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
actual := securityGroups.FilterByID(1).FindOne()
if actual.ID != 1 {
t.Fatal("expected ID 1, found: ", actual.ID)
}
}
func TestFilterByName(t *testing.T) {
actual := securityGroups.FilterByName("sg3").FindOne()
if actual.Name != "sg3" {
t.Fatal("expected Name sg3, found: ", actual.Name)
}
}
func TestFilterByDescription(t *testing.T) {
actual := securityGroups.FilterByDescription("some desc")
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.Description != "some desc" {
t.Fatal("expected Description 'some desc', found: ", item.Description)
}
}
}
func TestFilterByAccountID(t *testing.T) {
actual := securityGroups.FilterByAccountID(1).FindOne()
if actual.AccountID != 1 {
t.Fatal("expected AccountID 1, found: ", actual.AccountID)
}
}
func TestFilterByCreatedBy(t *testing.T) {
actual := securityGroups.FilterByCreatedBy("anotheruser")
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.CreatedBy != "anotheruser" {
t.Fatal("expected CreatedBy 'anotheruser', found: ", item.CreatedBy)
}
}
}
func TestFilterByUpdatedBy(t *testing.T) {
actual := securityGroups.FilterByUpdatedBy("user").FindOne()
if actual.UpdatedBy != "user" {
t.Fatal("expected UpdatedBy 'user', found: ", actual.UpdatedBy)
}
}

View File

@@ -0,0 +1,43 @@
package secgroup
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type GetRequest struct {
// ID of security group
// Required: true
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
}
func (sg SecurityGroup) Get(ctx context.Context, req GetRequest) (*RecordSecurityGroup, error) {
res, err := sg.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordSecurityGroup{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
func (sg SecurityGroup) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/security_group/get"
res, err := sg.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,86 @@
package secgroup
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type ListRequest struct {
// Search by security group id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Search by account id
// Required: false
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
// Search by security group name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Search by security group description
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// Search by created after time (unix timestamp)
// Required: false
CreatedMin uint64 `url:"created_min,omitempty" json:"created_min,omitempty"`
// Search by created before time (unix timestamp)
// Required: false
CreatedMax uint64 `url:"created_max,omitempty" json:"created_max,omitempty"`
// Search by updated after time (unix timestamp)
// Required: false
UpdatedMin uint64 `url:"updated_min,omitempty" json:"updated_min,omitempty"`
// Search by updated before time (unix timestamp)
// Required: false
UpdatedMax uint64 `url:"updated_max,omitempty" json:"updated_max,omitempty"`
// Sort by one of supported fields, format ±<field>
// Required: false
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
// 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 security groups as a ListSecurityGroups struct
func (sg SecurityGroup) List(ctx context.Context, req ListRequest) (*ListSecurityGroups, error) {
res, err := sg.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListSecurityGroups{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of security groups as an array of bytes
func (sg SecurityGroup) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/security_group/list"
res, err := sg.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,94 @@
package secgroup
type ListSecurityGroups struct {
// List
Data []ItemSecurityGroup `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
type ItemSecurityGroup struct {
// ID of the security group
ID uint64 `json:"id"`
// Account ID that owns the security group
AccountID uint64 `json:"account_id"`
// Name of the security group
Name string `json:"name"`
// Description of the security group
Description string `json:"description"`
// List of rules
Rules Rules `json:"rules"`
// Created at
CreatedAt uint64 `json:"created_at"`
// Updated at
UpdatedAt uint64 `json:"updated_at"`
// Created by
CreatedBy string `json:"created_by"`
// Updated by
UpdatedBy string `json:"updated_by"`
}
type RecordSecurityGroup struct {
// ID of the security group
ID uint64 `json:"id"`
// Account ID that owns the security group
AccountID uint64 `json:"account_id"`
// Name of the security group
Name string `json:"name"`
// Description of the security group
Description string `json:"description"`
// List of rules
Rules Rules `json:"rules"`
// Created at
CreatedAt uint64 `json:"created_at"`
// Updated at
UpdatedAt uint64 `json:"updated_at"`
// Created by
CreatedBy string `json:"created_by"`
// Updated by
UpdatedBy string `json:"updated_by"`
}
type Rules []Rule
type Rule struct {
// ID of the rule
ID uint64 `json:"id"`
// Traffic direction (inbound/outbound)
Direction string `json:"direction"`
// IP protocol version
Ethertype string `json:"ethertype"`
// Network protocol
Protocol string `json:"protocol"`
// Start port number (for TCP/UDP)
PortRangeMin uint64 `json:"port_range_min"`
// End port number (for TCP/UDP)
PortRangeMax uint64 `json:"port_range_max"`
// Remote IP prefix in CIDR notation
RemoteIPPrefix string `json:"remote_ip_prefix"`
RemoteGroupID uint64 `json:"remote_group_id"`
}

View File

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

View File

@@ -0,0 +1,41 @@
package secgroup
import "sort"
// SortByCreatedAt sorts ListSecurityGroups by the CreatedAt field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lsg ListSecurityGroups) SortByCreatedAt(inverse bool) ListSecurityGroups {
if len(lsg.Data) < 2 {
return lsg
}
sort.Slice(lsg.Data, func(i, j int) bool {
if inverse {
return lsg.Data[i].CreatedAt > lsg.Data[j].CreatedAt
}
return lsg.Data[i].CreatedAt < lsg.Data[j].CreatedAt
})
return lsg
}
// SortByUpdatedAt sorts ListSecurityGroups by the UpdatedAt field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lsg ListSecurityGroups) SortByUpdatedAt(inverse bool) ListSecurityGroups {
if len(lsg.Data) < 2 {
return lsg
}
sort.Slice(lsg.Data, func(i, j int) bool {
if inverse {
return lsg.Data[i].UpdatedAt > lsg.Data[j].UpdatedAt
}
return lsg.Data[i].UpdatedAt < lsg.Data[j].UpdatedAt
})
return lsg
}

View File

@@ -0,0 +1,51 @@
package secgroup
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type UpdateRequest struct {
// Security group ID
// Required: true
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
// New security group name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// New security group description
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
}
func (sg SecurityGroup) Update(ctx context.Context, req UpdateRequest) (*RecordSecurityGroup, error) {
res, err := sg.UpdateRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordSecurityGroup{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
func (sg SecurityGroup) UpdateRaw(ctx context.Context, req UpdateRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/security_group/update"
res, err := sg.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,10 @@
package cloudapi
import (
secgroup "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/secgroup"
)
// Accessing the Security Group method group
func (ca *CloudAPI) SecurityGroup() *secgroup.SecurityGroup {
return secgroup.New(ca.client)
}

View File

@@ -0,0 +1,10 @@
package cloudapi
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/stpolicy"
)
// Accessing the Storage Policy method group
func (ca *CloudAPI) StPolicy() *stpolicy.StPolicy {
return stpolicy.New(ca.client)
}

View File

@@ -0,0 +1,43 @@
package stpolicy
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type GetRequest struct {
// ID of storage policy
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
}
func (sp StPolicy) Get(ctx context.Context, req GetRequest) (*InfoStoragePolicy, error) {
res, err := sp.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := InfoStoragePolicy{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
func (sp StPolicy) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/storage_policy/get"
res, err := sp.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,90 @@
package stpolicy
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type ListRequest struct {
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Search by storage policy ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Search by storage policy name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Search by storage policy status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Search by storage policy desc
// Required: false
Desc string `url:"desc,omitempty" json:"desc,omitempty"`
// Search by storage policy iops limit
// Required: false
LimitIOPS uint64 `url:"limit_iops,omitempty" json:"limit_iops,omitempty"`
// Sort by one of supported fields, format ±<field>
// Required: false
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
// ID of account ID
// Required: false
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
// Search by resgroup id
// Required: false
ResgroupID uint64 `url:"resgroup_id,omitempty" json:"resgroup_id,omitempty"`
// Search by sep id
// Required: false
SepID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
// Search by pool name
// Required: false
PoolName string `url:"pool_name,omitempty" json:"pool_name,omitempty"`
}
// List gets list of storage policies as a ListStoragePolicies struct
func (sp StPolicy) List(ctx context.Context, req ListRequest) (*ListStoragePolicies, error) {
res, err := sp.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListStoragePolicies{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of storage policies as an array of bytes
func (sp StPolicy) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/storage_policy/list"
res, err := sp.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,88 @@
package stpolicy
type ListStoragePolicies struct {
// List
Data []ItemStoragePolicy `json:"data"`
// Entry Count
EntryCount uint64 `json:"entryCount"`
}
type ItemStoragePolicy struct {
// ID of the storage policy
ID uint64 `json:"id"`
// GUID
GUID uint64 `json:"guid"`
// Name of the storage policy
Name string `json:"name"`
// Description of the storage policy
Description string `json:"description"`
// List of pools in SEP for storage policy
AccessSEPPools ListAccessSEPPools `json:"access_seps_pools"`
// Status of the storage policy
Status string `json:"status"`
// Max IOPS for the sotrage policy
LimitIOPS uint64 `json:"limit_iops"`
// Storage policy ID
StoragePolicyID uint64 `json:"storage_policy_id"`
// Which accounts and resource groups use the storage policy
Usage Usage `json:"usage"`
}
type InfoStoragePolicy struct {
// ID of the storage policy
ID uint64 `json:"id"`
// GUID
GUID uint64 `json:"guid"`
// Name of the storage policy
Name string `json:"name"`
// Description of the storage policy
Description string `json:"description"`
// List of pools in SEP for storage policy
AccessSEPPools ListAccessSEPPools `json:"access_seps_pools"`
// Status of the storage policy
Status string `json:"status"`
// Max IOPS for the sotrage policy
LimitIOPS uint64 `json:"limit_iops"`
// ID of the storage policy
StoragePolicyID uint64 `json:"storage_policy_id"`
// Which accounts and resource groups use the storage policy
Usage Usage `json:"usage"`
}
type ListAccessSEPPools []AccessSEPPool
type AccessSEPPool struct {
// SEP ID
SEPID uint64 `json:"sep_id"`
// SEP name
Name string `json:"sep_name"`
// Pool names
PoolNames []string `json:"pool_names"`
}
type Usage struct {
// List of accounts
Accounts []uint64 `json:"accounts"`
// List of resource groups
Resgroups []uint64 `json:"resgroups"`
}

View File

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

View File

@@ -27,6 +27,9 @@ type ListRequest struct {
// Page size
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Status
Status string `url:"status,omitempty" json:"status,omitempty"`
}
// List gets list of all trunks as a ListTrunks struct

View File

@@ -46,6 +46,11 @@ type ListRequest struct {
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -211,6 +211,12 @@ type RecordVNFDev struct {
// VNC password
VNCPassword string `json:"vncPasswd"`
// Zone ID
ZoneID uint64 `json:"zoneId"`
// Live migration job ID
LiveMigrationJobID uint64 `json:"live_migration_job_id"`
}
// VNF config
@@ -269,6 +275,9 @@ type ItemVNFInterface struct {
// Enabled
Enabled bool `json:"enabled"`
// Enable security groups
EnableSecGroups bool `json:"enable_secgroups"`
// FLIPGroup ID
FLIPGroupID uint64 `json:"flipgroupId"`
@@ -305,6 +314,9 @@ type ItemVNFInterface struct {
// NodeID
NodeID int64 `json:"nodeId"`
// List of security groups
SecGroups []uint64 `json:"security_groups"`
// SDNInterfaceID
SDNInterfaceID string `json:"sdn_interface_id"`
@@ -418,6 +430,9 @@ type RecordNAT struct {
// Type
Type string `json:"type"`
// Zone ID
ZoneID uint64 `json:"zoneId"`
}
// NAT configuration
@@ -486,6 +501,9 @@ type RecordGW struct {
// Type
Type string `json:"type"`
// Zone ID
ZoneID uint64 `json:"zoneId"`
}
// GW configuration
@@ -576,6 +594,9 @@ type RecordDHCP struct {
// Type
Type string `json:"type"`
// Zone ID
ZoneID uint64 `json:"zoneId"`
}
// DHCP configuration
@@ -673,6 +694,9 @@ type RecordVINS struct {
// Description
Description string `json:"desc"`
// Enable Security Groups
EnableSecGroups bool `json:"enable_secgroups"`
// Grid ID
GID uint64 `json:"gid"`

View File

@@ -22,12 +22,30 @@ type RecordZone struct {
// Name
Name string `json:"name"`
// List of associated account IDs
AccountIDs []uint64 `json:"accountIds"`
// List of associated bservice IDs
BserviceIDs []uint64 `json:"bserviceIds"`
// List of associated compute IDs
ComputeIDs []uint64 `json:"computeIds"`
// Description
Description string `json:"description"`
// Deletable flag
Deletable bool `json:"deletable"`
// List of associated ExtNet IDs
ExtnetIDs []uint64 `json:"extnetIds"`
// List of associated K8s IDs
K8SIDs []uint64 `json:"k8sIds"`
// List of associated LB IDs
LBIDs []uint64 `json:"lbIds"`
// Status
Status string `json:"status"`
@@ -39,4 +57,7 @@ type RecordZone struct {
// List of associated Node IDs
NodeIDs []uint64 `json:"nodeIds"`
// List of associated VINS IDs
VinsIDs []uint64 `json:"vinsIds"`
}

View File

@@ -0,0 +1,46 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AddStoragePolicyRequest struct for adding storage policy to the account
type AddStoragePolicyRequest struct {
// ID of account to add to
// Required: true
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
// ID of the storage policy to which to connect account
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// Limit storage resources GB. Or -1 unlimit
// Required: false
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
}
// AddStoragePolicy add storage policy to the account.
func (a Account) AddStoragePolicy(ctx context.Context, req AddStoragePolicyRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/add_storage_policy"
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

@@ -5,6 +5,7 @@ import (
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
@@ -26,6 +27,10 @@ type CreateRequest struct {
// Required: false
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
// Storage policies
// Required: false
StoragePolicies []StoragePolicy `url:"-" json:"storage_policies,omitempty"`
// Max size of memory in MB
// Required: false
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
@@ -73,6 +78,11 @@ type CreateRequest struct {
ZoneIDs []uint64 `url:"zoneIds,omitempty" json:"zoneIds,omitempty"`
}
type StoragePolicy struct {
ID uint64 `url:"id" json:"id"`
Limit int `url:"limit" json:"limit"`
}
// 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) {
@@ -83,7 +93,7 @@ func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error)
url := "/cloudbroker/account/create"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := a.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return 0, err
}

View File

@@ -0,0 +1,42 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DelStoragePolicyRequest struct for deleting storage policy to the account
type DelStoragePolicyRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
// ID of the storage policy to which to disconnect account
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
}
// DelStoragePolicy delete storage policy to the account.
func (a Account) DelStoragePolicy(ctx context.Context, req DelStoragePolicyRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/del_storage_policy"
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

@@ -7,7 +7,6 @@ import (
var accounts = ListAccounts{
Data: []ItemAccount{
{
Meta: []interface{}{},
InfoAccount: InfoAccount{
CreatedTime: 1676878820,
DeletedTime: 0,
@@ -28,7 +27,6 @@ var accounts = ListAccounts{
},
},
{
Meta: []interface{}{},
InfoAccount: InfoAccount{
CreatedTime: 1676645275,
DeletedTime: 1677723401,
@@ -49,7 +47,6 @@ var accounts = ListAccounts{
},
},
{
Meta: []interface{}{},
InfoAccount: InfoAccount{
CreatedTime: 1676883850,
DeletedTime: 1676883899,

View File

@@ -30,6 +30,11 @@ type ListRequest struct {
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -46,6 +46,18 @@ type ListResources struct {
EntryCount uint64 `json:"entryCount"`
}
// Policy
type Policy struct {
// Size of the disk
DiskSize float64 `json:"disksize"`
// Max size of the disk
DiskSizeMax float64 `json:"disksizemax"`
// SEPs used
SEPs map[string]map[string]DiskUsage `json:"seps"`
}
type Resource struct {
// Number of cores
CPU int64 `json:"cpu"`
@@ -70,6 +82,9 @@ type Resource struct {
// SEPs
SEPs map[string]map[string]DiskUsage `json:"seps"`
// Policies
Policies map[string]Policy `json:"policies"`
}
// Disk usage
@@ -133,6 +148,9 @@ type ResourceLimits struct {
// GPUUnits
GPUUnits float64 `json:"gpu_units"`
// Storage policies
StoragePolicies []StoragePolicy `json:"storage_policy"`
}
// Main information about account
@@ -140,9 +158,6 @@ type InfoAccount struct {
// DCLocation
DCLocation string `json:"DCLocation"`
// CKey
CKey string `json:"_ckey"`
// Company
Company string `json:"company"`
@@ -200,6 +215,9 @@ type InfoAccount struct {
// Status
Status string `json:"status"`
// Storage policy ids
StoragePolicyIDs []uint64 `json:"storage_policy_ids"`
// UniqPools
UniqPools []string `json:"uniqPools"`
@@ -234,13 +252,11 @@ type RecordAccount struct {
ACL []ACLWithEmails `json:"acl"`
// Zones IDs
ZoneIDs []ZoneID
ZoneIDs []ZoneID `json:"zoneIds"`
}
// More information about account
type ItemAccount struct {
// Meta
Meta []interface{} `json:"_meta"`
// Access Control List
ACL []ACL `json:"acl"`
@@ -249,7 +265,7 @@ type ItemAccount struct {
InfoAccount
// Zones
ZoneIDs []uint64
ZoneIDs []uint64 `json:"zoneIds"`
}
// List of accounts

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
@@ -46,6 +47,10 @@ type UpdateRequest struct {
// Required: false
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
// Storage policies
// Required: false
StoragePolicies []StoragePolicy `url:"-" json:"storage_policies,omitempty"`
// Limit (positive) or disable (0) GPU resources
// Required: false
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
@@ -74,7 +79,7 @@ func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
url := "/cloudbroker/account/update"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := a.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return false, err
}

View File

@@ -0,0 +1,81 @@
package audit
// FilterByID returns ListAudits with specified ID.
func (la ListAudits) FilterByID(guid string) ListAudits {
predicate := func(ia ItemAudit) bool {
return ia.GUID == guid
}
return la.FilterFunc(predicate)
}
// FilterByCall returns ListAudits with specified call.
func (la ListAudits) FilterByCall(call string) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.Call == call
}
return la.FilterFunc(predicate)
}
// FilterByCorrelationID returns ListAudits with specified correlation id.
func (la ListAudits) FilterByCorrelationID(correlationID string) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.CorrelationID == correlationID
}
return la.FilterFunc(predicate)
}
// FilterByRemoteAddr returns ListAudits with specified remote address.
func (la ListAudits) FilterByRemoteAddr(remoteAddr string) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.RemoteAddr == remoteAddr
}
return la.FilterFunc(predicate)
}
// FilterByUser returns ListAudits with specified user name.
func (la ListAudits) FilterByUser(user string) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.User == user
}
return la.FilterFunc(predicate)
}
// FilterByStatusCode return ListAudits with specified status code.
func (la ListAudits) FilterByStatusCode(statusCode uint64) ListAudits {
predicate := func(ic ItemAudit) bool {
return ic.StatusCode == statusCode
}
return la.FilterFunc(predicate)
}
// FilterFunc allows filtering ListAudits based on a user-specified predicate.
func (la ListAudits) FilterFunc(predicate func(ItemAudit) bool) ListAudits {
var result ListAudits
for _, item := range la.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemAudit
// If none was found, returns an empty struct.
func (la ListAudits) FindOne() ItemAudit {
if len(la.Data) == 0 {
return ItemAudit{}
}
return la.Data[0]
}

View File

@@ -0,0 +1,115 @@
package audit
import (
"testing"
)
var audits = ListAudits{
Data: []ItemAudit{
{
Args: "[]",
Call: "/restmachine/cloudapi/audit/linkedJobs",
GUID: "550e8400-e29b-41d4-a716-446655440001",
CorrelationID: "550e8400-e29b-41d4-a716-446655440001",
Kwargs: `{\"audit_guid\":\"dd8623a1-a887-48c1-a500-c10210d404cf\"}`,
RemoteAddr: "192.168.1.100",
ResponseTime: 1,
Result: `[]`,
StatusCode: 200,
Timestamp: 1640995200,
TimestampEnd: 1640995201,
User: "test@example.com",
TTL: "2025-07-31T14:22:57.028000",
},
{
Args: "[]",
Call: "/restmachine/cloudapi/audit/test",
GUID: "550e8400-e29b-41d4-a716-446655440002",
CorrelationID: "550e8400-e29b-41d4-a716-446655440002",
Kwargs: `{\"audit_guid\":\"dd8623a1-a887-48c1-a500-c10210d404cf\"}`,
RemoteAddr: "192.168.1.105",
ResponseTime: 5,
Result: `[]`,
StatusCode: 400,
Timestamp: 1640995200,
TimestampEnd: 1640995201,
User: "test2@example.com",
TTL: "2025-07-31T14:22:57.028000",
},
},
EntryCount: 2,
}
func TestFilterByID(t *testing.T) {
actual := audits.FilterByID("550e8400-e29b-41d4-a716-446655440002").FindOne()
if actual.GUID != "550e8400-e29b-41d4-a716-446655440002" {
t.Fatal("expected GUID 550e8400-e29b-41d4-a716-446655440002, found: ", actual.GUID)
}
actualEmpty := audits.FilterByID("")
if len(actualEmpty.Data) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
}
}
func TestFilterByCorrelationID(t *testing.T) {
actual := audits.FilterByCorrelationID("550e8400-e29b-41d4-a716-446655440002").FindOne()
if actual.CorrelationID != "550e8400-e29b-41d4-a716-446655440002" {
t.Fatal("expected GUID 550e8400-e29b-41d4-a716-446655440002, found: ", actual.CorrelationID)
}
actualEmpty := audits.FilterByCorrelationID("")
if len(actualEmpty.Data) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
}
}
func TestFilterByRemoteAddr(t *testing.T) {
actual := audits.FilterByRemoteAddr("192.168.1.100").FindOne()
if actual.RemoteAddr != "192.168.1.100" {
t.Fatal("expected remote address 192.168.1.100, found: ", actual.RemoteAddr)
}
actualEmpty := audits.FilterByRemoteAddr("")
if len(actualEmpty.Data) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
}
}
func TestFilterByUser(t *testing.T) {
actual := audits.FilterByUser("test@example.com").FindOne()
if actual.User != "test@example.com" {
t.Fatal("expected user test@example.com, found: ", actual.RemoteAddr)
}
actualEmpty := audits.FilterByUser("")
if len(actualEmpty.Data) != 0 {
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
}
}
func TestFilterByCall(t *testing.T) {
actual := audits.FilterByCall("/restmachine/cloudapi/audit/test").FindOne()
if actual.Call != "/restmachine/cloudapi/audit/test" {
t.Fatal("expected call /restmachine/cloudapi/audit/test, found: ", actual.Call)
}
}
func TestFilterByStatusCode(t *testing.T) {
actual := audits.FilterByStatusCode(200)
for _, item := range actual.Data {
if item.StatusCode != 200 {
t.Fatal("expected 200 status code, found: ", item.StatusCode)
}
}
}

View File

@@ -50,6 +50,50 @@ type ListRequest struct {
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Find by resource group id
// Required: false
RGID uint64 `url:"resgroup_id,omitempty" json:"resgroup_id,omitempty"`
// Find by compute id
// Required: false
ComputeID uint64 `url:"compute_id,omitempty" json:"compute_id,omitempty"`
// Find by account id
// Required: false
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
// Find by vins id
// Required: false
VINSID uint64 `url:"vins_id,omitempty" json:"vins_id,omitempty"`
// Find by service id
// Required: false
ServiceID uint64 `url:"service_id,omitempty" json:"service_id,omitempty"`
// Find by k8s id
// Required: false
K8SID uint64 `url:"k8s_id,omitempty" json:"k8s_id,omitempty"`
// Find by flipgroup id
// Required: false
FLIPGroupID uint64 `url:"flipgroup_id,omitempty" json:"flipgroup_id,omitempty"`
// Find by load balancer id
// Required: false
LBID uint64 `url:"lb_id,omitempty" json:"lb_id,omitempty"`
// Find by sep id
// Required: false
SEPID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
// Find by node id
// Required: false
NodeID uint64 `url:"node_id,omitempty" json:"node_id,omitempty"`
// Exclude audit lines from response
// Required: false
ExcludeAuditLines bool `url:"exclude_audit_lines,omitempty" json:"exclude_audit_lines,omitempty"`
}
// List gets audit records for the specified account object

View File

@@ -11,6 +11,9 @@ type ItemAudit struct {
// GUID
GUID string `json:"guid"`
// Correlation ID
CorrelationID string `json:"correlation_id"`
// Kwargs
Kwargs string `json:"kwargs"`
@@ -37,9 +40,6 @@ type ItemAudit struct {
// TTL
TTL string `json:"_ttl"`
// Tags
Tags string `json:"tags"`
}
// List of audits
@@ -60,6 +60,9 @@ type RecordAudit struct {
// Call
Call string `json:"call"`
// Correlation ID
CorrelationID string `json:"correlation_id"`
// GUID
GUID string `json:"guid"`

View File

@@ -38,11 +38,9 @@ type GroupAddRequest struct {
// Required: true
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
// Compute driver
// should be one of:
// - KVM_X86
// Compute driver like a KVM_X86, etc.
// Required: true
Driver string `url:"driver" json:"driver" validate:"driver"`
Driver string `url:"driver" json:"driver" validate:"required"`
// Storage endpoint provider ID
// Required: false
@@ -75,6 +73,10 @@ type GroupAddRequest struct {
//Chipset "i440fx" or "Q35
//Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"chipset"`
// ID of the chosen storage policy
// Required: false
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
}
// GetRAM returns RAM field values

View File

@@ -42,6 +42,11 @@ type ListRequest struct {
// Required: false
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`

View File

@@ -12,11 +12,47 @@ import (
type AuditsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
// Find all audits after point in time
// Required: false
TimestampAT uint64 `url:"timestamp_at,omitempty" json:"timestamp_at,omitempty"`
// Find all audits before point in time
// Required: false
TimestampTO uint64 `url:"timestamp_to,omitempty" json:"timestamp_to,omitempty"`
// Find by user
// Required: false
User string `url:"user,omitempty" json:"user,omitempty"`
// Find by api endpoints
// Required: false
Call string `url:"call,omitempty" json:"call,omitempty"`
// Sort by one of supported fields, format ±<field>
// Required: false
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
// 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 HTTP min status code
// Required: false
MinStatusCode uint64 `url:"min_status_code,omitempty" json:"min_status_code,omitempty"`
// Find by HTTP max status code
// Required: false
MaxStatusCode uint64 `url:"max_status_code,omitempty" json:"max_status_code,omitempty"`
}
// Audits gets audit records for the specified compute object
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListDetailedAudits, error) {
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))
@@ -24,7 +60,7 @@ func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListDetailedAud
url := "/cloudbroker/compute/audits"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return nil, err
}
@@ -36,5 +72,5 @@ func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListDetailedAud
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -0,0 +1,50 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ChangeSecGroupsRequest struct to change security groups for compute
type ChangeSecGroupsRequest struct {
// Identifier compute
// Required: true
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
// Interface name or MAC address
// Required: true
Interface string `url:"interface" json:"interface" validate:"required"`
// List of security group IDs to assign to this interface
// Required: false
SecGroups []uint64 `url:"security_groups,omitempty" json:"security_groups,omitempty"`
// Flag indicating whether security groups are enabled for this interface
// Required: false
EnableSecGroups interface{} `url:"enable_secgroups,omitempty" json:"enable_secgroups,omitempty" validate:"omitempty,isBool"`
}
// ChangeSecGroups changes security groups for compute
func (c Compute) ChangeSecGroups(ctx context.Context, req ChangeSecGroupsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/change_security_groups"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -3,8 +3,8 @@ package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
@@ -18,6 +18,10 @@ type CloneRequest struct {
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// ID of the Storage Policy
// Required: true
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
// Timestamp of the parent's snapshot to create clone from
// Required: false
SnapshotTimestamp uint64 `url:"snapshotTimestamp" json:"snapshotTimestamp"`
@@ -30,26 +34,29 @@ type CloneRequest struct {
// Default: false
// Required: false
Force bool `url:"force" json:"force"`
// The name of the pool to migrate disks to
// Required: false
PoolName string `url:"pool_name" json:"pool_name"`
// The ID of the SEP to migrate disks to
// Required: false
SEPID uint64 `url:"sep_id" json:"sep_id"`
}
// Clone clones compute instance
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
func (c Compute) Clone(ctx context.Context, req CloneRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/clone"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := c.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return 0, err
return "", err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
return string(res), nil
}

View File

@@ -0,0 +1,39 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CloneAbortRequest struct to abort a compute clone
type CloneAbortRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
}
// CloneAbort aborts a compute clone
func (c Compute) CloneAbort(ctx context.Context, req CloneAbortRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/clone_abort"
res, err := c.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

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