Compare commits

..

21 Commits

Author SHA1 Message Date
b666789c7d v1.6.6 2023-10-23 12:40:54 +03:00
b069c31745 v1.6.5 2023-10-11 12:18:27 +03:00
2953ef0a85 v1.6.4 2023-10-03 16:44:32 +03:00
50a4d5ade2 v1.6.3 2023-09-29 12:28:16 +03:00
1575b75fa6 v1.6.2 2023-09-28 19:34:23 +03:00
35fa4af0d6 v1.6.0 2023-09-28 15:37:28 +03:00
d3e6309ef8 v1.6.0-teta 2023-09-27 15:06:18 +03:00
78a4152471 v1.6.0-zeta 2023-09-25 19:11:33 +03:00
3e55195831 1.6.0-epsilon 2023-09-24 14:41:21 +03:00
9f5e76aee4 1.6.0-delta 2023-09-24 12:11:31 +03:00
df8b045e77 v1.5.8 2023-09-18 14:13:55 +03:00
4d9b8fc9d8 v1.5.7 2023-09-04 18:48:22 +03:00
e8270453cc 1.5.6 2023-08-30 13:54:30 +03:00
7de095302b v1.5.5 2023-08-25 13:53:43 +03:00
a3711057ba v1.5.4 2023-08-22 15:28:39 +03:00
1c59ca338a v1.5.3 2023-08-15 11:42:30 +03:00
f1529c9aac v1.5.2 2023-08-09 19:33:50 +03:00
040235f92f v1.5.1 2023-07-24 18:13:52 +03:00
4a152cb44c v1.5.0 2023-07-24 16:43:10 +03:00
c78b1348e3 v1.5.0 2023-07-24 15:13:04 +03:00
8f152a2f63 v1.5.0 2023-07-21 15:14:10 +03:00
211 changed files with 5765 additions and 1655 deletions

4
.gitignore vendored
View File

@@ -1,3 +1,5 @@
cmd/
.idea/
.vscode/
.vscode/
.fleet/
.DS_Store

View File

@@ -1,143 +1,10 @@
## Version 1.5.0
## Version 1.6.6
### Feature
## Bugfix
- Fixed model RecordExtNet in cloudbroker/extnet/models for correct work of get request
- Fixed json tags in ItemResourceConsumption model and delete extra model Consumed in cloudbroker/account/models
- Fixed statelessSepId field type from uint64 to int64 in cloudbroker/compute/models for correct work of list request
- Updated lists responses models in:
- - cloudapi/account/list
- - cloudbroker/account/list
- - cloudapi/bservice/list
- - cloudapi/compute/list
- - cloudbroker/compute/list
- - cloudapi/computeci/list
- - cloudapi/disks/list
- - cloudbroker/disks/list
- - cloudapi/extnet/list
- - cloudbroker/extnet/list
- - cloudapi/flipgroup/list
- - cloudapi/image/list
- - cloudbroker/image/list
- - cloudapi/k8ci/list
- - cloudbroker/k8ci/list
- - cloudapi/k8s/list
- - cloudapi/k8s/listDeleted
- - cloudbroker/k8s/list
- - cloudbroker/k8s/listDeleted
- - cloudapi/tasks/list
- - cloudbroker/tasks/list
- - cloudapi/rg/list
- - cloudbroker/rg/list
- - cloudapi/vins/list
- - cloudbroker/vins/list
- - cloudapi/account/listDeleted
- - cloudapi/account/listCompute
- - cloudapi/account/listDisks
- - cloudapi/account/listFlipGroups
- - cloudapi/account/listRG
- - cloudapi/account/listVINS
- - cloudapi/compute/listDeleted
- - cloudapi/disks/listDeleted
- - cloudapi/disks/listTypes
- - cloudapi/k8ci/listDeleted
- - cloudapi/lb/list
- - cloudapi/lb/listDeleted
- - cloudbroker/lb/list
- - cloudbroker/lb/listDeleted
- - cloudapi/rg/listComputes
- - cloudapi/rg/listDeleted
- - cloudapi/rg/listLb
- - cloudapi/rg/listPFW
- - cloudapi/rg/listVins
- - cloudapi/vins/listDeleted
- - cloudbroker/account/listComputes
- - cloudbroker/account/listDeleted
- - cloudbroker/account/listDisks
- - cloudbroker/account/listFlipGroups
- - cloudbroker/account/listRG
- - cloudbroker/account/listVINS
- - cloudbroker/compute/listDeleted
- - cloudapi/compute/listPciDevice
- - cloudbroker/compute/listPciDevice
- - cloudapi/compute/listVGpu
- - cloudbroker/compute/listVGpu
- - cloudbroker/disks/listTypes
- - cloudbroker/grid/list
- - cloudbroker/grid/listEmails
- - cloudbroker/k8ci/listDeleted
- - cloudbroker/pcidevice/list
- - cloudbroker/rg/affinityGroupsList
- - cloudbroker/rg/listDeleted
- - cloudbroker/rg/listComputes
- - cloudbroker/rg/listLB
- - cloudbroker/rg/listPfw
- - cloudbroker/rg/listResourceConsumption
- - cloudbroker/rg/listVins
- - cloudbroker/sep/list
- - cloudbroker/vgpu/list
- - cloudbroker/vins/extnetList
- - cloudbroker/vins/IpList
- - cloudbroker/vins/natRuleList
- Added new endpoints:
- - cloudapi/rg/getResourceConsumption
- - cloudapi/rg/listResourceConsumption
- - cloudbroker/rg/getResourceConsumption
- - cloudbroker/rg/listResourceConsumption
- - cloudapi/account/getResourceConsumption
- - cloudapi/account/listResourceConsumption
- - cloudbroker/account/getResourceConsumption
- - cloudbroker/account/listResourceConsumption
- - cloudbroker/grid/getResourceConsumption
- - cloudbroker/grid/listResourceConsumption
- Added field CU_DM to ResourceLimits model (account, rg)
- Added field ReferenceID to SnapshotExtended model in cloudapi/compute/get
- Added field Interfaces in requests:
- - cloudapi/kvmppc/create
- - cloudapi/kvmppc/createBlank
- - cloudapi/kvmx86/create
- - cloudapi/kvmx86/createBlank
- - cloudbroker/kvmppc/create
- - cloudbroker/kvmppc/createBlank
- - cloudbroker/kvmx86/create
- - cloudbroker/kvmx86/createBlank
- Added UpdatedBy field to task model in cloudbroker/task/get
- Made optional fields in requests:
- - Reason (cloudbroker/account/delete)
- - Reason (cloudbroker/account/restore)
- - Gateway (cloudbroker/extnet/create)
- - Reason (cloudbroker/image/delete)
- - Num (cloudapi/k8s/workerAdd)
- - NetID (cloudbroker/vins/extnetConnect)
- Updated cloudapi/rg/get model
- Deleted field Username from cloudbroker/account/update request
- Deleted field EmailAddress from cloudbroker/account/update request
- Added field DiskType to cloudbroker/compute/diskAttach request
- Added field Reason to cloudbroker/compute/diskQos request
- Added field Enabled to cloudbroker/compute/netAttach response model
- Added field CPUAllocationRatio to cloudbroker/image/listStacks response model
- Added field Descr to cloudbroker/image/listStacks response model
- Added field MemAllocationRatio to cloudbroker/image/listStacks response model
- Updated cloudapi/k8s/workersGroupByName response model
- Deleted field LBImageID from cloudbroker/k8ci/create request
- Deleted field ImageID from cloudbroker/lb/create request
- Deleted field Reason from cloudbroker/vins/extnetList request
### Bugfix
- Changed the Excluded field type in cloudbroker/extnet/get response model
## Feature
- Added GetRaw and ListRaw methods that give response as an array of bytes for cloudAPI groups: account, compute, k8s, disks, rg, bservice, disks,extnet, flipgroup, image, k8ci, lb, locations(list), sizes(list), stack, tasks, vins
- Added GetRaw and ListRaw methods that give response as an array of bytes for cloudbroker groups: account, apiaccess, compute, disks, extnet, flipgroup, grid, group, image, k8ci, k8s, lb, rg, sep, stack, tasks, user, vgpu, vins

106
README.md
View File

@@ -10,6 +10,7 @@ Decort SDK - это библиотека, написанная на языке G
- Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы
- Версия 1.4.x Decort-SDK соответствует 3.8.6 версии платформы
- Версия 1.5.x Decort-SDK соответствует 3.8.7 версии платформы
- Версия 1.6.x Decort-SDK соответствует 3.8.8 версии платформы
## Оглавление
@@ -62,12 +63,11 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
- `BService` - управление группами виртуальных машин (computes);
- `Compute` - управление виртуальными машинами (индивидуально);
- `ComputeCI` - управление конвейром для создания виртуальных машин;
- `Disks` - управление виртуальными дисками;
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
- `FLIPgroup` - управление группами "плавающими" ip - адресами;
- `Image` - управление образами операционных систем;
- `K8CI` - управление конвейром для создания кластера;
- `K8CI` - получение информации о конвейере для создания кластера;
- `K8S` - управление кластерами kubernetes;
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
- `KVMx86` - создание виртуальной машины x86;
@@ -75,6 +75,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
- `Locations` - получение информации о grid площадки;
- `RG` - управление ресурсными группами аккаунта;
- `Sizes` - получение информации о потребляемых ресурсах виртуальными машинами и дисками;
- `Stack` - получение информации о вычислительных узлах;
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
- `VINS` - управление виртуальными изолированными сетями.
@@ -84,30 +85,39 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
Данная группа ручек позволяет выполнять следующие операции в платформе:
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
- `APIAccess` - управление доступом к API и его объектам;
- `Backup` - управление резервным копированием;
- `Compute` - управление виртуальными машинами (индивидуально);
- `Disks` - управление виртуальными дисками;
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
- `FLIPGroup` - управление группами с «плавающими» ip адресами;
- `Grid` - управление площадками;
- `Group` - управление группами пользователей;
- `Image` - управление образами операционных систем;
- `K8CI` - управление конвейром для создания кластера;
- `K8S` - управление кластерами kubernetes;
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
- `KVMx86` - создание виртуальной машины x86;
- `LB` - управление балансировщиками нагрузки;
- `PCIDevice` - управление устройствами;
- `RG` - управление ресурсными группами аккаунта;
- `SEP` - управление storage endpoint (sep);
- `Stack` - получение информации о вычислительных узлах;
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
- `User` - управление пользователями (индивидуально);
- `VGPU` - управление виртуальными графическими процессорами;
- `VINS` - управление виртуальными изолированными сетями.
## Работа с библиотекой
Алгоритм работы с библиотекой выглядит следующим образом:
1. Настройка конфигурации клиента.
2. Парсинг конфигурации из файла.
3. Создание клиента.
4. Создание структуры запроса.
5. Выполнение запроса.
1. Выполнение одного из действий:
- настройка конфигурации клиента;
- парсинг конфигурации из файла.
2. Создание клиента.
3. Создание структуры запроса.
4. Выполнение запроса.
### Настройка конфигурации клиента
@@ -120,7 +130,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
| Token | string | Нет | JWT токен |
#### Пример конфигурации клиента
@@ -231,7 +241,6 @@ func main() {
- `pkg/cloudapi/account` - для `Account`
- `pkg/cloudapi/bservice` - для `Basic Service`
- `pkg/cloudapi/compute` - для `Compute`
- `pkg/cloudapi/computeci` - для `ComputeCI`
- `pkg/cloudapi/disks` - для `Disks`
- `pkg/cloudapi/extnet` - для `ExtNet`
- `pkg/cloudapi/flipgroup` - для `FLIPGroup`
@@ -243,24 +252,33 @@ func main() {
- `pkg/cloudapi/lb` - для `LB`
- `pkg/cloudapi/locations` - для `Locations`
- `pkg/cloudapi/rg` - для `RG`
- `pkg/cloudapi/sizes` - для `RG`
- `pkg/cloudapi/sizes` - для `Sizes`
- `pkg/cloudapi/stack` - для `Stack`
- `pkg/cloudapi/tasks` - для `Tasks`
- `pkg/cloudapi/vins` - для `VINS`
- **cloudbroker**:
- `pkg/cloudbroker/account` - для `Account`
- `pkg/cloudbroker/apiaccess` - для `APIAccess`
- `pkg/cloudbroker/backup` - для `Backup`
- `pkg/cloudbroker/compute` - для `Compute`
- `pkg/cloudbroker/disks` - для `Disks`
- `pkg/cloudbroker/extnet` - для `ExtNet`
- `pkg/cloudbroker/flipgroup` - для `FLIPGroup`
- `pkg/cloudbroker/grid` - для `Grid`
- `pkg/cloudbroker/group` - для `Group`
- `pkg/cloudbroker/image` - для `Image`
- `pkg/cloudbroker/k8ci` - для `K8CI`
- `pkg/cloudbroker/k8s` - для `K8S`
- `pkg/cloudbroker/kvmppc` - для `KVMPPC`
- `pkg/cloudbroker/kvmx86` - для `KVMX86`
- `pkg/cloudbroker/lb` - для `LB`
- `pkg/cloudbroker/pcidevice` - для `PCIDevice`
- `pkg/cloudbroker/rg` - для `RG`
- `pkg/cloudbroker/sep` - для `SEP`
- `pkg/cloudbroker/stack` - для `Stack`
- `pkg/cloudbroker/tasks` - для `Tasks`
- `pkg/cloudbroker/user` - для `User`
- `pkg/cloudbroker/vgpu` - для `VGPU`
- `pkg/cloudbroker/vins` - для `VINS`
Все поля структуры имеют описание, в которых содержится:
@@ -397,7 +415,7 @@ func main() {
Чтобы выполнить запрос, необходимо:
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно соверать запросы.
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно совершать запросы.
2. Вызвать у возвращенной структуры метод, определяющий группу ручек для взаимодействия.
Доступные методы для `.CloudAPI()`:
@@ -405,7 +423,6 @@ func main() {
- `.Account()` - для работы с `Account`
- `.BService()` - для работы с `BService`
- `.Compute()` - для работы с `Compute`
- `.ComputeCI()` - для работы с `ComputeCI`
- `.Disks()` - для работы с `Disks`
- `.ExtNet()` - для работы с `ExtNet`
- `.FLIPgroup()` - для работы с `FLIPGroup`
@@ -418,37 +435,46 @@ func main() {
- `.Locations()` - для работы с `Locations`
- `.RG()` - для работы с `RG`
- `.Sizes()` - для работы с `Sizes`
- `.Stack()` - для работы с `Stack`
- `.Tasks()` - для работы с `Tasks`
- `.VINS()` - для работы с `VINS`
Доступные методы для `.CloudBroker()`:
- `.Account()` - для работы с `Account`
- `.APIAccess()` - для работы с `APIAccess`
- `.Backup()` - для работы с `Backup`
- `.Compute()` - для работы с `Compute`
- `.Disks()` - для работы с `Disks`
- `.ExtNet()` - для работы с `ExtNet`
- `.FLIPGroup()` - для работы с `FLIPGroup`
- `.Grid()` - для работы с `Grid`
- `.Group()` - для работы с `Group`
- `.Image()` - для работы с `Image`
- `.K8CI()` - для работы с `K8CI`
- `.K8S()` - для работы с `K8S`
- `.KVMPPC()` - для работы с `KVMPPC`
- `.KVMx86()` - для работы с `KVMX86`
- `.LB()` - для работы с `LB`
- `.PCIDevice()` - для работы с `PCIDevice`
- `.RG()` - для работы с `RG`
- `.SEP()` - для работы с `SEP`
- `.Stack()` - для работы с `Stack`
- `.Tasks()` - для работы с `Tasks`
- `.User()` - для работы с `User`
- `.VGPU()` - для работы с `VGPU`
- `.VINS()` - для работы с `VINS`
3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
- контекст;
- структуру запроса.
У кождой группы ручек API имеются свои доступные методы, которые определяются платформой.
У каждой группы ручек API имеются свои доступные методы, которые определяются платформой.
4. Обработать результат и ошибки.
Т.к. все вызовы методов идут последовательно, можно их объеденить в конвейер:
Общий вид вонвейра будет выглядеть так:
Общий вид конвейера будет выглядеть так:
```go
client.<API>.<группа>.<метод>
@@ -501,6 +527,56 @@ func main() {
}
```
Для запросов Get и List реализованы запросы GetRaw и ListRaw, которые возвращают ответ не в виде соответствующей структуры, а в виде массива байт (JSON).
Выполнение таких запросов происходит аналогично.
#### Пример выполнения GetRaw и ListRaw запросов
```go
package main
import (
"log"
"fmt"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
)
func main() {
// Настройка конфигурации
cfg := config.Config{
AppID: "<APPID>",
AppSecret: "<APPSECRET>",
SSOURL: "https://sso.digitalenergy.online",
DecortURL: "https://mr4.digitalenergy.online",
Retries: 5,
}
// Создание клиента
client := decort.New(cfg)
// 1. Создание структуры запроса GetRequest на создание аккаунта и выполнение GetRaw запроса с помощью конвейера
req1 := account.GetRequest{
AccountID: 123,
}
res1, err := client.CloudAPI().Account().GetRaw(context.Background(), req1)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(res1))
// 2. Создание структуры запроса ListRequest на получение аккаунтов и выполнение ListRaw запроса с помощью конвейера
req2 := account.ListRequest{}
res2, err := client.CloudAPI().Account().ListRaw(context.Background(), req2)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(res2))
}
```
### Фильтрация
Для каждого `ListRequest` в SDK есть группа функций для фильтрации ответа платформы. Для того чтобы произвести фильтрацию по заданным полям, достаточно описать анонимную функцию (предикат) в `.FilterFunc()`, например:
@@ -705,7 +781,7 @@ func main() {
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
| Token | string | Нет | JWT токен |
#### Пример конфигурации legacy клиента

407
client.go
View File

@@ -1,24 +1,34 @@
package decortsdk
import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"mime/multipart"
"net/http"
"strconv"
"strings"
"sync"
"time"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
k8s_ca "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
k8s_cb"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
"github.com/google/go-querystring/query"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/client"
)
// HTTP-client for platform
type DecortClient struct {
decortURL string
client *http.Client
decortURL string
client *http.Client
cfg config.Config
expiryTime time.Time
mutex *sync.Mutex
}
// Сlient builder
@@ -27,9 +37,25 @@ 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: client.NewHttpClient(cfg),
client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
//nolint:gosec
InsecureSkipVerify: cfg.SSLSkipVerify,
},
},
},
cfg: cfg,
expiryTime: expiryTime,
mutex: &sync.Mutex{},
}
}
@@ -45,6 +71,283 @@ func (dc *DecortClient) CloudBroker() *cloudbroker.CloudBroker {
// DecortApiCall method for sending requests to the platform
func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
k8sCaCreateReq, okCa := params.(k8s_ca.CreateRequest)
k8sCbCreateReq, okCb := params.(k8s_cb.CreateRequest)
if okCa {
reqBody := &bytes.Buffer{}
writer := multipart.NewWriter(reqBody)
if k8sCaCreateReq.OidcCertificate != "" {
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
_, _ = io.Copy(part, strings.NewReader(k8sCaCreateReq.OidcCertificate))
}
_ = writer.WriteField("name", k8sCaCreateReq.Name)
_ = writer.WriteField("rgId", strconv.FormatUint(k8sCaCreateReq.RGID, 10))
_ = writer.WriteField("k8ciId", strconv.FormatUint(k8sCaCreateReq.K8SCIID, 10))
_ = writer.WriteField("workerGroupName", k8sCaCreateReq.WorkerGroupName)
_ = writer.WriteField("networkPlugin", k8sCaCreateReq.NetworkPlugin)
if k8sCaCreateReq.MasterSEPID != 0 {
_ = writer.WriteField("masterSepId", strconv.FormatUint(k8sCaCreateReq.MasterSEPID, 10))
}
if k8sCaCreateReq.MasterSEPPool != "" {
_ = writer.WriteField("masterSepPool", k8sCaCreateReq.MasterSEPPool)
}
if k8sCaCreateReq.WorkerSEPID != 0 {
_ = writer.WriteField("workerSepId", strconv.FormatUint(k8sCaCreateReq.WorkerSEPID, 10))
}
if k8sCaCreateReq.WorkerSEPPool != "" {
_ = writer.WriteField("workerSepPool", k8sCaCreateReq.WorkerSEPPool)
}
if k8sCaCreateReq.Labels != nil {
for _, v := range k8sCaCreateReq.Labels {
_ = writer.WriteField("labels", v)
}
}
if k8sCaCreateReq.Taints != nil {
for _, v := range k8sCaCreateReq.Taints {
_ = writer.WriteField("taints", v)
}
}
if k8sCaCreateReq.Annotations != nil {
for _, v := range k8sCaCreateReq.Annotations {
_ = writer.WriteField("annotations", v)
}
}
if k8sCaCreateReq.MasterCPU != 0 {
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(k8sCaCreateReq.MasterCPU), 10))
}
if k8sCaCreateReq.MasterNum != 0 {
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(k8sCaCreateReq.MasterNum), 10))
}
if k8sCaCreateReq.MasterRAM != 0 {
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(k8sCaCreateReq.MasterRAM), 10))
}
if k8sCaCreateReq.MasterDisk != 0 {
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(k8sCaCreateReq.MasterDisk), 10))
}
if k8sCaCreateReq.WorkerCPU != 0 {
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerCPU), 10))
}
if k8sCaCreateReq.WorkerNum != 0 {
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerNum), 10))
}
if k8sCaCreateReq.WorkerRAM != 0 {
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerRAM), 10))
}
if k8sCaCreateReq.WorkerDisk != 0 {
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerDisk), 10))
}
if k8sCaCreateReq.ExtNetID != 0 {
_ = writer.WriteField("extnetId", strconv.FormatUint(k8sCaCreateReq.ExtNetID, 10))
}
if k8sCaCreateReq.VinsId != 0 {
_ = writer.WriteField("vinsId", strconv.FormatUint(k8sCaCreateReq.VinsId, 10))
}
if !k8sCaCreateReq.WithLB {
_ = writer.WriteField("withLB", strconv.FormatBool(k8sCaCreateReq.WithLB))
}
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(k8sCaCreateReq.HighlyAvailable))
if k8sCaCreateReq.AdditionalSANs != nil {
for _, v := range k8sCaCreateReq.AdditionalSANs {
_ = writer.WriteField("additionalSANs", v)
}
}
if k8sCaCreateReq.InitConfiguration != "" {
_ = writer.WriteField("initConfiguration", k8sCaCreateReq.InitConfiguration)
}
if k8sCaCreateReq.ClusterConfiguration != "" {
_ = writer.WriteField("clusterConfiguration", k8sCaCreateReq.ClusterConfiguration)
}
if k8sCaCreateReq.KubeletConfiguration != "" {
_ = writer.WriteField("kubeletConfiguration", k8sCaCreateReq.KubeletConfiguration)
}
if k8sCaCreateReq.KubeProxyConfiguration != "" {
_ = writer.WriteField("kubeProxyConfiguration", k8sCaCreateReq.KubeProxyConfiguration)
}
if k8sCaCreateReq.JoinConfiguration != "" {
_ = writer.WriteField("joinConfiguration", k8sCaCreateReq.JoinConfiguration)
}
if k8sCaCreateReq.Description != "" {
_ = writer.WriteField("desc", k8sCaCreateReq.Description)
}
if k8sCaCreateReq.UserData != "" {
_ = writer.WriteField("userData", k8sCaCreateReq.UserData)
}
_ = writer.WriteField("extnetOnly", strconv.FormatBool(k8sCaCreateReq.ExtNetOnly))
_ = writer.FormDataContentType()
ct := writer.FormDataContentType()
writer.Close()
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, reqBody)
if err != nil {
return nil, err
}
if err = dc.getToken(ctx); err != nil {
return nil, err
}
resp, err := dc.domp(req, ct)
if err != nil {
return nil, err
}
defer resp.Body.Close()
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, errors.New(string(respBytes))
}
return respBytes, nil
} else if okCb {
reqBody := &bytes.Buffer{}
writer := multipart.NewWriter(reqBody)
if k8sCbCreateReq.OidcCertificate != "" {
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
_, _ = io.Copy(part, strings.NewReader(k8sCbCreateReq.OidcCertificate))
}
_ = writer.WriteField("name", k8sCbCreateReq.Name)
_ = writer.WriteField("rgId", strconv.FormatUint(k8sCbCreateReq.RGID, 10))
_ = writer.WriteField("k8ciId", strconv.FormatUint(k8sCbCreateReq.K8CIID, 10))
_ = writer.WriteField("workerGroupName", k8sCbCreateReq.WorkerGroupName)
_ = writer.WriteField("networkPlugin", k8sCbCreateReq.NetworkPlugin)
if k8sCbCreateReq.MasterSEPID != 0 {
_ = writer.WriteField("masterSepId", strconv.FormatUint(k8sCbCreateReq.MasterSEPID, 10))
}
if k8sCbCreateReq.MasterSEPPool != "" {
_ = writer.WriteField("masterSepPool", k8sCbCreateReq.MasterSEPPool)
}
if k8sCbCreateReq.WorkerSEPID != 0 {
_ = writer.WriteField("workerSepId", strconv.FormatUint(k8sCbCreateReq.WorkerSEPID, 10))
}
if k8sCbCreateReq.WorkerSEPPool != "" {
_ = writer.WriteField("workerSepPool", k8sCbCreateReq.WorkerSEPPool)
}
if k8sCbCreateReq.Labels != nil {
for _, v := range k8sCbCreateReq.Labels {
_ = writer.WriteField("labels", v)
}
}
if k8sCbCreateReq.Taints != nil {
for _, v := range k8sCbCreateReq.Taints {
_ = writer.WriteField("taints", v)
}
}
if k8sCbCreateReq.Annotations != nil {
for _, v := range k8sCbCreateReq.Annotations {
_ = writer.WriteField("annotations", v)
}
}
if k8sCbCreateReq.MasterCPU != 0 {
_ = writer.WriteField("masterCpu", strconv.FormatUint(k8sCbCreateReq.MasterCPU, 10))
}
if k8sCbCreateReq.MasterNum != 0 {
_ = writer.WriteField("masterNum", strconv.FormatUint(k8sCbCreateReq.MasterNum, 10))
}
if k8sCbCreateReq.MasterRAM != 0 {
_ = writer.WriteField("masterRam", strconv.FormatUint(k8sCbCreateReq.MasterRAM, 10))
}
if k8sCbCreateReq.MasterDisk != 0 {
_ = writer.WriteField("masterDisk", strconv.FormatUint(k8sCbCreateReq.MasterDisk, 10))
}
if k8sCbCreateReq.WorkerCPU != 0 {
_ = writer.WriteField("workerCpu", strconv.FormatUint(k8sCbCreateReq.WorkerCPU, 10))
}
if k8sCbCreateReq.WorkerNum != 0 {
_ = writer.WriteField("workerNum", strconv.FormatUint(k8sCbCreateReq.WorkerNum, 10))
}
if k8sCbCreateReq.WorkerRAM != 0 {
_ = writer.WriteField("workerRam", strconv.FormatUint(k8sCbCreateReq.WorkerRAM, 10))
}
if k8sCbCreateReq.WorkerDisk != 0 {
_ = writer.WriteField("workerDisk", strconv.FormatUint(k8sCbCreateReq.WorkerDisk, 10))
}
if k8sCbCreateReq.ExtNetID != 0 {
_ = writer.WriteField("extnetId", strconv.FormatUint(k8sCbCreateReq.ExtNetID, 10))
}
if k8sCbCreateReq.VinsId != 0 {
_ = writer.WriteField("vinsId", strconv.FormatUint(k8sCbCreateReq.VinsId, 10))
}
if !k8sCbCreateReq.WithLB {
_ = writer.WriteField("withLB", strconv.FormatBool(k8sCbCreateReq.WithLB))
}
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(k8sCbCreateReq.HighlyAvailable))
if k8sCbCreateReq.AdditionalSANs != nil {
for _, v := range k8sCbCreateReq.AdditionalSANs {
_ = writer.WriteField("additionalSANs", v)
}
}
if k8sCbCreateReq.InitConfiguration != "" {
_ = writer.WriteField("initConfiguration", k8sCbCreateReq.InitConfiguration)
}
if k8sCbCreateReq.ClusterConfiguration != "" {
_ = writer.WriteField("clusterConfiguration", k8sCbCreateReq.ClusterConfiguration)
}
if k8sCbCreateReq.KubeletConfiguration != "" {
_ = writer.WriteField("kubeletConfiguration", k8sCbCreateReq.KubeletConfiguration)
}
if k8sCbCreateReq.KubeProxyConfiguration != "" {
_ = writer.WriteField("kubeProxyConfiguration", k8sCbCreateReq.KubeProxyConfiguration)
}
if k8sCbCreateReq.JoinConfiguration != "" {
_ = writer.WriteField("joinConfiguration", k8sCbCreateReq.JoinConfiguration)
}
if k8sCbCreateReq.Description != "" {
_ = writer.WriteField("desc", k8sCbCreateReq.Description)
}
if k8sCbCreateReq.UserData != "" {
_ = writer.WriteField("userData", k8sCbCreateReq.UserData)
}
_ = writer.WriteField("extnetOnly", strconv.FormatBool(k8sCbCreateReq.ExtNetOnly))
_ = writer.FormDataContentType()
ct := writer.FormDataContentType()
writer.Close()
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, reqBody)
if err != nil {
return nil, err
}
if err = dc.getToken(ctx); err != nil {
return nil, err
}
resp, err := dc.domp(req, ct)
if err != nil {
return nil, err
}
defer resp.Body.Close()
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, errors.New(string(respBytes))
}
return respBytes, nil
}
values, err := query.Values(params)
if err != nil {
return nil, err
@@ -56,7 +359,11 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
return nil, err
}
resp, err := dc.client.Do(req)
if err = dc.getToken(ctx); err != nil {
return nil, err
}
resp, err := dc.do(req)
if err != nil {
return nil, err
}
@@ -73,3 +380,91 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
return respBytes, nil
}
func (dc *DecortClient) getToken(ctx context.Context) error {
dc.mutex.Lock()
defer dc.mutex.Unlock()
if dc.cfg.Token == "" || time.Now().After(dc.expiryTime) {
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", dc.cfg.AppID, dc.cfg.AppSecret)
bodyReader := strings.NewReader(body)
dc.cfg.SSOURL = strings.TrimSuffix(dc.cfg.SSOURL, "/")
req, _ := http.NewRequestWithContext(ctx, "POST", dc.cfg.SSOURL+"/v1/oauth/access_token", bodyReader)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, err := dc.client.Do(req)
if err != nil {
return fmt.Errorf("cannot get token: %w", err)
}
tokenBytes, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("cannot get token: %s", tokenBytes)
}
token := string(tokenBytes)
dc.cfg.Token = token
dc.expiryTime = time.Now().AddDate(0, 0, 1)
}
return nil
}
func (dc *DecortClient) do(req *http.Request) (*http.Response, error) {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
req.Header.Set("Accept", "application/json")
// var resp *http.Response
// var err error
buf, _ := io.ReadAll(req.Body)
// req = req.Clone(req.Context())
// for i := uint64(0); i < dc.cfg.Retries; i++ {
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := dc.client.Do(req)
// if err == nil {
if resp.StatusCode == 200 {
return resp, err
}
respBytes, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("%s", respBytes)
resp.Body.Close()
// }
// }
return nil, fmt.Errorf("could not execute request: %w", err)
}
func (dc *DecortClient) domp(req *http.Request, ctype string) (*http.Response, error) {
req.Header.Add("Content-Type", ctype)
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
req.Header.Set("Accept", "application/json")
// var resp *http.Response
// var err error
buf, _ := io.ReadAll(req.Body)
// req = req.Clone(req.Context())
// for i := uint64(0); i < dc.cfg.Retries; i++ {
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := dc.client.Do(req)
// if err == nil {
if resp.StatusCode == 200 {
return resp, err
}
respBytes, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("%s", respBytes)
resp.Body.Close()
// }
// }
return nil, fmt.Errorf("could not execute request: %w", err)
}

View File

@@ -42,7 +42,7 @@ type Config struct {
// Required: false
Retries uint64 `json:"retries" yaml:"retries"`
// Skip verify, true by default
// Skip verify
// Required: false
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`

View File

@@ -36,7 +36,7 @@ type LegacyConfig struct {
// Required: false
Retries uint64 `json:"retries" yaml:"retries"`
// Skip verify, true by default
// Skip verify
// Required: false
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`

View File

@@ -23,7 +23,7 @@ func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
*d = Duration(tmp)
return nil
default:
return fmt.Errorf("Invalid duration %v", value)
return fmt.Errorf("invalid duration %v", value)
}
}
@@ -41,7 +41,7 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
*d = Duration(tmp)
return nil
default:
return fmt.Errorf("Invalid duration %v", value)
return fmt.Errorf("invalid duration %v", value)
}
}

View File

@@ -1,40 +0,0 @@
package client
import (
"crypto/tls"
"net/http"
"time"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
)
func NewHttpClient(cfg config.Config) *http.Client {
transCfg := &http.Transport{
TLSClientConfig: &tls.Config{
//nolint:gosec
InsecureSkipVerify: cfg.SSLSkipVerify,
},
}
var expiredTime time.Time
if cfg.Token != "" {
expiredTime = time.Now().AddDate(0, 0, 1)
}
return &http.Client{
Transport: &transport{
base: transCfg,
retries: cfg.Retries,
clientID: cfg.AppID,
clientSecret: cfg.AppSecret,
ssoURL: cfg.SSOURL,
token: cfg.Token,
expiryTime: expiredTime,
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Timeout: cfg.Timeout.Get(),
}
}

View File

@@ -1,32 +0,0 @@
package client
import (
"crypto/tls"
"net/http"
"net/url"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
)
// NewLegacyHttpClient creates legacy HTTP Client
func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
transCfg := &http.Transport{
TLSClientConfig: &tls.Config{
//nolint:gosec
InsecureSkipVerify: cfg.SSLSkipVerify,
},
}
return &http.Client{
Transport: &transportLegacy{
base: transCfg,
username: url.QueryEscape(cfg.Username),
password: url.QueryEscape(cfg.Password),
retries: cfg.Retries,
token: cfg.Token,
decortURL: cfg.DecortURL,
},
Timeout: cfg.Timeout.Get(),
}
}

View File

@@ -1,70 +0,0 @@
package client
import (
"fmt"
"io"
"net/http"
"strings"
"time"
)
type transportLegacy struct {
base http.RoundTripper
username string
password string
retries uint64
token string
decortURL string
}
func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, error) {
if t.token == "" {
body := fmt.Sprintf("username=%s&password=%s", t.username, t.password)
bodyReader := strings.NewReader(body)
req, _ := http.NewRequestWithContext(request.Context(), "POST", t.decortURL+"/restmachine/cloudapi/user/authenticate", bodyReader)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, err := t.base.RoundTrip(req)
if err != nil {
return nil, fmt.Errorf("unable to get token: %w", err)
}
tokenBytes, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("unable to get token: %s", tokenBytes)
}
token := string(tokenBytes)
t.token = token
}
tokenValue := fmt.Sprintf("&authkey=%s", t.token)
tokenReader := strings.NewReader(tokenValue)
newBody := io.MultiReader(request.Body, tokenReader)
req, _ := http.NewRequestWithContext(request.Context(), request.Method, request.URL.String(), newBody)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "application/json")
var resp *http.Response
var err error
for i := uint64(0); i < t.retries; i++ {
resp, err = t.base.RoundTrip(req)
if err == nil {
if resp.StatusCode == 200 {
return resp, nil
}
respBytes, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("%s", respBytes)
resp.Body.Close()
}
time.Sleep(time.Second * 5)
}
return nil, fmt.Errorf("could not execute request: %w", err)
}

View File

@@ -1,69 +0,0 @@
package client
import (
"fmt"
"io"
"net/http"
"strings"
"time"
)
type transport struct {
base http.RoundTripper
retries uint64
clientID string
clientSecret string
token string
ssoURL string
expiryTime time.Time
}
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
if t.token == "" || time.Now().After(t.expiryTime) {
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientID, t.clientSecret)
bodyReader := strings.NewReader(body)
t.ssoURL = strings.TrimSuffix(t.ssoURL, "/")
req, _ := http.NewRequestWithContext(req.Context(), "POST", t.ssoURL+"/v1/oauth/access_token", bodyReader)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, err := t.base.RoundTrip(req)
if err != nil {
return nil, fmt.Errorf("cannot get token: %w", err)
}
tokenBytes, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("cannot get token: %s", tokenBytes)
}
token := string(tokenBytes)
t.token = token
t.expiryTime = time.Now().AddDate(0, 0, 1)
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "bearer "+t.token)
req.Header.Set("Accept", "application/json")
var resp *http.Response
var err error
for i := uint64(0); i < t.retries; i++ {
resp, err = t.base.RoundTrip(req)
if err == nil {
if resp.StatusCode == 200 {
return resp, nil
}
respBytes, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("%s", respBytes)
resp.Body.Close()
}
//logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries)
time.Sleep(time.Second * 5)
}
return nil, fmt.Errorf("could not execute request: %w", err)
}

View File

@@ -1,11 +1,19 @@
package validators
import (
"github.com/go-playground/validator/v10"
"regexp"
"strings"
"github.com/go-playground/validator/v10"
)
// computeDriverValidator is used to validate Driver field in kvmx86/kvmppc create.
func computeDriverValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeDriverValues)
}
// protoValidator is used to validate Proto fields.
func protoValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
@@ -256,3 +264,11 @@ func strictLooseValidator(fe validator.FieldLevel) bool {
return StringInSlice(fieldValue, strictLooseValues)
}
// name workerGroup must be more 3 symbol
func workerGroupNameValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
fieldValue = strings.Trim(fieldValue, " ")
return len(fieldValue) >= 3
}

View File

@@ -107,6 +107,12 @@ 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",
@@ -121,6 +127,12 @@ func errorMessage(fe validator.FieldError) string {
fe.Field(),
joinValues(flipgroupClientTypeValues))
// k8s Validators
case "workerGroupName":
return fmt.Sprintf("%s %s must be more 3 symbol",
prefix,
fe.Field())
// KVM_X86/KVM_PPC Validators
case "kvmNetType":
return fmt.Sprintf("%s %s must be one of the following: %s",

View File

@@ -30,6 +30,11 @@ func registerAllValidators(validate *validator.Validate) error {
return err
}
err = validate.RegisterValidation("computeDriver", computeDriverValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("accessType", accessTypeValidator)
if err != nil {
return err
@@ -175,5 +180,10 @@ func registerAllValidators(validate *validator.Validate) error {
return err
}
err = validate.RegisterValidation("workerGroupName", workerGroupNameValidator)
if err != nil {
return err
}
return nil
}

View File

@@ -17,6 +17,7 @@ var (
computeNetTypeValues = []string{"EXTNET", "VINS"}
computeOrderValues = []string{"cdrom", "network", "hd"}
computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"}
computeDriverValues = []string{"KVM_X86", "SVA_KVM_X86"}
diskTypeValues = []string{"B", "T", "D"}

View File

@@ -1,23 +1,34 @@
package decortsdk
import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"time"
"github.com/google/go-querystring/query"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/client"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
)
// Legacy HTTP-client for platform
type LegacyDecortClient struct {
decortURL string
client *http.Client
decortURL string
client *http.Client
cfg config.LegacyConfig
expiryTime time.Time
mutex *sync.Mutex
}
// Legacy client builder
@@ -26,9 +37,25 @@ func NewLegacy(cfg config.LegacyConfig) *LegacyDecortClient {
cfg.Retries = 5
}
var expiryTime time.Time
if cfg.Token != "" {
expiryTime = time.Now().AddDate(0, 0, 1)
}
return &LegacyDecortClient{
decortURL: cfg.DecortURL,
client: client.NewLegacyHttpClient(cfg),
client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
//nolint:gosec
InsecureSkipVerify: cfg.SSLSkipVerify,
},
},
},
cfg: cfg,
expiryTime: expiryTime,
mutex: &sync.Mutex{},
}
}
@@ -44,18 +71,165 @@ func (ldc *LegacyDecortClient) CloudBroker() *cloudbroker.CloudBroker {
// DecortApiCall method for sending requests to the platform
func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
if k8sCreateReq, ok := params.(k8s.CreateRequest); ok {
reqBody := &bytes.Buffer{}
writer := multipart.NewWriter(reqBody)
if k8sCreateReq.OidcCertificate != "" {
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
_, _ = io.Copy(part, strings.NewReader(k8sCreateReq.OidcCertificate))
}
_ = writer.WriteField("name", k8sCreateReq.Name)
_ = writer.WriteField("rgId", strconv.FormatUint(k8sCreateReq.RGID, 10))
_ = writer.WriteField("k8ciId", strconv.FormatUint(k8sCreateReq.K8SCIID, 10))
_ = writer.WriteField("workerGroupName", k8sCreateReq.WorkerGroupName)
_ = writer.WriteField("networkPlugin", k8sCreateReq.NetworkPlugin)
if k8sCreateReq.MasterSEPID != 0 {
_ = writer.WriteField("masterSepId", strconv.FormatUint(k8sCreateReq.MasterSEPID, 10))
}
if k8sCreateReq.MasterSEPPool != "" {
_ = writer.WriteField("masterSepPool", k8sCreateReq.MasterSEPPool)
}
if k8sCreateReq.WorkerSEPID != 0 {
_ = writer.WriteField("workerSepId", strconv.FormatUint(k8sCreateReq.WorkerSEPID, 10))
}
if k8sCreateReq.WorkerSEPPool != "" {
_ = writer.WriteField("workerSepPool", k8sCreateReq.WorkerSEPPool)
}
if k8sCreateReq.Labels != nil {
for _, v := range k8sCreateReq.Labels {
_ = writer.WriteField("labels", v)
}
}
if k8sCreateReq.Taints != nil {
for _, v := range k8sCreateReq.Taints {
_ = writer.WriteField("taints", v)
}
}
if k8sCreateReq.Annotations != nil {
for _, v := range k8sCreateReq.Annotations {
_ = writer.WriteField("annotations", v)
}
}
if k8sCreateReq.MasterCPU != 0 {
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(k8sCreateReq.MasterCPU), 10))
}
if k8sCreateReq.MasterNum != 0 {
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(k8sCreateReq.MasterNum), 10))
}
if k8sCreateReq.MasterRAM != 0 {
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(k8sCreateReq.MasterRAM), 10))
}
if k8sCreateReq.MasterDisk != 0 {
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(k8sCreateReq.MasterDisk), 10))
}
if k8sCreateReq.WorkerCPU != 0 {
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(k8sCreateReq.WorkerCPU), 10))
}
if k8sCreateReq.WorkerNum != 0 {
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(k8sCreateReq.WorkerNum), 10))
}
if k8sCreateReq.WorkerRAM != 0 {
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(k8sCreateReq.WorkerRAM), 10))
}
if k8sCreateReq.WorkerDisk != 0 {
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(k8sCreateReq.WorkerDisk), 10))
}
if k8sCreateReq.ExtNetID != 0 {
_ = writer.WriteField("extnetId", strconv.FormatUint(k8sCreateReq.ExtNetID, 10))
}
if k8sCreateReq.VinsId != 0 {
_ = writer.WriteField("vinsId", strconv.FormatUint(k8sCreateReq.VinsId, 10))
}
if !k8sCreateReq.WithLB {
_ = writer.WriteField("withLB", strconv.FormatBool(k8sCreateReq.WithLB))
}
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(k8sCreateReq.HighlyAvailable))
if k8sCreateReq.AdditionalSANs != nil {
for _, v := range k8sCreateReq.AdditionalSANs {
_ = writer.WriteField("additionalSANs", v)
}
}
if k8sCreateReq.InitConfiguration != "" {
_ = writer.WriteField("initConfiguration", k8sCreateReq.InitConfiguration)
}
if k8sCreateReq.ClusterConfiguration != "" {
_ = writer.WriteField("clusterConfiguration", k8sCreateReq.ClusterConfiguration)
}
if k8sCreateReq.KubeletConfiguration != "" {
_ = writer.WriteField("kubeletConfiguration", k8sCreateReq.KubeletConfiguration)
}
if k8sCreateReq.KubeProxyConfiguration != "" {
_ = writer.WriteField("kubeProxyConfiguration", k8sCreateReq.KubeProxyConfiguration)
}
if k8sCreateReq.JoinConfiguration != "" {
_ = writer.WriteField("joinConfiguration", k8sCreateReq.JoinConfiguration)
}
if k8sCreateReq.Description != "" {
_ = writer.WriteField("desc", k8sCreateReq.Description)
}
if k8sCreateReq.UserData != "" {
_ = writer.WriteField("userData", k8sCreateReq.UserData)
}
_ = writer.WriteField("extnetOnly", strconv.FormatBool(k8sCreateReq.ExtNetOnly))
_ = writer.FormDataContentType()
ct := writer.FormDataContentType()
if err := ldc.getToken(ctx); err != nil {
return nil, err
}
_ = writer.WriteField("authkey", ldc.cfg.Token)
writer.Close()
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, reqBody)
if err != nil {
return nil, err
}
resp, err := ldc.domp(req, ct)
if err != nil {
return nil, err
}
defer resp.Body.Close()
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, errors.New(string(respBytes))
}
return respBytes, nil
}
values, err := query.Values(params)
if err != nil {
return nil, err
}
body := strings.NewReader(values.Encode())
if err = ldc.getToken(ctx); err != nil {
return nil, err
}
body := strings.NewReader(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token))
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body)
if err != nil {
return nil, err
}
resp, err := ldc.client.Do(req)
resp, err := ldc.do(req)
if err != nil {
return nil, err
}
@@ -72,3 +246,88 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st
return respBytes, nil
}
func (ldc *LegacyDecortClient) getToken(ctx context.Context) error {
ldc.mutex.Lock()
defer ldc.mutex.Unlock()
if ldc.cfg.Token == "" || time.Now().After(ldc.expiryTime) {
body := fmt.Sprintf("username=%s&password=%s", url.QueryEscape(ldc.cfg.Username), url.QueryEscape(ldc.cfg.Password))
bodyReader := strings.NewReader(body)
req, _ := http.NewRequestWithContext(ctx, "POST", ldc.cfg.DecortURL+"/restmachine/cloudapi/user/authenticate", bodyReader)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, err := ldc.client.Do(req)
if err != nil {
return fmt.Errorf("unable to get token: %w", err)
}
tokenBytes, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("unable to get token: %s", tokenBytes)
}
token := string(tokenBytes)
ldc.cfg.Token = token
ldc.expiryTime = time.Now().AddDate(0, 0, 1)
}
return nil
}
func (ldc *LegacyDecortClient) do(req *http.Request) (*http.Response, error) {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "application/json")
// var resp *http.Response
// var err error
buf, _ := io.ReadAll(req.Body)
// req = req.Clone(req.Context())
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := ldc.client.Do(req)
// if err == nil {
if resp.StatusCode == 200 {
return resp, err
}
respBytes, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("%s", respBytes)
resp.Body.Close()
// }
// }
return nil, fmt.Errorf("could not execute request: %w", err)
}
func (ldc *LegacyDecortClient) domp(req *http.Request, ctype string) (*http.Response, error) {
req.Header.Add("Content-Type", ctype)
req.Header.Add("Authorization", "bearer "+ldc.cfg.Token)
req.Header.Set("Accept", "application/json")
// var resp *http.Response
// var err error
buf, _ := io.ReadAll(req.Body)
// req = req.Clone(req.Context())
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := ldc.client.Do(req)
// if err == nil {
if resp.StatusCode == 200 {
return resp, err
}
respBytes, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("%s", respBytes)
resp.Body.Close()
// }
// }
return nil, fmt.Errorf("could not execute request: %w", err)
}

View File

@@ -8,25 +8,16 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get information about account
// GetRequest struct to get information about account
type GetRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Get gets account details
// Get gets account details as a RecordAccount struct
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/get"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := a.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -41,3 +32,18 @@ func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error
return &info, nil
}
// GetRaw gets account details as an array of bytes
func (a Account) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/get"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -16,7 +16,7 @@ type GetResourceConsumptionRequest struct {
}
// GetResourceConsumption show amount of consumed and reserved resources (cpu, ram, disk) by specific account
func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*ItemResourceConsumption, error) {
func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResourceConsumption, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -26,7 +26,7 @@ func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceCons
url := "/cloudapi/account/getResourceConsumption"
info := ItemResourceConsumption{}
info := RecordResourceConsumption{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list of accounts
// ListRequest struct to get list of accounts
type ListRequest struct {
// Find by ID
// Required: false
@@ -33,11 +33,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list all accounts the user has access to
// List gets a list of all accounts the user has access to a ListAccounts struct
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
url := "/cloudapi/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := a.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -51,3 +49,11 @@ func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, erro
return &list, nil
}
// ListRaw gets a list of all accounts the user has access to as an array of bytes
func (a Account) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -12,15 +12,35 @@ import (
type ListTemplatesRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Include deleted images
// Required: false
IncludeDeleted bool `url:"includedeleted" json:"includedeleted"`
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
// Find by image id
// Required: false
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by type
// Required: false
Type string `url:"type,omitempty" json:"type,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"`
}
// ListTemplates gets list templates which can be managed by this account
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (ListTemplates, error) {
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (*ListTemplates, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -42,5 +62,5 @@ func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (L
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -33,7 +33,7 @@ type ResourceLimits struct {
CUD float64 `json:"CU_D"`
// Max disk size, GB
CU_DM float64 `json:"CU_DM"`
CUDM float64 `json:"CU_DM"`
// Number of public IP addresses
CUI float64 `json:"CU_I"`
@@ -88,7 +88,7 @@ type Resource struct {
DiskSize float64 `json:"disksize"`
// Max disk size
DiskSizeMax uint64 `json:"disksizemax"`
DiskSizeMax float64 `json:"disksizemax"`
// Number of External IPs
ExtIPs int64 `json:"extips"`
@@ -115,13 +115,21 @@ type DiskUsage struct {
DiskSizeMax float64 `json:"disksizemax"`
}
// Information about resource consumption
type RecordResourceConsumption struct {
ItemResourceConsumption
// Resource limits
ResourceLimits ResourceLimits `json:"resourceLimits"`
}
// Information about resources
type ItemResourceConsumption struct {
// Current information about resources
Current Resource `json:"Current"`
Consumed Resource `json:"consumed"`
// Reserved information about resources
Reserved Resource `json:"Reserved"`
Reserved Resource `json:"reserved"`
// Account ID
AccountID uint64 `json:"id"`
@@ -557,7 +565,13 @@ type ItemTemplate struct {
}
// List of templates
type ListTemplates []ItemTemplate
type ListTemplates struct {
// Data
Data []ItemTemplate `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about FLIPGroup
type ItemFLIPGroup struct {

View File

@@ -8,15 +8,32 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get detailed information about service
// GetRequest struct to get detailed information about service
type GetRequest struct {
// ID of the service to query information
// Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
}
// Get gets detailed specifications for the BasicService.
// Get gets detailed specifications for the BasicService as a RecordBasicService struct
func (b BService) Get(ctx context.Context, req GetRequest) (*RecordBasicService, error) {
res, err := b.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordBasicService{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets detailed specifications for the BasicService as an array of bytes
func (b BService) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -26,17 +43,6 @@ func (b BService) Get(ctx context.Context, req GetRequest) (*RecordBasicService,
url := "/cloudapi/bservice/get"
bsRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := RecordBasicService{}
err = json.Unmarshal(bsRaw, &info)
if err != nil {
return nil, err
}
return &info, nil
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -68,6 +68,10 @@ type GroupAddRequest struct {
// Time of Compute Group readiness
// Required: false
TimeoutStart uint64 `url:"timeoutStart,omitempty" json:"timeoutStart,omitempty"`
// Meta data for working group computes, format YAML "user_data": 1111
// Required: false
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
}
// GroupAdd creates new Compute Group within BasicService.

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list BasicService instances
// ListRequest struct to get list of BasicService instances
type ListRequest struct {
// Find by ID
// Required: false
@@ -49,11 +49,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list BasicService instances associated with the specified Resource Group
// List gets list of BasicService instances associated with the specified Resource Group as a ListBasicServices struct
func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices, error) {
url := "/cloudapi/bservice/list"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := b.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -67,3 +65,11 @@ func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices
return &list, nil
}
// ListRaw gets list of BasicService instances associated with the specified Resource Group as an array of bytes
func (b BService) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/bservice/list"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,40 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for deleting compute's custome fields
type DeleteCustomFieldsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// DeleteCustomFields deletes computes custom fields
func (c Compute) DeleteCustomFields(ctx context.Context, req DeleteCustomFieldsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/deleteCustomFields"
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

@@ -22,11 +22,6 @@ type DiskAddRequest struct {
// Required: true
Size uint64 `url:"size" json:"size" validate:"required"`
// Storage endpoint provider ID
// By default the same with boot disk
// Required: false
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Type of the disk
// Should be one of:
// - D
@@ -34,6 +29,11 @@ type DiskAddRequest struct {
// Required: false
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
// Storage endpoint provider ID
// By default the same with boot disk
// Required: false
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Pool name
// By default will be chosen automatically
// Required: false

View File

@@ -20,7 +20,7 @@ type DiskDelRequest struct {
// False if disk is to be deleted to recycle bin
// Required: true
Permanently bool `url:"permanently" json:"permanently" validate:"required"`
Permanently bool `url:"permanently" json:"permanently"`
}
// DiskDel delete disk and detach from compute

View File

@@ -8,25 +8,16 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request for get information about compute
// GetRequest struct to get information about compute
type GetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Get Gets information about compute
// Get gets information about compute as a RecordCompute struct
func (c Compute) Get(ctx context.Context, req GetRequest) (*RecordCompute, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/get"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := c.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -40,3 +31,18 @@ func (c Compute) Get(ctx context.Context, req GetRequest) (*RecordCompute, error
return &info, nil
}
// GetRaw gets information about compute as an array of bytes
func (c Compute) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/get"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,42 @@
package compute
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for getting Compute's customFields
type GetCustomFieldsRequest struct {
// Compute ID
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// GetCustomFields gets Compute's customFields
func (c Compute) GetCustomFields(ctx context.Context, req GetCustomFieldsRequest) (interface{}, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/getCustomFields"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
var info interface{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list available computes
// ListRequest struct to get list of available computes
type ListRequest struct {
// Find by ID
// Required: false
@@ -64,9 +64,7 @@ type ListRequest struct {
// List gets list of the available computes.
// Filtering based on status is possible
func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, error) {
url := "/cloudapi/compute/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := c.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -80,3 +78,11 @@ func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, erro
return &list, nil
}
// ListRaw gets list of the available computes.
func (c Compute) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/compute/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -22,9 +22,9 @@ type ListPCIDeviceRequest struct {
// Required: false
DevID uint64 `url:"devId,omitempty" json:"devId,omitempty"`
// Find by type
// Find by name
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by status
// Required: false

View File

@@ -14,6 +14,14 @@ type RecordACL struct {
RGACL ListACL `json:"rgAcl"`
}
type ListUsers struct {
// Data
Data RecordACL `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
type Explicit bool
func (e *Explicit) UnmarshalJSON(b []byte) error {
@@ -89,7 +97,13 @@ type ItemSnapshot struct {
}
// List of snapshots
type ListSnapShots []ItemSnapshot
type ListSnapShots struct {
// Data
Data []ItemSnapshot `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about port forward
type ItemPFW struct {
@@ -116,7 +130,13 @@ type ItemPFW struct {
}
// List port forwards
type ListPFWs []ItemPFW
type ListPFWs struct {
// Data
Data []ItemPFW `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about affinity relations
type RecordAffinityRelations struct {
@@ -403,7 +423,7 @@ type RecordCompute struct {
SnapSets ListSnapSets `json:"snapSets"`
// Stateless SepID
StatelessSepID uint64 `json:"statelessSepId"`
StatelessSepID int64 `json:"statelessSepId"`
// Stateless SepType
StatelessSepType string `json:"statelessSepType"`
@@ -862,7 +882,7 @@ type ItemCompute struct {
SnapSets ListSnapSets `json:"snapSets"`
// Stateless SepID
StatelessSepID uint64 `json:"statelessSepId"`
StatelessSepID int64 `json:"statelessSepId"`
// Stateless SepType
StatelessSepType string `json:"statelessSepType"`

View File

@@ -16,7 +16,7 @@ type PFWListRequest struct {
}
// PFWList gets compute port forwards list
func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (ListPFWs, error) {
func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (*ListPFWs, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -38,5 +38,5 @@ func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (ListPFWs, err
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -0,0 +1,43 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for setting customFields values for the Compute
type SetCustomFieldsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Custom fields for Compute. Must be dict.
// Required: true
CustomFields string `url:"customFields" json:"customFields" validate:"required"`
}
// SetCustomFields sets customFields values for the Compute
func (c Compute) SetCustomFields(ctx context.Context, req SetCustomFieldsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/setCustomFields"
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

@@ -16,7 +16,7 @@ type SnapshotListRequest struct {
}
// SnapshotList gets list compute snapshots
func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapShots, error) {
func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (*ListSnapShots, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -38,5 +38,5 @@ func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (Lis
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -16,7 +16,7 @@ type UserListRequest struct {
}
// UserList gets users list for compute
func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL, error) {
func (c Compute) UserList(ctx context.Context, req UserListRequest) (*ListUsers, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -31,7 +31,7 @@ func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL,
return nil, err
}
list := RecordACL{}
list := ListUsers{}
err = json.Unmarshal(res, &list)
if err != nil {

View File

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

View File

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

View File

@@ -1,53 +0,0 @@
package computeci
// FilterByID returns ListComputeCI with specified ID.
func (lci ListComputeCI) FilterByID(id uint64) ListComputeCI {
predicate := func(ic ItemComputeCI) bool {
return ic.ID == id
}
return lci.FilterFunc(predicate)
}
// FilterByName returns ListComputeCI with specified Name.
func (lci ListComputeCI) FilterByName(name string) ListComputeCI {
predicate := func(ic ItemComputeCI) bool {
return ic.Name == name
}
return lci.FilterFunc(predicate)
}
// FilterByStatus returns ListComputeCI with specified Status.
func (lci ListComputeCI) FilterByStatus(status string) ListComputeCI {
predicate := func(ic ItemComputeCI) bool {
return ic.Status == status
}
return lci.FilterFunc(predicate)
}
// FilterFunc allows filtering ListComputeCI based on a user-specified predicate.
func (lci ListComputeCI) FilterFunc(predicate func(ItemComputeCI) bool) ListComputeCI {
var result ListComputeCI
for _, item := range lci.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemComputeCI
// If none was found, returns an empty struct.
func (lci ListComputeCI) FindOne() ItemComputeCI {
if lci.EntryCount == 0 {
return ItemComputeCI{}
}
return lci.Data[0]
}

View File

@@ -1,98 +0,0 @@
package computeci
import "testing"
var computeciItems = ListComputeCI{
Data: []ItemComputeCI{
{
CustomFields: map[string]interface{}{},
Description: "",
Drivers: []string{
"KVM_X86",
},
GUID: 1,
ID: 1,
Name: "computeci_1",
Status: "ENABLED",
Template: "",
},
{
CustomFields: map[string]interface{}{},
Description: "",
Drivers: []string{
"KVM_X86",
},
GUID: 2,
ID: 2,
Name: "computeci_2",
Status: "ENABLED",
Template: "",
},
{
CustomFields: map[string]interface{}{},
Description: "",
Drivers: []string{
"SVA_KVM_X86",
},
GUID: 3,
ID: 3,
Name: "computeci_3",
Status: "DISABLED",
Template: "",
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
actual := computeciItems.FilterByID(2).FindOne()
if actual.ID != 2 {
t.Fatal("expected ID 2, found: ", actual.ID)
}
}
func TestFilterByName(t *testing.T) {
actual := computeciItems.FilterByName("computeci_3").FindOne()
if actual.Name != "computeci_3" {
t.Fatal("expected Name 'computeci_2', found: ", actual.Name)
}
}
func TestFilterByStatus(t *testing.T) {
actual := computeciItems.FilterByStatus("ENABLED")
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.Status != "ENABLED" {
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
}
}
}
func TestFilterFunc(t *testing.T) {
actual := computeciItems.FilterFunc(func(icc ItemComputeCI) bool {
for _, item := range icc.Drivers {
if item == "KVM_X86" {
return true
}
}
return false
})
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
for _, driver := range item.Drivers {
if driver != "KVM_X86" {
t.Fatal("expected 'KVM_X86' Driver, found: ", driver)
}
}
}
}

View File

@@ -1,42 +0,0 @@
package computeci
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for information about computeci
type GetRequest struct {
// ID of the Compute CI
// Required: true
ComputeCIID uint64 `url:"computeciId" json:"computeciId" validate:"required"`
}
// Get gets information about computeci by ID
func (c ComputeCI) Get(ctx context.Context, req GetRequest) (*ItemComputeCI, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validatonError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validatonError)
}
}
url := "/cloudapi/computeci/get"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := ItemComputeCI{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -1,53 +0,0 @@
package computeci
import (
"context"
"encoding/json"
"net/http"
)
// Request struct for get list of computeci
type ListRequest struct {
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by computeci ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by drivers
// Find by computeci ID
Drivers []string `url:"drivers,omitempty" json:"drivers,omitempty"`
// If true list deleted instances as well
// Required: false
IncludeDeleted bool `url:"includeDeleted,omitempty" json:"includeDeleted,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 computeci instances
func (c ComputeCI) List(ctx context.Context, req ListRequest) (*ListComputeCI, error) {
url := "/cloudapi/computeci/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListComputeCI{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -1,35 +0,0 @@
package computeci
// Main information about computeci
type ItemComputeCI struct {
// Custom fields
CustomFields map[string]interface{} `json:"customFields"`
// Description
Description string `json:"desc"`
// List drivers
Drivers []string `json:"drivers"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Template
Template string `json:"template"`
}
// List of computeci instances
type ListComputeCI struct {
Data []ItemComputeCI `json:"data"`
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -8,26 +8,17 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get information about disk
// GetRequest struct to get information about disk
type GetRequest struct {
// ID of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// Get gets disk details
// Get gets disk details as a RecordDisk struct
// Notice: the devicename field is the name as it is passed to the kernel (kname in linux) for unattached disks this field has no relevant value
func (d Disks) Get(ctx context.Context, req GetRequest) (*RecordDisk, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/disks/get"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := d.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -41,3 +32,19 @@ func (d Disks) Get(ctx context.Context, req GetRequest) (*RecordDisk, error) {
return &info, nil
}
// GetRaw gets disk details as an array of bytes
// Notice: the devicename field is the name as it is passed to the kernel (kname in linux) for unattached disks this field has no relevant value
func (d Disks) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/disks/get"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list of disks
// ListRequest struct to get list of disks
type ListRequest struct {
// Find by id
// Required: false
@@ -40,6 +40,14 @@ type ListRequest struct {
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -49,11 +57,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list the created disks belonging to an account
// List gets list of the created disks belonging to an account as a ListDisks struct
func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) {
url := "/cloudapi/disks/list"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := d.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -67,3 +73,11 @@ func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) {
return &list, nil
}
// ListRaw gets list of the created disks belonging to an account as an array of bytes
func (d Disks) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/disks/list"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -24,10 +24,6 @@ type ListUnattachedRequest struct {
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by shared, true or false
// Required: false
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
// Type of the disks
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
@@ -36,6 +32,14 @@ type ListUnattachedRequest struct {
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -8,25 +8,16 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get detailed information about external network
// GetRequest struct to get detailed information about external network
type GetRequest struct {
// ID of external network
// Required: true
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
}
// Get gets detailed information about external network
// Get gets detailed information about external network as a RecordExtNet struct
func (e ExtNet) Get(ctx context.Context, req GetRequest) (*RecordExtNet, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/extnet/get"
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := e.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -40,3 +31,18 @@ func (e ExtNet) Get(ctx context.Context, req GetRequest) (*RecordExtNet, error)
return &info, nil
}
// GetRaw gets detailed information about external network as an array of bytes
func (e ExtNet) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/extnet/get"
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list external network
// ListRequest struct to get list of external network
type ListRequest struct {
// Find by account ID
// Required: false
@@ -45,11 +45,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list all available external networks
// List gets list of all available external networks as a ListExtNets struct
func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNets, error) {
url := "/cloudapi/extnet/list"
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := e.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -63,3 +61,11 @@ func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNets, error)
return &list, nil
}
// ListRaw gets list of all available external networks as an array of bytes
func (e ExtNet) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/extnet/list"
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -13,10 +13,26 @@ type ListComputesRequest struct {
// Filter by account ID
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Find by rg ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by compute ID
// Required: false
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,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"`
}
// ListComputes gets computes from account with extnets
func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (ListExtNetComputes, error) {
func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (*ListExtNetComputes, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -38,5 +54,5 @@ func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (List
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -59,7 +59,13 @@ type ItemExtNetCompute struct {
}
// List of information about computes with external network
type ListExtNetComputes []ItemExtNetCompute
type ListExtNetComputes struct {
// Data
Data []ItemExtNetCompute `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// QOS
type QOS struct {
@@ -118,6 +124,12 @@ type Excluded struct {
// ClientType
ClientType string `json:"clientType"`
// Domain name
DomainName string `json:"domainname"`
// Host name
HostName string `json:"hostname"`
// IP
IP string `json:"ip"`

View File

@@ -45,7 +45,7 @@ type CreateRequest struct {
}
// Create method will create a new FLIPGorup in the specified Account
func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGroup, error) {
func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGroupCreated, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -60,7 +60,7 @@ func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGr
return nil, err
}
info := RecordFLIPGroup{}
info := RecordFLIPGroupCreated{}
err = json.Unmarshal(res, &info)
if err != nil {

View File

@@ -8,15 +8,32 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get information about FLIPGroup
// GetRequest struct to get information about FLIPGroup
type GetRequest struct {
// FLIPGroup ID
// Required: true
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
}
// Get gets details of the specified Floating IP group
func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*ItemFLIPGroup, error) {
// Get gets details of the specified Floating IP group as a RecordFLIPGroup struct
func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*RecordFLIPGroup, error) {
res, err := f.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordFLIPGroup{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets details of the specified Floating IP group as an array of bytes
func (f FLIPGroup) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -27,16 +44,5 @@ func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*ItemFLIPGroup, err
url := "/cloudapi/flipgroup/get"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := ItemFLIPGroup{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
return res, err
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list FLIPGroup available to the current user
// ListRequest struct to get list of FLIPGroup available to the current user
type ListRequest struct {
// Find by name
// Required: false
@@ -25,11 +25,11 @@ type ListRequest struct {
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
// Find by IP
// Reuqired: false
// Required: false
ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"`
// Find by resource group ID
// Reuqired: false
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by id
@@ -45,11 +45,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list FLIPGroup managed cluster instances available to the current user
// List gets list of FLIPGroup managed cluster instances available to the current user as a ListFLIPGroups struct
func (f FLIPGroup) List(ctx context.Context, req ListRequest) (*ListFLIPGroups, error) {
url := "/cloudapi/flipgroup/list"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := f.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -63,3 +61,11 @@ func (f FLIPGroup) List(ctx context.Context, req ListRequest) (*ListFLIPGroups,
return &list, nil
}
// ListRaw gets list of FLIPGroup managed cluster instances available to the current user as an array of bytes
func (f FLIPGroup) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/flipgroup/list"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -1,7 +1,7 @@
package flipgroup
// Main information about FLIPGroup
type RecordFLIPGroup struct {
type RecordFLIPGroupCreated struct {
// Default GW
DefaultGW string `json:"defaultGW"`
@@ -18,6 +18,89 @@ type RecordFLIPGroup struct {
NetMask uint64 `json:"netmask"`
}
type RecordFLIPGroup struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// List of client IDs
ClientIDs []uint64 `json:"clientIds"`
// Client names
ClientNames []string `json:"clientNames"`
// Client type
ClientType string `json:"clientType"`
// Connection ID
ConnID uint64 `json:"connId"`
// Connection type
ConnType string `json:"connType"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Default GW
DefaultGW string `json:"defaultGW"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// IP
IP string `json:"ip"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Network ID
NetID uint64 `json:"netId"`
// Network type
NetType string `json:"netType"`
// Network
Network string `json:"network"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RGName string `json:"rgName"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
// Detailed information about FLIPGroup
type ItemFLIPGroup struct {
// CKey

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get detailed information about image
// GetRequest struct to get detailed information about image
type GetRequest struct {
// ID of image to get
// Required: true
@@ -20,18 +20,9 @@ type GetRequest struct {
}
// Get gets image by ID.
// Returns image if user has rights on it
// Returns image as a RecordImage struct if user has rights on it
func (i Image) Get(ctx context.Context, req GetRequest) (*RecordImage, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/image/get"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := i.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -45,3 +36,19 @@ func (i Image) Get(ctx context.Context, req GetRequest) (*RecordImage, error) {
return &info, nil
}
// GetRaw gets image by ID.
// Returns image as an array of bytes if user has rights on it
func (i Image) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/image/get"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list available images
// ListRequest struct to get list of available images
type ListRequest struct {
// Find by storage endpoint provider ID
// Required: false
@@ -65,11 +65,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list available images, optionally filtering by account ID
// List gets list of available images as a ListImages struct, optionally filtering by account ID
func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
url := "/cloudapi/image/list"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := i.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -83,3 +81,11 @@ func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
return &list, nil
}
// ListRaw gets list of available images as an array of bytes
func (i Image) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/image/list"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -8,25 +8,16 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get information about K8CI
// GetRequest struct to get information about K8CI
type GetRequest struct {
// ID of the K8 catalog item to get
// Required: true
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
}
// Get gets details of the specified K8 catalog item
// Get gets details of the specified K8 catalog item as a RecordK8CI struct
func (k K8CI) Get(ctx context.Context, req GetRequest) (*RecordK8CI, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/k8ci/get"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := k.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -39,3 +30,18 @@ func (k K8CI) Get(ctx context.Context, req GetRequest) (*RecordK8CI, error) {
return &info, nil
}
// GetRaw gets details of the specified K8 catalog item as an array of bytes
func (k K8CI) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/k8ci/get"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list information about images
// ListRequest struct to get list of information about images
type ListRequest struct {
// Find by ID
// Required: false
@@ -45,11 +45,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list all k8ci catalog items available to the current user
// List gets list of all k8ci catalog items available to the current user as a ListK8CI struct
func (k K8CI) List(ctx context.Context, req ListRequest) (*ListK8CI, error) {
url := "/cloudapi/k8ci/list"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := k.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -63,3 +61,11 @@ func (k K8CI) List(ctx context.Context, req ListRequest) (*ListK8CI, error) {
return &list, nil
}
// ListRaw gets list of all k8ci catalog items available to the current user as an array of bytes
func (k K8CI) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/k8ci/list"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -8,6 +8,8 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// type Params []string
// Request struct for create kubernetes cluster
type CreateRequest struct {
// Name of Kubernetes cluster
@@ -24,7 +26,7 @@ type CreateRequest struct {
// Name for first worker group created with cluster
// Required: true
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"`
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required,workerGroupName"`
// Network plugin
// Must be one of these values: flannel, weawenet, calico
@@ -98,18 +100,80 @@ type CreateRequest struct {
// Required: false
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
// ID of the ViNS to connect k8s cluster. If nothing is specified, ViNS will be created automatically
// Required: false
VinsId uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
// Create Kubernetes cluster with masters nodes behind load balancer if true.
// Otherwise give all cluster nodes direct external addresses from selected ExtNet
// Required: false
WithLB bool `url:"withLB" json:"withLB"`
// Custom sysctl values for Load Balancer instance. Applied on boot
// Required: false
LbSysctlParams string `url:"lbSysctlParams,omitempty" json:"lbSysctlParams,omitempty"`
// Use Highly Available schema for LB deploy
// Required: false
HighlyAvailable bool `url:"highlyAvailableLB,omitempty" json:"highlyAvailableLB,omitempty"`
// Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names
// Required: false
AdditionalSANs []string `url:"additionalSANs,omitempty" json:"additionalSANs,omitempty"`
// Is used to define settings and actions that should be performed before any other component in the cluster starts.
// It allows you to configure things like node registration, network setup, and other initialization tasks. insert a valid JSON string with all levels of nesting
// Required: false
InitConfiguration string `url:"initConfiguration,omitempty" json:"initConfiguration,omitempty"`
// Is used to define global settings and configurations for the entire cluster.
// It includes parameters such as cluster name, DNS settings, authentication methods, and other cluster-wide configurations.
// Insert a valid JSON string with all levels of nesting
// Required: false
ClusterConfiguration string `url:"clusterConfiguration,omitempty" json:"clusterConfiguration,omitempty"`
// Is used to configure the behavior and settings of the Kubelet, which is the primary node agent that runs on each node in the cluster.
// It includes parameters such as node IP address, resource allocation, pod eviction policies, and other Kubelet-specific configurations.
// Insert a valid JSON string with all levels of nesting
// Required: false
KubeletConfiguration string `url:"kubeletConfiguration,omitempty" json:"kubeletConfiguration,omitempty"`
// Is used to configure the behavior and settings of the Kube-proxy, which is responsible for network proxying and load balancing within the cluster.
// It includes parameters such as proxy mode, cluster IP ranges, and other Kube-proxy specific configurations.
// Insert a valid JSON string with all levels of nesting
// Required: false
KubeProxyConfiguration string `url:"kubeProxyConfiguration,omitempty" json:"kubeProxyConfiguration,omitempty"`
// Is used to configure the behavior and settings for joining a node to a cluster.
// It includes parameters such as the cluster's control plane endpoint, token, and certificate key. insert a valid JSON string with all levels of nesting
// Required: false
JoinConfiguration string `url:"joinConfiguration,omitempty" json:"joinConfiguration,omitempty"`
// Text description of this Kubernetes cluster
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
// Meta data for working group computes, format YAML "user_data": 1111
// Required: false
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
// Use only selected ExtNet for infrastructure connections
// Required: false
ExtNetOnly bool `url:"extnetOnly,omitempty" json:"extnetOnly,omitempty"`
// Insert ssl certificate in x509 pem format
// Required: false
OidcCertificate string `url:"oidcCertificate,omitempty" json:"oidcCertificate,omitempty"`
}
// type wrapperCreateRequest struct {
// CreateRequest
// Params []string `url:"lbSysctlParams,omitempty"`
// }
// Create creates a new Kubernetes cluster in the specified Resource Group
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -117,6 +181,28 @@ func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
}
}
// var params []string
// if len(req.LbSysctlParams) != 0 {
// params = make([]string, 0, len(req.LbSysctlParams))
// for r := range req.LbSysctlParams {
// b, err := json.Marshal(req.LbSysctlParams[r])
// if err != nil {
// return "", err
// }
// params = append(params, string(b))
// }
// } else {
// params = []string{"[]"}
// }
// reqWrapped := wrapperCreateRequest{
// CreateRequest: req,
// Params: params,
// }
url := "/cloudapi/k8s/create"
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -8,25 +8,16 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get detailed information about kubernetes cluster
// GetRequest struct to get detailed information about kubernetes cluster
type GetRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
}
// Get gets information about Kubernetes cluster
// Get gets information about Kubernetes cluster as a RecordK8S struct
func (k8s K8S) Get(ctx context.Context, req GetRequest) (*RecordK8S, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/k8s/get"
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := k8s.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -40,3 +31,18 @@ func (k8s K8S) Get(ctx context.Context, req GetRequest) (*RecordK8S, error) {
return &info, nil
}
// GetRaw gets information about Kubernetes cluster as an array of bytes
func (k8s K8S) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/k8s/get"
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,38 @@
package k8s
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get worker group metadata by ID
type GetWorkerNodesMetaDataRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// ID of the workers compute group
// Required: true
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
}
// Get worker group metadata by ID
func (k K8S) GetWorkerNodesMetaData(ctx context.Context, req GetWorkerNodesMetaDataRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/k8s/getWorkerNodesMetaData"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list information K8S
// ListRequest struct to get list information K8S
type ListRequest struct {
// Find by ID
// Required: false
@@ -53,11 +53,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list all kubernetes clusters the user has access to
// List gets list of all kubernetes clusters the user has access to as a ListK8SClusters
func (k8s K8S) List(ctx context.Context, req ListRequest) (*ListK8SClusters, error) {
url := "/cloudapi/k8s/list"
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := k8s.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -71,3 +69,11 @@ func (k8s K8S) List(ctx context.Context, req ListRequest) (*ListK8SClusters, err
return &list, nil
}
// ListRaw gets list of all kubernetes clusters the user has access to as an array of bytes
func (k8s K8S) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/k8s/list"
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -32,10 +32,6 @@ type ListDeletedRequest struct {
// Required: false
BasicServiceID uint64 `url:"basicServiceId,omitempty" json:"basicServiceId,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by techStatus
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`

View File

@@ -41,6 +41,9 @@ type ListK8SGroups []ItemK8SGroup
// Detailed information
type ItemDetailedInfo struct {
// Externalip
Externalip string `json:"externalip"`
// ID
ID uint64 `json:"id"`

View File

@@ -0,0 +1,48 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for add worker to a kubernetes cluster
type UpdateWorkerNodesMetaDataRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// ID of the workers compute group
// Required: true
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
// Meta data for working group computes, format YAML "user_data": 1111
// Required: true
UserData string `url:"userData" json:"userData" validate:"required"`
}
// WorkerAdd adds worker nodes to a kubernetes cluster
func (k K8S) UpdateWorkerNodesMetaData(ctx context.Context, req UpdateWorkerNodesMetaDataRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/k8s/updateWorkerNodesMetaData"
res, err := k.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

@@ -56,6 +56,10 @@ type WorkersGroupAddRequest struct {
// Worker node boot disk size in GB If 0 is specified, size is defined by the OS image size
// Required: false
WorkerDisk uint64 `url:"workerDisk,omitempty" json:"workerDisk,omitempty"`
// Meta data for working group computes, format YAML "user_data": 1111
// Required: false
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
}
// WorkersGroupAdd adds workers group to Kubernetes cluster

View File

@@ -64,8 +64,10 @@ type CreateRequest struct {
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Slice of structs with net interface description.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"`
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Input data for cloud-init facility
// Required: false
@@ -77,7 +79,7 @@ type CreateRequest struct {
// Start VM upon success
// Required: false
Start bool `url:"start,omitempty" json:"start,omitempty"`
Start bool `url:"start" json:"start"`
// System name
// Required: false
@@ -102,15 +104,21 @@ func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
}
}
interfaces := make([]string, 0, len(req.Interfaces))
var interfaces []string
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
interfaces = append(interfaces, string(b))
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateRequest{

View File

@@ -41,9 +41,11 @@ type CreateBlankRequest struct {
// Required: true
Pool string `url:"pool" json:"pool" validate:"required"`
// Slice of structs with net interface description
// Slice of structs with net interface description.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"`
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Text description of this VM
// Required: false
@@ -64,15 +66,21 @@ func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
}
}
interfaces := make([]string, 0, len(req.Interfaces))
var interfaces []string
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
interfaces = append(interfaces, string(b))
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateBlankRequest{

View File

@@ -64,8 +64,10 @@ type CreateRequest struct {
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Slice of structs with net interface description.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"`
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Input data for cloud-init facility
// Required: false
@@ -77,7 +79,7 @@ type CreateRequest struct {
// Start VM upon success
// Required: false
Start bool `url:"start,omitempty" json:"start,omitempty"`
Start bool `url:"start" json:"start"`
// System name
// Required: false
@@ -86,6 +88,14 @@ type CreateRequest struct {
// Compute purpose
// Required: false
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
// Custom fields for compute. Must be a dict
// Required: false
CustomFields string `url:"customFields,omitempty" json:"customFields,omitempty"`
// Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
// Required: false
Driver string `url:"driver,omitempty" json:"driver,omitempty" validate:"omitempty,computeDriver"`
}
type wrapperCreateRequest struct {
@@ -102,15 +112,21 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
}
}
interfaces := make([]string, 0, len(req.Interfaces))
var interfaces []string
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
interfaces = append(interfaces, string(b))
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateRequest{

View File

@@ -42,8 +42,14 @@ type CreateBlankRequest struct {
Pool string `url:"pool" json:"pool" validate:"required"`
// Slice of structs with net interface description.
// If not specified, compute will be created with default interface from RG.
// To create compute without interfaces, pass initialized empty slice .
// Required: false
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"`
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
// Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
// Required: false
Driver string `url:"driver,omitempty" json:"driver,omitempty" validate:"omitempty,computeDriver"`
// Text description of this VM
// Required: false
@@ -64,15 +70,21 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
}
}
interfaces := make([]string, 0, len(req.Interfaces))
var interfaces []string
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
if req.Interfaces != nil && len(req.Interfaces) != 0 {
interfaces = make([]string, 0, len(req.Interfaces))
for i := range req.Interfaces {
b, err := json.Marshal(req.Interfaces[i])
if err != nil {
return 0, err
}
interfaces = append(interfaces, string(b))
}
interfaces = append(interfaces, string(b))
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
interfaces = []string{"[]"}
}
reqWrapped := wrapperCreateBlankRequest{

View File

@@ -2,12 +2,16 @@ package lb
import (
"context"
"encoding/json"
"errors"
"net/http"
"strings"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type Params []string
// Request struct for create load balancer
type CreateRequest struct {
// ID of the resource group where this load balancer instance will be located
@@ -20,39 +24,81 @@ type CreateRequest struct {
Name string `url:"name" json:"name" validate:"required"`
// External network to connect this load balancer to
// Required: true
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
// Required: false
ExtNetID uint64 `url:"extnetId" json:"extnetId"`
// Internal network (VINS) to connect this load balancer to
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Required: false
VINSID uint64 `url:"vinsId" json:"vinsId"`
// Custom sysctl values for Load Balancer instance. Applied on boot
// Required: false
SysctlParams Params `url:"-" json:"sysctlParams,omitempty" validate:"omitempty,dive"`
// Use Highly Available schema for LB deploy
// Required: false
HighlyAvailable bool `url:"highlyAvailable,omitempty" json:"highlyAvailable,omitempty"`
// Start now Load balancer
// Required: true
Start bool `url:"start" json:"start" validate:"required"`
// Required: false
Start bool `url:"start" json:"start"`
// Text description of this load balancer
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
}
type wrapperCreateRequest struct {
CreateRequest
Params []string `url:"sysctlParams,omitempty"`
}
// Create method will create a new load balancer instance
func (l LB) Create(ctx context.Context, req CreateRequest) (string, error) {
func (l LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
return 0, validators.ValidationError(validationError)
}
}
if req.ExtNetID == 0 && req.VINSID == 0 {
return 0, errors.New("vinsId and extNetId cannot be both in the value 0")
}
var params []string
if len(req.SysctlParams) != 0 {
params = make([]string, 0, len(req.SysctlParams))
for r := range req.SysctlParams {
b, err := json.Marshal(req.SysctlParams[r])
if err != nil {
return 0, err
}
params = append(params, string(b))
}
} else {
params = []string{}
}
reqWrapped := wrapperCreateRequest{
CreateRequest: req,
Params: params,
}
url := "/cloudapi/lb/create"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
return 0, err
}
result := strings.ReplaceAll(string(res), "\"", "")
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -20,18 +20,18 @@ type FrontendBindRequest struct {
// Name of the binding to update
// Required: true
BindingName string `url:"bindingName" json:"bindingName"`
BindingName string `url:"bindingName" json:"bindingName" validate:"required"`
// If specified must be within the IP range of either Ext Net or ViNS,
// where this load balancer is connected - new IP address to use for this binding.
// If omitted, current IP address is retained
// Required: false
BindingAddress string `url:"bindingAddress,omitempty" json:"bindingAddress,omitempty"`
// Required: true
BindingAddress string `url:"bindingAddress" json:"bindingAddress" validate:"required"`
// New port number to use for this binding.
// If omitted, current port number is retained
// Required: false
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
// Required: true
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
}
// FrontendBind bind frontend from specified load balancer instance

View File

@@ -25,13 +25,13 @@ type FrontendBindUpdateRequest struct {
// If specified must be within the IP range of either Ext Net or ViNS,
// where this load balancer is connected - new IP address to use for this binding.
// If omitted, current IP address is retained
// Required: false
BindingAddress string `url:"bindingAddress,omitempty" json:"bindingAddress,omitempty"`
// Required: true
BindingAddress string `url:"bindingAddress" json:"bindingAddress" validate:"required"`
// New port number to use for this binding.
// If omitted, current port number is retained
// Required: false
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
// Required: true
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
}
// FrontendBindUpdate updates binding for the specified load balancer frontend

View File

@@ -8,25 +8,16 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get detailed information about load balancer
// GetRequest struct to get detailed information about load balancer
type GetRequest struct {
// ID of the load balancer to get details for
// Required: true
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
}
// Get gets detailed information about load balancer
// Get gets detailed information about load balancer as a RecordLB struct
func (l LB) Get(ctx context.Context, req GetRequest) (*RecordLB, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/get"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := l.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -40,3 +31,18 @@ func (l LB) Get(ctx context.Context, req GetRequest) (*RecordLB, error) {
return &info, nil
}
// GetRaw gets detailed information about load balancer as an array of bytes
func (l LB) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/get"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list of load balancers
// ListRequest struct to get list of load balancers
type ListRequest struct {
// Find by ID
// Required: false
@@ -53,11 +53,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list all load balancers
// List gets list of all load balancers as a ListLB struct
func (l LB) List(ctx context.Context, req ListRequest) (*ListLB, error) {
url := "/cloudapi/lb/list"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := l.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -71,3 +69,11 @@ func (l LB) List(ctx context.Context, req ListRequest) (*ListLB, error) {
return &list, nil
}
// ListRaw gets list of all load balancers as an array of bytes
func (l LB) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/lb/list"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,40 @@
package lb
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for make Load Balancer Highly available
type HighlyAvailableRequest struct {
// ID of the LB instance
// Required: true
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
}
// Make Load Balancer Highly available
func (l LB) HighlyAvailable(ctx context.Context, req HighlyAvailableRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/makeHighlyAvailable"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -8,6 +8,9 @@ type RecordLB struct {
// Access Control List
ACL interface{} `json:"acl"`
// BackendHAIP
BackendHAIP string `json:"backendHAIP"`
// List of load balancer backends
Backends ListBackends `json:"backends"`
@@ -32,6 +35,9 @@ type RecordLB struct {
// External network ID
ExtNetID uint64 `json:"extnetId"`
// FrontendHAIP
FrontendHAIP string `json:"frontendHAIP"`
// List of load balancer frontends
Frontends ListFrontends `json:"frontends"`
@@ -53,6 +59,9 @@ type RecordLB struct {
// Name
Name string `json:"name"`
// Part K8s
PartK8s bool `json:"partK8s"`
// Primary node
PrimaryNode RecordNode `json:"primaryNode"`
@@ -68,6 +77,9 @@ type RecordLB struct {
// Status
Status string `json:"status"`
// Sysctl Params
SysctlParams interface{} `json:"sysctlParams"`
// Tech status
TechStatus string `json:"techStatus"`

View File

@@ -0,0 +1,72 @@
package lb
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update sysct params for lb
type UpdateSysctParamsRequest struct {
// ID of the LB instance
// Required: true
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Custom sysctl values for Load Balancer instance. Applied on boot
// Required: true
SysctlParams Params `url:"-" json:"sysctlParams" validate:"required,dive"`
}
type wrapperUpdateSysctParamsRequest struct {
UpdateSysctParamsRequest
Params []string `url:"sysctlParams" validate:"required"`
}
// Create method will create a new load balancer instance
func (l LB) UpdateSysctParams(ctx context.Context, req UpdateSysctParamsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
var params []string
if len(req.SysctlParams) != 0 {
params = make([]string, 0, len(req.SysctlParams))
for r := range req.SysctlParams {
b, err := json.Marshal(req.SysctlParams[r])
if err != nil {
return false, err
}
params = append(params, string(b))
}
} else {
params = []string{}
}
reqWrapped := wrapperUpdateSysctParamsRequest{
UpdateSysctParamsRequest: req,
Params: params,
}
url := "/cloudapi/lb/updateSysctParams"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list of locations
// ListRequest struct to get list of locations
type ListRequest struct {
// Page number
// Required: false
@@ -33,11 +33,9 @@ type ListRequest struct {
LocationCode string `url:"locationCode,omitempty" json:"locationCode,omitempty"`
}
// List gets list all locations
// List gets list of all locations as a ListLocations struct
func (l Locations) List(ctx context.Context, req ListRequest) (*ListLocations, error) {
url := "/cloudapi/locations/list"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := l.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -51,3 +49,11 @@ func (l Locations) List(ctx context.Context, req ListRequest) (*ListLocations, e
return &list, nil
}
// ListRaw gets list of all locations as an array of bytes
func (l Locations) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/locations/list"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -20,7 +20,7 @@ type AffinityGroupComputesRequest struct {
}
// AffinityGroupComputes gets list of all computes with their relationships to another computes
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (ListAffinityGroups, error) {
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (ListAffinityGroupsComputes, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -35,7 +35,7 @@ func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputes
return nil, err
}
list := ListAffinityGroups{}
list := ListAffinityGroupsComputes{}
err = json.Unmarshal(res, &list)
if err != nil {

View File

@@ -13,10 +13,18 @@ type AffinityGroupsListRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (map[string][]uint64, error) {
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (*ListAffinityGroups, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -31,7 +39,7 @@ func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListReques
return nil, err
}
list := map[string][]uint64{}
list := &ListAffinityGroups{}
err = json.Unmarshal(res, &list)
if err != nil {

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get detailed information about resource group
// GetRequest struct to get detailed information about resource group
type GetRequest struct {
// Resource group ID
// Required: true
@@ -19,18 +19,9 @@ type GetRequest struct {
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// Get gets current configuration of the resource group
// Get gets current configuration of the resource group as a RecordResourceGroup struct
func (r RG) Get(ctx context.Context, req GetRequest) (*RecordResourceGroup, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/get"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -44,3 +35,18 @@ func (r RG) Get(ctx context.Context, req GetRequest) (*RecordResourceGroup, erro
return &info, nil
}
// GetRaw gets current configuration of the resource group as an array of bytes
func (r RG) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/get"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list of resource groups
// ListRequest struct to get list of resource groups
type ListRequest struct {
// Find by ID
// Required: false
@@ -53,11 +53,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of all resource groups the user has access to
// List gets list of all resource groups the user has access to as a ListResourceGroups struct
func (r RG) List(ctx context.Context, req ListRequest) (*ListResourceGroups, error) {
url := "/cloudapi/rg/list"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := r.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -71,3 +69,11 @@ func (r RG) List(ctx context.Context, req ListRequest) (*ListResourceGroups, err
return &list, nil
}
// ListRaw gets list of all resource groups the user has access to as an array of bytes
func (r RG) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/rg/list"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -48,10 +48,13 @@ type Resources struct {
// Detailed information about resource consumption
type ItemResourceConsumption struct {
// Consumed information about resources
Consumed Resource `json:"Consumed"`
Consumed Resource `json:"consumed"`
// Reserved information about resources
Reserved Resource `json:"Reserved"`
Reserved Resource `json:"reserved"`
// Resource limits
ResourceLimits ResourceLimits `json:"resourceLimits"`
// Resource group ID
RGID uint64 `json:"rgid"`
@@ -302,7 +305,7 @@ type ResourceLimits struct {
}
// Main information about affinity group
type ItemAffinityGroup struct {
type ItemAffinityGroupComputes struct {
// Compute ID
ComputeID uint64 `json:"computeId"`
@@ -326,7 +329,15 @@ type ItemAffinityGroup struct {
}
// List of affinity groups
type ListAffinityGroups []ItemAffinityGroup
type ListAffinityGroupsComputes []ItemAffinityGroupComputes
type ListAffinityGroups struct {
// Data
Data []map[string][]uint64 `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about audit
type ItemAudit struct {

View File

@@ -37,6 +37,7 @@ func (r RG) Usage(ctx context.Context, req UsageRequest) (*RecordResourceUsage,
info := RecordResourceUsage{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}

View File

@@ -22,21 +22,23 @@ func (ls ListSizes) FilterByName(name string) ListSizes {
func (ls ListSizes) FilterFunc(predicate func(ItemSize) bool) ListSizes {
var result ListSizes
for _, item := range ls {
for _, item := range ls.Data {
if predicate(item) {
result = append(result, item)
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemSize
// If none was found, returns an empty struct.
func (ls ListSizes) FindOne() ItemSize {
if len(ls) == 0 {
if len(ls.Data) == 0 {
return ItemSize{}
}
return ls[0]
return ls.Data[0]
}

View File

@@ -3,30 +3,33 @@ package sizes
import "testing"
var sizeItems = ListSizes{
{
Description: "",
Disks: []uint64{},
ID: 1,
Memory: 512,
Name: "size_1",
VCPUs: 2,
},
{
Description: "",
Disks: []uint64{},
ID: 2,
Memory: 1024,
Name: "size_2",
VCPUs: 4,
},
{
Description: "",
Disks: []uint64{},
ID: 2,
Memory: 2048,
Name: "size_3",
VCPUs: 6,
Data: []ItemSize{
{
Description: "",
Disks: []uint64{},
ID: 1,
Memory: 512,
Name: "size_1",
VCPUs: 2,
},
{
Description: "",
Disks: []uint64{},
ID: 2,
Memory: 1024,
Name: "size_2",
VCPUs: 4,
},
{
Description: "",
Disks: []uint64{},
ID: 2,
Memory: 2048,
Name: "size_3",
VCPUs: 6,
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
@@ -50,11 +53,11 @@ func TestFilterFunc(t *testing.T) {
return is.Memory > 512
})
if len(actual) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual))
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual {
for _, item := range actual.Data {
if item.Memory <= 512 {
t.Fatal("expected Memory greater than 512, found: ", item.Memory)
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for list the available flavors
// ListRequest struct for list of the available flavors
type ListRequest struct {
// ID of the cloudspace
// Required: false
@@ -25,16 +25,14 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list the available flavors, filtering can be based on the user which is doing the request
func (s Sizes) List(ctx context.Context, req ListRequest) (ListSizes, error) {
url := "/cloudapi/sizes/list"
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
// List gets list of the available flavors as a ListSizes struct, filtering can be based on the user which is doing the request
func (s Sizes) List(ctx context.Context, req ListRequest) (*ListSizes, error) {
res, err := s.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListSizes{}
list := &ListSizes{}
err = json.Unmarshal(res, &list)
if err != nil {
@@ -43,3 +41,11 @@ func (s Sizes) List(ctx context.Context, req ListRequest) (ListSizes, error) {
return list, nil
}
// ListRaw gets list of the available flavors as an array of bytes
func (s Sizes) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/sizes/list"
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -22,4 +22,10 @@ type ItemSize struct {
}
// List of configured available flavors
type ListSizes []ItemSize
type ListSizes struct {
// Data
Data []ItemSize `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix
// - Second argument -> indent
func (ls ListSizes) Serialize(params ...string) (serialization.Serialized, error) {
if len(ls) == 0 {
if len(ls.Data) == 0 {
return []byte{}, nil
}

10
pkg/cloudapi/stack.go Normal file
View File

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

48
pkg/cloudapi/stack/get.go Normal file
View File

@@ -0,0 +1,48 @@
package stack
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get info of stack
type GetRequest struct {
// Find by ID
// Required: true
StackId uint64 `url:"stackId" json:"stackId" validate:"required"`
}
// Get gets stack details by ID as an InfoStack struct
func (i Stack) Get(ctx context.Context, req GetRequest) (*InfoStack, error) {
res, err := i.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := InfoStack{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets stack details by ID as an array of bytes
func (i Stack) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/stack/get"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,59 @@
package stack
import (
"context"
"encoding/json"
"net/http"
)
// ListRequest struct to get list of stacks
type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by type
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,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 stacks as a ListStacks struct
func (i Stack) List(ctx context.Context, req ListRequest) (*ListStacks, error) {
res, err := i.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListStacks{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of stacks as an array of bytes
func (i Stack) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/stack/list"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,53 @@
package stack
// Main information about stack
type InfoStack struct {
// CPU allocation ratio
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
// Descr
Descr string `json:"descr"`
// Drivers
Drivers []string `json:"drivers"`
// ID
ID uint64 `json:"id"`
// Mem allocation ratio
MemAllocationRatio float64 `json:"mem_allocation_ratio"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
}
// Information about stack in list
type ItemStack struct {
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
}
// List of stacks
type ListStacks struct {
//List
Data []ItemStack `json:"data"`
//Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

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

View File

@@ -8,25 +8,16 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get infromation about task
// GetRequest struct to get information about task
type GetRequest struct {
// ID of audit
// Required: true
AuditID string `url:"auditId" json:"auditId" validate:"required"`
}
// Get gets background API task status and result
// Get gets background API task status and result as a RecordAsyncTask struct
func (t Tasks) Get(ctx context.Context, req GetRequest) (*RecordAsyncTask, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/tasks/get"
res, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := t.GetRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -41,3 +32,18 @@ func (t Tasks) Get(ctx context.Context, req GetRequest) (*RecordAsyncTask, error
return &info, nil
}
// GetRaw gets background API task status and result as an array of bytes
func (t Tasks) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/tasks/get"
res, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list of tasks
// ListRequest struct to get list of tasks
type ListRequest struct {
// Page number
// Required: false
@@ -17,11 +17,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list user API tasks with status PROCESSING
// List gets list of user API tasks with status PROCESSING as a ListTasks struct
func (t Tasks) List(ctx context.Context, req ListRequest) (*ListTasks, error) {
url := "/cloudapi/tasks/list"
res, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := t.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -35,3 +33,11 @@ func (t Tasks) List(ctx context.Context, req ListRequest) (*ListTasks, error) {
return &list, nil
}
// ListRaw gets list of user API tasks with status PROCESSING as an array of bytes
func (t Tasks) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/tasks/list"
res, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -2,12 +2,24 @@ package vins
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type Route struct {
// Destination network
Destination string `url:"destination" json:"destination" validate:"required"`
//Destination network mask in 255.255.255.255 format
Netmask string `url:"netmask" json:"netmask" validate:"required"`
//Next hop host, IP address from ViNS ID free IP pool
Gateway string `url:"gateway" json:"gateway" validate:"required"`
}
// Request struct for create VINS in account
type CreateInAccountRequest struct {
// VINS name
@@ -33,6 +45,15 @@ type CreateInAccountRequest struct {
// Number of pre created reservations
// Required: false
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
// List of static routes, each item must have destination, netmask, and gateway fields
// Required: false
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
}
type wrapperCreateRequestInAcc struct {
CreateInAccountRequest
Routes []string `url:"routes,omitempty"`
}
// CreateInAccount creates VINS in account level
@@ -44,9 +65,31 @@ func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (
}
}
var routes []string
if len(req.Routes) != 0 {
routes = make([]string, 0, len(req.Routes))
for r := range req.Routes {
b, err := json.Marshal(req.Routes[r])
if err != nil {
return 0, err
}
routes = append(routes, string(b))
}
} else {
routes = []string{}
}
reqWrapped := wrapperCreateRequestInAcc{
CreateInAccountRequest: req,
Routes: routes,
}
url := "/cloudapi/vins/createInAccount"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}

View File

@@ -2,6 +2,7 @@ package vins
import (
"context"
"encoding/json"
"net/http"
"strconv"
@@ -36,7 +37,16 @@ type CreateInRGRequest struct {
// Number of pre created reservations
// Required: false
PreReservationsNum uint `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
// List of static routes, each item must have destination, netmask, and gateway fields
// Required: false
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
}
type wrapperCreateRequestInRG struct {
CreateInRGRequest
Routes []string `url:"routes,omitempty"`
}
// CreateInRG creates VINS in resource group level
@@ -48,9 +58,31 @@ func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, er
}
}
var routes []string
if len(req.Routes) != 0 {
routes = make([]string, 0, len(req.Routes))
for r := range req.Routes {
b, err := json.Marshal(req.Routes[r])
if err != nil {
return 0, err
}
routes = append(routes, string(b))
}
} else {
routes = []string{}
}
reqWrapped := wrapperCreateRequestInRG{
CreateInRGRequest: req,
Routes: routes,
}
url := "/cloudapi/vins/createInRG"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}

View File

@@ -16,7 +16,7 @@ type ExtNetListRequest struct {
}
// ExtNetList show list of VINS external network connections
func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (ListExtNets, error) {
func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (*ListExtNets, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -31,7 +31,7 @@ func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (ListExtNet
return nil, err
}
list := ListExtNets{}
list := &ListExtNets{}
err = json.Unmarshal(res, &list)
if err != nil {

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