Compare commits
19 Commits
v1.5.0-gam
...
v1.6.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 35fa4af0d6 | |||
| d3e6309ef8 | |||
| 78a4152471 | |||
| 3e55195831 | |||
| 9f5e76aee4 | |||
| df8b045e77 | |||
| 4d9b8fc9d8 | |||
| e8270453cc | |||
| 7de095302b | |||
| a3711057ba | |||
| 1c59ca338a | |||
| f1529c9aac | |||
| 040235f92f | |||
| 4a152cb44c | |||
| c78b1348e3 | |||
| 8f152a2f63 | |||
| 0be4d8fb0c | |||
|
|
5025a17ea4 | ||
| 7c787f6fce |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
cmd/
|
cmd/
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.fleet/
|
||||||
|
.DS_Store
|
||||||
|
|||||||
52
CHANGELOG.md
52
CHANGELOG.md
@@ -1,4 +1,52 @@
|
|||||||
## Version 1.4.7
|
## Version 1.6.0
|
||||||
|
|
||||||
### Bugfix
|
### Bugfix
|
||||||
- Deleted validate:"required" tag from IPCIDR field in cloudapi/vins/createInRg request struct
|
- Fix client and legacy-client, the cyclicity of sending requests has been removed
|
||||||
|
- Edit description field SSLSkipVerify in config/config and config/legacy-config
|
||||||
|
- Remove tags required fields ExtNetID VINSID Start in model CreateRequest in cloudapi/lb/create and cloudbroker/lb/create
|
||||||
|
- Add tags required fields BindingName BindingAddress BindingPort in model FrontendBindRequest in cloudapi/lb/frontend_bind
|
||||||
|
- Add tags required fields BindingAddress BindingPort in model FrontendBindUpdateRequest in cloudapi/lb/frontend_bind_update
|
||||||
|
- Remove tags omitempty in field Start in model kvmx86 and kvmppc in cloudapi and cloudbroker /create /mass_create
|
||||||
|
- Add field Driver in models cloudbroker/kvmx86/create and cloudbroker/kvmx86/create_blank
|
||||||
|
- Add field ExternalIp in model ItemDetailedInfo cloudbroker/k8s/models and cloudapi/k8s/models
|
||||||
|
- Add fields StackID and Reason in model CreateRequest cloudbroker/kvmppc
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
- Add field UserData in cloudapi/bservice/group_add
|
||||||
|
- Add fields VinsId, LbSysctlParams, HighlyAvailable, AdditionalSANs, InitConfiguration, ClusterConfiguration, KubeletConfiguration, KubeProxyConfiguration, JoinConfiguration, UserData, ExtNetOnly, OidcCertificate in model request cloudapi/k8s/create and cloudbroker/k8s/create
|
||||||
|
- Add fields SysctlParams, HighlyAvailable in model CreateRequest in cloudapi/lb/create and cloudbroker/lb/create
|
||||||
|
- Add fields BackendHAIP, FrontendHAIP, PartK8s, SysctlParams in model RecordLB in cloudapi/lb/models and cloudbroker/lb/models
|
||||||
|
- Add models InfoStack, ItemStack, ListStacks cloudapi/stack/models
|
||||||
|
- Add field Routes and type Route in CreateInAccountRequest and CreateInRGRequest models in cloudapi/vins/create_in_rg and /cloudapi/vins/create_in_account
|
||||||
|
- Add field Enabled in model ItemVNFInterface in cloudapi/vins/models
|
||||||
|
- Add fields Routes in models RecordNAT, RecordDHCP, RecordGW and add type ListStaticRoutes, ListRoutes, ItemRoutes in cloudapi/vins/models
|
||||||
|
|
||||||
|
- Added new endpoints:
|
||||||
|
- cloudapi/k8s/get_worker_nodes_meta_data
|
||||||
|
- cloudapi/k8s/update_worker_nodes_meta_data
|
||||||
|
- cloudapi/lb/make_highly_available
|
||||||
|
- cloudapi/lb/updateSysctParams
|
||||||
|
- cloudapi/stack/get
|
||||||
|
- cloudapi/stack/list
|
||||||
|
- cloudapi/vins/static_route_list
|
||||||
|
- cloudapi/vins/static_route_access_grant
|
||||||
|
- cloudapi/vins/static_route_access_revoke
|
||||||
|
- cloudapi/vins/static_route_add
|
||||||
|
- cloudapi/vins/static_route_del
|
||||||
|
- cloudbroker/compute/set_custom_fields
|
||||||
|
- cloudbroker/k8s/get_worker_nodes_meta_data
|
||||||
|
- cloudbroker/k8s/update_worker_nodes_meta_data
|
||||||
|
- cloudbroker/lb/make_highly_available
|
||||||
|
- cloudbroker/lb/updateSysctParams
|
||||||
|
- cloudbroker/vins/static_route_list
|
||||||
|
- cloudbroker/vins/static_route_access_grant
|
||||||
|
- cloudbroker/vins/static_route_access_revoke
|
||||||
|
- cloudbroker/vins/static_route_add
|
||||||
|
- cloudbroker/vins/static_route_del
|
||||||
|
- cloudbroker/extnet/static_route_list
|
||||||
|
- cloudbroker/extnet/static_route_access_grant
|
||||||
|
- cloudbroker/extnet/static_route_access_revoke
|
||||||
|
- cloudbroker/extnet/static_route_add
|
||||||
|
- cloudbroker/extnet/static_route_del
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
57
README.md
57
README.md
@@ -9,6 +9,8 @@ Decort SDK - это библиотека, написанная на языке G
|
|||||||
- Версия 1.2.x Decort-SDK соответствует 3.8.5 версии платформы
|
- Версия 1.2.x Decort-SDK соответствует 3.8.5 версии платформы
|
||||||
- Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы
|
- Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы
|
||||||
- Версия 1.4.x Decort-SDK соответствует 3.8.6 версии платформы
|
- Версия 1.4.x Decort-SDK соответствует 3.8.6 версии платформы
|
||||||
|
- Версия 1.5.x Decort-SDK соответствует 3.8.7 версии платформы
|
||||||
|
- Версия 1.6.x Decort-SDK соответствует 3.8.8 версии платформы
|
||||||
|
|
||||||
## Оглавление
|
## Оглавление
|
||||||
|
|
||||||
@@ -61,12 +63,11 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
||||||
- `BService` - управление группами виртуальных машин (computes);
|
- `BService` - управление группами виртуальных машин (computes);
|
||||||
- `Compute` - управление виртуальными машинами (индивидуально);
|
- `Compute` - управление виртуальными машинами (индивидуально);
|
||||||
- `ComputeCI` - управление конвейром для создания виртуальных машин;
|
|
||||||
- `Disks` - управление виртуальными дисками;
|
- `Disks` - управление виртуальными дисками;
|
||||||
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
||||||
- `FLIPgroup` - управление группами "плавающими" ip - адресами;
|
- `FLIPgroup` - управление группами "плавающими" ip - адресами;
|
||||||
- `Image` - управление образами операционных систем;
|
- `Image` - управление образами операционных систем;
|
||||||
- `K8CI` - управление конвейром для создания кластера;
|
- `K8CI` - получение информации о конвейере для создания кластера;
|
||||||
- `K8S` - управление кластерами kubernetes;
|
- `K8S` - управление кластерами kubernetes;
|
||||||
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
||||||
- `KVMx86` - создание виртуальной машины x86;
|
- `KVMx86` - создание виртуальной машины x86;
|
||||||
@@ -74,6 +75,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
- `Locations` - получение информации о grid площадки;
|
- `Locations` - получение информации о grid площадки;
|
||||||
- `RG` - управление ресурсными группами аккаунта;
|
- `RG` - управление ресурсными группами аккаунта;
|
||||||
- `Sizes` - получение информации о потребляемых ресурсах виртуальными машинами и дисками;
|
- `Sizes` - получение информации о потребляемых ресурсах виртуальными машинами и дисками;
|
||||||
|
- `Stack` - получение информации о вычислительных узлах;
|
||||||
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
||||||
- `VINS` - управление виртуальными изолированными сетями.
|
- `VINS` - управление виртуальными изолированными сетями.
|
||||||
|
|
||||||
@@ -83,30 +85,39 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
Данная группа ручек позволяет выполнять следующие операции в платформе:
|
Данная группа ручек позволяет выполнять следующие операции в платформе:
|
||||||
|
|
||||||
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
||||||
|
- `APIAccess` - управление доступом к API и его объектам;
|
||||||
|
- `Backup` - управление резервным копированием;
|
||||||
- `Compute` - управление виртуальными машинами (индивидуально);
|
- `Compute` - управление виртуальными машинами (индивидуально);
|
||||||
- `Disks` - управление виртуальными дисками;
|
- `Disks` - управление виртуальными дисками;
|
||||||
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
||||||
|
- `FLIPGroup` - управление группами с «плавающими» ip адресами;
|
||||||
- `Grid` - управление площадками;
|
- `Grid` - управление площадками;
|
||||||
|
- `Group` - управление группами пользователей;
|
||||||
- `Image` - управление образами операционных систем;
|
- `Image` - управление образами операционных систем;
|
||||||
- `K8CI` - управление конвейром для создания кластера;
|
- `K8CI` - управление конвейром для создания кластера;
|
||||||
- `K8S` - управление кластерами kubernetes;
|
- `K8S` - управление кластерами kubernetes;
|
||||||
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
||||||
- `KVMx86` - создание виртуальной машины x86;
|
- `KVMx86` - создание виртуальной машины x86;
|
||||||
- `LB` - управление балансировщиками нагрузки;
|
- `LB` - управление балансировщиками нагрузки;
|
||||||
|
- `PCIDevice` - управление устройствами;
|
||||||
- `RG` - управление ресурсными группами аккаунта;
|
- `RG` - управление ресурсными группами аккаунта;
|
||||||
- `SEP` - управление storage endpoint (sep);
|
- `SEP` - управление storage endpoint (sep);
|
||||||
|
- `Stack` - получение информации о вычислительных узлах;
|
||||||
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
||||||
|
- `User` - управление пользователями (индивидуально);
|
||||||
|
- `VGPU` - управление виртуальными графическими процессорами;
|
||||||
- `VINS` - управление виртуальными изолированными сетями.
|
- `VINS` - управление виртуальными изолированными сетями.
|
||||||
|
|
||||||
## Работа с библиотекой
|
## Работа с библиотекой
|
||||||
|
|
||||||
Алгоритм работы с библиотекой выглядит следующим образом:
|
Алгоритм работы с библиотекой выглядит следующим образом:
|
||||||
|
|
||||||
1. Настройка конфигурации клиента.
|
1. Выполнение одного из действий:
|
||||||
2. Парсинг конфигурации из файла.
|
- настройка конфигурации клиента;
|
||||||
3. Создание клиента.
|
- парсинг конфигурации из файла.
|
||||||
4. Создание структуры запроса.
|
2. Создание клиента.
|
||||||
5. Выполнение запроса.
|
3. Создание структуры запроса.
|
||||||
|
4. Выполнение запроса.
|
||||||
|
|
||||||
### Настройка конфигурации клиента
|
### Настройка конфигурации клиента
|
||||||
|
|
||||||
@@ -119,7 +130,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
#### Пример конфигурации клиента
|
#### Пример конфигурации клиента
|
||||||
@@ -230,7 +241,6 @@ func main() {
|
|||||||
- `pkg/cloudapi/account` - для `Account`
|
- `pkg/cloudapi/account` - для `Account`
|
||||||
- `pkg/cloudapi/bservice` - для `Basic Service`
|
- `pkg/cloudapi/bservice` - для `Basic Service`
|
||||||
- `pkg/cloudapi/compute` - для `Compute`
|
- `pkg/cloudapi/compute` - для `Compute`
|
||||||
- `pkg/cloudapi/computeci` - для `ComputeCI`
|
|
||||||
- `pkg/cloudapi/disks` - для `Disks`
|
- `pkg/cloudapi/disks` - для `Disks`
|
||||||
- `pkg/cloudapi/extnet` - для `ExtNet`
|
- `pkg/cloudapi/extnet` - для `ExtNet`
|
||||||
- `pkg/cloudapi/flipgroup` - для `FLIPGroup`
|
- `pkg/cloudapi/flipgroup` - для `FLIPGroup`
|
||||||
@@ -242,24 +252,33 @@ func main() {
|
|||||||
- `pkg/cloudapi/lb` - для `LB`
|
- `pkg/cloudapi/lb` - для `LB`
|
||||||
- `pkg/cloudapi/locations` - для `Locations`
|
- `pkg/cloudapi/locations` - для `Locations`
|
||||||
- `pkg/cloudapi/rg` - для `RG`
|
- `pkg/cloudapi/rg` - для `RG`
|
||||||
- `pkg/cloudapi/sizes` - для `RG`
|
- `pkg/cloudapi/sizes` - для `Sizes`
|
||||||
|
- `pkg/cloudapi/stack` - для `Stack`
|
||||||
- `pkg/cloudapi/tasks` - для `Tasks`
|
- `pkg/cloudapi/tasks` - для `Tasks`
|
||||||
- `pkg/cloudapi/vins` - для `VINS`
|
- `pkg/cloudapi/vins` - для `VINS`
|
||||||
- **cloudbroker**:
|
- **cloudbroker**:
|
||||||
- `pkg/cloudbroker/account` - для `Account`
|
- `pkg/cloudbroker/account` - для `Account`
|
||||||
|
- `pkg/cloudbroker/apiaccess` - для `APIAccess`
|
||||||
|
- `pkg/cloudbroker/backup` - для `Backup`
|
||||||
- `pkg/cloudbroker/compute` - для `Compute`
|
- `pkg/cloudbroker/compute` - для `Compute`
|
||||||
- `pkg/cloudbroker/disks` - для `Disks`
|
- `pkg/cloudbroker/disks` - для `Disks`
|
||||||
- `pkg/cloudbroker/extnet` - для `ExtNet`
|
- `pkg/cloudbroker/extnet` - для `ExtNet`
|
||||||
|
- `pkg/cloudbroker/flipgroup` - для `FLIPGroup`
|
||||||
- `pkg/cloudbroker/grid` - для `Grid`
|
- `pkg/cloudbroker/grid` - для `Grid`
|
||||||
|
- `pkg/cloudbroker/group` - для `Group`
|
||||||
- `pkg/cloudbroker/image` - для `Image`
|
- `pkg/cloudbroker/image` - для `Image`
|
||||||
- `pkg/cloudbroker/k8ci` - для `K8CI`
|
- `pkg/cloudbroker/k8ci` - для `K8CI`
|
||||||
- `pkg/cloudbroker/k8s` - для `K8S`
|
- `pkg/cloudbroker/k8s` - для `K8S`
|
||||||
- `pkg/cloudbroker/kvmppc` - для `KVMPPC`
|
- `pkg/cloudbroker/kvmppc` - для `KVMPPC`
|
||||||
- `pkg/cloudbroker/kvmx86` - для `KVMX86`
|
- `pkg/cloudbroker/kvmx86` - для `KVMX86`
|
||||||
- `pkg/cloudbroker/lb` - для `LB`
|
- `pkg/cloudbroker/lb` - для `LB`
|
||||||
|
- `pkg/cloudbroker/pcidevice` - для `PCIDevice`
|
||||||
- `pkg/cloudbroker/rg` - для `RG`
|
- `pkg/cloudbroker/rg` - для `RG`
|
||||||
- `pkg/cloudbroker/sep` - для `SEP`
|
- `pkg/cloudbroker/sep` - для `SEP`
|
||||||
|
- `pkg/cloudbroker/stack` - для `Stack`
|
||||||
- `pkg/cloudbroker/tasks` - для `Tasks`
|
- `pkg/cloudbroker/tasks` - для `Tasks`
|
||||||
|
- `pkg/cloudbroker/user` - для `User`
|
||||||
|
- `pkg/cloudbroker/vgpu` - для `VGPU`
|
||||||
- `pkg/cloudbroker/vins` - для `VINS`
|
- `pkg/cloudbroker/vins` - для `VINS`
|
||||||
|
|
||||||
Все поля структуры имеют описание, в которых содержится:
|
Все поля структуры имеют описание, в которых содержится:
|
||||||
@@ -396,7 +415,7 @@ func main() {
|
|||||||
|
|
||||||
Чтобы выполнить запрос, необходимо:
|
Чтобы выполнить запрос, необходимо:
|
||||||
|
|
||||||
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно соверать запросы.
|
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно совершать запросы.
|
||||||
2. Вызвать у возвращенной структуры метод, определяющий группу ручек для взаимодействия.
|
2. Вызвать у возвращенной структуры метод, определяющий группу ручек для взаимодействия.
|
||||||
|
|
||||||
Доступные методы для `.CloudAPI()`:
|
Доступные методы для `.CloudAPI()`:
|
||||||
@@ -404,7 +423,6 @@ func main() {
|
|||||||
- `.Account()` - для работы с `Account`
|
- `.Account()` - для работы с `Account`
|
||||||
- `.BService()` - для работы с `BService`
|
- `.BService()` - для работы с `BService`
|
||||||
- `.Compute()` - для работы с `Compute`
|
- `.Compute()` - для работы с `Compute`
|
||||||
- `.ComputeCI()` - для работы с `ComputeCI`
|
|
||||||
- `.Disks()` - для работы с `Disks`
|
- `.Disks()` - для работы с `Disks`
|
||||||
- `.ExtNet()` - для работы с `ExtNet`
|
- `.ExtNet()` - для работы с `ExtNet`
|
||||||
- `.FLIPgroup()` - для работы с `FLIPGroup`
|
- `.FLIPgroup()` - для работы с `FLIPGroup`
|
||||||
@@ -417,37 +435,46 @@ func main() {
|
|||||||
- `.Locations()` - для работы с `Locations`
|
- `.Locations()` - для работы с `Locations`
|
||||||
- `.RG()` - для работы с `RG`
|
- `.RG()` - для работы с `RG`
|
||||||
- `.Sizes()` - для работы с `Sizes`
|
- `.Sizes()` - для работы с `Sizes`
|
||||||
|
- `.Stack()` - для работы с `Stack`
|
||||||
- `.Tasks()` - для работы с `Tasks`
|
- `.Tasks()` - для работы с `Tasks`
|
||||||
- `.VINS()` - для работы с `VINS`
|
- `.VINS()` - для работы с `VINS`
|
||||||
|
|
||||||
Доступные методы для `.CloudBroker()`:
|
Доступные методы для `.CloudBroker()`:
|
||||||
|
|
||||||
- `.Account()` - для работы с `Account`
|
- `.Account()` - для работы с `Account`
|
||||||
|
- `.APIAccess()` - для работы с `APIAccess`
|
||||||
|
- `.Backup()` - для работы с `Backup`
|
||||||
- `.Compute()` - для работы с `Compute`
|
- `.Compute()` - для работы с `Compute`
|
||||||
- `.Disks()` - для работы с `Disks`
|
- `.Disks()` - для работы с `Disks`
|
||||||
- `.ExtNet()` - для работы с `ExtNet`
|
- `.ExtNet()` - для работы с `ExtNet`
|
||||||
|
- `.FLIPGroup()` - для работы с `FLIPGroup`
|
||||||
- `.Grid()` - для работы с `Grid`
|
- `.Grid()` - для работы с `Grid`
|
||||||
|
- `.Group()` - для работы с `Group`
|
||||||
- `.Image()` - для работы с `Image`
|
- `.Image()` - для работы с `Image`
|
||||||
- `.K8CI()` - для работы с `K8CI`
|
- `.K8CI()` - для работы с `K8CI`
|
||||||
- `.K8S()` - для работы с `K8S`
|
- `.K8S()` - для работы с `K8S`
|
||||||
- `.KVMPPC()` - для работы с `KVMPPC`
|
- `.KVMPPC()` - для работы с `KVMPPC`
|
||||||
- `.KVMx86()` - для работы с `KVMX86`
|
- `.KVMx86()` - для работы с `KVMX86`
|
||||||
- `.LB()` - для работы с `LB`
|
- `.LB()` - для работы с `LB`
|
||||||
|
- `.PCIDevice()` - для работы с `PCIDevice`
|
||||||
- `.RG()` - для работы с `RG`
|
- `.RG()` - для работы с `RG`
|
||||||
- `.SEP()` - для работы с `SEP`
|
- `.SEP()` - для работы с `SEP`
|
||||||
|
- `.Stack()` - для работы с `Stack`
|
||||||
- `.Tasks()` - для работы с `Tasks`
|
- `.Tasks()` - для работы с `Tasks`
|
||||||
|
- `.User()` - для работы с `User`
|
||||||
|
- `.VGPU()` - для работы с `VGPU`
|
||||||
- `.VINS()` - для работы с `VINS`
|
- `.VINS()` - для работы с `VINS`
|
||||||
|
|
||||||
3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
|
3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
|
||||||
|
|
||||||
- контекст;
|
- контекст;
|
||||||
- структуру запроса.
|
- структуру запроса.
|
||||||
У кождой группы ручек API имеются свои доступные методы, которые определяются платформой.
|
У каждой группы ручек API имеются свои доступные методы, которые определяются платформой.
|
||||||
|
|
||||||
4. Обработать результат и ошибки.
|
4. Обработать результат и ошибки.
|
||||||
|
|
||||||
Т.к. все вызовы методов идут последовательно, можно их объеденить в конвейер:
|
Т.к. все вызовы методов идут последовательно, можно их объеденить в конвейер:
|
||||||
Общий вид вонвейра будет выглядеть так:
|
Общий вид конвейера будет выглядеть так:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
client.<API>.<группа>.<метод>
|
client.<API>.<группа>.<метод>
|
||||||
@@ -704,7 +731,7 @@ func main() {
|
|||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
#### Пример конфигурации legacy клиента
|
#### Пример конфигурации legacy клиента
|
||||||
|
|||||||
407
client.go
407
client.go
@@ -1,24 +1,34 @@
|
|||||||
package decortsdk
|
package decortsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
"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"
|
"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"
|
"github.com/google/go-querystring/query"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/client"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTP-client for platform
|
// HTTP-client for platform
|
||||||
type DecortClient struct {
|
type DecortClient struct {
|
||||||
decortURL string
|
decortURL string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
cfg config.Config
|
||||||
|
expiryTime time.Time
|
||||||
|
mutex *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сlient builder
|
// Сlient builder
|
||||||
@@ -27,9 +37,25 @@ func New(cfg config.Config) *DecortClient {
|
|||||||
cfg.Retries = 5
|
cfg.Retries = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var expiryTime time.Time
|
||||||
|
|
||||||
|
if cfg.Token != "" {
|
||||||
|
expiryTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
return &DecortClient{
|
return &DecortClient{
|
||||||
decortURL: cfg.DecortURL,
|
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
|
// DecortApiCall method for sending requests to the platform
|
||||||
func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
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("highlyAvailable", 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("highlyAvailable", 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)
|
values, err := query.Values(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -56,7 +359,11 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
|
|||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -73,3 +380,91 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
|
|||||||
|
|
||||||
return respBytes, nil
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ type Config struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Retries uint64 `json:"retries" yaml:"retries"`
|
Retries uint64 `json:"retries" yaml:"retries"`
|
||||||
|
|
||||||
// Skip verify, true by default
|
// Skip verify
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type LegacyConfig struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Retries uint64 `json:"retries" yaml:"retries"`
|
Retries uint64 `json:"retries" yaml:"retries"`
|
||||||
|
|
||||||
// Skip verify, true by default
|
// Skip verify
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
*d = Duration(tmp)
|
*d = Duration(tmp)
|
||||||
return nil
|
return nil
|
||||||
default:
|
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)
|
*d = Duration(tmp)
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Invalid duration %v", value)
|
return fmt.Errorf("invalid duration %v", value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,19 @@
|
|||||||
package validators
|
package validators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-playground/validator/v10"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"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.
|
// protoValidator is used to validate Proto fields.
|
||||||
func protoValidator(fe validator.FieldLevel) bool {
|
func protoValidator(fe validator.FieldLevel) bool {
|
||||||
fieldValue := fe.Field().String()
|
fieldValue := fe.Field().String()
|
||||||
@@ -256,3 +264,11 @@ func strictLooseValidator(fe validator.FieldLevel) bool {
|
|||||||
|
|
||||||
return StringInSlice(fieldValue, strictLooseValues)
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -107,6 +107,12 @@ func errorMessage(fe validator.FieldError) string {
|
|||||||
fe.Field(),
|
fe.Field(),
|
||||||
joinValues(computeDataDisksValues))
|
joinValues(computeDataDisksValues))
|
||||||
|
|
||||||
|
case "computeDriver":
|
||||||
|
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||||
|
prefix,
|
||||||
|
fe.Field(),
|
||||||
|
joinValues(computeDriverValues))
|
||||||
|
|
||||||
// Disk Validators
|
// Disk Validators
|
||||||
case "diskType":
|
case "diskType":
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||||
@@ -121,6 +127,12 @@ func errorMessage(fe validator.FieldError) string {
|
|||||||
fe.Field(),
|
fe.Field(),
|
||||||
joinValues(flipgroupClientTypeValues))
|
joinValues(flipgroupClientTypeValues))
|
||||||
|
|
||||||
|
// k8s Validators
|
||||||
|
case "workerGroupName":
|
||||||
|
return fmt.Sprintf("%s %s must be more 3 symbol",
|
||||||
|
prefix,
|
||||||
|
fe.Field())
|
||||||
|
|
||||||
// KVM_X86/KVM_PPC Validators
|
// KVM_X86/KVM_PPC Validators
|
||||||
case "kvmNetType":
|
case "kvmNetType":
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ func registerAllValidators(validate *validator.Validate) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = validate.RegisterValidation("computeDriver", computeDriverValidator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = validate.RegisterValidation("accessType", accessTypeValidator)
|
err = validate.RegisterValidation("accessType", accessTypeValidator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -175,5 +180,10 @@ func registerAllValidators(validate *validator.Validate) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = validate.RegisterValidation("workerGroupName", workerGroupNameValidator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ var (
|
|||||||
computeNetTypeValues = []string{"EXTNET", "VINS"}
|
computeNetTypeValues = []string{"EXTNET", "VINS"}
|
||||||
computeOrderValues = []string{"cdrom", "network", "hd"}
|
computeOrderValues = []string{"cdrom", "network", "hd"}
|
||||||
computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"}
|
computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"}
|
||||||
|
computeDriverValues = []string{"KVM_X86", "SVA_KVM_X86"}
|
||||||
|
|
||||||
diskTypeValues = []string{"B", "T", "D"}
|
diskTypeValues = []string{"B", "T", "D"}
|
||||||
|
|
||||||
|
|||||||
271
legacy-client.go
271
legacy-client.go
@@ -1,23 +1,34 @@
|
|||||||
package decortsdk
|
package decortsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"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"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Legacy HTTP-client for platform
|
// Legacy HTTP-client for platform
|
||||||
type LegacyDecortClient struct {
|
type LegacyDecortClient struct {
|
||||||
decortURL string
|
decortURL string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
cfg config.LegacyConfig
|
||||||
|
expiryTime time.Time
|
||||||
|
mutex *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy client builder
|
// Legacy client builder
|
||||||
@@ -26,9 +37,25 @@ func NewLegacy(cfg config.LegacyConfig) *LegacyDecortClient {
|
|||||||
cfg.Retries = 5
|
cfg.Retries = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var expiryTime time.Time
|
||||||
|
|
||||||
|
if cfg.Token != "" {
|
||||||
|
expiryTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
return &LegacyDecortClient{
|
return &LegacyDecortClient{
|
||||||
decortURL: cfg.DecortURL,
|
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
|
// DecortApiCall method for sending requests to the platform
|
||||||
func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
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("highlyAvailable", 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)
|
values, err := query.Values(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := ldc.client.Do(req)
|
resp, err := ldc.do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -72,3 +246,88 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st
|
|||||||
|
|
||||||
return respBytes, nil
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func (la ListAccounts) FilterFunc(predicate func(ItemAccount) bool) ListAccounts
|
|||||||
// FindOne returns first found ItemAccount.
|
// FindOne returns first found ItemAccount.
|
||||||
// If none was found, returns an empty struct.
|
// If none was found, returns an empty struct.
|
||||||
func (la ListAccounts) FindOne() ItemAccount {
|
func (la ListAccounts) FindOne() ItemAccount {
|
||||||
if la.EntryCount == 0 {
|
if len(la.Data) == 0 {
|
||||||
return ItemAccount{}
|
return ItemAccount{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type GetResourceConsumptionRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetResourceConsumption show amount of consumed and reserved resources (cpu, ram, disk) by specific account
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -26,7 +26,7 @@ func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceCons
|
|||||||
|
|
||||||
url := "/cloudapi/account/getResourceConsumption"
|
url := "/cloudapi/account/getResourceConsumption"
|
||||||
|
|
||||||
info := ItemResourceConsumption{}
|
info := RecordResourceConsumption{}
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type ListRequest struct {
|
|||||||
|
|
||||||
// Find by name
|
// Find by name
|
||||||
// Required: false
|
// Required: false
|
||||||
Name string `urL:"name,omitempty" json:"name,omitempty"`
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
// Find by access control list
|
// Find by access control list
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -13,10 +13,50 @@ type ListComputesRequest struct {
|
|||||||
// ID an account
|
// ID an account
|
||||||
// Required: true
|
// Required: true
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
|
// Find by compute id
|
||||||
|
// Required: false
|
||||||
|
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group name
|
||||||
|
// Required: false
|
||||||
|
RGName string `url:"rgName,omitempty" json:"rgName,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group id
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by tech status
|
||||||
|
// Required: false
|
||||||
|
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||||
|
|
||||||
|
// Find by ip address
|
||||||
|
// Required: false
|
||||||
|
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
|
||||||
|
|
||||||
|
// Find by external network name
|
||||||
|
// Required: false
|
||||||
|
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
|
||||||
|
|
||||||
|
// Find by external network id
|
||||||
|
// Required: false
|
||||||
|
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListComputes gets list all compute instances under specified account, accessible by the user
|
// ListComputes gets list all compute instances under specified account, accessible by the user
|
||||||
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) {
|
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -38,5 +78,5 @@ func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (Lis
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,18 @@ type ListDeletedRequest struct {
|
|||||||
// Page size
|
// Page size
|
||||||
// Required: false
|
// Required: false
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by access control list
|
||||||
|
// Required: false
|
||||||
|
ACL string `url:"acl,omitempty" json:"acl,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListDeleted gets list all deleted accounts the user has access to
|
// ListDeleted gets list all deleted accounts the user has access to
|
||||||
|
|||||||
@@ -13,10 +13,34 @@ type ListDisksRequest struct {
|
|||||||
// ID an account
|
// ID an account
|
||||||
// Required: true
|
// Required: true
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
|
// Find by disk id
|
||||||
|
// Required: false
|
||||||
|
DiskID uint64 `url:"diskId,omitempty" json:"diskId,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by max size disk
|
||||||
|
// Required: false
|
||||||
|
DiskMaxSize uint64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
|
||||||
|
|
||||||
|
// Type of the disks
|
||||||
|
// Required: false
|
||||||
|
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListDisks gets list all currently unattached disks under specified account
|
// ListDisks gets list all currently unattached disks under specified account
|
||||||
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) {
|
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (*ListDisks, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -38,5 +62,5 @@ func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,45 @@ import (
|
|||||||
|
|
||||||
// Request struct for get list FLIPGroups
|
// Request struct for get list FLIPGroups
|
||||||
type ListFLIPGroupsRequest struct {
|
type ListFLIPGroupsRequest struct {
|
||||||
// ID an account
|
// ID of the account
|
||||||
// Required: true
|
// Required: true
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by vinsId
|
||||||
|
// Required: false
|
||||||
|
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
||||||
|
|
||||||
|
// Find by VINS name
|
||||||
|
// Required: false
|
||||||
|
VINSName string `url:"vinsName,omitempty" json:"vinsName,omitempty"`
|
||||||
|
|
||||||
|
// Find by external network id
|
||||||
|
// Required: false
|
||||||
|
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
||||||
|
|
||||||
|
// Find by IP
|
||||||
|
// Required: false
|
||||||
|
ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"`
|
||||||
|
|
||||||
|
// Find by flipGroup Id
|
||||||
|
// Required: false
|
||||||
|
FLIPGroupID uint64 `url:"flipGroupId,omitempty" json:"flipGroupId,omitempty"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user
|
// ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user
|
||||||
func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (ListFLIPGroups, error) {
|
func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (*ListFLIPGroups, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -38,5 +70,5 @@ func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,38 @@ type ListRGRequest struct {
|
|||||||
// ID an account
|
// ID an account
|
||||||
// Required: true
|
// Required: true
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group id
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by vinsId
|
||||||
|
// Required: false
|
||||||
|
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
||||||
|
|
||||||
|
// Find by VM ID
|
||||||
|
// Required: false
|
||||||
|
VMID uint64 `url:"vmId,omitempty" json:"vmId,omitempty"`
|
||||||
|
|
||||||
|
// Find by status
|
||||||
|
// Required: false
|
||||||
|
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListRG gets list all resource groups under specified account, accessible by the user
|
// ListRG gets list all resource groups under specified account, accessible by the user
|
||||||
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) {
|
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (*ListRG, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -38,5 +66,5 @@ func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,35 @@ import (
|
|||||||
type ListTemplatesRequest struct {
|
type ListTemplatesRequest struct {
|
||||||
// ID an account
|
// ID an account
|
||||||
// Required: true
|
// Required: true
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
// Include deleted images
|
// Include deleted images
|
||||||
// Required: false
|
// 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
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -42,5 +62,5 @@ func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (L
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,34 @@ type ListVINSRequest struct {
|
|||||||
// ID an account
|
// ID an account
|
||||||
// Required: true
|
// Required: true
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
|
// Find by VINS ID
|
||||||
|
// Required: false
|
||||||
|
VINSID uint64 `url:"vins,omitempty" json:"vinsId,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group id
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by external network ip
|
||||||
|
// Required: false
|
||||||
|
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListVINS gets list all ViNSes under specified account, accessible by the user
|
// ListVINS gets list all ViNSes under specified account, accessible by the user
|
||||||
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) {
|
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -38,5 +62,5 @@ func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, e
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ type ResourceLimits struct {
|
|||||||
CUD float64 `json:"CU_D"`
|
CUD float64 `json:"CU_D"`
|
||||||
|
|
||||||
// Max disk size, GB
|
// Max disk size, GB
|
||||||
CU_DM float64 `json:"CU_DM"`
|
CUDM float64 `json:"CU_DM"`
|
||||||
|
|
||||||
// Number of public IP addresses
|
// Number of public IP addresses
|
||||||
CUI float64 `json:"CU_I"`
|
CUI float64 `json:"CU_I"`
|
||||||
@@ -112,7 +112,15 @@ type DiskUsage struct {
|
|||||||
DiskSize float64 `json:"disksize"`
|
DiskSize float64 `json:"disksize"`
|
||||||
|
|
||||||
// Disk size max
|
// Disk size max
|
||||||
DiskSizeMax uint64 `json:"disksizemax"`
|
DiskSizeMax float64 `json:"disksizemax"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Information about resource consumption
|
||||||
|
type RecordResourceConsumption struct {
|
||||||
|
ItemResourceConsumption
|
||||||
|
|
||||||
|
// Resource limits
|
||||||
|
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Information about resources
|
// Information about resources
|
||||||
@@ -299,7 +307,13 @@ type ItemCompute struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of computes
|
// List of computes
|
||||||
type ListComputes []ItemCompute
|
type ListComputes struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemCompute `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main information about disk
|
// Main information about disk
|
||||||
type ItemDisk struct {
|
type ItemDisk struct {
|
||||||
@@ -326,7 +340,13 @@ type ItemDisk struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of disks
|
// List of disks
|
||||||
type ListDisks []ItemDisk
|
type ListDisks struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemDisk `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main information about VINS
|
// Main information about VINS
|
||||||
type ItemVINS struct {
|
type ItemVINS struct {
|
||||||
@@ -383,7 +403,13 @@ type ItemVINS struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of VINS
|
// List of VINS
|
||||||
type ListVINS []ItemVINS
|
type ListVINS struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemVINS `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main info about audit
|
// Main info about audit
|
||||||
type ItemAudit struct {
|
type ItemAudit struct {
|
||||||
@@ -497,7 +523,13 @@ type ItemRG struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of Resource groups
|
// List of Resource groups
|
||||||
type ListRG []ItemRG
|
type ListRG struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemRG `json:"data"`
|
||||||
|
|
||||||
|
// Enrtry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main information about template
|
// Main information about template
|
||||||
type ItemTemplate struct {
|
type ItemTemplate struct {
|
||||||
@@ -533,7 +565,13 @@ type ItemTemplate struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of templates
|
// List of templates
|
||||||
type ListTemplates []ItemTemplate
|
type ListTemplates struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemTemplate `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main information about FLIPGroup
|
// Main information about FLIPGroup
|
||||||
type ItemFLIPGroup struct {
|
type ItemFLIPGroup struct {
|
||||||
@@ -602,4 +640,10 @@ type ItemFLIPGroup struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of FLIPGroups
|
// List of FLIPGroups
|
||||||
type ListFLIPGroups []ItemFLIPGroup
|
type ListFLIPGroups struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemFLIPGroup `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
// - First argument -> prefix
|
// - First argument -> prefix
|
||||||
// - Second argument -> indent
|
// - Second argument -> indent
|
||||||
func (la ListAccounts) Serialize(params ...string) (serialization.Serialized, error) {
|
func (la ListAccounts) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
if la.EntryCount == 0 {
|
if len(la.Data) == 0 {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import "sort"
|
|||||||
//
|
//
|
||||||
// If inverse param is set to true, the order is reversed.
|
// If inverse param is set to true, the order is reversed.
|
||||||
func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts {
|
func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts {
|
||||||
if la.EntryCount < 2 {
|
if len(la.Data) < 2 {
|
||||||
return la
|
return la
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts {
|
|||||||
//
|
//
|
||||||
// If inverse param is set to true, the order is reversed.
|
// If inverse param is set to true, the order is reversed.
|
||||||
func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts {
|
func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts {
|
||||||
if la.EntryCount < 2 {
|
if len(la.Data) < 2 {
|
||||||
return la
|
return la
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts {
|
|||||||
//
|
//
|
||||||
// If inverse param is set to true, the order is reversed.
|
// If inverse param is set to true, the order is reversed.
|
||||||
func (la ListAccounts) SortByDeletedTime(inverse bool) ListAccounts {
|
func (la ListAccounts) SortByDeletedTime(inverse bool) ListAccounts {
|
||||||
if la.EntryCount < 2 {
|
if len(la.Data) < 2 {
|
||||||
return la
|
return la
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ type GroupAddRequest struct {
|
|||||||
// Time of Compute Group readiness
|
// Time of Compute Group readiness
|
||||||
// Required: false
|
// Required: false
|
||||||
TimeoutStart uint64 `url:"timeoutStart,omitempty" json:"timeoutStart,omitempty"`
|
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.
|
// GroupAdd creates new Compute Group within BasicService.
|
||||||
|
|||||||
40
pkg/cloudapi/compute/delete_custom_fields.go
Normal file
40
pkg/cloudapi/compute/delete_custom_fields.go
Normal 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
|
||||||
|
}
|
||||||
@@ -22,11 +22,6 @@ type DiskAddRequest struct {
|
|||||||
// Required: true
|
// Required: true
|
||||||
Size uint64 `url:"size" json:"size" validate:"required"`
|
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
|
// Type of the disk
|
||||||
// Should be one of:
|
// Should be one of:
|
||||||
// - D
|
// - D
|
||||||
@@ -34,6 +29,11 @@ type DiskAddRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
|
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
|
// Pool name
|
||||||
// By default will be chosen automatically
|
// By default will be chosen automatically
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type DiskDelRequest struct {
|
|||||||
|
|
||||||
// False if disk is to be deleted to recycle bin
|
// False if disk is to be deleted to recycle bin
|
||||||
// Required: true
|
// Required: true
|
||||||
Permanently bool `url:"permanently" json:"permanently" validate:"required"`
|
Permanently bool `url:"permanently" json:"permanently"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiskDel delete disk and detach from compute
|
// DiskDel delete disk and detach from compute
|
||||||
|
|||||||
@@ -8,19 +8,15 @@ import (
|
|||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Request struct for get list GPU for compute
|
// Request struct for getting Compute's customFields
|
||||||
type ListGPURequest struct {
|
type GetCustomFieldsRequest struct {
|
||||||
// ID of compute instance
|
// Compute ID
|
||||||
// Required: true
|
// Required: true
|
||||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
// Also list destroyed
|
|
||||||
// Required: false
|
|
||||||
ListDestroyed bool `url:"list_destroyed,omitempty" json:"list_destroyed,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListVGPU gets list GPU for compute
|
// GetCustomFields gets Compute's customFields
|
||||||
func (c Compute) ListGPU(ctx context.Context, req ListGPURequest) ([]interface{}, error) {
|
func (c Compute) GetCustomFields(ctx context.Context, req GetCustomFieldsRequest) (interface{}, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -28,19 +24,19 @@ func (c Compute) ListGPU(ctx context.Context, req ListGPURequest) ([]interface{}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
url := "/cloudbroker/compute/listGpu"
|
url := "/cloudapi/compute/getCustomFields"
|
||||||
|
|
||||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list := make([]interface{}, 0)
|
var info interface{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
err = json.Unmarshal(res, &info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &info, nil
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,42 @@ import (
|
|||||||
|
|
||||||
// Request struct for get deleted computes list
|
// Request struct for get deleted computes list
|
||||||
type ListDeletedRequest struct {
|
type ListDeletedRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by account ID
|
||||||
|
// Required: false
|
||||||
|
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group name
|
||||||
|
// Required: false
|
||||||
|
RGName string `url:"rgName,omitempty" json:"rgName,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group ID
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by tech status
|
||||||
|
// Required: false
|
||||||
|
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||||
|
|
||||||
|
// Find by IP address
|
||||||
|
// Required: false
|
||||||
|
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
|
||||||
|
|
||||||
|
// Find by external network name
|
||||||
|
// Required: false
|
||||||
|
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
|
||||||
|
|
||||||
|
// Find by external network ID
|
||||||
|
// Required: false
|
||||||
|
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|||||||
@@ -13,10 +13,34 @@ type ListPCIDeviceRequest struct {
|
|||||||
// Identifier compute
|
// Identifier compute
|
||||||
// Required: true
|
// Required: true
|
||||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Find by resource group ID
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by device id
|
||||||
|
// Required: false
|
||||||
|
DevID uint64 `url:"devId,omitempty" json:"devId,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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPCIDevice gets list PCI device
|
// ListPCIDevice gets list PCI device
|
||||||
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([]interface{}, error) {
|
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (*ListPCIDevices, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -31,12 +55,12 @@ func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list := []interface{}{}
|
list := ListPCIDevices{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
err = json.Unmarshal(res, &list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,34 @@ type ListVGPURequest struct {
|
|||||||
// Identifier compute
|
// Identifier compute
|
||||||
// Required: true
|
// Required: true
|
||||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Find by GPU id
|
||||||
|
// Required: false
|
||||||
|
GPUID uint64 `url:"gpuId,omitempty" json:"gpuId,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"`
|
||||||
|
|
||||||
|
// Include deleted computes. If using field 'status', then includedeleted will be ignored
|
||||||
|
// Required: false
|
||||||
|
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListVGPU gets list vGPU
|
// ListVGPU gets list vGPU
|
||||||
func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface{}, error) {
|
func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) (*ListVGPUs, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -24,19 +48,19 @@ func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
url := "/cloudapi/compute/listVgpu"
|
url := "/cloudapi/compute/listVGpu"
|
||||||
|
|
||||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list := []interface{}{}
|
list := ListVGPUs{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
err = json.Unmarshal(res, &list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ type RecordACL struct {
|
|||||||
RGACL ListACL `json:"rgAcl"`
|
RGACL ListACL `json:"rgAcl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListUsers struct {
|
||||||
|
// Data
|
||||||
|
Data RecordACL `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
type Explicit bool
|
type Explicit bool
|
||||||
|
|
||||||
func (e *Explicit) UnmarshalJSON(b []byte) error {
|
func (e *Explicit) UnmarshalJSON(b []byte) error {
|
||||||
@@ -89,7 +97,13 @@ type ItemSnapshot struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of snapshots
|
// 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
|
// Main information about port forward
|
||||||
type ItemPFW struct {
|
type ItemPFW struct {
|
||||||
@@ -116,7 +130,13 @@ type ItemPFW struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List port forwards
|
// 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
|
// Main information about affinity relations
|
||||||
type RecordAffinityRelations struct {
|
type RecordAffinityRelations struct {
|
||||||
@@ -403,7 +423,7 @@ type RecordCompute struct {
|
|||||||
SnapSets ListSnapSets `json:"snapSets"`
|
SnapSets ListSnapSets `json:"snapSets"`
|
||||||
|
|
||||||
// Stateless SepID
|
// Stateless SepID
|
||||||
StatelessSepID uint64 `json:"statelessSepId"`
|
StatelessSepID int64 `json:"statelessSepId"`
|
||||||
|
|
||||||
// Stateless SepType
|
// Stateless SepType
|
||||||
StatelessSepType string `json:"statelessSepType"`
|
StatelessSepType string `json:"statelessSepType"`
|
||||||
@@ -862,7 +882,7 @@ type ItemCompute struct {
|
|||||||
SnapSets ListSnapSets `json:"snapSets"`
|
SnapSets ListSnapSets `json:"snapSets"`
|
||||||
|
|
||||||
// Stateless SepID
|
// Stateless SepID
|
||||||
StatelessSepID uint64 `json:"statelessSepId"`
|
StatelessSepID int64 `json:"statelessSepId"`
|
||||||
|
|
||||||
// Stateless SepType
|
// Stateless SepType
|
||||||
StatelessSepType string `json:"statelessSepType"`
|
StatelessSepType string `json:"statelessSepType"`
|
||||||
@@ -915,3 +935,21 @@ type ListComputes struct {
|
|||||||
// Entry count
|
// Entry count
|
||||||
EntryCount uint64 `json:"entryCount"`
|
EntryCount uint64 `json:"entryCount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List VGPUs
|
||||||
|
type ListVGPUs struct {
|
||||||
|
// Data
|
||||||
|
Data []interface{} `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List PCI devices
|
||||||
|
type ListPCIDevices struct {
|
||||||
|
// Data
|
||||||
|
Data []interface{} `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type PFWListRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PFWList gets compute port forwards list
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
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 nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
43
pkg/cloudapi/compute/set_custom_fields.go
Normal file
43
pkg/cloudapi/compute/set_custom_fields.go
Normal 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
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ type SnapshotListRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SnapshotList gets list compute snapshots
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -38,5 +38,5 @@ func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (Lis
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type UserListRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UserList gets users list for compute
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -31,7 +31,7 @@ func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list := RecordACL{}
|
list := ListUsers{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
err = json.Unmarshal(res, &list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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]
|
|
||||||
}
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -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"`
|
|
||||||
}
|
|
||||||
@@ -40,6 +40,14 @@ type ListRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
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
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|||||||
@@ -8,6 +8,26 @@ import (
|
|||||||
|
|
||||||
// Request struct for get list of deleted disks
|
// Request struct for get list of deleted disks
|
||||||
type ListDeletedRequest struct {
|
type ListDeletedRequest struct {
|
||||||
|
// Find by id
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by account name
|
||||||
|
// Required: false
|
||||||
|
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
|
||||||
|
|
||||||
|
// Find by max size disk
|
||||||
|
// Required: false
|
||||||
|
DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
|
||||||
|
|
||||||
|
// Find by shared, true or false
|
||||||
|
// Required: false
|
||||||
|
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
|
||||||
|
|
||||||
// ID of the account the disks belong to
|
// ID of the account the disks belong to
|
||||||
// Required: false
|
// Required: false
|
||||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||||
|
|||||||
@@ -11,10 +11,18 @@ type ListTypesRequest struct {
|
|||||||
// Show detailed disk types by seps
|
// Show detailed disk types by seps
|
||||||
// Required: true
|
// Required: true
|
||||||
Detailed bool `url:"detailed" json:"detailed" validate:"required"`
|
Detailed bool `url:"detailed" json:"detailed" 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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListTypes gets list defined disk types
|
// ListTypes gets list defined disk types
|
||||||
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface{}, error) {
|
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) (*ListTypes, error) {
|
||||||
url := "/cloudapi/disks/listTypes"
|
url := "/cloudapi/disks/listTypes"
|
||||||
|
|
||||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
@@ -22,12 +30,12 @@ func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list := make([]interface{}, 0)
|
list := ListTypes{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
err = json.Unmarshal(res, &list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ type ListUnattachedRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
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
|
// Type of the disks
|
||||||
// Required: false
|
// Required: false
|
||||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||||
@@ -36,6 +32,14 @@ type ListUnattachedRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
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
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|||||||
@@ -442,3 +442,11 @@ type RecordDisk struct {
|
|||||||
// Virtual machine ID
|
// Virtual machine ID
|
||||||
VMID uint64 `json:"vmid"`
|
VMID uint64 `json:"vmid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListTypes struct {
|
||||||
|
// Data
|
||||||
|
Data []interface{} `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,10 +13,26 @@ type ListComputesRequest struct {
|
|||||||
// Filter by account ID
|
// Filter by account ID
|
||||||
// Required: true
|
// Required: true
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
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
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -38,5 +54,5 @@ func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (List
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,13 @@ type ItemExtNetCompute struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of information about computes with external network
|
// 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
|
// QOS
|
||||||
type QOS struct {
|
type QOS struct {
|
||||||
@@ -118,6 +124,12 @@ type Excluded struct {
|
|||||||
// ClientType
|
// ClientType
|
||||||
ClientType string `json:"clientType"`
|
ClientType string `json:"clientType"`
|
||||||
|
|
||||||
|
// Domain name
|
||||||
|
DomainName string `json:"domainname"`
|
||||||
|
|
||||||
|
// Host name
|
||||||
|
HostName string `json:"hostname"`
|
||||||
|
|
||||||
// IP
|
// IP
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
|
|
||||||
@@ -139,11 +151,8 @@ type RecordExtNet struct {
|
|||||||
// Meta
|
// Meta
|
||||||
Meta []interface{} `json:"_meta"`
|
Meta []interface{} `json:"_meta"`
|
||||||
|
|
||||||
// CheckIPs
|
|
||||||
CheckIPs []string `json:"checkIPs"`
|
|
||||||
|
|
||||||
// CheckIps
|
// CheckIps
|
||||||
CheckIps []string `json:"checkIps"`
|
CheckIPs []string `json:"checkIps"`
|
||||||
|
|
||||||
// Default
|
// Default
|
||||||
Default bool `json:"default"`
|
Default bool `json:"default"`
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type CreateRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create method will create a new FLIPGorup in the specified Account
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -60,7 +60,7 @@ func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGr
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := RecordFLIPGroup{}
|
info := RecordFLIPGroupCreated{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
err = json.Unmarshal(res, &info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type GetRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get gets details of the specified Floating IP group
|
// Get gets details of the specified Floating IP group
|
||||||
func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*ItemFLIPGroup, error) {
|
func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*RecordFLIPGroup, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -31,7 +31,7 @@ func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*ItemFLIPGroup, err
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := ItemFLIPGroup{}
|
info := RecordFLIPGroup{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
err = json.Unmarshal(res, &info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package flipgroup
|
package flipgroup
|
||||||
|
|
||||||
// Main information about FLIPGroup
|
// Main information about FLIPGroup
|
||||||
type RecordFLIPGroup struct {
|
type RecordFLIPGroupCreated struct {
|
||||||
// Default GW
|
// Default GW
|
||||||
DefaultGW string `json:"defaultGW"`
|
DefaultGW string `json:"defaultGW"`
|
||||||
|
|
||||||
@@ -18,6 +18,89 @@ type RecordFLIPGroup struct {
|
|||||||
NetMask uint64 `json:"netmask"`
|
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
|
// Detailed information about FLIPGroup
|
||||||
type ItemFLIPGroup struct {
|
type ItemFLIPGroup struct {
|
||||||
// CKey
|
// CKey
|
||||||
|
|||||||
@@ -40,21 +40,23 @@ func (li ListImages) FilterByBootType(bootType string) ListImages {
|
|||||||
func (li ListImages) FilterFunc(predicate func(ItemImage) bool) ListImages {
|
func (li ListImages) FilterFunc(predicate func(ItemImage) bool) ListImages {
|
||||||
var result ListImages
|
var result ListImages
|
||||||
|
|
||||||
for _, item := range li {
|
for _, item := range li.Data {
|
||||||
if predicate(item) {
|
if predicate(item) {
|
||||||
result = append(result, item)
|
result.Data = append(result.Data, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.EntryCount = uint64(len(result.Data))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindOne returns first found ItemImage
|
// FindOne returns first found ItemImage
|
||||||
// If none was found, returns an empty struct.
|
// If none was found, returns an empty struct.
|
||||||
func (li ListImages) FindOne() ItemImage {
|
func (li ListImages) FindOne() ItemImage {
|
||||||
if len(li) == 0 {
|
if len(li.Data) == 0 {
|
||||||
return ItemImage{}
|
return ItemImage{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return li[0]
|
return li.Data[0]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,66 +3,69 @@ package image
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
var images = ListImages{
|
var images = ListImages{
|
||||||
ItemImage{
|
Data: []ItemImage{
|
||||||
AccountID: 0,
|
{
|
||||||
Architecture: "X86_64",
|
AccountID: 0,
|
||||||
BootType: "bios",
|
Architecture: "X86_64",
|
||||||
Bootable: true,
|
BootType: "bios",
|
||||||
Description: "",
|
Bootable: true,
|
||||||
Drivers: []string{
|
Description: "",
|
||||||
"KVM_X86",
|
Drivers: []string{
|
||||||
|
"KVM_X86",
|
||||||
|
},
|
||||||
|
HotResize: true,
|
||||||
|
ID: 9882,
|
||||||
|
LinkTo: 0,
|
||||||
|
Name: "u16",
|
||||||
|
Pool: "vmstor",
|
||||||
|
Size: 5,
|
||||||
|
Status: "CREATED",
|
||||||
|
Type: "linux",
|
||||||
|
Username: "",
|
||||||
|
Virtual: false,
|
||||||
},
|
},
|
||||||
HotResize: true,
|
{
|
||||||
ID: 9882,
|
AccountID: 0,
|
||||||
LinkTo: 0,
|
Architecture: "X86_64",
|
||||||
Name: "u16",
|
BootType: "bois",
|
||||||
Pool: "vmstor",
|
Bootable: true,
|
||||||
Size: 5,
|
Description: "",
|
||||||
Status: "CREATED",
|
Drivers: []string{
|
||||||
Type: "linux",
|
"KVM_X86",
|
||||||
Username: "",
|
},
|
||||||
Virtual: false,
|
HotResize: false,
|
||||||
},
|
ID: 9884,
|
||||||
ItemImage{
|
LinkTo: 0,
|
||||||
AccountID: 0,
|
Name: "alpine-virt-3.17",
|
||||||
Architecture: "X86_64",
|
Pool: "vmstor",
|
||||||
BootType: "bois",
|
Size: 1,
|
||||||
Bootable: true,
|
Status: "CREATED",
|
||||||
Description: "",
|
Type: "linux",
|
||||||
Drivers: []string{
|
Username: "",
|
||||||
"KVM_X86",
|
Virtual: true,
|
||||||
},
|
},
|
||||||
HotResize: false,
|
{
|
||||||
ID: 9884,
|
AccountID: 1,
|
||||||
LinkTo: 0,
|
Architecture: "X86_64",
|
||||||
Name: "alpine-virt-3.17",
|
BootType: "bios",
|
||||||
Pool: "vmstor",
|
Bootable: true,
|
||||||
Size: 1,
|
Description: "",
|
||||||
Status: "CREATED",
|
Drivers: []string{
|
||||||
Type: "linux",
|
"KVM_X86",
|
||||||
Username: "",
|
},
|
||||||
Virtual: true,
|
HotResize: true,
|
||||||
},
|
ID: 9885,
|
||||||
ItemImage{
|
LinkTo: 0,
|
||||||
AccountID: 1,
|
Name: "test",
|
||||||
Architecture: "X86_64",
|
Pool: "vmstor",
|
||||||
BootType: "bios",
|
Size: 4,
|
||||||
Bootable: true,
|
Status: "DESTROYED",
|
||||||
Description: "",
|
Type: "linux",
|
||||||
Drivers: []string{
|
Username: "",
|
||||||
"KVM_X86",
|
Virtual: false,
|
||||||
},
|
},
|
||||||
HotResize: true,
|
|
||||||
ID: 9885,
|
|
||||||
LinkTo: 0,
|
|
||||||
Name: "test",
|
|
||||||
Pool: "vmstor",
|
|
||||||
Size: 4,
|
|
||||||
Status: "DESTROYED",
|
|
||||||
Type: "linux",
|
|
||||||
Username: "",
|
|
||||||
Virtual: false,
|
|
||||||
},
|
},
|
||||||
|
EntryCount: 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterByID(t *testing.T) {
|
func TestFilterByID(t *testing.T) {
|
||||||
@@ -84,11 +87,11 @@ func TestFilterByName(t *testing.T) {
|
|||||||
func TestFilterByStatus(t *testing.T) {
|
func TestFilterByStatus(t *testing.T) {
|
||||||
actual := images.FilterByStatus("CREATED")
|
actual := images.FilterByStatus("CREATED")
|
||||||
|
|
||||||
if len(actual) != 2 {
|
if len(actual.Data) != 2 {
|
||||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range actual {
|
for _, item := range actual.Data {
|
||||||
if item.Status != "CREATED" {
|
if item.Status != "CREATED" {
|
||||||
t.Fatal("expected Status 'CREATED', found: ", item.Status)
|
t.Fatal("expected Status 'CREATED', found: ", item.Status)
|
||||||
}
|
}
|
||||||
@@ -98,11 +101,11 @@ func TestFilterByStatus(t *testing.T) {
|
|||||||
func TestFilterByBootType(t *testing.T) {
|
func TestFilterByBootType(t *testing.T) {
|
||||||
actual := images.FilterByBootType("bios")
|
actual := images.FilterByBootType("bios")
|
||||||
|
|
||||||
if len(actual) != 2 {
|
if len(actual.Data) != 2 {
|
||||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range actual {
|
for _, item := range actual.Data {
|
||||||
if item.BootType != "bios" {
|
if item.BootType != "bios" {
|
||||||
t.Fatal("expected BootType 'bios', found: ", item.BootType)
|
t.Fatal("expected BootType 'bios', found: ", item.BootType)
|
||||||
}
|
}
|
||||||
@@ -110,15 +113,15 @@ func TestFilterByBootType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterFunc(t *testing.T) {
|
func TestFilterFunc(t *testing.T) {
|
||||||
actual := images.FilterFunc(func(ii ItemImage) bool {
|
actual := images.FilterFunc(func(ii ItemImage) bool {
|
||||||
return ii.Virtual == true
|
return ii.Virtual == true
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(actual) != 1 {
|
if len(actual.Data) != 1 {
|
||||||
t.Fatal("expected 1 found, actual: ", len(actual))
|
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
||||||
}
|
}
|
||||||
|
|
||||||
if actual[0].Virtual != true {
|
if actual.Data[0].Virtual != true {
|
||||||
t.Fatal("expected Virtual true, found false")
|
t.Fatal("expected Virtual true, found false")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,53 @@ import (
|
|||||||
|
|
||||||
// Request struct for get list available images
|
// Request struct for get list available images
|
||||||
type ListRequest struct {
|
type ListRequest struct {
|
||||||
// Optional account ID to include account images
|
// Find by storage endpoint provider ID
|
||||||
// Required: false
|
// Required: false
|
||||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||||
|
|
||||||
|
// Find by id
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by status
|
||||||
|
// Required: false
|
||||||
|
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||||
|
|
||||||
|
// Find by architecture
|
||||||
|
// Required: false
|
||||||
|
Architecture string `url:"architecture,omitempty" json:"architecture,omitempty"`
|
||||||
|
|
||||||
|
// Find by type
|
||||||
|
// Required: false
|
||||||
|
TypeImage string `url:"typeImage,omitempty" json:"typeImage,omitempty"`
|
||||||
|
|
||||||
|
// Find by image size
|
||||||
|
// Required: false
|
||||||
|
ImageSize uint64 `url:"imageSize,omitempty" json:"imageSize,omitempty"`
|
||||||
|
|
||||||
|
// Find by SEP name
|
||||||
|
// Required: false
|
||||||
|
SEPName string `url:"sepName,omitempty" json:"sepName,omitempty"`
|
||||||
|
|
||||||
|
// Find by pool
|
||||||
|
// Required: false
|
||||||
|
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||||
|
|
||||||
|
// Find by public True or False
|
||||||
|
// Required: false
|
||||||
|
Public bool `url:"public,omitempty" json:"public,omitempty"`
|
||||||
|
|
||||||
|
// Find by hot resize True or False
|
||||||
|
// Required: false
|
||||||
|
HotResize bool `url:"hotResize,omitempty" json:"hotResize,omitempty"`
|
||||||
|
|
||||||
|
// Find by bootable True or False
|
||||||
|
// Required: false
|
||||||
|
Bootable bool `url:"bootable,omitempty" json:"bootable,omitempty"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -22,7 +66,7 @@ type ListRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List gets list available images, optionally filtering by account ID
|
// List gets list available images, optionally filtering by account ID
|
||||||
func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) {
|
func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
|
||||||
url := "/cloudapi/image/list"
|
url := "/cloudapi/image/list"
|
||||||
|
|
||||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
@@ -37,5 +81,5 @@ func (i Image) List(ctx context.Context, req ListRequest) (ListImages, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,13 @@ type ItemImage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of information about images
|
// List of information about images
|
||||||
type ListImages []ItemImage
|
type ListImages struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemImage `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// History
|
// History
|
||||||
type History struct {
|
type History struct {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
// - First argument -> prefix
|
// - First argument -> prefix
|
||||||
// - Second argument -> indent
|
// - Second argument -> indent
|
||||||
func (li ListImages) Serialize(params ...string) (serialization.Serialized, error) {
|
func (li ListImages) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
if len(li) == 0 {
|
if len(li.Data) == 0 {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,26 @@ import (
|
|||||||
|
|
||||||
// Request struct for get list information about deleted images
|
// Request struct for get list information about deleted images
|
||||||
type ListDeletedRequest struct {
|
type ListDeletedRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"k8cId,omitempty" json:"k8cId,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by worker driver
|
||||||
|
// Required: false
|
||||||
|
WorkerDriver string `url:"workerDriver,omitempty" json:"workerDriver,omitempty"`
|
||||||
|
|
||||||
|
// Find by master driver
|
||||||
|
// Required: false
|
||||||
|
MasterDriver string `url:"masterDriver,omitempty" json:"masterDriver,omitempty"`
|
||||||
|
|
||||||
|
// Find by network plugin
|
||||||
|
// Required: false
|
||||||
|
NetworkPlugins string `url:"netPlugins,omitempty" json:"netPlugins,omitempty"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// type Params []string
|
||||||
|
|
||||||
// Request struct for create kubernetes cluster
|
// Request struct for create kubernetes cluster
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// Name of Kubernetes cluster
|
// Name of Kubernetes cluster
|
||||||
@@ -24,7 +26,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Name for first worker group created with cluster
|
// Name for first worker group created with cluster
|
||||||
// Required: true
|
// Required: true
|
||||||
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"`
|
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required,workerGroupName"`
|
||||||
|
|
||||||
// Network plugin
|
// Network plugin
|
||||||
// Must be one of these values: flannel, weawenet, calico
|
// Must be one of these values: flannel, weawenet, calico
|
||||||
@@ -98,18 +100,80 @@ type CreateRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
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.
|
// Create Kubernetes cluster with masters nodes behind load balancer if true.
|
||||||
// Otherwise give all cluster nodes direct external addresses from selected ExtNet
|
// Otherwise give all cluster nodes direct external addresses from selected ExtNet
|
||||||
// Required: false
|
// Required: false
|
||||||
WithLB bool `url:"withLB" json:"withLB"`
|
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:"highlyAvailable,omitempty" json:"highlyAvailable,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
|
// Text description of this Kubernetes cluster
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
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
|
// Create creates a new Kubernetes cluster in the specified Resource Group
|
||||||
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||||
|
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
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"
|
url := "/cloudapi/k8s/create"
|
||||||
|
|
||||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
|||||||
@@ -76,21 +76,23 @@ func (lkc ListK8SClusters) FilterByDeletedBy(deletedBy string) ListK8SClusters {
|
|||||||
func (lkc ListK8SClusters) FilterFunc(predicate func(ItemK8SCluster) bool) ListK8SClusters {
|
func (lkc ListK8SClusters) FilterFunc(predicate func(ItemK8SCluster) bool) ListK8SClusters {
|
||||||
var result ListK8SClusters
|
var result ListK8SClusters
|
||||||
|
|
||||||
for _, item := range lkc {
|
for _, item := range lkc.Data {
|
||||||
if predicate(item) {
|
if predicate(item) {
|
||||||
result = append(result, item)
|
result.Data = append(result.Data, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.EntryCount = uint64(len(result.Data))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindOne returns first found ItemK8SCluster
|
// FindOne returns first found ItemK8SCluster
|
||||||
// If none was found, returns an empty struct.
|
// If none was found, returns an empty struct.
|
||||||
func (lkc ListK8SClusters) FindOne() ItemK8SCluster {
|
func (lkc ListK8SClusters) FindOne() ItemK8SCluster {
|
||||||
if len(lkc) == 0 {
|
if len(lkc.Data) == 0 {
|
||||||
return ItemK8SCluster{}
|
return ItemK8SCluster{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lkc[0]
|
return lkc.Data[0]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,86 +3,88 @@ package k8s
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
var k8sItems = ListK8SClusters{
|
var k8sItems = ListK8SClusters{
|
||||||
ItemK8SCluster{
|
Data: []ItemK8SCluster{
|
||||||
AccountID: 1,
|
{
|
||||||
AccountName: "test_1",
|
AccountID: 1,
|
||||||
ACL: []interface{}{},
|
AccountName: "test_1",
|
||||||
BServiceID: 1,
|
ACL: []interface{}{},
|
||||||
CIID: 1,
|
BServiceID: 1,
|
||||||
Config: nil,
|
CIID: 1,
|
||||||
CreatedBy: "test_user",
|
Config: nil,
|
||||||
CreatedTime: 132454563,
|
CreatedBy: "test_user",
|
||||||
DeletedBy: "",
|
CreatedTime: 132454563,
|
||||||
DeletedTime: 0,
|
DeletedBy: "",
|
||||||
Description: "",
|
DeletedTime: 0,
|
||||||
ExtNetID: 1,
|
Description: "",
|
||||||
GID: 0,
|
ExtNetID: 1,
|
||||||
GUID: 1,
|
GID: 0,
|
||||||
ID: 1,
|
GUID: 1,
|
||||||
LBID: 1,
|
ID: 1,
|
||||||
Milestones: 999999,
|
LBID: 1,
|
||||||
Name: "k8s_1",
|
Milestones: 999999,
|
||||||
RGID: 1,
|
Name: "k8s_1",
|
||||||
RGName: "rg_1",
|
RGID: 1,
|
||||||
Status: "ENABLED",
|
RGName: "rg_1",
|
||||||
TechStatus: "STARTED",
|
Status: "ENABLED",
|
||||||
UpdatedBy: "",
|
TechStatus: "STARTED",
|
||||||
UpdatedTime: 0,
|
UpdatedBy: "",
|
||||||
VINSID: 0,
|
UpdatedTime: 0,
|
||||||
},
|
VINSID: 0,
|
||||||
ItemK8SCluster{
|
},
|
||||||
AccountID: 2,
|
{
|
||||||
AccountName: "test_2",
|
AccountID: 2,
|
||||||
ACL: []interface{}{},
|
AccountName: "test_2",
|
||||||
BServiceID: 2,
|
ACL: []interface{}{},
|
||||||
CIID: 2,
|
BServiceID: 2,
|
||||||
Config: nil,
|
CIID: 2,
|
||||||
CreatedBy: "test_user",
|
Config: nil,
|
||||||
CreatedTime: 132454638,
|
CreatedBy: "test_user",
|
||||||
DeletedBy: "",
|
CreatedTime: 132454638,
|
||||||
DeletedTime: 0,
|
DeletedBy: "",
|
||||||
Description: "",
|
DeletedTime: 0,
|
||||||
ExtNetID: 2,
|
Description: "",
|
||||||
GID: 0,
|
ExtNetID: 2,
|
||||||
GUID: 2,
|
GID: 0,
|
||||||
ID: 2,
|
GUID: 2,
|
||||||
LBID: 2,
|
ID: 2,
|
||||||
Milestones: 999999,
|
LBID: 2,
|
||||||
Name: "k8s_2",
|
Milestones: 999999,
|
||||||
RGID: 2,
|
Name: "k8s_2",
|
||||||
RGName: "rg_2",
|
RGID: 2,
|
||||||
Status: "ENABLED",
|
RGName: "rg_2",
|
||||||
TechStatus: "STARTED",
|
Status: "ENABLED",
|
||||||
UpdatedBy: "",
|
TechStatus: "STARTED",
|
||||||
UpdatedTime: 0,
|
UpdatedBy: "",
|
||||||
VINSID: 0,
|
UpdatedTime: 0,
|
||||||
},
|
VINSID: 0,
|
||||||
ItemK8SCluster{
|
},
|
||||||
AccountID: 3,
|
{
|
||||||
AccountName: "test_3",
|
AccountID: 3,
|
||||||
ACL: []interface{}{},
|
AccountName: "test_3",
|
||||||
BServiceID: 3,
|
ACL: []interface{}{},
|
||||||
CIID: 3,
|
BServiceID: 3,
|
||||||
Config: nil,
|
CIID: 3,
|
||||||
CreatedBy: "test_user",
|
Config: nil,
|
||||||
CreatedTime: 132454682,
|
CreatedBy: "test_user",
|
||||||
DeletedBy: "",
|
CreatedTime: 132454682,
|
||||||
DeletedTime: 0,
|
DeletedBy: "",
|
||||||
Description: "",
|
DeletedTime: 0,
|
||||||
ExtNetID: 3,
|
Description: "",
|
||||||
GID: 0,
|
ExtNetID: 3,
|
||||||
GUID: 3,
|
GID: 0,
|
||||||
ID: 3,
|
GUID: 3,
|
||||||
LBID: 3,
|
ID: 3,
|
||||||
Milestones: 999999,
|
LBID: 3,
|
||||||
Name: "k8s_3",
|
Milestones: 999999,
|
||||||
RGID: 3,
|
Name: "k8s_3",
|
||||||
RGName: "rg_3",
|
RGID: 3,
|
||||||
Status: "DISABLED",
|
RGName: "rg_3",
|
||||||
TechStatus: "STOPPED",
|
Status: "DISABLED",
|
||||||
UpdatedBy: "",
|
TechStatus: "STOPPED",
|
||||||
UpdatedTime: 0,
|
UpdatedBy: "",
|
||||||
VINSID: 0,
|
UpdatedTime: 0,
|
||||||
|
VINSID: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,11 +123,11 @@ func TestFilterByRGID(t *testing.T) {
|
|||||||
func TestFilterByStatus(t *testing.T) {
|
func TestFilterByStatus(t *testing.T) {
|
||||||
actual := k8sItems.FilterByStatus("ENABLED")
|
actual := k8sItems.FilterByStatus("ENABLED")
|
||||||
|
|
||||||
if len(actual) != 2 {
|
if len(actual.Data) != 2 {
|
||||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range actual {
|
for _, item := range actual.Data {
|
||||||
if item.Status != "ENABLED" {
|
if item.Status != "ENABLED" {
|
||||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||||
}
|
}
|
||||||
@@ -135,11 +137,11 @@ func TestFilterByStatus(t *testing.T) {
|
|||||||
func TestFilterByTechStatus(t *testing.T) {
|
func TestFilterByTechStatus(t *testing.T) {
|
||||||
actual := k8sItems.FilterByTechStatus("STARTED")
|
actual := k8sItems.FilterByTechStatus("STARTED")
|
||||||
|
|
||||||
if len(actual) != 2 {
|
if len(actual.Data) != 2 {
|
||||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range actual {
|
for _, item := range actual.Data {
|
||||||
if item.TechStatus != "STARTED" {
|
if item.TechStatus != "STARTED" {
|
||||||
t.Fatal("expected TechStatus 'STARTED', found: ", item.TechStatus)
|
t.Fatal("expected TechStatus 'STARTED', found: ", item.TechStatus)
|
||||||
}
|
}
|
||||||
@@ -149,11 +151,11 @@ func TestFilterByTechStatus(t *testing.T) {
|
|||||||
func TestFilterByCreatedBy(t *testing.T) {
|
func TestFilterByCreatedBy(t *testing.T) {
|
||||||
actual := k8sItems.FilterByCreatedBy("test_user")
|
actual := k8sItems.FilterByCreatedBy("test_user")
|
||||||
|
|
||||||
if len(actual) != 3 {
|
if len(actual.Data) != 3 {
|
||||||
t.Fatal("expected 3 found, actual: ", len(actual))
|
t.Fatal("expected 3 found, actual: ", len(actual.Data))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range actual {
|
for _, item := range actual.Data {
|
||||||
if item.CreatedBy != "test_user" {
|
if item.CreatedBy != "test_user" {
|
||||||
t.Fatal("expected CreatedBy 'test_user', found: ", item.CreatedBy)
|
t.Fatal("expected CreatedBy 'test_user', found: ", item.CreatedBy)
|
||||||
}
|
}
|
||||||
@@ -163,8 +165,8 @@ func TestFilterByCreatedBy(t *testing.T) {
|
|||||||
func TestFilterByDeletedBy(t *testing.T) {
|
func TestFilterByDeletedBy(t *testing.T) {
|
||||||
actual := k8sItems.FilterByDeletedBy("test_user")
|
actual := k8sItems.FilterByDeletedBy("test_user")
|
||||||
|
|
||||||
if len(actual) != 0 {
|
if len(actual.Data) != 0 {
|
||||||
t.Fatal("expected 0 found, actual: ", len(actual))
|
t.Fatal("expected 0 found, actual: ", len(actual.Data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +184,7 @@ func TestFilterFunc(t *testing.T) {
|
|||||||
func TestSortByCreatedTime(t *testing.T) {
|
func TestSortByCreatedTime(t *testing.T) {
|
||||||
actual := k8sItems.SortByCreatedTime(false)
|
actual := k8sItems.SortByCreatedTime(false)
|
||||||
|
|
||||||
if actual[0].CreatedTime != 132454563 || actual[2].CreatedTime != 132454682 {
|
if actual.Data[0].CreatedTime != 132454563 || actual.Data[2].CreatedTime != 132454682 {
|
||||||
t.Fatal("expected ascending sort, seems to be inversed")
|
t.Fatal("expected ascending sort, seems to be inversed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
pkg/cloudapi/k8s/get_worker_nodes_meta_data.go
Normal file
38
pkg/cloudapi/k8s/get_worker_nodes_meta_data.go
Normal 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
|
||||||
|
}
|
||||||
@@ -8,6 +8,38 @@ import (
|
|||||||
|
|
||||||
// Request struct for get list information K8S
|
// Request struct for get list information K8S
|
||||||
type ListRequest struct {
|
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 IP address
|
||||||
|
// Required: false
|
||||||
|
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group ID
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by lbId
|
||||||
|
// Required: false
|
||||||
|
LBID uint64 `url:"lbId,omitempty" json:"lbId,omitempty"`
|
||||||
|
|
||||||
|
// Find by basicServiceId
|
||||||
|
// 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"`
|
||||||
|
|
||||||
// Include deleted clusters in result
|
// Include deleted clusters in result
|
||||||
// Required: false
|
// Required: false
|
||||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||||
@@ -22,7 +54,7 @@ type ListRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List gets list all kubernetes clusters the user has access to
|
// List gets list all kubernetes clusters the user has access to
|
||||||
func (k8s K8S) List(ctx context.Context, req ListRequest) (ListK8SClusters, error) {
|
func (k8s K8S) List(ctx context.Context, req ListRequest) (*ListK8SClusters, error) {
|
||||||
url := "/cloudapi/k8s/list"
|
url := "/cloudapi/k8s/list"
|
||||||
|
|
||||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
@@ -37,5 +69,5 @@ func (k8s K8S) List(ctx context.Context, req ListRequest) (ListK8SClusters, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,38 @@ import (
|
|||||||
|
|
||||||
// Request struct for get list deleted kubernetes cluster
|
// Request struct for get list deleted kubernetes cluster
|
||||||
type ListDeletedRequest struct {
|
type ListDeletedRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by IP address
|
||||||
|
// Required: false
|
||||||
|
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group ID
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by lbId
|
||||||
|
// Required: false
|
||||||
|
LBID uint64 `url:"lbId,omitempty" json:"lbId,omitempty"`
|
||||||
|
|
||||||
|
// Find by basicServiceId
|
||||||
|
// 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"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
@@ -18,7 +50,7 @@ type ListDeletedRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListDeleted gets all deleted kubernetes clusters the user has access to
|
// ListDeleted gets all deleted kubernetes clusters the user has access to
|
||||||
func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8SClusters, error) {
|
func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8SClusters, error) {
|
||||||
url := "/cloudapi/k8s/listDeleted"
|
url := "/cloudapi/k8s/listDeleted"
|
||||||
|
|
||||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
@@ -33,5 +65,5 @@ func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8S
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ type ListK8SGroups []ItemK8SGroup
|
|||||||
|
|
||||||
// Detailed information
|
// Detailed information
|
||||||
type ItemDetailedInfo struct {
|
type ItemDetailedInfo struct {
|
||||||
|
// Externalip
|
||||||
|
Externalip string `json:"externalip"`
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
@@ -293,4 +296,10 @@ type RecordServiceAccount struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of kubernetes clusters
|
// List of kubernetes clusters
|
||||||
type ListK8SClusters []ItemK8SCluster
|
type ListK8SClusters struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemK8SCluster `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
// - First argument -> prefix
|
// - First argument -> prefix
|
||||||
// - Second argument -> indent
|
// - Second argument -> indent
|
||||||
func (lkc ListK8SClusters) Serialize(params ...string) (serialization.Serialized, error) {
|
func (lkc ListK8SClusters) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
if len(lkc) == 0 {
|
if len(lkc.Data) == 0 {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import "sort"
|
|||||||
//
|
//
|
||||||
// If inverse param is set to true, the order is reversed.
|
// If inverse param is set to true, the order is reversed.
|
||||||
func (lkc ListK8SClusters) SortByCreatedTime(inverse bool) ListK8SClusters {
|
func (lkc ListK8SClusters) SortByCreatedTime(inverse bool) ListK8SClusters {
|
||||||
if len(lkc) < 2 {
|
if len(lkc.Data) < 2 {
|
||||||
return lkc
|
return lkc
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(lkc, func(i, j int) bool {
|
sort.Slice(lkc.Data, func(i, j int) bool {
|
||||||
if inverse {
|
if inverse {
|
||||||
return lkc[i].CreatedTime > lkc[j].CreatedTime
|
return lkc.Data[i].CreatedTime > lkc.Data[j].CreatedTime
|
||||||
}
|
}
|
||||||
|
|
||||||
return lkc[i].CreatedTime < lkc[j].CreatedTime
|
return lkc.Data[i].CreatedTime < lkc.Data[j].CreatedTime
|
||||||
})
|
})
|
||||||
|
|
||||||
return lkc
|
return lkc
|
||||||
@@ -25,16 +25,16 @@ func (lkc ListK8SClusters) SortByCreatedTime(inverse bool) ListK8SClusters {
|
|||||||
//
|
//
|
||||||
// If inverse param is set to true, the order is reversed.
|
// If inverse param is set to true, the order is reversed.
|
||||||
func (lkc ListK8SClusters) SortByUpdatedTime(inverse bool) ListK8SClusters {
|
func (lkc ListK8SClusters) SortByUpdatedTime(inverse bool) ListK8SClusters {
|
||||||
if len(lkc) < 2 {
|
if len(lkc.Data) < 2 {
|
||||||
return lkc
|
return lkc
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(lkc, func(i, j int) bool {
|
sort.Slice(lkc.Data, func(i, j int) bool {
|
||||||
if inverse {
|
if inverse {
|
||||||
return lkc[i].UpdatedTime > lkc[j].UpdatedTime
|
return lkc.Data[i].UpdatedTime > lkc.Data[j].UpdatedTime
|
||||||
}
|
}
|
||||||
|
|
||||||
return lkc[i].UpdatedTime < lkc[j].UpdatedTime
|
return lkc.Data[i].UpdatedTime < lkc.Data[j].UpdatedTime
|
||||||
})
|
})
|
||||||
|
|
||||||
return lkc
|
return lkc
|
||||||
@@ -44,16 +44,16 @@ func (lkc ListK8SClusters) SortByUpdatedTime(inverse bool) ListK8SClusters {
|
|||||||
//
|
//
|
||||||
// If inverse param is set to true, the order is reversed.
|
// If inverse param is set to true, the order is reversed.
|
||||||
func (lkc ListK8SClusters) SortByDeletedTime(inverse bool) ListK8SClusters {
|
func (lkc ListK8SClusters) SortByDeletedTime(inverse bool) ListK8SClusters {
|
||||||
if len(lkc) < 2 {
|
if len(lkc.Data) < 2 {
|
||||||
return lkc
|
return lkc
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(lkc, func(i, j int) bool {
|
sort.Slice(lkc.Data, func(i, j int) bool {
|
||||||
if inverse {
|
if inverse {
|
||||||
return lkc[i].DeletedTime > lkc[j].DeletedTime
|
return lkc.Data[i].DeletedTime > lkc.Data[j].DeletedTime
|
||||||
}
|
}
|
||||||
|
|
||||||
return lkc[i].DeletedTime < lkc[j].DeletedTime
|
return lkc.Data[i].DeletedTime < lkc.Data[j].DeletedTime
|
||||||
})
|
})
|
||||||
|
|
||||||
return lkc
|
return lkc
|
||||||
|
|||||||
48
pkg/cloudapi/k8s/update_worker_nodes_meta_data.go
Normal file
48
pkg/cloudapi/k8s/update_worker_nodes_meta_data.go
Normal 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
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,8 +19,8 @@ type WorkerAddRequest struct {
|
|||||||
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||||
|
|
||||||
// How many worker nodes to add
|
// How many worker nodes to add
|
||||||
// Required: true
|
// Required: false
|
||||||
Num uint64 `url:"num" json:"num" validate:"required"`
|
Num uint64 `url:"num,omitempty" json:"num,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WorkerAdd add worker nodes to a Kubernetes cluster
|
// WorkerAdd add worker nodes to a Kubernetes cluster
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type WorkersGroupGetByNameRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WorkersGroupGetByName gets worker group metadata by name
|
// WorkersGroupGetByName gets worker group metadata by name
|
||||||
func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*RecordK8SGroups, error) {
|
func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*ItemK8SGroup, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -35,7 +35,7 @@ func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByN
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := RecordK8SGroups{}
|
info := ItemK8SGroup{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
err = json.Unmarshal(res, &info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -2,12 +2,30 @@ package kvmppc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Interface struct {
|
||||||
|
// Network type
|
||||||
|
// Should be one of:
|
||||||
|
// - VINS
|
||||||
|
// - EXTNET
|
||||||
|
NetType string `url:"netType" json:"netType" validate:"required,kvmNetType"`
|
||||||
|
|
||||||
|
// Network ID for connect to,
|
||||||
|
// for EXTNET - external network ID,
|
||||||
|
// for VINS - VINS ID,
|
||||||
|
NetID uint64 `url:"netId" json:"netId" validate:"required"`
|
||||||
|
|
||||||
|
// IP address to assign to this VM when connecting to the specified network
|
||||||
|
// Required: false
|
||||||
|
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Request struct for create KVM PowerPC VM
|
// Request struct for create KVM PowerPC VM
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// ID of the resource group, which will own this VM
|
// ID of the resource group, which will own this VM
|
||||||
@@ -45,24 +63,11 @@ type CreateRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||||
|
|
||||||
// Network type
|
// Slice of structs with net interface description.
|
||||||
// Should be one of:
|
// If not specified, compute will be created with default interface from RG.
|
||||||
// - VINS
|
// To create compute without interfaces, pass initialized empty slice .
|
||||||
// - EXTNET
|
|
||||||
// - NONE
|
|
||||||
// Required: false
|
// Required: false
|
||||||
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"`
|
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||||
|
|
||||||
// Network ID for connect to,
|
|
||||||
// for EXTNET - external network ID,
|
|
||||||
// for ViNS - ViNS ID,
|
|
||||||
// when netType is not "NONE"
|
|
||||||
// Required: false
|
|
||||||
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
|
|
||||||
|
|
||||||
// IP address to assign to this VM when connecting to the specified network
|
|
||||||
// Required: false
|
|
||||||
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
|
|
||||||
|
|
||||||
// Input data for cloud-init facility
|
// Input data for cloud-init facility
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -74,7 +79,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// System name
|
// System name
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -85,6 +90,11 @@ type CreateRequest struct {
|
|||||||
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type wrapperCreateRequest struct {
|
||||||
|
CreateRequest
|
||||||
|
Interfaces []string `url:"interfaces,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Create creates KVM PowerPC VM based on specified OS image
|
// Create creates KVM PowerPC VM based on specified OS image
|
||||||
func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -94,9 +104,31 @@ func (k KVMPPC) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var interfaces []string
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||||
|
interfaces = []string{"[]"}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequest{
|
||||||
|
CreateRequest: req,
|
||||||
|
Interfaces: interfaces,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/kvmppc/create"
|
url := "/cloudapi/kvmppc/create"
|
||||||
|
|
||||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package kvmppc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ type CreateBlankRequest struct {
|
|||||||
// Required: true
|
// Required: true
|
||||||
BootDisk uint64 `url:"bootDisk" json:"bootDisk" validate:"required"`
|
BootDisk uint64 `url:"bootDisk" json:"bootDisk" validate:"required"`
|
||||||
|
|
||||||
// ID of SEP to create boot disk on.
|
// ID of SEP to create boot disk on
|
||||||
// Uses images SEP ID if not set
|
// Uses images SEP ID if not set
|
||||||
// Required: true
|
// Required: true
|
||||||
SEPID uint64 `url:"sepId" json:"sepId" validate:"required"`
|
SEPID uint64 `url:"sepId" json:"sepId" validate:"required"`
|
||||||
@@ -40,30 +41,22 @@ type CreateBlankRequest struct {
|
|||||||
// Required: true
|
// Required: true
|
||||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||||
|
|
||||||
// Network type
|
// Slice of structs with net interface description.
|
||||||
// Should be one of:
|
// If not specified, compute will be created with default interface from RG.
|
||||||
// - VINS
|
// To create compute without interfaces, pass initialized empty slice .
|
||||||
// - EXTNET
|
|
||||||
// - NONE
|
|
||||||
// Required: false
|
// Required: false
|
||||||
NetType string `url:"netType,omitempty" json:"netType,omitempty" validate:"omitempty,kvmNetType"`
|
Interfaces []Interface `url:"-" json:"interfaces,omitempty" validate:"omitempty,dive"`
|
||||||
|
|
||||||
// Network ID for connect to,
|
|
||||||
// for EXTNET - external network ID,
|
|
||||||
// for VINS - VINS ID,
|
|
||||||
// when network type is not "NONE"
|
|
||||||
// Required: false
|
|
||||||
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
|
|
||||||
|
|
||||||
// IP address to assign to this VM when connecting to the specified network
|
|
||||||
// Required: false
|
|
||||||
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
|
|
||||||
|
|
||||||
// Text description of this VM
|
// Text description of this VM
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type wrapperCreateBlankRequest struct {
|
||||||
|
CreateBlankRequest
|
||||||
|
Interfaces []string `url:"interfaces,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// CreateBlank creates KVM PowerPC VM from scratch
|
// CreateBlank creates KVM PowerPC VM from scratch
|
||||||
func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
|
func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -73,9 +66,31 @@ func (k KVMPPC) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var interfaces []string
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||||
|
interfaces = []string{"[]"}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateBlankRequest{
|
||||||
|
CreateBlankRequest: req,
|
||||||
|
Interfaces: interfaces,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/kvmppc/createBlank"
|
url := "/cloudapi/kvmppc/createBlank"
|
||||||
|
|
||||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package kvmx86
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -63,7 +64,10 @@ type CreateRequest struct {
|
|||||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||||
|
|
||||||
// Slice of structs with net interface description.
|
// Slice of structs with net interface description.
|
||||||
Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"`
|
// 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,dive"`
|
||||||
|
|
||||||
// Input data for cloud-init facility
|
// Input data for cloud-init facility
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -75,7 +79,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// System name
|
// System name
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -84,6 +88,19 @@ type CreateRequest struct {
|
|||||||
// Compute purpose
|
// Compute purpose
|
||||||
// Required: false
|
// Required: false
|
||||||
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
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 {
|
||||||
|
CreateRequest
|
||||||
|
Interfaces []string `url:"interfaces,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates KVM x86 VM based on specified OS image
|
// Create creates KVM x86 VM based on specified OS image
|
||||||
@@ -95,9 +112,31 @@ func (k KVMX86) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var interfaces []string
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||||
|
interfaces = []string{"[]"}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequest{
|
||||||
|
CreateRequest: req,
|
||||||
|
Interfaces: interfaces,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/kvmx86/create"
|
url := "/cloudapi/kvmx86/create"
|
||||||
|
|
||||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package kvmx86
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -41,12 +42,25 @@ type CreateBlankRequest struct {
|
|||||||
Pool string `url:"pool" json:"pool" validate:"required"`
|
Pool string `url:"pool" json:"pool" validate:"required"`
|
||||||
|
|
||||||
// Slice of structs with net interface description.
|
// Slice of structs with net interface description.
|
||||||
Interfaces []Interface `url:"interfaces,omitempty" json:"interfaces,omitempty" validate:"omitempty,min=1,dive"`
|
// 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,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
|
// Text description of this VM
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type wrapperCreateBlankRequest struct {
|
||||||
|
CreateBlankRequest
|
||||||
|
Interfaces []string `url:"interfaces,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// CreateBlank creates KVM x86 VM from scratch
|
// CreateBlank creates KVM x86 VM from scratch
|
||||||
func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
|
func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -56,9 +70,31 @@ func (k KVMX86) CreateBlank(ctx context.Context, req CreateBlankRequest) (uint64
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var interfaces []string
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
} else if req.Interfaces != nil && len(req.Interfaces) == 0 {
|
||||||
|
interfaces = []string{"[]"}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateBlankRequest{
|
||||||
|
CreateBlankRequest: req,
|
||||||
|
Interfaces: interfaces,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/kvmx86/createBlank"
|
url := "/cloudapi/kvmx86/createBlank"
|
||||||
|
|
||||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ package lb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strconv"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Params []string
|
||||||
|
|
||||||
// Request struct for create load balancer
|
// Request struct for create load balancer
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// ID of the resource group where this load balancer instance will be located
|
// 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"`
|
Name string `url:"name" json:"name" validate:"required"`
|
||||||
|
|
||||||
// External network to connect this load balancer to
|
// External network to connect this load balancer to
|
||||||
// Required: true
|
// Required: false
|
||||||
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
ExtNetID uint64 `url:"extnetId" json:"extnetId"`
|
||||||
|
|
||||||
// Internal network (VINS) to connect this load balancer to
|
// Internal network (VINS) to connect this load balancer to
|
||||||
// Required: true
|
// Required: false
|
||||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
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
|
// Start now Load balancer
|
||||||
// Required: true
|
// Required: false
|
||||||
Start bool `url:"start" json:"start" validate:"required"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Text description of this load balancer
|
// Text description of this load balancer
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
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
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
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"
|
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 {
|
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
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FilterByK8SID returns ListLB used by specified K8S cluster.
|
// FilterByK8SID returns ListLB used by specified K8S cluster.
|
||||||
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListLB, error) {
|
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListLB, error) {
|
||||||
caller := k8s.New(decortClient)
|
caller := k8s.New(decortClient)
|
||||||
|
|
||||||
req := k8s.GetRequest{
|
req := k8s.GetRequest{
|
||||||
@@ -60,28 +60,32 @@ func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient i
|
|||||||
return cluster.LBID == ill.ID
|
return cluster.LBID == ill.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
return ll.FilterFunc(predicate), nil
|
result := ll.FilterFunc(predicate)
|
||||||
|
|
||||||
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilterFunc allows filtering ListLB based on a user-specified predicate.
|
// FilterFunc allows filtering ListLB based on a user-specified predicate.
|
||||||
func (ll ListLB) FilterFunc(predicate func(ItemLoadBalancer) bool) ListLB {
|
func (ll ListLB) FilterFunc(predicate func(ItemLoadBalancer) bool) ListLB {
|
||||||
var result ListLB
|
var result ListLB
|
||||||
|
|
||||||
for _, item := range ll {
|
for _, item := range ll.Data {
|
||||||
if predicate(item) {
|
if predicate(item) {
|
||||||
result = append(result, item)
|
result.Data = append(result.Data, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.EntryCount = uint64(len(ll.Data))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindOne returns first found ItemLoadBalancer
|
// FindOne returns first found ItemLoadBalancer
|
||||||
// If none was found, returns an empty struct.
|
// If none was found, returns an empty struct.
|
||||||
func (ll ListLB) FindOne() ItemLoadBalancer {
|
func (ll ListLB) FindOne() ItemLoadBalancer {
|
||||||
if len(ll) == 0 {
|
if len(ll.Data) == 0 {
|
||||||
return ItemLoadBalancer{}
|
return ItemLoadBalancer{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ll[0]
|
return ll.Data[0]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,93 +3,96 @@ package lb
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
var lbs = ListLB{
|
var lbs = ListLB{
|
||||||
ItemLoadBalancer{
|
Data: []ItemLoadBalancer{
|
||||||
DPAPIPassword: "0000",
|
{
|
||||||
RecordLB: RecordLB{
|
DPAPIPassword: "0000",
|
||||||
HAMode: true,
|
RecordLB: RecordLB{
|
||||||
ACL: []interface{}{},
|
HAMode: true,
|
||||||
Backends: []ItemBackend{},
|
ACL: []interface{}{},
|
||||||
CreatedBy: "test_user_1",
|
Backends: []ItemBackend{},
|
||||||
CreatedTime: 1636667448,
|
CreatedBy: "test_user_1",
|
||||||
DeletedBy: "",
|
CreatedTime: 1636667448,
|
||||||
DeletedTime: 0,
|
DeletedBy: "",
|
||||||
Description: "",
|
DeletedTime: 0,
|
||||||
DPAPIUser: "api_user",
|
Description: "",
|
||||||
ExtNetID: 2522,
|
DPAPIUser: "api_user",
|
||||||
Frontends: []ItemFrontend{},
|
ExtNetID: 2522,
|
||||||
GID: 212,
|
Frontends: []ItemFrontend{},
|
||||||
GUID: 1,
|
GID: 212,
|
||||||
ID: 1,
|
GUID: 1,
|
||||||
ImageID: 2121,
|
ID: 1,
|
||||||
Milestones: 129000,
|
ImageID: 2121,
|
||||||
Name: "k8s-lb-test-1",
|
Milestones: 129000,
|
||||||
RGID: 25090,
|
Name: "k8s-lb-test-1",
|
||||||
RGName: "",
|
RGID: 25090,
|
||||||
Status: "ENABLED",
|
RGName: "",
|
||||||
TechStatus: "STARTED",
|
Status: "ENABLED",
|
||||||
UpdatedBy: "",
|
TechStatus: "STARTED",
|
||||||
UpdatedTime: 0,
|
UpdatedBy: "",
|
||||||
VINSID: 101,
|
UpdatedTime: 0,
|
||||||
},
|
VINSID: 101,
|
||||||
},
|
},
|
||||||
ItemLoadBalancer{
|
},
|
||||||
DPAPIPassword: "0000",
|
{
|
||||||
RecordLB: RecordLB{
|
DPAPIPassword: "0000",
|
||||||
HAMode: false,
|
RecordLB: RecordLB{
|
||||||
ACL: []interface{}{},
|
HAMode: false,
|
||||||
Backends: []ItemBackend{},
|
ACL: []interface{}{},
|
||||||
CreatedBy: "test_user_2",
|
Backends: []ItemBackend{},
|
||||||
CreatedTime: 1636667506,
|
CreatedBy: "test_user_2",
|
||||||
DeletedBy: "",
|
CreatedTime: 1636667506,
|
||||||
DeletedTime: 0,
|
DeletedBy: "",
|
||||||
Description: "",
|
DeletedTime: 0,
|
||||||
DPAPIUser: "api_user_2",
|
Description: "",
|
||||||
ExtNetID: 2524,
|
DPAPIUser: "api_user_2",
|
||||||
Frontends: []ItemFrontend{},
|
ExtNetID: 2524,
|
||||||
GID: 212,
|
Frontends: []ItemFrontend{},
|
||||||
GUID: 2,
|
GID: 212,
|
||||||
ID: 2,
|
GUID: 2,
|
||||||
ImageID: 2129,
|
ID: 2,
|
||||||
Milestones: 129013,
|
ImageID: 2129,
|
||||||
Name: "k8s-lb-test-2",
|
Milestones: 129013,
|
||||||
RGID: 25092,
|
Name: "k8s-lb-test-2",
|
||||||
RGName: "",
|
RGID: 25092,
|
||||||
Status: "ENABLED",
|
RGName: "",
|
||||||
TechStatus: "STOPPED",
|
Status: "ENABLED",
|
||||||
UpdatedBy: "",
|
TechStatus: "STOPPED",
|
||||||
UpdatedTime: 0,
|
UpdatedBy: "",
|
||||||
VINSID: 102,
|
UpdatedTime: 0,
|
||||||
},
|
VINSID: 102,
|
||||||
},
|
},
|
||||||
ItemLoadBalancer{
|
},
|
||||||
DPAPIPassword: "0000",
|
{
|
||||||
RecordLB: RecordLB{
|
DPAPIPassword: "0000",
|
||||||
HAMode: true,
|
RecordLB: RecordLB{
|
||||||
ACL: []interface{}{},
|
HAMode: true,
|
||||||
Backends: []ItemBackend{},
|
ACL: []interface{}{},
|
||||||
CreatedBy: "te2t_user_3",
|
Backends: []ItemBackend{},
|
||||||
CreatedTime: 1636667534,
|
CreatedBy: "te2t_user_3",
|
||||||
DeletedBy: "",
|
CreatedTime: 1636667534,
|
||||||
DeletedTime: 0,
|
DeletedBy: "",
|
||||||
Description: "",
|
DeletedTime: 0,
|
||||||
DPAPIUser: "api_user_3",
|
Description: "",
|
||||||
ExtNetID: 2536,
|
DPAPIUser: "api_user_3",
|
||||||
Frontends: []ItemFrontend{},
|
ExtNetID: 2536,
|
||||||
GID: 212,
|
Frontends: []ItemFrontend{},
|
||||||
GUID: 3,
|
GID: 212,
|
||||||
ID: 3,
|
GUID: 3,
|
||||||
ImageID: 2139,
|
ID: 3,
|
||||||
Milestones: 129025,
|
ImageID: 2139,
|
||||||
Name: "k8s-lb-test-3",
|
Milestones: 129025,
|
||||||
RGID: 25106,
|
Name: "k8s-lb-test-3",
|
||||||
RGName: "",
|
RGID: 25106,
|
||||||
Status: "DISABLED",
|
RGName: "",
|
||||||
TechStatus: "STOPPED",
|
Status: "DISABLED",
|
||||||
UpdatedBy: "",
|
TechStatus: "STOPPED",
|
||||||
UpdatedTime: 0,
|
UpdatedBy: "",
|
||||||
VINSID: 118,
|
UpdatedTime: 0,
|
||||||
|
VINSID: 118,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
EntryCount: 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterByID(t *testing.T) {
|
func TestFilterByID(t *testing.T) {
|
||||||
@@ -129,7 +132,7 @@ func TestFilterFunc(t *testing.T) {
|
|||||||
return rl.Status == "DISABLED"
|
return rl.Status == "DISABLED"
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, item := range actual {
|
for _, item := range actual.Data {
|
||||||
if item.Status != "DISABLED" {
|
if item.Status != "DISABLED" {
|
||||||
t.Fatal("expected Status 'DISABLED', found: ", item.Status)
|
t.Fatal("expected Status 'DISABLED', found: ", item.Status)
|
||||||
}
|
}
|
||||||
@@ -139,7 +142,7 @@ func TestFilterFunc(t *testing.T) {
|
|||||||
func TestSortByCreatedTime(t *testing.T) {
|
func TestSortByCreatedTime(t *testing.T) {
|
||||||
actual := lbs.SortByCreatedTime(true)
|
actual := lbs.SortByCreatedTime(true)
|
||||||
|
|
||||||
if actual[0].CreatedTime != 1636667534 || actual[2].CreatedTime != 1636667448 {
|
if actual.Data[0].CreatedTime != 1636667534 || actual.Data[2].CreatedTime != 1636667448 {
|
||||||
t.Fatal("expected descending order, found ascending")
|
t.Fatal("expected descending order, found ascending")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,18 @@ type FrontendBindRequest struct {
|
|||||||
|
|
||||||
// Name of the binding to update
|
// Name of the binding to update
|
||||||
// Required: true
|
// 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,
|
// 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.
|
// where this load balancer is connected - new IP address to use for this binding.
|
||||||
// If omitted, current IP address is retained
|
// If omitted, current IP address is retained
|
||||||
// Required: false
|
// Required: true
|
||||||
BindingAddress string `url:"bindingAddress,omitempty" json:"bindingAddress,omitempty"`
|
BindingAddress string `url:"bindingAddress" json:"bindingAddress" validate:"required"`
|
||||||
|
|
||||||
// New port number to use for this binding.
|
// New port number to use for this binding.
|
||||||
// If omitted, current port number is retained
|
// If omitted, current port number is retained
|
||||||
// Required: false
|
// Required: true
|
||||||
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
|
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FrontendBind bind frontend from specified load balancer instance
|
// FrontendBind bind frontend from specified load balancer instance
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ type FrontendBindUpdateRequest struct {
|
|||||||
// If specified must be within the IP range of either Ext Net or ViNS,
|
// 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.
|
// where this load balancer is connected - new IP address to use for this binding.
|
||||||
// If omitted, current IP address is retained
|
// If omitted, current IP address is retained
|
||||||
// Required: false
|
// Required: true
|
||||||
BindingAddress string `url:"bindingAddress,omitempty" json:"bindingAddress,omitempty"`
|
BindingAddress string `url:"bindingAddress" json:"bindingAddress" validate:"required"`
|
||||||
|
|
||||||
// New port number to use for this binding.
|
// New port number to use for this binding.
|
||||||
// If omitted, current port number is retained
|
// If omitted, current port number is retained
|
||||||
// Required: false
|
// Required: true
|
||||||
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
|
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FrontendBindUpdate updates binding for the specified load balancer frontend
|
// FrontendBindUpdate updates binding for the specified load balancer frontend
|
||||||
|
|||||||
@@ -8,6 +8,38 @@ import (
|
|||||||
|
|
||||||
// Request struct for get list of load balancers
|
// Request struct for get list of load balancers
|
||||||
type ListRequest struct {
|
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 account ID
|
||||||
|
// Required: false
|
||||||
|
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group ID
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by tech status
|
||||||
|
// Required: false
|
||||||
|
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||||
|
|
||||||
|
// Find by status
|
||||||
|
// Required: false
|
||||||
|
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||||
|
|
||||||
|
// Find by frontend Ip
|
||||||
|
// Required: false
|
||||||
|
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
|
||||||
|
|
||||||
|
// Find by backend Ip
|
||||||
|
// Required: false
|
||||||
|
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
|
||||||
|
|
||||||
// Included deleted load balancers
|
// Included deleted load balancers
|
||||||
// Required: false
|
// Required: false
|
||||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
||||||
@@ -22,7 +54,7 @@ type ListRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List gets list all load balancers
|
// List gets list all load balancers
|
||||||
func (l LB) List(ctx context.Context, req ListRequest) (ListLB, error) {
|
func (l LB) List(ctx context.Context, req ListRequest) (*ListLB, error) {
|
||||||
url := "/cloudapi/lb/list"
|
url := "/cloudapi/lb/list"
|
||||||
|
|
||||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
@@ -37,5 +69,5 @@ func (l LB) List(ctx context.Context, req ListRequest) (ListLB, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,34 @@ import (
|
|||||||
|
|
||||||
// Request struct for get list of deleted load balancers
|
// Request struct for get list of deleted load balancers
|
||||||
type ListDeletedRequest struct {
|
type ListDeletedRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by account ID
|
||||||
|
// Required: false
|
||||||
|
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group ID
|
||||||
|
// Required: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by tech status
|
||||||
|
// Required: false
|
||||||
|
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||||
|
|
||||||
|
// Find by frontend Ip
|
||||||
|
// Required: false
|
||||||
|
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
|
||||||
|
|
||||||
|
// Find by backend Ip
|
||||||
|
// Required: false
|
||||||
|
BackIP string `url:"backIp,omitempty" json:"backIp,omitempty"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
@@ -18,7 +46,7 @@ type ListDeletedRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListDeleted gets list of deleted load balancers
|
// ListDeleted gets list of deleted load balancers
|
||||||
func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, error) {
|
func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListLB, error) {
|
||||||
url := "/cloudapi/lb/listDeleted"
|
url := "/cloudapi/lb/listDeleted"
|
||||||
|
|
||||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
@@ -33,5 +61,5 @@ func (l LB) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListLB, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
40
pkg/cloudapi/lb/make_highly_available.go
Normal file
40
pkg/cloudapi/lb/make_highly_available.go
Normal 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
|
||||||
|
}
|
||||||
@@ -6,7 +6,10 @@ type RecordLB struct {
|
|||||||
HAMode bool `json:"HAmode"`
|
HAMode bool `json:"HAmode"`
|
||||||
|
|
||||||
// Access Control List
|
// Access Control List
|
||||||
ACL interface{} `json:"acl"`
|
ACL []interface{} `json:"acl"`
|
||||||
|
|
||||||
|
// BackendHAIP
|
||||||
|
BackendHAIP string `json:"backendHAIP"`
|
||||||
|
|
||||||
// List of load balancer backends
|
// List of load balancer backends
|
||||||
Backends ListBackends `json:"backends"`
|
Backends ListBackends `json:"backends"`
|
||||||
@@ -32,6 +35,9 @@ type RecordLB struct {
|
|||||||
// External network ID
|
// External network ID
|
||||||
ExtNetID uint64 `json:"extnetId"`
|
ExtNetID uint64 `json:"extnetId"`
|
||||||
|
|
||||||
|
// FrontendHAIP
|
||||||
|
FrontendHAIP string `json:"frontendHAIP"`
|
||||||
|
|
||||||
// List of load balancer frontends
|
// List of load balancer frontends
|
||||||
Frontends ListFrontends `json:"frontends"`
|
Frontends ListFrontends `json:"frontends"`
|
||||||
|
|
||||||
@@ -53,6 +59,9 @@ type RecordLB struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Part K8s
|
||||||
|
PartK8s bool `json:"partK8s"`
|
||||||
|
|
||||||
// Primary node
|
// Primary node
|
||||||
PrimaryNode RecordNode `json:"primaryNode"`
|
PrimaryNode RecordNode `json:"primaryNode"`
|
||||||
|
|
||||||
@@ -68,6 +77,9 @@ type RecordLB struct {
|
|||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Sysctl Params
|
||||||
|
SysctlParams []interface{} `json:"sysctlParams"`
|
||||||
|
|
||||||
// Tech status
|
// Tech status
|
||||||
TechStatus string `json:"techStatus"`
|
TechStatus string `json:"techStatus"`
|
||||||
|
|
||||||
@@ -90,7 +102,13 @@ type ItemLoadBalancer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of load balancers
|
// List of load balancers
|
||||||
type ListLB []ItemLoadBalancer
|
type ListLB struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemLoadBalancer `json:"data"`
|
||||||
|
|
||||||
|
// EntryCount
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main information about backend
|
// Main information about backend
|
||||||
type ItemBackend struct {
|
type ItemBackend struct {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
// - First argument -> prefix
|
// - First argument -> prefix
|
||||||
// - Second argument -> indent
|
// - Second argument -> indent
|
||||||
func (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) {
|
func (ll ListLB) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
if len(ll) == 0 {
|
if len(ll.Data) == 0 {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import "sort"
|
|||||||
//
|
//
|
||||||
// If inverse param is set to true, the order is reversed.
|
// If inverse param is set to true, the order is reversed.
|
||||||
func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
|
func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
|
||||||
if len(ll) < 2 {
|
if len(ll.Data) < 2 {
|
||||||
return ll
|
return ll
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(ll, func(i, j int) bool {
|
sort.Slice(ll.Data, func(i, j int) bool {
|
||||||
if inverse {
|
if inverse {
|
||||||
return ll[i].CreatedTime > ll[j].CreatedTime
|
return ll.Data[i].CreatedTime > ll.Data[j].CreatedTime
|
||||||
}
|
}
|
||||||
|
|
||||||
return ll[i].CreatedTime < ll[j].CreatedTime
|
return ll.Data[i].CreatedTime < ll.Data[j].CreatedTime
|
||||||
})
|
})
|
||||||
|
|
||||||
return ll
|
return ll
|
||||||
@@ -25,16 +25,16 @@ func (ll ListLB) SortByCreatedTime(inverse bool) ListLB {
|
|||||||
//
|
//
|
||||||
// If inverse param is set to true, the order is reversed.
|
// If inverse param is set to true, the order is reversed.
|
||||||
func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
|
func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
|
||||||
if len(ll) < 2 {
|
if len(ll.Data) < 2 {
|
||||||
return ll
|
return ll
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(ll, func(i, j int) bool {
|
sort.Slice(ll.Data, func(i, j int) bool {
|
||||||
if inverse {
|
if inverse {
|
||||||
return ll[i].UpdatedTime > ll[j].UpdatedTime
|
return ll.Data[i].UpdatedTime > ll.Data[j].UpdatedTime
|
||||||
}
|
}
|
||||||
|
|
||||||
return ll[i].UpdatedTime < ll[j].UpdatedTime
|
return ll.Data[i].UpdatedTime < ll.Data[j].UpdatedTime
|
||||||
})
|
})
|
||||||
|
|
||||||
return ll
|
return ll
|
||||||
@@ -44,16 +44,16 @@ func (ll ListLB) SortByUpdatedTime(inverse bool) ListLB {
|
|||||||
//
|
//
|
||||||
// If inverse param is set to true, the order is reversed.
|
// If inverse param is set to true, the order is reversed.
|
||||||
func (ll ListLB) SortByDeletedTime(inverse bool) ListLB {
|
func (ll ListLB) SortByDeletedTime(inverse bool) ListLB {
|
||||||
if len(ll) < 2 {
|
if len(ll.Data) < 2 {
|
||||||
return ll
|
return ll
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(ll, func(i, j int) bool {
|
sort.Slice(ll.Data, func(i, j int) bool {
|
||||||
if inverse {
|
if inverse {
|
||||||
return ll[i].DeletedTime > ll[j].DeletedTime
|
return ll.Data[i].DeletedTime > ll.Data[j].DeletedTime
|
||||||
}
|
}
|
||||||
|
|
||||||
return ll[i].DeletedTime < ll[j].DeletedTime
|
return ll.Data[i].DeletedTime < ll.Data[j].DeletedTime
|
||||||
})
|
})
|
||||||
|
|
||||||
return ll
|
return ll
|
||||||
|
|||||||
72
pkg/cloudapi/lb/updateSysctParams.go
Normal file
72
pkg/cloudapi/lb/updateSysctParams.go
Normal 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
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ type AffinityGroupComputesRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AffinityGroupComputes gets list of all computes with their relationships to another computes
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -35,7 +35,7 @@ func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputes
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list := ListAffinityGroups{}
|
list := ListAffinityGroupsComputes{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
err = json.Unmarshal(res, &list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type AffinityGroupsListRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -31,7 +31,7 @@ func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListReques
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list := map[string][]uint64{}
|
list := &ListAffinityGroups{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
err = json.Unmarshal(res, &list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -14,13 +14,49 @@ type ListComputesRequest struct {
|
|||||||
// Required: true
|
// Required: true
|
||||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||||
|
|
||||||
// Reason for action
|
// Find by compute id
|
||||||
// Required: false
|
// Required: false
|
||||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// ID an account
|
||||||
|
// Required: false
|
||||||
|
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||||
|
|
||||||
|
// Find by tech status
|
||||||
|
// Required: false
|
||||||
|
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||||
|
|
||||||
|
// Find by status
|
||||||
|
// Required: false
|
||||||
|
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||||
|
|
||||||
|
// Find by ip address
|
||||||
|
// Required: false
|
||||||
|
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
|
||||||
|
|
||||||
|
// Find by external network name
|
||||||
|
// Required: false
|
||||||
|
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
|
||||||
|
|
||||||
|
// Find by external network id
|
||||||
|
// Required: false
|
||||||
|
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListComputes gets list of all compute instances under specified resource group, accessible by the user
|
// ListComputes gets list of all compute instances under specified resource group, accessible by the user
|
||||||
func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) {
|
func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -42,5 +78,5 @@ func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComp
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,34 @@ import (
|
|||||||
|
|
||||||
// Request struct for get list deleted resource groups
|
// Request struct for get list deleted resource groups
|
||||||
type ListDeletedRequest struct {
|
type ListDeletedRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by account ID
|
||||||
|
// Required: false
|
||||||
|
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||||
|
|
||||||
|
// Find by name account
|
||||||
|
// Required: false
|
||||||
|
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
|
||||||
|
|
||||||
|
// Find by created after time (unix timestamp)
|
||||||
|
// Required: false
|
||||||
|
CreatedAfter uint64 `url:"createdAfter,omitempty" json:"createdAfter,omitempty"`
|
||||||
|
|
||||||
|
// Find by created before time (unix timestamp)
|
||||||
|
// Required: false
|
||||||
|
CreatedBefore uint64 `url:"createdBefore,omitempty" json:"createdBefore,omitempty"`
|
||||||
|
|
||||||
|
// Find by status lock
|
||||||
|
// Required: false
|
||||||
|
LockStatus string `url:"lockStatus,omitempty" json:"lockStatus,omitempty"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|||||||
@@ -13,10 +13,46 @@ type ListLBRequest struct {
|
|||||||
// Resource group ID
|
// Resource group ID
|
||||||
// Required: true
|
// Required: true
|
||||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||||
|
|
||||||
|
// 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 account ID
|
||||||
|
// Required: false
|
||||||
|
AccountID uint64 `url:"accountID,omitempty" json:"accountID,omitempty"`
|
||||||
|
|
||||||
|
// Find by tech status
|
||||||
|
// Required: false
|
||||||
|
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||||
|
|
||||||
|
// Find by status
|
||||||
|
// Required: false
|
||||||
|
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||||
|
|
||||||
|
// Find by frontend Ip
|
||||||
|
// Required: false
|
||||||
|
FrontIP string `url:"frontIp,omitempty" json:"frontIp,omitempty"`
|
||||||
|
|
||||||
|
// Find by backend Ip
|
||||||
|
// Required: false
|
||||||
|
BackIP string `url:"backIp,omitempty" json:"backIp,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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListLB gets list all load balancers in the specified resource group, accessible by the user
|
// ListLB gets list all load balancers in the specified resource group, accessible by the user
|
||||||
func (r RG) ListLB(ctx context.Context, req ListLBRequest) (ListLB, error) {
|
func (r RG) ListLB(ctx context.Context, req ListLBRequest) (*ListLB, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -38,5 +74,5 @@ func (r RG) ListLB(ctx context.Context, req ListLBRequest) (ListLB, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type ListPFWRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListPFW gets list port forward rules for the specified resource group
|
// ListPFW gets list port forward rules for the specified resource group
|
||||||
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPortForwards, error) {
|
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (*ListPortForwards, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -38,5 +38,5 @@ func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPortForwards,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,13 +14,33 @@ type ListVINSRequest struct {
|
|||||||
// Required: true
|
// Required: true
|
||||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||||
|
|
||||||
// Reason for action
|
// Find by name
|
||||||
// Required: false
|
// Required: false
|
||||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// ID an account
|
||||||
|
// Required: false
|
||||||
|
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||||
|
|
||||||
|
// Find by ip extnet address
|
||||||
|
// Required: false
|
||||||
|
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
|
||||||
|
|
||||||
|
// Find by vins id
|
||||||
|
// Required: false
|
||||||
|
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListVINS gets list all ViNSes under specified resource group, accessible by the user
|
// ListVINS gets list all ViNSes under specified resource group, accessible by the user
|
||||||
func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) {
|
func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -42,5 +62,5 @@ func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ type ItemResourceConsumption struct {
|
|||||||
// Reserved information about resources
|
// Reserved information about resources
|
||||||
Reserved Resource `json:"Reserved"`
|
Reserved Resource `json:"Reserved"`
|
||||||
|
|
||||||
|
// Resource limits
|
||||||
|
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||||
|
|
||||||
// Resource group ID
|
// Resource group ID
|
||||||
RGID uint64 `json:"rgid"`
|
RGID uint64 `json:"rgid"`
|
||||||
}
|
}
|
||||||
@@ -302,7 +305,7 @@ type ResourceLimits struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Main information about affinity group
|
// Main information about affinity group
|
||||||
type ItemAffinityGroup struct {
|
type ItemAffinityGroupComputes struct {
|
||||||
// Compute ID
|
// Compute ID
|
||||||
ComputeID uint64 `json:"computeId"`
|
ComputeID uint64 `json:"computeId"`
|
||||||
|
|
||||||
@@ -326,7 +329,15 @@ type ItemAffinityGroup struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of affinity groups
|
// 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
|
// Main information about audit
|
||||||
type ItemAudit struct {
|
type ItemAudit struct {
|
||||||
@@ -449,7 +460,13 @@ type ItemCompute struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of computes
|
// List of computes
|
||||||
type ListComputes []ItemCompute
|
type ListComputes struct {
|
||||||
|
//Data
|
||||||
|
Data []ItemCompute `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main information about load balancer
|
// Main information about load balancer
|
||||||
type RecordLoadBalancer struct {
|
type RecordLoadBalancer struct {
|
||||||
@@ -563,7 +580,13 @@ type ItemBackend struct {
|
|||||||
type ListBackends []ItemBackend
|
type ListBackends []ItemBackend
|
||||||
|
|
||||||
// List of load balancers
|
// List of load balancers
|
||||||
type ListLB []ItemLoadBalancer
|
type ListLB struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemLoadBalancer `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Server settings
|
// Server settings
|
||||||
type RecordServerSettings struct {
|
type RecordServerSettings struct {
|
||||||
@@ -704,7 +727,13 @@ type ItemPortForward struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of port forwards
|
// List of port forwards
|
||||||
type ListPortForwards []ItemPortForward
|
type ListPortForwards struct {
|
||||||
|
//Data
|
||||||
|
Data []ItemPortForward `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main information about VINS
|
// Main information about VINS
|
||||||
type ItemVINS struct {
|
type ItemVINS struct {
|
||||||
@@ -761,7 +790,13 @@ type ItemVINS struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List of VINSes
|
// List of VINSes
|
||||||
type ListVINS []ItemVINS
|
type ListVINS struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemVINS `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main information about usage of resource
|
// Main information about usage of resource
|
||||||
type RecordResourceUsage struct {
|
type RecordResourceUsage struct {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user