Compare commits

...

20 Commits

Author SHA1 Message Date
8a101c6fcb v1.11.0 2025-04-09 11:21:07 +03:00
asteam
3f21a89e80 v1.10.2 2025-03-11 13:09:17 +03:00
cbce7f434f v1.10.1 2025-02-07 11:11:43 +03:00
e04dc42d2b v1.10.0 2024-12-27 11:35:22 +03:00
asteam
88eb9e8898 v1.9.2 2024-12-04 11:50:22 +03:00
9ec34c6bfc v1.9.1 2024-11-22 12:09:50 +03:00
80491ed643 v1.9.0 2024-11-12 12:51:21 +03:00
f1e0f7abb6 v1.8.3 2024-08-26 17:51:34 +03:00
8eeef825c0 v1.8.2 2024-06-28 10:54:20 +03:00
9a7a7b6f36 v1.8.1 2024-06-05 12:42:19 +03:00
3393934456 v1.8.1 2024-05-31 13:35:39 +03:00
e7c968797b v1.8.0 2024-04-16 14:26:06 +03:00
bc264c4d90 v1.7.7 2024-03-14 14:58:32 +03:00
d137c7507a v1.7.6 2024-03-14 14:52:56 +03:00
55027a1605 v1.6.13 2024-03-14 10:17:08 +03:00
de9cca4053 v1.7.6 2024-03-06 17:02:50 +03:00
83bf1fb1fa v1.6.12 2024-03-06 16:50:27 +03:00
16cad7a3e7 v1.7.5 2024-02-01 10:50:38 +03:00
96273d2a12 v1.7.4 2024-01-22 13:10:00 +03:00
d4065938ac v1.7.3 2023-12-18 16:27:15 +03:00
552 changed files with 18132 additions and 3501 deletions

5
.gitignore vendored
View File

@@ -3,3 +3,8 @@ cmd/
.vscode/ .vscode/
.fleet/ .fleet/
.DS_Store .DS_Store
tests/platform_upgrade/.env
tests/platform_upgrade/input.json
tests/platform_upgrade/*.txt
tests/platform_upgrade/*.log
*.env

View File

@@ -1,30 +1,202 @@
## Version 1.7.2 ## Version 1.11
## Bugfix ### Добавлено
- Fix panic in clients
- Add refresh Token in BVS authorization mode and refactoring bvs_client
- Delete tag validate and omitempty in Permanently field, DeleteRequest model in cloudApi/k8s/delete cloudBroker/k8s/delete
- Add Page and Size fields into model AffinityGroupsListRequest in cloudbroker/rg/affinity_groups_list;
- Change type of Data field from for model ListAffinityGroup in cloudbroker/rg/affinity_groups_list for correct parsing;
- Add new models ListAffinityGroupItems and ItemAffinityGroup to support correct parsing for model ListAffinityGroup in cloudbroker/rg/affinity_groups_list;
- Add missing IDs() method for model ListAffinityGroupItems in cloudbroker/rg/affinity_groups_list;
- Add ResourceLimits field into model ItemResourceConsumption in cloudbroker/rg/models;
- Add LockStatus field into model ListRequest in cloudbroker/rg/list;
- Fix url for cloudbroker/grid/getDiagnosisGet
- Create ListUsers model with Data and EntryCount fields in cloudbroker/compute/models;
- Change type of return structure for UserList method from RecordACL to ListUsers in cloudbroker/compute/user_list;
- Create ListSnapShot model with Data and EntryCount fields in cloudbroker/compute/models;
- Change type of return structure for SnapshotList from ListSnapshots to *ListSnapShot in cloudbroker/compute/snapshot_list;
- Change json tag for TotalDiskSize field for model ItemCompute in cloudbroker/compute/models;
- Add NeedReboot and CdImageId fields for model InfoCompute in cloudbroker/compute/models;
- Reorganize ListPFW model by adding Data and EntryCount fields with json tags in cloudbroker/compute/models;
- Fix IDs() method for ListPFW model in cloudbroker/compute/ids;
- Change type of return structure for PFWList method from ListPFW to *ListPFW in cloudbroker/compute/pfw_list.
#### account
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-304 | Опциональное поле `Description` в структуру запроса `UpdateCreateRequest` в cloudapi/account |
| BGOS-304 | Опциональное поле `Description` в структуры запроса `CreateRequest`, `UpdateCreateRequest` в cloudbroker/account |
| BGOS-304 | Поле `Description` в структуры ответа `ItemRG`, `RecordAccount`, `ItemAccount` в cloudapi/account и cloudbroker/account |
| BGOS-316 | Опциональное поле `Reason` в структуру запроса `DisableEnableRequest` в cloudapi/account |
| BGOS-316 | Опциональное поле `Reason` в структуры запроса `RestoreRequest`, `DisableAccountsRequest`, `DisableRequest` в cloudbroker/account |
## Feature #### apiaccess
- Add endpoints AccessAdd AccessRemote in cloudBroker/k8ci | Идентификатор<br>задачи | Описание |
- Add endpoints Audit in cloudBroker | --- | --- |
- Add AuthBroker field to model RecordGrid in cloudbroker/grid/models | BGOS-306 | Метод `GetDefault` и структура ответа `ItemAPIAccessDefault` в cloudbroker/apiaccess |
- Add AuthBroker field to model ItemGridList in cloudbroker/grid/models | BGOS-309 | Обязательные поля `APIGroup`, `APIMethod`, `APIObject` в структуру запроса `APIFindRequest` в cloudbroker/apiaccess |
- Add endpoints DeleteCustomFields in cloudbroker/compute | BGOS-309 | Поле `DPDK` в структуры ответа `CloudAPIEndpoints` и `CloudBrokerEndpoints` в cloudbroker/apiaccess |
#### audit
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-307 | Опциональное поле `RequestID` в структуру запроса `ListRequest` в cloudapi/audit |
| BGOS-337 | Поле `PhysicalNode` в структуру ответа `ItemLinkedJobs` в cloudbroker/audit |
| BGOS-395 | Поле `TTL` в структуру ответа `RecordAudit` в cloudbroker/audit |
| BGOS-395 | Поля `Args`, `Kwargs`, `RemoteAddr`, `Result`, `TimestampEnd`, `TTL` в структуру ответа `ItemAudit` в cloudbroker/audit |
| BGOS-340 | Поле `Tags` в структуре ответа `ItemAudit` в cloudbroker/audit |
### bservice
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-317 | Опциональное поле `Chipset` в структуру запроса `GroupAddRequest` в cloudapi/bservice |
| BGOS-354 | Опциональное поле `Chipset` в структуру запроса `GroupResizeRequest` в cloudapi/bservice |
| BGOS-357 | Поле `Chipset` в структуру ответа `ItemGroupCompute` в cloudapi/bservice |
#### compute
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-311 | Опциональное поле `StackName` в структуру запроса `ListRequest` в cloudbroker/list |
| BGOS-312 | Опциональные поля `LoaderType`, `BootType`, `NetworkInterfaceNaming`, `HotResize` в структуру запроса `UpdateRequest` в cloudapi/compute и cloudbroker/compute |
| BGOS-312 | Поля `LoaderType`, `BootType`, `NetworkInterfaceNaming`, `HotResize` в структуры ответа `InfoCompute`, `RecordCompute`, `ItemCompute` в cloudapi/compute и cloudbroker/compute |
| BGOS-348 | Полe `NID` в структуру ответа `ItemCompute` в cloudbroker/compute |
| BGOS-348 | Структуры ответов `ItemDeletedCompute`, `ListDeletedComputes` в cloudbroker/compute |
| BGOS-388 | Поля `UpdatedBy`, `SizeAvailable` в структуру ответа `ItemDisk` в cloudapi/compute |
| BGOS-388 | Поле `SizeAvailable` в структуру ответа `ItemDisk` в cloudbroker/compute |
| BGOS-392 | Метод `ChangeMAC` и структура запроса `ChangeMACRequest` в cloudapi/compute и cloudbroker/compute |
| BGOS-403 | Опциональное поле `MACAddr` в cloudapi/compute/netAttach и cloudbroker/compute/netAttach |
#### disks
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-318 | Опциональное поле `Name` в структуру запроса `DeleteRequest` в cloudbroker/disks |
| BGOS-408 | Поля `DeletedBy`, `CreatedBy`, `MachineID`, `MachineName`, `UpdatedTime` и `Milestones` в структуру ответа `ItemDisk` и `RecordDisk` в cloudapi/disks |
| BGOS-408 | Поля `DeletedBy`, `CreatedBy`, `UpdatedTime` и `UpdatedBy` в структуру ответа `RecordDisk` в cloudbroker/disks |
| BGOS-401 | Поля `SizeAvailable` и `UpdatedBy` в структуру ответа `InfoDisk` в cloudbroker/disks |
| BGOS-401 | Поля `SizeAvailable` и `UpdatedBy` в структуры ответа `ItemDisk` и `RecordDisk` в cloudapi/disks |
#### extnet
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-356 | Опциональное поле `OVSBridge` в структуру запроса `ListRequest` в cloudapi/extnet |
| BGOS-351 | Поле `NTP` в структуру ответа `RecordExtNet` в cloudapi/extnet и cloudbroker/extnet |
#### image
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-315 | Поле `SnapshotID` в структуру ответа `RecordImage` в cloudapi/image |
#### k8s
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-304 | Поле `Description` в структуру ответа `RecordK8S` в cloudapi/k8s и cloudbroker/k8s |
#### kvmx86
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-312 | Опциональные поля `LoaderType`, `BootType`, `NetworkInterfaceNaming`, `HotResize` в структуру запроса `CreateBlankRequest` в cloudapi/kvmx86 и cloudbroker/kvmx86 |
| BGOS-312 | Опциональное поле `MAC` в структуру запроса `Interface` в cloudapi/kvmx86 и cloudbroker/kvmx86 |
#### node
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-397 | Метод `SetVFsParams` и структура запроса `SetVFsParamsRequest` в cloudbroker/node |
#### prometheus
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-405 | Метод `Computes` структура запроса `ComputesRequest` и структура ответа `ComputesData` в cloudbroker/prometheus |
#### resmon
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-341 | Поля `ID`, `SizeAvailable` в структуру ответа `ItemDisk` сloudbroker/resmon |
#### sep
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-343 | Метод `GetTemplate` и структура запроса `GetTemplateRequest` в cloudbroker/sep |
| BGOS-301 | Метод `ListAvailableSEPAndPools` структура запроса `ListAvailableSEPAndPoolsRequest` и структура ответа `ListAvailableSEP` в cloudapi/sep и cloudbroker/sep |
| BGOS-299 | Обязательное поле `Force` в структуру запроса `DelConsumerNodesRequest` в cloudbroker/sep |
#### stack
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-389 | Структура ответа `LibGuestFSTools` входящая в структуру ответа `Packages` в cloudbroker/stack |
#### user
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-303 | Опциональное поле `SortBy` в структуру запроса `GetAuditRequest` cloudapi/user |
#### vins
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-300 | Опциональное поле `Status` в структуру запроса `ListRequest` cloudapi/vins и cloudbroker/vins |
### Удалено
#### apiaccess
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-309 | Обязательное поле `APIName` из структуры запроса `APIFindRequest` в cloudbroker/apiacces |
| BGOS-309 | Метод `GetPreGroups` в cloudbroker/apiaccess |
| BGOS-309 | Опциональное поле `CreatedBy` из структуры запроса `ListRequest` в cloudbroker/apiaccess |
| BGOS-309 | Метод `ListDeletedRequest` и структура запроса `ListDeletedRequest` и в cloudbroker/apiaccess |
| BGOS-309 | Поля `CreatedBy`, `UpdatedBy`, `DeletedBy`, `Milestone` из структуры ответа `ItemAPIAccess` в cloudbroker/apiaccess |
#### compute
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-338 | Опциональное поле `Depresent` из структуры запроса `StopRequest` в cloudbroker/compute |
| BGOS-344 | Методы `RepairBootFS`, `MassRepairBootFS`, `Registration` в cloudbroker/compute |
| BGOS-353 | Поля `PCISlot`, `BusNumber` из структуры ответа `InfoDisk` в cloudapi/compute и cloudbroker/compute |
#### disks
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-298 | Опциональные поля `Type, SSDSize` из структуры запроса `CreateRequest` в cloudapi/disks и cloudbroker/disks |
| BGOS-338 | Обязательное поле `GID` из структуры запроса `CreateRequest` в cloudapi/disks и cloudbroker/disks |
#### image
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-338 | Обязательное поле `GID` из структур запроса `CreateRequest`, `CreateCDROMImageRequest` в cloudbroker/image |
#### node
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-308 | Опциональное поле `VDiskAction` из структуры запроса `MaintenanceRequest` в cloudbroker/node |
#### rg
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-342 | Опциональное поле `RegisterComputes` из структур запроса `CreateRequest`, `UpdateRequest` в cloudapi/rg и cloudbroker/rg |
### Исправлено
#### apiaccess
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-308 | Изменены все теги `json` и `url` в структурах ответов и запросов с `CamelCase` на `snake_case` в cloudbroker/apiaccess |
#### audit
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-346 | Изменены все теги `json` и `url` в структурах запросов с `CamelCase` на `snake_case` в cloudapi/audit и cloudbroker/audit |
#### compute
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-314 | Измененен тип с `[]uint64` на `map[strint]uint64` полей `PresentTo` в структурах ответа `ItemComputeDisk`, `ItemDisk` в cloudapi/compute и cloudbroker/compute |
| BGOS-355 | Переименованны поля с `Pinned` на `PinnedToStack` в структурах ответа `InfoCompute, RecordCompute, ItemCompute` в cloudapi/compute и cloudbroker/compute |
| BGOS-355 | Изменен тип поля с `PinnedToStack` (ранее `Pinned`) с `bool` на `int` в структурах ответа `InfoCompute, RecordCompute` в cloudbroker/compute |
| BGOS-388 | Изменен json тег поля `PCISlot` с `pciSlot` на `pci_slot` в структурах ответа `ItemDisk` в cloudapi/compute и cloudbroker/compute |
| BGOS-392 | Изменены все теги `json` и `url` в структуре запроса `ChangeIPRequest` с `CamelCase` на `snake_case` в cloudapi/compute и cloudbroker/compute |
#### disks
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-314 | Измененен тип с `[]uint64` на `map[strint]uint64` полей `PresentTo` в структурах ответа `ItemDiskUnattached`, `RecordDisk`, `ItemDisk`, `InfoDisk` в cloudapi/disks и cloudbroker/disks |
| BGOS-408 | Перенесены поля с `MachindeID` и `MachineName` из структуры ответа `ItemDisk` в `RecordDisk` в cloudbroker/disks |
#### image
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-314 | Измененен тип с `[]uint64` на `map[strint]uint64` полей `PresentTo` в структурах ответа `ItemImage`, `RecordImage` в cloudapi/image и cloudbroker/image |
#### image
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-305 | Изменен тип опционального поля `AccountIDs` c []uint64 на []int64 в моделях `GrantAccessRequest`, `RevokeAccessRequest` в cloudbroker/image |
#### resmon
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-341 | Изменен тип поле `SizeUsed`, `SizeMax` с int64 на float64 в структуре ответа `ItemDisk` сloudbroker/resmon |
#### sep
| Идентификатор<br>задачи | Описание |
| --- | --- |
| BGOS-398 | Обязательные поля `Trust` и `Spoofchk` заменены на `VFParams` в структуре запроса `SetVFsNumberRequest` в cloudbroker/node |

View File

@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
same "printed page" as the copyright notice for easier same "printed page" as the copyright notice for easier
identification within third-party archives. identification within third-party archives.
Copyright [yyyy] [name of copyright owner] Copyright 2022 Basis LTD
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

602
README.md
View File

@@ -1,6 +1,6 @@
# Decort SDK # Decort SDK
Decort SDK - это библиотека, написанная на языке GO, позволяющая взаимодействовать с API облачной платформы **DECORT**. Библиотека содеражит в себе структуры и методы, необходимые для отправки запросов. Decort SDK имеет встроенный http-клиент и поддерживает разные способы авторизации на платформе. Библиотека так же содержит в себе модели ответов от платформы. Decort SDK - это библиотека, написанная на языке GO, позволяющая взаимодействовать с API облачной платформы **DECORT**. Библиотека содержит в себе структуры и методы, необходимые для отправки запросов. Decort SDK имеет встроенный http-клиент и поддерживает разные способы авторизации на платформе. Библиотека так же содержит в себе модели ответов от платформы.
## Версии ## Версии
@@ -12,34 +12,73 @@ Decort SDK - это библиотека, написанная на языке G
- Версия 1.5.x Decort-SDK соответствует 3.8.7 версии платформы - Версия 1.5.x Decort-SDK соответствует 3.8.7 версии платформы
- Версия 1.6.x Decort-SDK соответствует 3.8.8 версии платформы - Версия 1.6.x Decort-SDK соответствует 3.8.8 версии платформы
- Версия 1.7.х Decort-SDK соответствует 3.8.9 версии платформы - Версия 1.7.х Decort-SDK соответствует 3.8.9 версии платформы
- Версия 1.8.х Decort-SDK соответствует 4.0.0 версии платформы
- Версия 1.9.х Decort-SDK соответствует 4.1.0 версии платформы
- Версия 1.10.х Decort-SDK соответствует 4.2.0 версии платформы
- Версия 1.11.х Decort-SDK соответствует 4.3.0 версии платформы
## Оглавление ## Оглавление
- [Установка](#установка) - [Decort SDK](#decort-sdk)
- [Список API](#список-api) - [Версии](#версии)
- [Cloudapi](#cloudapi) - [Оглавление](#оглавление)
- [Cloudbroker](#cloudbroker) - [Установка](#установка)
- [Работа с библиотекой](#работа-с-библиотекой) - [Список API](#список-api)
- [Настройка конфигурации клиента](#настройка-конфигурации-клиента) - [Cloudapi](#cloudapi)
- [Пример конфигурации клиента](#пример-конфигурации-клиента) - [Cloudbroker](#cloudbroker)
- [Парсинг конфигурации из файла](#парсинг-конфигурации-из-файла) - [Работа с библиотекой](#работа-с-библиотекой)
- [Пример JSON конфигурации](#пример-json-конфигурации) - [Настройка конфигурации клиента](#настройка-конфигурации-клиента)
- [Пример YAML конфигурации](#пример-yaml-конфигурации) - [Пример конфигурации клиента](#пример-конфигурации-клиента)
- [Создание клиента](#создание-клиента) - [Парсинг конфигурации из файла](#парсинг-конфигурации-из-файла)
- [Создание структуры запроса](#cоздание-структуры-запроса) - [Пример JSON конфигурации](#пример-json-конфигурации)
- [Выполнение запроса](#выполнение-запроса) - [Пример YAML конфигурации](#пример-yaml-конфигурации)
- [Фильтрация](#фильтрация) - [Создание клиента](#создание-клиента)
- [Сортировка](#сортировка) - [Пример](#пример)
- [Сериализация](#сериализация) - [Создание структуры запроса](#создание-структуры-запроса)
- [Работа с legacy клиентом](#работа-с-legacy-клиентом) - [Пример комментариев структуры](#пример-комментариев-структуры)
- [Настройка конфигурации legacy клиента](#настройка-конфигурации-legacy-клиента) - [Пример создания запроса для развертывания виртуальной машины:](#пример-создания-запроса-для-развертывания-виртуальной-машины)
- [Пример конфигурации legacy клиента](#пример-конфигурации-legacy-клиента) - [Выполнение запроса](#выполнение-запроса)
- [Парсинг legacy конфигурации из файла](#парсинг-legacy-конфигурации-из-файла) - [Пример выполнения запроса](#пример-выполнения-запроса)
- [Пример legacy JSON конфигурации](#пример-legacy-json-конфигурации) - [Пример выполнения GetRaw и ListRaw запросов](#пример-выполнения-getraw-и-listraw-запросов)
- [Пример legacy YAML конфигурации](#пример-legacy-yaml-конфигурации) - [Фильтрация](#фильтрация)
- [Создание legacy клиента](#создание-legacy-клиента) - [Использование на примере `compute.FilterByK8SID`:](#использование-на-примере-computefilterbyk8sid)
- [Создание структуры запроса](#cоздание-структуры-запроса) - [Сортировка](#сортировка)
- [Выполнение запроса](#выполнение-запроса) - [Сериализация](#сериализация)
- [Комплексный пример](#комплексный-пример)
- [Получение списка уникальных идентификаторов ID объекта](#получение-списка-уникальных-идентификаторов-id-объекта)
- [Методы поля Result для группы tasks](#методы-поля-result-для-группы-tasks)
- [Работа с legacy клиентом](#работа-с-legacy-клиентом)
- [Настройка конфигурации legacy клиента](#настройка-конфигурации-legacy-клиента)
- [Пример конфигурации legacy клиента](#пример-конфигурации-legacy-клиента)
- [Парсинг legacy конфигурации из файла](#парсинг-legacy-конфигурации-из-файла)
- [Пример legacy JSON конфигурации](#пример-legacy-json-конфигурации)
- [Пример legacy YAML конфигурации](#пример-legacy-yaml-конфигурации)
- [Создание legacy клиента](#создание-legacy-клиента)
- [Пример создания legacy клиента](#пример-создания-legacy-клиента)
- [Пример выполнения запроса](#пример-выполнения-запроса-1)
- [Работа с BVS клиентом](#работа-с-bvs-клиентом)
- [Настройка параметров BVS в кабинете администратора](#настройка-параметров-bvs-в-кабинете-администратора)
- [Настройка конфигурации BVS клиента](#настройка-конфигурации-bvs-клиента)
- [Описание структуры token](#описание-структуры-token)
- [Пример конфигурации BVS клиента](#пример-конфигурации-bvs-клиента)
- [Парсинг BVS конфигурации из файла](#парсинг-bvs-конфигурации-из-файла)
- [Парсинг BVS токена из файла](#парсинг-bvs-токена-из-файла)
- [Пример BVS JSON конфигурации](#пример-bvs-json-конфигурации)
- [Пример BVS YAML конфигурации](#пример-bvs-yaml-конфигурации)
- [Создание BVS клиента](#создание-bvs-клиента)
- [Пример создания BVS клиента](#пример-создания-bvs-клиента)
- [Пример получения BVS токена](#пример-получения-bvs-токена)
- [Пример обновления BVS токена](#пример-обновления-bvs-токена)
- [Пример выполнения запроса](#пример-выполнения-запроса-2)
- [Пример валидации запросов, имеющих в своей структуре поле RAM (или MasterRam/WorkerRAM)](#пример-валидации-запросов-имеющих-в-своей-структуре-поле-ram-или-masterramworkerram)
- [Пример выполнения запроса](#пример-выполнения-запроса-3)
- [Работа с универсальным клиентом](#работа-с-универсальным-клиентом)
- [Настройка конфигурации универсального клиента](#настройка-конфигурации-универсального-клиента)
- [Пример конфигурации универсального клиента](#пример-конфигурации-универсального-клиента)
- [Парсинг универсальной конфигурации из файла](#парсинг-универсальной-конфигурации-из-файла)
- [Создание универсального клиента](#создание-универсального-клиента)
- [Пример создания универсального клиента](#пример-создания-универсального-клиента)
- [Пример выполнения запроса](#пример-выполнения-запроса-4)
## Установка ## Установка
@@ -62,22 +101,24 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
Данная группа ручек позволяет выполнять следующие операции в платформе: Данная группа ручек позволяет выполнять следующие операции в платформе:
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов; - `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
- `Audit` - получение информации о событиях системы;
- `BService` - управление группами виртуальных машин (computes); - `BService` - управление группами виртуальных машин (computes);
- `Compute` - управление виртуальными машинами (индивидуально); - `Compute` - управление виртуальными машинами (индивидуально);
- `Disks` - управление виртуальными дисками; - `Disks` - управление виртуальными дисками;
- `DPDK` - управление виртуальными сетями DPDK;
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ; - `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
- `FLIPgroup` - управление группами "плавающими" ip - адресами; - `FLIPgroup` - управление группами "плавающими" ip - адресами;
- `Image` - управление образами операционных систем; - `Image` - управление образами операционных систем;
- `K8CI` - получение информации о конвейере для создания кластера; - `K8CI` - получение информации о конвейере для создания кластера;
- `K8S` - управление кластерами kubernetes; - `K8S` - управление кластерами kubernetes;
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
- `KVMx86` - создание виртуальной машины x86; - `KVMx86` - создание виртуальной машины x86;
- `LB` - управление балансировщиками нагрузки; - `LB` - управление балансировщиками нагрузки;
- `Locations` - получение информации о grid площадки; - `Locations` - получение информации о grid площадки;
- `RG` - управление ресурсными группами аккаунта; - `RG` - управление ресурсными группами аккаунта;
- `Sizes` - получение информации о потребляемых ресурсах виртуальными машинами и дисками; - `SEP` - управление storage endpoint (sep);
- `Stack` - получение информации о вычислительных узлах; - `Stack` - получение информации о вычислительных узлах;
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера); - `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
- `VFPool` - управление пулом виртуальных сетевых функций;
- `VINS` - управление виртуальными изолированными сетями. - `VINS` - управление виртуальными изолированными сетями.
### Cloudbroker ### Cloudbroker
@@ -86,10 +127,12 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
Данная группа ручек позволяет выполнять следующие операции в платформе: Данная группа ручек позволяет выполнять следующие операции в платформе:
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов; - `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
- `Audit` - получение информации о событиях системы;
- `APIAccess` - управление доступом к API и его объектам; - `APIAccess` - управление доступом к API и его объектам;
- `Backup` - управление резервным копированием; - `Backup` - управление резервным копированием;
- `Compute` - управление виртуальными машинами (индивидуально); - `Compute` - управление виртуальными машинами (индивидуально);
- `Disks` - управление виртуальными дисками; - `Disks` - управление виртуальными дисками;
- `DPDK` - управление виртуальными сетями DPDK;
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ; - `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
- `FLIPGroup` - управление группами с «плавающими» ip адресами; - `FLIPGroup` - управление группами с «плавающими» ip адресами;
- `Grid` - управление площадками; - `Grid` - управление площадками;
@@ -97,16 +140,19 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
- `Image` - управление образами операционных систем; - `Image` - управление образами операционных систем;
- `K8CI` - управление конвейром для создания кластера; - `K8CI` - управление конвейром для создания кластера;
- `K8S` - управление кластерами kubernetes; - `K8S` - управление кластерами kubernetes;
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
- `KVMx86` - создание виртуальной машины x86; - `KVMx86` - создание виртуальной машины x86;
- `LB` - управление балансировщиками нагрузки; - `LB` - управление балансировщиками нагрузки;
- `Node` - управление нодами платформы;
- `PCIDevice` - управление устройствами; - `PCIDevice` - управление устройствами;
- `Prometheus` - получение статистики prometheus;
- `Resmon` - получение статистики resource monitoring;
- `RG` - управление ресурсными группами аккаунта; - `RG` - управление ресурсными группами аккаунта;
- `SEP` - управление storage endpoint (sep); - `SEP` - управление storage endpoint (sep);
- `Stack` - получение информации о вычислительных узлах; - `Stack` - получение информации о вычислительных узлах;
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера); - `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
- `User` - управление пользователями (индивидуально); - `User` - управление пользователями (индивидуально);
- `VGPU` - управление виртуальными графическими процессорами; - `VGPU` - управление виртуальными графическими процессорами;
- `VFPool` - управление пулом виртуальных сетевых функций;
- `VINS` - управление виртуальными изолированными сетями. - `VINS` - управление виртуальными изолированными сетями.
## Работа с библиотекой ## Работа с библиотекой
@@ -114,8 +160,8 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
Алгоритм работы с библиотекой выглядит следующим образом: Алгоритм работы с библиотекой выглядит следующим образом:
1. Выполнение одного из действий: 1. Выполнение одного из действий:
- настройка конфигурации клиента; - настройка конфигурации клиента;
- парсинг конфигурации из файла. - парсинг конфигурации из файла.
2. Создание клиента. 2. Создание клиента.
3. Создание структуры запроса. 3. Создание структуры запроса.
4. Выполнение запроса. 4. Выполнение запроса.
@@ -134,7 +180,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата | | SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
| Token | string | Нет | JWT токен | | Token | string | Нет | JWT токен |
#### Пример конфигурации клиента ##### Пример конфигурации клиента
```go ```go
import ( import (
@@ -239,48 +285,55 @@ func main() {
В каждом пакете находятся пакеты групп API: В каждом пакете находятся пакеты групп API:
- **cloudapi**: - **cloudapi**:
- `pkg/cloudapi/account` - для `Account` - `pkg/cloudapi/account` - для `Account`
- `pkg/cloudapi/bservice` - для `Basic Service` - `pkg/cloudapi/audit` - для `Audit`
- `pkg/cloudapi/compute` - для `Compute` - `pkg/cloudapi/bservice` - для `Basic Service`
- `pkg/cloudapi/disks` - для `Disks` - `pkg/cloudapi/compute` - для `Compute`
- `pkg/cloudapi/extnet` - для `ExtNet` - `pkg/cloudapi/disks` - для `Disks`
- `pkg/cloudapi/flipgroup` - для `FLIPGroup` - `pkg/cloudapi/dpdknet` - для `DPDK`
- `pkg/cloudapi/image` - для `Image` - `pkg/cloudapi/extnet` - для `ExtNet`
- `pkg/cloudapi/k8ci` - для `K8CI` - `pkg/cloudapi/flipgroup` - для `FLIPGroup`
- `pkg/cloudapi/k8s` - для `K8S` - `pkg/cloudapi/image` - для `Image`
- `pkg/cloudapi/kvmppc` - для `KVMPPC` - `pkg/cloudapi/k8ci` - для `K8CI`
- `pkg/cloudapi/kvmx86` - для `KVMX86` - `pkg/cloudapi/k8s` - для `K8S`
- `pkg/cloudapi/lb` - для `LB` - `pkg/cloudapi/kvmx86` - для `KVMX86`
- `pkg/cloudapi/locations` - для `Locations` - `pkg/cloudapi/lb` - для `LB`
- `pkg/cloudapi/rg` - для `RG` - `pkg/cloudapi/locations` - для `Locations`
- `pkg/cloudapi/sizes` - для `Sizes` - `pkg/cloudapi/rg` - для `RG`
- `pkg/cloudapi/stack` - для `Stack` - `pkg/cloudbroker/sep` - для `SEP`
- `pkg/cloudapi/tasks` - для `Tasks` - `pkg/cloudapi/stack` - для `Stack`
- `pkg/cloudapi/vins` - для `VINS` - `pkg/cloudapi/tasks` - для `Tasks`
- `pkg/cloudapi/vfpool` - для `VFPool`
- `pkg/cloudapi/vins` - для `VINS`
- **cloudbroker**: - **cloudbroker**:
- `pkg/cloudbroker/account` - для `Account` - `pkg/cloudbroker/account` - для `Account`
- `pkg/cloudbroker/apiaccess` - для `APIAccess` - `pkg/cloudbroker/audit` - для `Audit`
- `pkg/cloudbroker/backup` - для `Backup` - `pkg/cloudbroker/apiaccess` - для `APIAccess`
- `pkg/cloudbroker/compute` - для `Compute` - `pkg/cloudbroker/backup` - для `Backup`
- `pkg/cloudbroker/disks` - для `Disks` - `pkg/cloudbroker/compute` - для `Compute`
- `pkg/cloudbroker/extnet` - для `ExtNet` - `pkg/cloudbroker/disks` - для `Disks`
- `pkg/cloudbroker/flipgroup` - для `FLIPGroup` - `pkg/cloudbroker/dpdknet` - для `DPDK`
- `pkg/cloudbroker/grid` - для `Grid` - `pkg/cloudbroker/extnet` - для `ExtNet`
- `pkg/cloudbroker/group` - для `Group` - `pkg/cloudbroker/flipgroup` - для `FLIPGroup`
- `pkg/cloudbroker/image` - для `Image` - `pkg/cloudbroker/grid` - для `Grid`
- `pkg/cloudbroker/k8ci` - для `K8CI` - `pkg/cloudbroker/group` - для `Group`
- `pkg/cloudbroker/k8s` - для `K8S` - `pkg/cloudbroker/image` - для `Image`
- `pkg/cloudbroker/kvmppc` - для `KVMPPC` - `pkg/cloudbroker/k8ci` - для `K8CI`
- `pkg/cloudbroker/kvmx86` - для `KVMX86` - `pkg/cloudbroker/k8s` - для `K8S`
- `pkg/cloudbroker/lb` - для `LB` - `pkg/cloudbroker/kvmx86` - для `KVMX86`
- `pkg/cloudbroker/pcidevice` - для `PCIDevice` - `pkg/cloudbroker/lb` - для `LB`
- `pkg/cloudbroker/rg` - для `RG` - `pkg/cloudbroker/node` - для `Node`
- `pkg/cloudbroker/sep` - для `SEP` - `pkg/cloudbroker/pcidevice` - для `PCIDevice`
- `pkg/cloudbroker/stack` - для `Stack` - `pkg/cloudbroker/prometheus` - для `Prometheus`
- `pkg/cloudbroker/tasks` - для `Tasks` - `pkg/cloudbroker/resmon` - для `Resmon`
- `pkg/cloudbroker/user` - для `User` - `pkg/cloudbroker/rg` - для `RG`
- `pkg/cloudbroker/vgpu` - для `VGPU` - `pkg/cloudbroker/sep` - для `SEP`
- `pkg/cloudbroker/vins` - для `VINS` - `pkg/cloudbroker/stack` - для `Stack`
- `pkg/cloudbroker/tasks` - для `Tasks`
- `pkg/cloudbroker/user` - для `User`
- `pkg/cloudbroker/vgpu` - для `VGPU`
- `pkg/cloudbroker/vfpool` - для `VFPool`
- `pkg/cloudbroker/vins` - для `VINS`
Все поля структуры имеют описание, в которых содержится: Все поля структуры имеют описание, в которых содержится:
@@ -370,9 +423,7 @@ type CreateRequest struct {
// Required: false // Required: false
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"` IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
``` ```
@@ -421,50 +472,57 @@ func main() {
Доступные методы для `.CloudAPI()`: Доступные методы для `.CloudAPI()`:
- `.Account()` - для работы с `Account` - `.Account()` - для работы с `Account`
- `.BService()` - для работы с `BService` - `.Audit()` - для работы с `Audit`
- `.Compute()` - для работы с `Compute` - `.BService()` - для работы с `BService`
- `.Disks()` - для работы с `Disks` - `.Compute()` - для работы с `Compute`
- `.ExtNet()` - для работы с `ExtNet` - `.Disks()` - для работы с `Disks`
- `.FLIPgroup()` - для работы с `FLIPGroup` - `.DPDKNet()` - для работы с `DPDK`
- `.Image()` - для работы с `Image` - `.ExtNet()` - для работы с `ExtNet`
- `.K8CI()` - для работы с `K8CI` - `.FLIPgroup()` - для работы с `FLIPGroup`
- `.K8S()` - для работы с `K8S` - `.Image()` - для работы с `Image`
- `.KVMPPC()` - для работы с `KVMPPC` - `.K8CI()` - для работы с `K8CI`
- `.KVMx86()` - для работы с `KVMX86` - `.K8S()` - для работы с `K8S`
- `.LB()` - для работы с `LB` - `.KVMx86()` - для работы с `KVMX86`
- `.Locations()` - для работы с `Locations` - `.LB()` - для работы с `LB`
- `.RG()` - для работы с `RG` - `.Locations()` - для работы с `Locations`
- `.Sizes()` - для работы с `Sizes` - `.RG()` - для работы с `RG`
- `.Stack()` - для работы с `Stack` - `.SEP()` - для работы с `SEP`
- `.Tasks()` - для работы с `Tasks` - `.Stack()` - для работы с `Stack`
- `.VINS()` - для работы с `VINS` - `.Tasks()` - для работы с `Tasks`
- `.VFPool()` - для работы с `VFPool`
- `.VINS()` - для работы с `VINS`
Доступные методы для `.CloudBroker()`: Доступные методы для `.CloudBroker()`:
- `.Account()` - для работы с `Account` - `.Account()` - для работы с `Account`
- `.APIAccess()` - для работы с `APIAccess` - `.Audit()` - для работы с `Audit`
- `.Backup()` - для работы с `Backup` - `.APIAccess()` - для работы с `APIAccess`
- `.Compute()` - для работы с `Compute` - `.Backup()` - для работы с `Backup`
- `.Disks()` - для работы с `Disks` - `.Compute()` - для работы с `Compute`
- `.ExtNet()` - для работы с `ExtNet` - `.Disks()` - для работы с `Disks`
- `.FLIPGroup()` - для работы с `FLIPGroup` - `.DPDKNet()` - для работы с `DPDK`
- `.Grid()` - для работы с `Grid` - `.ExtNet()` - для работы с `ExtNet`
- `.Group()` - для работы с `Group` - `.FLIPGroup()` - для работы с `FLIPGroup`
- `.Image()` - для работы с `Image` - `.Grid()` - для работы с `Grid`
- `.K8CI()` - для работы с `K8CI` - `.Group()` - для работы с `Group`
- `.K8S()` - для работы с `K8S` - `.Image()` - для работы с `Image`
- `.KVMPPC()` - для работы с `KVMPPC` - `.K8CI()` - для работы с `K8CI`
- `.KVMx86()` - для работы с `KVMX86` - `.K8S()` - для работы с `K8S`
- `.LB()` - для работы с `LB` - `.KVMx86()` - для работы с `KVMX86`
- `.PCIDevice()` - для работы с `PCIDevice` - `.LB()` - для работы с `LB`
- `.RG()` - для работы с `RG` - `.Node()` - для работы с `Node`
- `.SEP()` - для работы с `SEP` - `.PCIDevice()` - для работы с `PCIDevice`
- `.Stack()` - для работы с `Stack` - `.Prometheus()` - для работы с `Prometheus`
- `.Tasks()` - для работы с `Tasks` - `.Resmon()` - для работы с `Resmon`
- `.User()` - для работы с `User` - `.RG()` - для работы с `RG`
- `.VGPU()` - для работы с `VGPU` - `.SEP()` - для работы с `SEP`
- `.VINS()` - для работы с `VINS` - `.Stack()` - для работы с `Stack`
- `.Tasks()` - для работы с `Tasks`
- `.User()` - для работы с `User`
- `.VGPU()` - для работы с `VGPU`
- `.VFPool()` - для работы с `VFPool`
- `.VINS()` - для работы с `VINS`
3. Вызвать метод, отвечающий за выполнение запроса и передать в него: 3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
@@ -767,7 +825,7 @@ func main() {
``` ```
### Получение списка уникальных идентификаторов (ID) объекта ### Получение списка уникальных идентификаторов ID объекта
Для всех структур, имеющих поля со списками объектов с уникальными числовыми идентификаторами (ID), добавлены методы IDs(), возвращающие массивы уникальных идентификаторов объектов в этих списках. Для всех структур, имеющих поля со списками объектов с уникальными числовыми идентификаторами (ID), добавлены методы IDs(), возвращающие массивы уникальных идентификаторов объектов в этих списках.
@@ -813,6 +871,87 @@ func main() {
} }
``` ```
### Методы поля Result для группы tasks
Поле Result внутри структур группы tasks имеет тип интерфейс и может содержать:
- строку о результате выполнения задачи, например `true`
- массив, содержащий ID и имя созданного ресурса, например `[12345, "resource_name"]`
- массив, содержащий информацию о восстновленных дисках, например `[{"computeId": 123, "diskId": 456}, {"computeId": 789, "diskId": 10}]`
Соответственно, для получения информации из поля Result доступны следующие методы:
- ToString(): строковое представление результата выполнения задачи
- ID() и Name(): получение ID и имени созданного в результате выполнения задачи ресурса
- ToMaps(): получение списка карт, содержащих информацию о дисках, восстановленных в результате выполнения задачи.
Все методы оборудованы возвратом ошибок. Непустая ошибка означает, что из поля Result нельзя получить информацию, которую предоставляет метод.
```go
package main
import (
"log"
"fmt"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
tasks_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/tasks"
)
func main() {
// Настройка конфигурации
cfg := config.Config{
AppID: "<APPID>",
AppSecret: "<APPSECRET>",
SSOURL: "https://sso.digitalenergy.online",
DecortURL: "https://mr4.digitalenergy.online",
Retries: 5,
}
// Создание клиента
client := decort.New(cfg)
// Создание структуры запроса GetRequest на получение информации о конкретной задаче и выполнение запроса с помощью конвейера
getReq := tasks.GetRequest{
AuditID: "b6316",
}
task, err := client.CloudAPI().Tasks().Get(context.Background(), getReq)
if err != nil {
log.Fatal(err)
}
// Получение списка карт с информацией о восстановленных дисках
maps, err := task.Result.ToMaps()
if err != nil {
log.Fatal(err)
}
fmt.Println(maps)
// Получение строкового результата выполнения задачи task
res, _ := task.Result.ToString()
fmt.Println(res)
// Создание структуры запроса ListRequest на получение информации о всех задачах и выполнение запроса с помощью конвейера
listReq := tasks_cb.ListRequest{}
tasks, err := client.CloudBroker().Tasks().List(context.Background(), listReq)
if err != nil {
log.Fatal(err)
}
for _, t := range tasks {
// Получение id ресурса, созданного в результате выполнения задачи t
id, err := task.Result.ID()
if err != nil {
log.Fatal(err)
}
fmt.Println(id)
// Получение имени ресурса, созданного в результате выполнения задачи t
name, _ := task.Result.Name()
fmt.Println(name)
}
}
```
## Работа с legacy клиентом ## Работа с legacy клиентом
Работа с legacy клиентом применяется для пользователей, которые не используют для авторизации decs3o. Работа с legacy клиентом применяется для пользователей, которые не используют для авторизации decs3o.
@@ -916,7 +1055,7 @@ func main() {
legacyCfg.SetTimeout(5 * time.Minute) legacyCfg.SetTimeout(5 * time.Minute)
// Создание клиента // Создание клиента
legacyClient := decort.NewLegacy(cfg) legacyClient := decort.NewLegacy(legacyCfg)
} }
``` ```
@@ -943,7 +1082,7 @@ func main() {
} }
// Создание клиента // Создание клиента
legacyClient := decort.NewLegacy(cfg) legacyClient := decort.NewLegacy(legacyCfg)
// Создание структуры запроса // Создание структуры запроса
// CreateRequest - реквест на создание виртуальной машины // CreateRequest - реквест на создание виртуальной машины
@@ -956,7 +1095,7 @@ func main() {
} }
// Выполнение запроса // Выполнение запроса
res, err := client.CloudAPI().KVMX86().Create(context.Background(), req) res, err := legacyClient.CloudAPI().KVMX86().Create(context.Background(), req)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -1021,9 +1160,9 @@ func main(){
AppSecret: "<APP_SECRET>", AppSecret: "<APP_SECRET>",
Username: "<USERNAME>", Username: "<USERNAME>",
Password: "<PASSWORD>", Password: "<PASSWORD>",
SSOURL: "https://bvs-delta.qa.loc:8443" SSOURL: "https://bvs-delta.qa.loc:8443",
DecortURL: "https://delta.qa.loc", DecortURL: "https://delta.qa.loc",
Domain: "dynamix" Domain: "dynamix",
Retries: 5, Retries: 5,
} }
@@ -1133,7 +1272,7 @@ func main() {
Password: "<PASSWORD>", Password: "<PASSWORD>",
AppID: "<APPID>", AppID: "<APPID>",
AppSecret: "<APPSECRET>", AppSecret: "<APPSECRET>",
SSOURL: "https://bvs-delta.qa.loc:8443" SSOURL: "https://bvs-delta.qa.loc:8443",
DecortURL: "https://mr4.digitalenergy.online", DecortURL: "https://mr4.digitalenergy.online",
Domain: "dynamix", Domain: "dynamix",
Retries: 5, Retries: 5,
@@ -1142,7 +1281,7 @@ func main() {
BVSCfg.SetTimeout(5 * time.Minute) BVSCfg.SetTimeout(5 * time.Minute)
// Создание клиента // Создание клиента
BVSClient := decort.NewBVS(cfg) BVSClient := decort.NewBVS(BVSCfg)
} }
``` ```
@@ -1162,12 +1301,12 @@ import (
func main() { func main() {
// Настройка конфигурации // Настройка конфигурации
BVSCfg := config.config.BVSConfig{ BVSCfg := config.BVSConfig{
Username: "<USERNAME>", Username: "<USERNAME>",
Password: "<PASSWORD>", Password: "<PASSWORD>",
AppID: "<APPID>", AppID: "<APPID>",
AppSecret: "<APPSECRET>", AppSecret: "<APPSECRET>",
SSOURL: "https://bvs-delta.qa.loc:8443" SSOURL: "https://bvs-delta.qa.loc:8443",
DecortURL: "https://mr4.digitalenergy.online", DecortURL: "https://mr4.digitalenergy.online",
Domain: "dynamix", Domain: "dynamix",
PathCfg: "config", PathCfg: "config",
@@ -1175,10 +1314,10 @@ func main() {
} }
// Создание клиента // Создание клиента
BVSClient := decort.NewBVS(cfg) BVSClient := decort.NewBVS(BVSCfg)
// Выполнение запроса на получение токена // Выполнение запроса на получение токена
token, err := client.GetToken(context.Background()) token, err := BVSClient.GetToken(context.Background())
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -1203,12 +1342,12 @@ import (
func main() { func main() {
// Настройка конфигурации // Настройка конфигурации
BVSCfg := config.config.BVSConfig{ BVSCfg := config.BVSConfig{
Username: "<USERNAME>", Username: "<USERNAME>",
Password: "<PASSWORD>", Password: "<PASSWORD>",
AppID: "<APPID>", AppID: "<APPID>",
AppSecret: "<APPSECRET>", AppSecret: "<APPSECRET>",
SSOURL: "https://bvs-delta.qa.loc:8443" SSOURL: "https://bvs-delta.qa.loc:8443",
DecortURL: "https://mr4.digitalenergy.online", DecortURL: "https://mr4.digitalenergy.online",
Domain: "dynamix", Domain: "dynamix",
PathToken: "token", PathToken: "token",
@@ -1216,10 +1355,10 @@ func main() {
} }
// Создание клиента // Создание клиента
BVSClient := decort.NewBVS(cfg) BVSClient := decort.NewBVS(BVSCfg)
// Выполнение запроса на обновление токена // Выполнение запроса на обновление токена
token, err := client.RefreshToken(context.Background()) token, err := BVSClient.RefreshToken(context.Background())
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -1242,19 +1381,19 @@ import (
func main() { func main() {
// Настройка конфигурации // Настройка конфигурации
BVSCfg := config.config.BVSConfig{ BVSCfg := config.BVSConfig{
Username: "<USERNAME>", Username: "<USERNAME>",
Password: "<PASSWORD>", Password: "<PASSWORD>",
AppID: "<APPID>", AppID: "<APPID>",
AppSecret: "<APPSECRET>", AppSecret: "<APPSECRET>",
SSOURL: "https://bvs-delta.qa.loc:8443" SSOURL: "https://bvs-delta.qa.loc:8443",
DecortURL: "https://mr4.digitalenergy.online", DecortURL: "https://mr4.digitalenergy.online",
Domain: "dynamix", Domain: "dynamix",
Retries: 5, Retries: 5,
} }
// Создание клиента // Создание клиента
BVSClient := decort.NewBVS(cfg) BVSClient := decort.NewBVS(BVSCfg)
// Создание структуры запроса // Создание структуры запроса
// CreateRequest - реквест на создание виртуальной машины // CreateRequest - реквест на создание виртуальной машины
@@ -1267,10 +1406,199 @@ func main() {
} }
// Выполнение запроса // Выполнение запроса
res, err := client.CloudAPI().KVMX86().Create(context.Background(), req) res, err := BVSClient.CloudAPI().KVMX86().Create(context.Background(), req)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Println(res) fmt.Println(res)
} }
```
#### Пример валидации запросов, имеющих в своей структуре поле RAM (или MasterRam/WorkerRAM)
Если структура запроса содержит поле RAM (или MasterRam/WorkerRAM), то он может быть проверен на валидность. Для этого запрос должен быть передан в функцию ValidateRAM. Вторым аргументом ValidateRAM ожидает число uint64. Рекомендуется использовать константу constants.RAM_DIVISIBILITY. Функция проверит кратно ли значение поля RAM (или MasterRam/WorkerRAM) этому числу.
#### Пример выполнения запроса
```go
package main
import (
"context"
"fmt"
"log"
"os"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/kvmx86"
)
func main() {
// Настройка конфигурации
cfg := config.Config{
AppID: "<APPID>",
AppSecret: "<APPSECRET>",
SSOURL: "https://sso-delta.qa.loc:8443",
DecortURL: "https://delta.qa.loc",
Retries: 5,
SSLSkipVerify: true,
}
// Создание клиента
client := decort.New(cfg)
// Создание структуры запроса
// CreateRequest - реквест на создание виртуальной машины
req := kvmx86.CreateRequest{
Name: "kvmx86",
RGID: 907,
CPU: 2048,
RAM: 1024,
ImageID: 161,
}
// Валидация запроса
err := validators.ValidateRAM(req, constants.RAM_DIVISIBILITY)
if err != nil {
log.Fatalf("unable to validate request: %v", err)
}
//Выполнение запроса с помощью конвейера
res, err := client.CloudBroker().KVMX86().Create(context.Background(), req)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
log.Println(res)
}
```
## Работа с универсальным клиентом
Работа с универсальным клиентом позволяет использовать любой тип авторизации
### Настройка конфигурации универсального клиента
| Параметр | Тип | Обязательный | Описание |
| --- | --- | --- | --- |
| Decs3oConfig | *Config | Нет | Конфигурация Decs3o |
| BVSConfig | *BVSConfig | Нет | Конфигурация BVS |
| LegacyConfig | string | Нет | Конфигурация Legacy |
В универсальном клиенте можно использовать только один тип конфигурации одновременно.
#### Пример конфигурации универсального клиента
```go
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
)
func main(){
// Настройка конфигурации
BVSConfig := config.BVSConfig{
AppID: "<APP_ID>",
AppSecret: "<APP_SECRET>",
SSOURL: "https://sso.digitalenergy.online",
DecortURL: "https://mr4.digitalenergy.online",
Username: "<Username>",
Password: "<Password>",
Retries: 5,
}
BVSConfig.SetTimeout(5 * time.Minute)
cfg := config.UniversalConfig{
BVSConfig: &BVScfg,
}
}
```
#### Создание универсального клиента
Создание клиента происходит с помощью функции-строителя `NewUniversal` из основного пакета `decort-sdk`, для избежания проблем с именами, пакету можно присвоить алиас `decort`. Функция принимает конфигурацию, возвращает структуру `ClientInterface`, с помощью которой можно взаимодействовать с платформой.
#### Пример создания универсального клиента
```go
package main
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
)
func main() {
// Настройка конфигурации
legacyCfg := config.LegacyConfig{
Username: "<USERNAME>",
Password: "<PASSWORD>",
DecortURL: "https://mr4.digitalenergy.online",
Retries: 5,
}
legacyCfg.SetTimeout(5 * time.Minute)
cfg := config.UniversalConfig{
LegacyConfig: &legacyCfg,
}
// Создание клиента
universalClient := decort.NewUniversal(cfg)
}
```
#### Пример выполнения запроса
```go
package main
import (
"fmt"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
)
func main() {
// Настройка конфигурации
legacyCfg := config.LegacyConfig{
Username: "<USERNAME>",
Password: "<PASSWORD>",
Domain: "dynamix",
DecortURL: "https://mr4.digitalenergy.online",
Retries: 5,
}
legacyCfg.SetTimeout(5 * time.Minute)
cfg := config.UniversalConfig{
LegacyConfig: &legacyCfg,
}
// Создание клиента
universalClient := decort.NewUniversal(cfg)
// Создание структуры запроса
// CreateRequest - реквест на создание виртуальной машины
req := kvmx86.CreateRequest{
RGID: 123,
Name: "compute",
CPU: 4,
RAM: 4096,
ImageID: 321,
}
// Выполнение запроса
res, err := universalClient.CloudAPI().KVMX86().Create(context.Background(), req)
if err != nil {
log.Fatal(err)
}
fmt.Println(res)
}
```

View File

@@ -1,62 +0,0 @@
# Decort SDK
Decort SDK is a library, written in GO (Golang) for interact with the **DECORT** API.
The library contents structures and methods for requesting to an user (cloudapi) and admin (cloudbroker) groups of API.
Also the library have structures for responses.
## Contents
- [Install](#install)
- [API List](#api-list)
- [Examples](#examples)
- [Examples2](#examples2)
## Install
```bash
go get -u repository.basistech.ru/BASIS/decort-golang-sdk
```
## API List
## Examples
```go
package main
import (
"context"
"fmt"
"log"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/kvmx86"
)
func main() {
cfg := config.Config{
AppID: "<APPID>",
AppSecret: "<APPSECRET>",
SSOURL: "https://sso.digitalenergy.online",
DecortURL: "https://mr4.digitalenergy.online",
Retries: 5,
}
client := decort.New(cfg)
req := kvmx86.CreateRequest{
RGID: 123,
Name: "compute",
CPU: 4,
RAM: 4096,
ImageID: 321,
}
res, err := client.KVMX86().Create(context.Background(), req)
if err != nil {
log.Fatal(err)
}
fmt.Println(res)
}
```
## Examples2

538
client.go
View File

@@ -4,11 +4,12 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/tls" "crypto/tls"
"errors" "encoding/json"
"fmt" "fmt"
"io" "io"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"reflect"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@@ -17,13 +18,12 @@ import (
"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/constants" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/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"
) )
// HTTP-client for platform // DecortClient is HTTP-client for platform
type DecortClient struct { type DecortClient struct {
decortURL string decortURL string
client *http.Client client *http.Client
@@ -54,7 +54,7 @@ func New(cfg config.Config) *DecortClient {
}, },
}, },
}, },
cfg: cfg, cfg: trimConfig(&cfg),
expiryTime: expiryTime, expiryTime: expiryTime,
mutex: &sync.Mutex{}, mutex: &sync.Mutex{},
} }
@@ -72,15 +72,15 @@ 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)
var body *bytes.Buffer var body *bytes.Buffer
var ctype string var ctype string
if okCa { byteSlice, ok := params.([]byte)
body, ctype = createK8sCloudApi(k8sCaCreateReq) if ok {
} else if okCb { body = bytes.NewBuffer(byteSlice)
body, ctype = createK8sCloudBroker(k8sCbCreateReq) // ctype = "application/x-iso9660-image"
ctype = "application/octet-stream"
} else { } else {
values, err := query.Values(params) values, err := query.Values(params)
if err != nil { if err != nil {
@@ -89,325 +89,289 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
body = bytes.NewBufferString(values.Encode()) body = bytes.NewBufferString(values.Encode())
} }
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+constants.Restmachine+url, body) req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+constants.RESTMACHINE+url, body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// get token
if err = dc.getToken(ctx); err != nil {
return nil, err
}
// perform request
respBytes, err := dc.do(req, ctype)
if err != nil {
return nil, err
}
return respBytes, err
}
// DecortApiCallMP method for sending requests to the platform
func (dc *DecortClient) DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
body, ctype, err := multiPartReq(params)
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+constants.RESTMACHINE+url, body)
if err != nil {
return nil, err
}
// get token
if err = dc.getToken(ctx); err != nil { if err = dc.getToken(ctx); err != nil {
return nil, err return nil, err
} }
resp, err := dc.do(req, ctype) // perform request
if err != nil { respBytes, err := dc.do(req, ctype)
return nil, err
}
defer resp.Body.Close()
respBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if resp.StatusCode != 200 { return respBytes, err
return nil, errors.New(string(respBytes))
}
return respBytes, nil
} }
func (dc *DecortClient) getToken(ctx context.Context) error { func (dc *DecortClient) getToken(ctx context.Context) error {
dc.mutex.Lock() dc.mutex.Lock()
defer dc.mutex.Unlock() defer dc.mutex.Unlock()
if dc.cfg.Token == "" || time.Now().After(dc.expiryTime) { // new token is not needed
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", dc.cfg.AppID, dc.cfg.AppSecret) if dc.cfg.Token != "" && !time.Now().After(dc.expiryTime) {
bodyReader := strings.NewReader(body) return nil
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)
} }
// set up request headers and body
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")
// request token
resp, err := dc.client.Do(req)
if err != nil || resp == nil {
return fmt.Errorf("cannot get token: %w", err)
}
defer resp.Body.Close()
var tokenBytes []byte
tokenBytes, err = io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("cannot get token: %w", err)
}
if resp.StatusCode != 200 {
return fmt.Errorf("cannot get token: %s", tokenBytes)
}
// save token in config
token := string(tokenBytes)
dc.cfg.Token = token
dc.expiryTime = time.Now().AddDate(0, 0, 1)
return nil return nil
} }
func (dc *DecortClient) do(req *http.Request, ctype string) (*http.Response, error) { // do method performs request and returns response as an array of bytes and nil error in case of response status code 200.
// In any other cases do returns nil response and error.
// Retries are implemented in case of connection reset errors.
func (dc *DecortClient) do(req *http.Request, ctype string) ([]byte, error) {
// set up request headers and body
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
if ctype != "" { if ctype != "" {
req.Header.Add("Content-Type", ctype) req.Header.Set("Content-Type", ctype)
} else {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
} }
req.Header.Add("Authorization", "bearer "+dc.cfg.Token) req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
// var resp *http.Response buf, err := io.ReadAll(req.Body)
// var err error
buf, _ := io.ReadAll(req.Body)
// for i := uint64(0); i < dc.cfg.Retries; i++ {
// req = req.Clone(req.Context())
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := dc.client.Do(req)
if err != nil || resp == nil {
return resp, err
}
if resp.StatusCode == 200 {
return resp, err
}
respBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.Body.Close()
return resp, errors.New(string(respBytes)) req.Body.Close()
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := dc.client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
// retries logic GOES HERE
// get http response
//var resp *http.Response
//for i := uint64(0); i < dc.cfg.Retries; i++ {
// req := req.Clone(req.Context())
// req.Body = io.NopCloser(bytes.NewBuffer(buf))
//
// if i > 0 {
// time.Sleep(5 * time.Second) // no time sleep for the first request
// }
//
// resp, err = dc.client.Do(req)
//
// // stop retries on success and close response body
// if resp != nil {
// defer resp.Body.Close()
// }
// if err == nil {
// break
// }
//
// // retries in case of connection errors with time sleep
// if isConnectionError(err) {
// continue
// }
//
// // return error in case of non-connection error
// return nil, err
//}
// handle http request errors
if err != nil {
return nil, err
}
if resp == nil {
return nil, fmt.Errorf("got empty response without error")
}
// handle successful request
respBytes, _ := io.ReadAll(resp.Body)
if resp.StatusCode == 200 {
return respBytes, nil
}
// handle errors with status code other than 200
err = fmt.Errorf("%s", respBytes)
return nil, fmt.Errorf("could not execute request: %w", err)
} }
func createK8sCloudApi(req k8s_ca.CreateRequest) (*bytes.Buffer, string) { // isConnectionError checks if given error falls within specific and associated connection errors
//func isConnectionError(err error) bool {
// if strings.Contains(err.Error(), "connection reset by peer") {
// return true
// }
// if errors.Is(err, io.EOF) {
// return true
// }
//
// return false
//}
// multiPartReq writes the request structure to the request body, and also returns string of the content-type
func multiPartReq(params interface{}) (*bytes.Buffer, string, error) {
reqBody := &bytes.Buffer{} reqBody := &bytes.Buffer{}
writer := multipart.NewWriter(reqBody) writer := multipart.NewWriter(reqBody)
if req.OidcCertificate != "" { values := reflect.ValueOf(params)
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt") types := values.Type()
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate)) defer writer.Close()
} for i := 0; i < values.NumField(); i++ {
if !values.Field(i).IsValid() {
continue
}
_ = writer.WriteField("name", req.Name) if values.Field(i).IsZero() {
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10)) continue
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8SCIID, 10)) }
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
if req.MasterSEPID != 0 { if file, ok := constants.FileName[types.Field(i).Name]; ok {
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10)) part, err := writer.CreateFormFile(trimString(types.Field(i)), file)
} if err != nil {
if req.MasterSEPPool != "" { return &bytes.Buffer{}, "", err
_ = writer.WriteField("masterSepPool", req.MasterSEPPool) }
} _, err = io.Copy(part, strings.NewReader(valueToString(values.Field(i).Interface())))
if req.WorkerSEPID != 0 { if err != nil {
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10)) return &bytes.Buffer{}, "", err
} }
if req.WorkerSEPPool != "" { continue
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool) }
}
if req.Labels != nil { if values.Field(i).Type().Kind() == reflect.Slice {
for _, v := range req.Labels { switch slice := values.Field(i).Interface().(type) {
_ = writer.WriteField("labels", v) case []string:
if validators.IsInSlice(trimString(types.Field(i)), constants.K8sValues) {
code, err := json.Marshal(slice)
if err != nil {
return &bytes.Buffer{}, "", err
}
err = writer.WriteField(trimString(types.Field(i)), string(code))
if err != nil {
return &bytes.Buffer{}, "", err
}
} else {
for _, val := range slice {
err := writer.WriteField(trimString(types.Field(i)), val)
if err != nil {
return &bytes.Buffer{}, "", err
}
}
}
case []uint:
for _, val := range slice {
err := writer.WriteField(trimString(types.Field(i)), strconv.FormatUint(uint64(val), 10))
if err != nil {
return &bytes.Buffer{}, "", err
}
}
case []uint64:
for _, val := range slice {
err := writer.WriteField(trimString(types.Field(i)), strconv.FormatUint(val, 10))
if err != nil {
return &bytes.Buffer{}, "", err
}
}
case []map[string]interface{}:
for _, val := range slice {
encodeStr, err := json.Marshal(val)
if err != nil {
return &bytes.Buffer{}, "", err
}
err = writer.WriteField(trimString(types.Field(i)), string(encodeStr))
if err != nil {
return &bytes.Buffer{}, "", err
}
}
default:
return &bytes.Buffer{}, "", fmt.Errorf("unsupported slice type:%T", slice)
}
continue
}
err := writer.WriteField(trimString(types.Field(i)), valueToString(values.Field(i).Interface()))
if err != nil {
return &bytes.Buffer{}, "", err
} }
} }
if req.Taints != nil {
for _, v := range req.Taints {
_ = writer.WriteField("taints", v)
}
}
if req.Annotations != nil {
for _, v := range req.Annotations {
_ = writer.WriteField("annotations", v)
}
}
if req.MasterCPU != 0 {
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(req.MasterCPU), 10))
}
if req.MasterNum != 0 {
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(req.MasterNum), 10))
}
if req.MasterRAM != 0 {
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(req.MasterRAM), 10))
}
if req.MasterDisk != 0 {
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(req.MasterDisk), 10))
}
if req.WorkerCPU != 0 {
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(req.WorkerCPU), 10))
}
if req.WorkerNum != 0 {
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(req.WorkerNum), 10))
}
if req.WorkerRAM != 0 {
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(req.WorkerRAM), 10))
}
if req.WorkerDisk != 0 {
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(req.WorkerDisk), 10))
}
if req.ExtNetID != 0 {
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
}
if req.VinsId != 0 {
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
}
if !req.WithLB {
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
}
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
if req.AdditionalSANs != nil {
for _, v := range req.AdditionalSANs {
_ = writer.WriteField("additionalSANs", v)
}
}
if req.InitConfiguration != "" {
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
}
if req.ClusterConfiguration != "" {
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
}
if req.KubeletConfiguration != "" {
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
}
if req.KubeProxyConfiguration != "" {
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
}
if req.JoinConfiguration != "" {
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
}
if req.Description != "" {
_ = writer.WriteField("desc", req.Description)
}
if req.UserData != "" {
_ = writer.WriteField("userData", req.UserData)
}
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
ct := writer.FormDataContentType() ct := writer.FormDataContentType()
writer.Close() return reqBody, ct, nil
return reqBody, ct
} }
func createK8sCloudBroker(req k8s_cb.CreateRequest) (*bytes.Buffer, string) { func valueToString(a any) string {
reqBody := &bytes.Buffer{} switch str := a.(type) {
writer := multipart.NewWriter(reqBody) case string:
if req.OidcCertificate != "" { return str
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt") case uint:
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate)) return strconv.FormatUint(uint64(str), 10)
case uint64:
return strconv.FormatUint(str, 10)
case bool:
return strconv.FormatBool(str)
default:
return ""
} }
}
_ = writer.WriteField("name", req.Name)
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10)) func trimString(el reflect.StructField) string {
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8CIID, 10)) return strings.TrimSuffix(el.Tag.Get("url"), ",omitempty")
_ = writer.WriteField("workerGroupName", req.WorkerGroupName) }
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
func trimConfig(cfg *config.Config) config.Config {
if req.MasterSEPID != 0 { cfg.SSOURL = strings.TrimSuffix(cfg.SSOURL, "/")
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10)) cfg.DecortURL = strings.TrimSuffix(cfg.DecortURL, "/")
} return *cfg
if req.MasterSEPPool != "" {
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
}
if req.WorkerSEPID != 0 {
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
}
if req.WorkerSEPPool != "" {
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
}
if req.Labels != nil {
for _, v := range req.Labels {
_ = writer.WriteField("labels", v)
}
}
if req.Taints != nil {
for _, v := range req.Taints {
_ = writer.WriteField("taints", v)
}
}
if req.Annotations != nil {
for _, v := range req.Annotations {
_ = writer.WriteField("annotations", v)
}
}
if req.MasterCPU != 0 {
_ = writer.WriteField("masterCpu", strconv.FormatUint(req.MasterCPU, 10))
}
if req.MasterNum != 0 {
_ = writer.WriteField("masterNum", strconv.FormatUint(req.MasterNum, 10))
}
if req.MasterRAM != 0 {
_ = writer.WriteField("masterRam", strconv.FormatUint(req.MasterRAM, 10))
}
if req.MasterDisk != 0 {
_ = writer.WriteField("masterDisk", strconv.FormatUint(req.MasterDisk, 10))
}
if req.WorkerCPU != 0 {
_ = writer.WriteField("workerCpu", strconv.FormatUint(req.WorkerCPU, 10))
}
if req.WorkerNum != 0 {
_ = writer.WriteField("workerNum", strconv.FormatUint(req.WorkerNum, 10))
}
if req.WorkerRAM != 0 {
_ = writer.WriteField("workerRam", strconv.FormatUint(req.WorkerRAM, 10))
}
if req.WorkerDisk != 0 {
_ = writer.WriteField("workerDisk", strconv.FormatUint(req.WorkerDisk, 10))
}
if req.ExtNetID != 0 {
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
}
if req.VinsId != 0 {
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
}
if !req.WithLB {
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
}
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
if req.AdditionalSANs != nil {
for _, v := range req.AdditionalSANs {
_ = writer.WriteField("additionalSANs", v)
}
}
if req.InitConfiguration != "" {
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
}
if req.ClusterConfiguration != "" {
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
}
if req.KubeletConfiguration != "" {
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
}
if req.KubeProxyConfiguration != "" {
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
}
if req.JoinConfiguration != "" {
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
}
if req.Description != "" {
_ = writer.WriteField("desc", req.Description)
}
if req.UserData != "" {
_ = writer.WriteField("userData", req.UserData)
}
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
ct := writer.FormDataContentType()
writer.Close()
return reqBody, ct
} }

View File

@@ -8,9 +8,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"mime/multipart"
"net/http" "net/http"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -19,12 +17,10 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"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"
) )
// HTTP-client for platform // BVSDecortClient is HTTP-client for platform
type BVSDecortClient struct { type BVSDecortClient struct {
client *http.Client client *http.Client
cfg config.BVSConfig cfg config.BVSConfig
@@ -58,7 +54,7 @@ func NewBVS(cfg config.BVSConfig) *BVSDecortClient {
}, },
}, },
}, },
cfg: cfg, cfg: trimBVSConfig(&cfg),
mutex: &sync.Mutex{}, mutex: &sync.Mutex{},
} }
} }
@@ -75,15 +71,14 @@ func (bdc *BVSDecortClient) CloudBroker() *cloudbroker.CloudBroker {
// DecortApiCall method for sending requests to the platform // DecortApiCall method for sending requests to the platform
func (bdc *BVSDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) { func (bdc *BVSDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
k8sCaCreateReq, okCa := params.(k8s_ca.CreateRequest)
k8sCbCreateReq, okCb := params.(k8s_cb.CreateRequest)
var body *bytes.Buffer var body *bytes.Buffer
var ctype string var ctype string
if okCa { byteSlice, ok := params.([]byte)
body, ctype = createK8sCloudApiBVS(k8sCaCreateReq) if ok {
} else if okCb { body = bytes.NewBuffer(byteSlice)
body, ctype = createK8sCloudBrokerBVS(k8sCbCreateReq) // ctype = "application/x-iso9660-image"
ctype = "application/octet-stream"
} else { } else {
values, err := query.Values(params) values, err := query.Values(params)
if err != nil { if err != nil {
@@ -92,17 +87,19 @@ func (bdc *BVSDecortClient) DecortApiCall(ctx context.Context, method, url strin
body = bytes.NewBufferString(values.Encode()) body = bytes.NewBufferString(values.Encode())
} }
req, err := http.NewRequestWithContext(ctx, method, bdc.decortURL+constants.Restmachine+url, body) req, err := http.NewRequestWithContext(ctx, method, bdc.decortURL+constants.RESTMACHINE+url, body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// get token
if bdc.cfg.Token.AccessToken == "" { if bdc.cfg.Token.AccessToken == "" {
if _, err = bdc.GetToken(ctx); err != nil { if _, err = bdc.GetToken(ctx); err != nil {
return nil, err return nil, err
} }
} }
// refresh token
if bdc.cfg.Token.RefreshToken != "" && bdc.cfg.Token.Expiry.Add(-time.Duration(bdc.cfg.TimeToRefresh)*time.Minute).Before(time.Now()) { if bdc.cfg.Token.RefreshToken != "" && bdc.cfg.Token.Expiry.Add(-time.Duration(bdc.cfg.TimeToRefresh)*time.Minute).Before(time.Now()) {
if _, err := bdc.RefreshToken(ctx); err != nil { if _, err := bdc.RefreshToken(ctx); err != nil {
if _, err = bdc.GetToken(ctx); err != nil { if _, err = bdc.GetToken(ctx); err != nil {
@@ -110,46 +107,87 @@ func (bdc *BVSDecortClient) DecortApiCall(ctx context.Context, method, url strin
} }
} }
} }
// perform request
reqCopy := req.Clone(ctx) reqCopy := req.Clone(ctx)
//nolint:bodyclose respBytes, err := bdc.do(req, ctype)
//work defer, error lint if err == nil {
resp, err := bdc.do(req, ctype) return respBytes, nil
if err != nil { }
if err.Error() == "access is denied" {
if _, err = bdc.GetToken(ctx); err != nil { // get token and retry in case of access denied
return nil, err if err.Error() == "access is denied" {
} _, err = bdc.GetToken(ctx)
//nolint:bodyclose if err != nil {
//we close the body in case of any error return nil, err
resp, err = bdc.do(reqCopy, ctype) }
if err != nil {
return nil, err respBytes, err = bdc.do(reqCopy, "")
} if err != nil {
} else {
return nil, err return nil, err
} }
} }
defer resp.Body.Close()
respBytes, err := io.ReadAll(resp.Body) return respBytes, err
}
func (bdc *BVSDecortClient) DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
body, ctype, err := multiPartReq(params)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if resp.StatusCode != 200 { req, err := http.NewRequestWithContext(ctx, method, bdc.decortURL+constants.RESTMACHINE+url, body)
return nil, errors.New(string(respBytes)) if err != nil {
return nil, err
} }
return respBytes, nil // get token
if bdc.cfg.Token.AccessToken == "" {
if _, err = bdc.GetToken(ctx); err != nil {
return nil, err
}
}
// refresh token
if bdc.cfg.Token.RefreshToken != "" && bdc.cfg.Token.Expiry.Add(-time.Duration(bdc.cfg.TimeToRefresh)*time.Minute).Before(time.Now()) {
if _, err := bdc.RefreshToken(ctx); err != nil {
if _, err = bdc.GetToken(ctx); err != nil {
return nil, err
}
}
}
// perform request
reqCopy := req.Clone(ctx)
respBytes, err := bdc.do(req, ctype)
if err == nil {
return respBytes, nil
}
// get token and retry in case of access denied
if err.Error() == "access is denied" {
_, err = bdc.GetToken(ctx)
if err != nil {
return nil, err
}
respBytes, err = bdc.do(reqCopy, ctype)
if err != nil {
return nil, err
}
}
return respBytes, err
} }
// GetToken allows you to get a token and returns the token structure, when specifying the PathCfg variable, // GetToken allows you to get a token and returns the token structure. When specifying the PathCfg variable,
// the token and configuration will be written to a file, // the token and configuration will be written to a file.
// when specifying the PathToken variable, the token will be written to a file // When specifying the PathToken variable, the token will be written to a file.
func (bdc *BVSDecortClient) GetToken(ctx context.Context) (config.Token, error) { func (bdc *BVSDecortClient) GetToken(ctx context.Context) (config.Token, error) {
bdc.mutex.Lock() bdc.mutex.Lock()
defer bdc.mutex.Unlock() defer bdc.mutex.Unlock()
// set up request headers and body
body := fmt.Sprintf("grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s&response_type=token&scope=openid", bdc.cfg.AppID, bdc.cfg.AppSecret, bdc.cfg.Username, bdc.cfg.Password) body := fmt.Sprintf("grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s&response_type=token&scope=openid", bdc.cfg.AppID, bdc.cfg.AppSecret, bdc.cfg.Username, bdc.cfg.Password)
bodyReader := strings.NewReader(body) bodyReader := strings.NewReader(body)
@@ -158,20 +196,25 @@ func (bdc *BVSDecortClient) GetToken(ctx context.Context) (config.Token, error)
req, _ := http.NewRequestWithContext(ctx, "POST", bdc.cfg.SSOURL+"/realms/"+bdc.cfg.Domain+"/protocol/openid-connect/token", bodyReader) req, _ := http.NewRequestWithContext(ctx, "POST", bdc.cfg.SSOURL+"/realms/"+bdc.cfg.Domain+"/protocol/openid-connect/token", bodyReader)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
// request token
resp, err := bdc.client.Do(req) resp, err := bdc.client.Do(req)
if err != nil || resp == nil {
return config.Token{}, fmt.Errorf("cannot get token: %w", err)
}
defer resp.Body.Close()
var tokenBytes []byte
tokenBytes, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return config.Token{}, fmt.Errorf("cannot get token: %w", err) return config.Token{}, fmt.Errorf("cannot get token: %w", err)
} }
tokenBytes, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
return config.Token{}, fmt.Errorf("cannot get token: %s", tokenBytes) return config.Token{}, fmt.Errorf("cannot get token: %s", tokenBytes)
} }
// save token in config
var tj tokenJSON var tj tokenJSON
if err = json.Unmarshal(tokenBytes, &tj); err != nil { if err = json.Unmarshal(tokenBytes, &tj); err != nil {
return config.Token{}, fmt.Errorf("cannot unmarshal token: %w", err) return config.Token{}, fmt.Errorf("cannot unmarshal token: %w", err)
} }
@@ -196,13 +239,14 @@ func (bdc *BVSDecortClient) GetToken(ctx context.Context) (config.Token, error)
return bdc.cfg.Token, nil return bdc.cfg.Token, nil
} }
// RefreshToken allows you to refresh a token and returns the token structure, when specifying the PathCfg variable, // RefreshToken allows you to refresh a token and returns the token structure. When specifying the PathCfg variable,
// the token and configuration will be written to a file, // the token and configuration will be written to a file.
// when specifying the PathToken variable, the token will be written to a file // When specifying the PathToken variable, the token will be written to a file
func (bdc *BVSDecortClient) RefreshToken(ctx context.Context) (config.Token, error) { func (bdc *BVSDecortClient) RefreshToken(ctx context.Context) (config.Token, error) {
bdc.mutex.Lock() bdc.mutex.Lock()
defer bdc.mutex.Unlock() defer bdc.mutex.Unlock()
// set up request headers and body
body := fmt.Sprintf("grant_type=refresh_token&client_id=%s&client_secret=%s&refresh_token=%s&scope=openid", bdc.cfg.AppID, bdc.cfg.AppSecret, bdc.cfg.Token.RefreshToken) body := fmt.Sprintf("grant_type=refresh_token&client_id=%s&client_secret=%s&refresh_token=%s&scope=openid", bdc.cfg.AppID, bdc.cfg.AppSecret, bdc.cfg.Token.RefreshToken)
bodyReader := strings.NewReader(body) bodyReader := strings.NewReader(body)
@@ -211,20 +255,25 @@ func (bdc *BVSDecortClient) RefreshToken(ctx context.Context) (config.Token, err
req, _ := http.NewRequestWithContext(ctx, "POST", bdc.cfg.SSOURL+"/realms/"+bdc.cfg.Domain+"/protocol/openid-connect/token", bodyReader) req, _ := http.NewRequestWithContext(ctx, "POST", bdc.cfg.SSOURL+"/realms/"+bdc.cfg.Domain+"/protocol/openid-connect/token", bodyReader)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
// refresh token
resp, err := bdc.client.Do(req) resp, err := bdc.client.Do(req)
if err != nil || resp == nil {
return config.Token{}, fmt.Errorf("cannot refresh token: %w", err)
}
defer resp.Body.Close()
var tokenBytes []byte
tokenBytes, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return config.Token{}, fmt.Errorf("cannot refresh token: %w", err) return config.Token{}, fmt.Errorf("cannot refresh token: %w", err)
} }
tokenBytes, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
return config.Token{}, fmt.Errorf("cannot refresh token: %s", tokenBytes) return config.Token{}, fmt.Errorf("cannot refresh token: %s", tokenBytes)
} }
// save token in config
var tj tokenJSON var tj tokenJSON
if err = json.Unmarshal(tokenBytes, &tj); err != nil { if err = json.Unmarshal(tokenBytes, &tj); err != nil {
return config.Token{}, fmt.Errorf("cannot unmarshal after refresh token: %w", err) return config.Token{}, fmt.Errorf("cannot unmarshal after refresh token: %w", err)
} }
@@ -256,264 +305,91 @@ func (e *tokenJSON) expiry() (t time.Time) {
return return
} }
func (bdc *BVSDecortClient) do(req *http.Request, ctype string) (*http.Response, error) { // do method performs request and returns response as an array of bytes and nil error in case of response status code 200.
// In any other cases do returns nil response and error.
// Retries are implemented in case of connection reset errors.
func (bdc *BVSDecortClient) do(req *http.Request, ctype string) ([]byte, error) {
// set up request headers and body
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
if ctype != "" { if ctype != "" {
req.Header.Add("Content-Type", ctype) req.Header.Set("Content-Type", ctype)
} else {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
} }
req.Header.Add("Authorization", "bearer "+bdc.cfg.Token.AccessToken) req.Header.Add("Authorization", "bearer "+bdc.cfg.Token.AccessToken)
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
buf, _ := io.ReadAll(req.Body) buf, err := io.ReadAll(req.Body)
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := bdc.client.Do(req)
if err != nil || resp == nil {
return resp, err
}
if resp.StatusCode == 401 {
resp.Body.Close()
return resp, errors.New("access is denied")
}
if resp.StatusCode == 200 {
return resp, err
}
respBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.Body.Close()
return resp, errors.New(string(respBytes)) req.Body.Close()
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := bdc.client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
// retries logic GOES HERE
// get http response
//var resp *http.Response
//for i := uint64(0); i < bdc.cfg.Retries; i++ {
// req := req.Clone(req.Context())
// req.Body = io.NopCloser(bytes.NewBuffer(buf))
//
// if i > 0 {
// time.Sleep(5 * time.Second) // no time sleep for the first request
// }
//
// resp, err = bdc.client.Do(req)
//
// // stop retries on success and close response body
// if resp != nil {
// defer resp.Body.Close()
// }
// if err == nil {
// break
// }
//
// // retries in case of connection errors with time sleep
// if isConnectionError(err) {
// continue
// }
//
// // return error in case of non-connection error
// return nil, err
//}
// handle http request errors
if err != nil {
return nil, err
}
if resp == nil {
return nil, fmt.Errorf("got empty response without error")
}
var respBytes []byte
respBytes, err = io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
// handle access denied and successful request
if resp.StatusCode == 401 {
return respBytes, errors.New("access is denied")
}
if resp.StatusCode == 200 {
return respBytes, nil
}
// handle errors with other status codes
err = fmt.Errorf("%s", respBytes)
return nil, fmt.Errorf("could not execute request: %w", err)
} }
func createK8sCloudApiBVS(req k8s_ca.CreateRequest) (*bytes.Buffer, string) { func trimBVSConfig(cfg *config.BVSConfig) config.BVSConfig {
reqBody := &bytes.Buffer{} cfg.SSOURL = strings.TrimSuffix(cfg.SSOURL, "/")
writer := multipart.NewWriter(reqBody) cfg.DecortURL = strings.TrimSuffix(cfg.DecortURL, "/")
if req.OidcCertificate != "" { return *cfg
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
}
_ = writer.WriteField("name", req.Name)
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8SCIID, 10))
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
if req.MasterSEPID != 0 {
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
}
if req.MasterSEPPool != "" {
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
}
if req.WorkerSEPID != 0 {
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
}
if req.WorkerSEPPool != "" {
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
}
if req.Labels != nil {
for _, v := range req.Labels {
_ = writer.WriteField("labels", v)
}
}
if req.Taints != nil {
for _, v := range req.Taints {
_ = writer.WriteField("taints", v)
}
}
if req.Annotations != nil {
for _, v := range req.Annotations {
_ = writer.WriteField("annotations", v)
}
}
if req.MasterCPU != 0 {
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(req.MasterCPU), 10))
}
if req.MasterNum != 0 {
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(req.MasterNum), 10))
}
if req.MasterRAM != 0 {
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(req.MasterRAM), 10))
}
if req.MasterDisk != 0 {
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(req.MasterDisk), 10))
}
if req.WorkerCPU != 0 {
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(req.WorkerCPU), 10))
}
if req.WorkerNum != 0 {
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(req.WorkerNum), 10))
}
if req.WorkerRAM != 0 {
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(req.WorkerRAM), 10))
}
if req.WorkerDisk != 0 {
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(req.WorkerDisk), 10))
}
if req.ExtNetID != 0 {
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
}
if req.VinsId != 0 {
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
}
if !req.WithLB {
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
}
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
if req.AdditionalSANs != nil {
for _, v := range req.AdditionalSANs {
_ = writer.WriteField("additionalSANs", v)
}
}
if req.InitConfiguration != "" {
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
}
if req.ClusterConfiguration != "" {
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
}
if req.KubeletConfiguration != "" {
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
}
if req.KubeProxyConfiguration != "" {
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
}
if req.JoinConfiguration != "" {
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
}
if req.Description != "" {
_ = writer.WriteField("desc", req.Description)
}
if req.UserData != "" {
_ = writer.WriteField("userData", req.UserData)
}
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
ct := writer.FormDataContentType()
writer.Close()
return reqBody, ct
}
func createK8sCloudBrokerBVS(req k8s_cb.CreateRequest) (*bytes.Buffer, string) {
reqBody := &bytes.Buffer{}
writer := multipart.NewWriter(reqBody)
if req.OidcCertificate != "" {
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
}
_ = writer.WriteField("name", req.Name)
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8CIID, 10))
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
if req.MasterSEPID != 0 {
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
}
if req.MasterSEPPool != "" {
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
}
if req.WorkerSEPID != 0 {
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
}
if req.WorkerSEPPool != "" {
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
}
if req.Labels != nil {
for _, v := range req.Labels {
_ = writer.WriteField("labels", v)
}
}
if req.Taints != nil {
for _, v := range req.Taints {
_ = writer.WriteField("taints", v)
}
}
if req.Annotations != nil {
for _, v := range req.Annotations {
_ = writer.WriteField("annotations", v)
}
}
if req.MasterCPU != 0 {
_ = writer.WriteField("masterCpu", strconv.FormatUint(req.MasterCPU, 10))
}
if req.MasterNum != 0 {
_ = writer.WriteField("masterNum", strconv.FormatUint(req.MasterNum, 10))
}
if req.MasterRAM != 0 {
_ = writer.WriteField("masterRam", strconv.FormatUint(req.MasterRAM, 10))
}
if req.MasterDisk != 0 {
_ = writer.WriteField("masterDisk", strconv.FormatUint(req.MasterDisk, 10))
}
if req.WorkerCPU != 0 {
_ = writer.WriteField("workerCpu", strconv.FormatUint(req.WorkerCPU, 10))
}
if req.WorkerNum != 0 {
_ = writer.WriteField("workerNum", strconv.FormatUint(req.WorkerNum, 10))
}
if req.WorkerRAM != 0 {
_ = writer.WriteField("workerRam", strconv.FormatUint(req.WorkerRAM, 10))
}
if req.WorkerDisk != 0 {
_ = writer.WriteField("workerDisk", strconv.FormatUint(req.WorkerDisk, 10))
}
if req.ExtNetID != 0 {
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
}
if req.VinsId != 0 {
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
}
if !req.WithLB {
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
}
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
if req.AdditionalSANs != nil {
for _, v := range req.AdditionalSANs {
_ = writer.WriteField("additionalSANs", v)
}
}
if req.InitConfiguration != "" {
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
}
if req.ClusterConfiguration != "" {
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
}
if req.KubeletConfiguration != "" {
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
}
if req.KubeProxyConfiguration != "" {
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
}
if req.JoinConfiguration != "" {
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
}
if req.Description != "" {
_ = writer.WriteField("desc", req.Description)
}
if req.UserData != "" {
_ = writer.WriteField("userData", req.UserData)
}
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
ct := writer.FormDataContentType()
writer.Close()
return reqBody, ct
} }

View File

@@ -0,0 +1,8 @@
package config
// UniversalConfig combines configurations for different types of clients
type UniversalConfig struct {
Decs3oConfig *Config `json:"decs3oConfig,omitempty" yaml:"decs3oConfig,omitempty"`
BVSConfig *BVSConfig `json:"bvsConfig,omitempty" yaml:"bvsConfig,omitempty"`
LegacyConfig *LegacyConfig `json:"legacyConfig,omitempty" yaml:"legacyConfig,omitempty"`
}

1
go.mod
View File

@@ -5,6 +5,7 @@ go 1.20
require ( require (
github.com/go-playground/validator/v10 v10.11.2 github.com/go-playground/validator/v10 v10.11.2
github.com/google/go-querystring v1.1.0 github.com/google/go-querystring v1.1.0
github.com/joho/godotenv v1.5.1
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )

2
go.sum
View File

@@ -13,6 +13,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=

View File

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

7
interfaces/request.go Normal file
View File

@@ -0,0 +1,7 @@
package interfaces
// Interface to valiate RAM values
type RequestWithRAM interface {
// GetRAM returns RAM values
GetRAM() map[string]uint64
}

View File

@@ -1,5 +1,14 @@
package constants package constants
const Restmachine = "/restmachine" const (
RESTMACHINE = "/restmachine"
// RAM_DIVISIBILITY sets divisibility of RAM value
RAM_DIVISIBILITY uint64 = 128
)
var FileName = map[string]string{
"OidcCertificate": "ca.crt",
}
var K8sValues = []string{"labels", "taints", "annotations, additionalSANs"}

View File

@@ -1,31 +1,44 @@
package validators package validators
import ( import (
"errors"
"fmt"
"net/url"
"reflect"
"regexp" "regexp"
"strings" "strings"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/multierror"
) )
// computeDriverValidator is used to validate Driver field in kvmx86/kvmppc create. // computeDriverValidator is used to validate Driver field in kvmx86 create.
func computeDriverValidator(fe validator.FieldLevel) bool { func computeDriverValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeDriverValues) return IsInSlice(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()
return StringInSlice(fieldValue, protoValues) return IsInSlice(fieldValue, protoValues)
}
// apiGroupValidator is used to validate APIGroup fields
func apiGroupValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, apiGroupValues)
} }
// accessTypeValidator is used to validate AccessType fields. // accessTypeValidator is used to validate AccessType fields.
func accessTypeValidator(fe validator.FieldLevel) bool { func accessTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, accessTypeValues) return IsInSlice(fieldValue, accessTypeValues)
} }
// resTypesValidator is used to validate ResTypes fields. // resTypesValidator is used to validate ResTypes fields.
@@ -36,7 +49,7 @@ func resTypesValidator(fe validator.FieldLevel) bool {
} }
for _, value := range fieldSlice { for _, value := range fieldSlice {
if !StringInSlice(value, resTypesValues) { if !IsInSlice(value, resTypesValues) {
return false return false
} }
} }
@@ -48,56 +61,63 @@ func resTypesValidator(fe validator.FieldLevel) bool {
func driverValidator(fe validator.FieldLevel) bool { func driverValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, driverValues) return IsInSlice(fieldValue, driverValues)
} }
// accountCUTypeValidator is used to validate CUType field. // accountCUTypeValidator is used to validate CUType field.
func accountCUTypeValidator(fe validator.FieldLevel) bool { func accountCUTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, accountCUTypeValues) return IsInSlice(fieldValue, accountCUTypeValues)
} }
// bserviceModeValidator is used to validate Mode field. // bserviceModeValidator is used to validate Mode field.
func bserviceModeValidator(fe validator.FieldLevel) bool { func bserviceModeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, bserviceModeValues) return IsInSlice(fieldValue, bserviceModeValues)
} }
// computeTopologyValidator is used to validate Topology field. // computeTopologyValidator is used to validate Topology field.
func computeTopologyValidator(fe validator.FieldLevel) bool { func computeTopologyValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeTopologyValues) return IsInSlice(fieldValue, computeTopologyValues)
} }
// computePolicyValidator is used to validate Policy field. // computePolicyValidator is used to validate Policy field.
func computePolicyValidator(fe validator.FieldLevel) bool { func computePolicyValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computePolicyValues) return IsInSlice(fieldValue, computePolicyValues)
} }
// computeModeValidator is used to validate Mode field. // computeModeValidator is used to validate Mode field.
func computeModeValidator(fe validator.FieldLevel) bool { func computeModeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeModeValues) return IsInSlice(fieldValue, computeModeValues)
} }
// computeDiskTypeValidator is used to validate DiskType field. // computeDiskTypeValidator is used to validate DiskType field.
func computeDiskTypeValidator(fe validator.FieldLevel) bool { func computeDiskTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeDiskTypeValues) return IsInSlice(fieldValue, computeDiskTypeValues)
} }
// computeNetTypeValidator is used to validate NetType field. // computeNetTypeValidator is used to validate NetType field.
func computeNetTypeValidator(fe validator.FieldLevel) bool { func computeNetTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeNetTypeValues) return IsInSlice(fieldValue, computeNetTypeValues)
}
// computex86NetTypeValidator is used to validate NetType field.
func computex86NetTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, computex86NetTypeValues)
} }
// computeOrderValidator is used to validate Order field. // computeOrderValidator is used to validate Order field.
@@ -108,7 +128,7 @@ func computeOrderValidator(fe validator.FieldLevel) bool {
} }
for _, value := range fieldSlice { for _, value := range fieldSlice {
if !StringInSlice(value, computeOrderValues) { if !IsInSlice(value, computeOrderValues) {
return false return false
} }
} }
@@ -120,70 +140,70 @@ func computeOrderValidator(fe validator.FieldLevel) bool {
func computeDataDisksValidator(fe validator.FieldLevel) bool { func computeDataDisksValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeDataDisksValues) return IsInSlice(fieldValue, computeDataDisksValues)
} }
// diskTypeValidator is used to validate Type field. // diskTypeValidator is used to validate Type field.
func diskTypeValidator(fe validator.FieldLevel) bool { func diskTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, diskTypeValues) return IsInSlice(fieldValue, diskTypeValues)
} }
// flipgroupClientTypeValidator is used to validate ClientType field. // flipgroupClientTypeValidator is used to validate ClientType field.
func flipgroupClientTypeValidator(fe validator.FieldLevel) bool { func flipgroupClientTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, flipgroupClientTypeValues) return IsInSlice(fieldValue, flipgroupClientTypeValues)
} }
// kvmNetTypeValidator is used to validate NetType field. // kvmNetTypeValidator is used to validate NetType field.
func kvmNetTypeValidator(fe validator.FieldLevel) bool { func kvmNetTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, kvmNetTypeValues) return IsInSlice(fieldValue, kvmNetTypeValues)
} }
// lbAlgorithmValidator is used to validate Algorithm field. // lbAlgorithmValidator is used to validate Algorithm field.
func lbAlgorithmValidator(fe validator.FieldLevel) bool { func lbAlgorithmValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, lbAlgorithmValues) return IsInSlice(fieldValue, lbAlgorithmValues)
} }
// rgDefNetValidator is used to validate DefNet field. // rgDefNetValidator is used to validate DefNet field.
func rgDefNetValidator(fe validator.FieldLevel) bool { func rgDefNetValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, rgDefNetValues) return IsInSlice(fieldValue, rgDefNetValues)
} }
// rgNetTypeValidator is used to validate NetType field. // rgNetTypeValidator is used to validate NetType field.
func rgNetTypeValidator(fe validator.FieldLevel) bool { func rgNetTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, rgNetTypeValues) return IsInSlice(fieldValue, rgNetTypeValues)
} }
// vinsTypeValidator is used to validate Type field. // vinsTypeValidator is used to validate Type field.
func vinsTypeValidator(fe validator.FieldLevel) bool { func vinsTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, vinsTypeValues) return IsInSlice(fieldValue, vinsTypeValues)
} }
// imageBootTypeValidator is used to validate BootType field. // imageBootTypeValidator is used to validate BootType field.
func imageBootTypeValidator(fe validator.FieldLevel) bool { func imageBootTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, imageBootTypeValues) return IsInSlice(fieldValue, imageBootTypeValues)
} }
// imageTypeValidator is used to validate ImageType field. // imageTypeValidator is used to validate ImageType field.
func imageTypeValidator(fe validator.FieldLevel) bool { func imageTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, imageTypeValues) return IsInSlice(fieldValue, imageTypeValues)
} }
// imageDriversValidator is used to validate Drivers field. // imageDriversValidator is used to validate Drivers field.
@@ -194,7 +214,7 @@ func imageDriversValidator(fe validator.FieldLevel) bool {
} }
for _, item := range fieldSlice { for _, item := range fieldSlice {
if !StringInSlice(item, imageDriversValues) { if !IsInSlice(item, imageDriversValues) {
return false return false
} }
} }
@@ -206,14 +226,14 @@ func imageDriversValidator(fe validator.FieldLevel) bool {
func imageArchitectureValidator(fe validator.FieldLevel) bool { func imageArchitectureValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, imageArchitectureValues) return IsInSlice(fieldValue, imageArchitectureValues)
} }
// sepFieldTypeValidator is used to validate FieldType field. // sepFieldTypeValidator is used to validate FieldType field.
func sepFieldTypeValidator(fe validator.FieldLevel) bool { func sepFieldTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
return StringInSlice(fieldValue, sepFieldTypeValues) return IsInSlice(fieldValue, sepFieldTypeValues)
} }
// hwPathValidator is used to validate HWPath field. // hwPathValidator is used to validate HWPath field.
@@ -230,7 +250,7 @@ func networkPluginValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
fieldValue = strings.ToLower(fieldValue) fieldValue = strings.ToLower(fieldValue)
return StringInSlice(fieldValue, networkPluginValues) return IsInSlice(fieldValue, networkPluginValues)
} }
// networkPluginsValidator is used to validate NetworkPlugins field // networkPluginsValidator is used to validate NetworkPlugins field
@@ -243,7 +263,7 @@ func networkPluginsValidator(fe validator.FieldLevel) bool {
for _, item := range fieldSlice { for _, item := range fieldSlice {
item = strings.ToLower(item) item = strings.ToLower(item)
if !StringInSlice(item, networkPluginValues) { if !IsInSlice(item, networkPluginValues) {
return false return false
} }
} }
@@ -255,14 +275,35 @@ func interfaceStateValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
fieldValue = strings.ToLower(fieldValue) fieldValue = strings.ToLower(fieldValue)
return StringInSlice(fieldValue, interfaceStateValues) return IsInSlice(fieldValue, interfaceStateValues)
}
func interfaceTXModelValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
fieldValue = strings.ToLower(fieldValue)
return IsInSlice(fieldValue, txModelValues)
}
func interfaceIOEventFDValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
fieldValue = strings.ToLower(fieldValue)
return IsInSlice(fieldValue, ioEventFDValues)
}
func interfaceEventIDxValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
fieldValue = strings.ToLower(fieldValue)
return IsInSlice(fieldValue, eventIDxValues)
} }
func strictLooseValidator(fe validator.FieldLevel) bool { func strictLooseValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String() fieldValue := fe.Field().String()
fieldValue = strings.ToLower(fieldValue) fieldValue = strings.ToLower(fieldValue)
return StringInSlice(fieldValue, strictLooseValues) return IsInSlice(fieldValue, strictLooseValues)
} }
// name workerGroup must be more 3 symbol // name workerGroup must be more 3 symbol
@@ -272,3 +313,132 @@ func workerGroupNameValidator(fe validator.FieldLevel) bool {
return len(fieldValue) >= 3 return len(fieldValue) >= 3
} }
func sortByValidator(fe validator.FieldLevel) bool {
sortByRegexp := regexp.MustCompile(`^[+-][a-zA-Z_]+`)
return sortByRegexp.MatchString(fe.Field().String())
}
func actionValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, actionValues)
}
func vmActionValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, vmActionValues)
}
func mtuValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().Uint()
return fieldValue >= uint64(mtuMin) && fieldValue <= uint64(mtuMax)
}
func computeFeaturesValidator(fe validator.FieldLevel) bool {
field := fe.Field()
slice, ok := field.Interface().([]string)
if !ok {
return false
}
return IsSubSlice(slice, computeFeaturesValues)
}
func networkInterfaceNamingValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, networkInterfaceNamingValues)
}
func numaAffinityValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, numaAffinityValues)
}
// kvmx86NetTypeValidator is used to validate NetType field for x86 compute.
func kvmx86NetTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, kvmx86NetTypeValues)
}
func isBoolTypeValidator(fe validator.FieldLevel) bool {
return fe.Field().CanConvert(reflect.TypeOf(true))
}
func urlValidartor(fl validator.FieldLevel) bool {
fieldValues := fl.Field().String()
_, err := url.ParseRequestURI(fieldValues)
return err == nil
}
func chipsetValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, chipsetValues)
}
func preferredCPUValidator(fe validator.FieldLevel) bool {
fieldSlice, ok := fe.Field().Interface().([]int64)
if !ok {
return false
}
for _, value := range fieldSlice {
if value < -1 {
return false
}
}
return true
}
// loaderTypeValidator is used to validate loaderType fields
func loaderTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, loaderTypeValues)
}
// languageValidator is used to validate language fields
func languageValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, languageValues)
}
// sepTypeValidator is used to validate sepType fields
func sepTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return IsInSlice(fieldValue, sepTypeValues)
}
// ValidateRAM checks if request contains RAM value that is positive integer divisible by divisibility passed.
// It is recommended to pass constants.RAM_DIVISIBILITY as divisility arguement
func ValidateRAM(r interfaces.RequestWithRAM, divisibility uint64) error {
if divisibility == 0 {
return errors.New("second argument of ValidateRAM should be greater than 0")
}
mapRAM := r.GetRAM()
errs := make([]error, 0, len(mapRAM))
for k, v := range mapRAM {
if v%divisibility != 0 {
errs = append(errs, fmt.Errorf("expected value of %s: \"%d\" should be divisible by %d", k, v, divisibility))
}
}
return multierror.Join(errs...)
}

View File

@@ -34,7 +34,7 @@ func GetErrors(err error) validator.ValidationErrors {
return err.(validator.ValidationErrors) return err.(validator.ValidationErrors)
} }
func StringInSlice(str string, target []string) bool { func IsInSlice(str string, target []string) bool {
for _, v := range target { for _, v := range target {
if v == str { if v == str {
return true return true
@@ -42,3 +42,12 @@ func StringInSlice(str string, target []string) bool {
} }
return false return false
} }
func IsSubSlice(source []string, target []string) bool {
for _, s := range source {
if !IsInSlice(s, target) {
return false
}
}
return true
}

View File

@@ -25,6 +25,8 @@ func errorMessage(fe validator.FieldError) string {
return fmt.Sprintf("%s %s: unexpected URL format", prefix, fe.Field()) return fmt.Sprintf("%s %s: unexpected URL format", prefix, fe.Field())
case "email": case "email":
return fmt.Sprintf("%s %s: unexpected E-Mail format", prefix, fe.Field()) return fmt.Sprintf("%s %s: unexpected E-Mail format", prefix, fe.Field())
case "isBool":
return fmt.Sprintf("%s %s: must be bool type", prefix, fe.Field())
case "driver": case "driver":
return fmt.Sprintf("%s %s must be one of the following: %s", return fmt.Sprintf("%s %s must be one of the following: %s",
@@ -50,6 +52,13 @@ func errorMessage(fe validator.FieldError) string {
fe.Field(), fe.Field(),
joinValues(protoValues)) joinValues(protoValues))
// apiGroup Validators
case "apiGroup":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(apiGroupValues))
// Account Validators // Account Validators
case "accountCUType": case "accountCUType":
return fmt.Sprintf("%s %s must be one of the following: %s", return fmt.Sprintf("%s %s must be one of the following: %s",
@@ -89,6 +98,18 @@ func errorMessage(fe validator.FieldError) string {
fe.Field(), fe.Field(),
joinValues(computeDiskTypeValues)) joinValues(computeDiskTypeValues))
case "mtu":
return fmt.Sprint(prefix, fe.Field(), "must be ", mtuMin, "-", mtuMax)
case "preferredCPU":
return fmt.Sprint(prefix, fe.Field(), "must be equal to or greater than", -1)
case "computex86NetType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computex86NetTypeValues))
case "computeNetType": case "computeNetType":
return fmt.Sprintf("%s %s must be one of the following: %s", return fmt.Sprintf("%s %s must be one of the following: %s",
prefix, prefix,
@@ -133,7 +154,7 @@ func errorMessage(fe validator.FieldError) string {
prefix, prefix,
fe.Field()) fe.Field())
// KVM_X86/KVM_PPC Validators // KVM_X86 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",
prefix, prefix,
@@ -229,6 +250,89 @@ func errorMessage(fe validator.FieldError) string {
prefix, prefix,
fe.Field(), fe.Field(),
joinValues(interfaceStateValues)) joinValues(interfaceStateValues))
case "interfaceTXModel":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(txModelValues))
case "interfaceIOEventFD":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(ioEventFDValues))
case "interfaceEventIDx":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(eventIDxValues))
case "sortBy":
return fmt.Sprintf("%s %s must be in format +|-(field)",
prefix,
fe.Field())
case "action":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(actionValues))
case "vmaction":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(vmActionValues))
case "computeFeatures":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeFeaturesValues))
case "networkInterfaceNaming":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(networkInterfaceNamingValues))
case "numaAffinity":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(numaAffinityValues))
case "kvmx86NetType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(kvmx86NetTypeValues))
case "chipset":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(chipsetValues))
case "loaderType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(loaderTypeValues))
case "language":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(languageValues))
case "sepType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(sepTypeValues))
} }
return fe.Error() return fe.Error()

View File

@@ -25,6 +25,7 @@ func getDecortValidator() *validator.Validate {
// registerAllValidators registers all custom validators in DecortValidator. // registerAllValidators registers all custom validators in DecortValidator.
func registerAllValidators(validate *validator.Validate) error { func registerAllValidators(validate *validator.Validate) error {
err := validate.RegisterValidation("proto", protoValidator) err := validate.RegisterValidation("proto", protoValidator)
if err != nil { if err != nil {
return err return err
@@ -35,6 +36,11 @@ func registerAllValidators(validate *validator.Validate) error {
return err return err
} }
err = validate.RegisterValidation("apiGroup", apiGroupValidator)
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
@@ -105,6 +111,11 @@ func registerAllValidators(validate *validator.Validate) error {
return err return err
} }
err = validate.RegisterValidation("computex86NetType", computex86NetTypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("computeOrder", computeOrderValidator) err = validate.RegisterValidation("computeOrder", computeOrderValidator)
if err != nil { if err != nil {
return err return err
@@ -180,10 +191,95 @@ func registerAllValidators(validate *validator.Validate) error {
return err return err
} }
err = validate.RegisterValidation("interfaceTXModel", interfaceTXModelValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("interfaceIOEventFD", interfaceIOEventFDValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("interfaceEventIDx", interfaceEventIDxValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("workerGroupName", workerGroupNameValidator) err = validate.RegisterValidation("workerGroupName", workerGroupNameValidator)
if err != nil { if err != nil {
return err return err
} }
err = validate.RegisterValidation("sortBy", sortByValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("action", actionValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("vmaction", vmActionValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("mtu", mtuValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("computeFeatures", computeFeaturesValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("networkInterfaceNaming", networkInterfaceNamingValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("numaAffinity", numaAffinityValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("kvmx86NetType", kvmx86NetTypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("isBool", isBoolTypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("url", urlValidartor)
if err != nil {
return err
}
err = validate.RegisterValidation("chipset", chipsetValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("preferredCPU", preferredCPUValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("language", languageValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("sepType", sepTypeValidator)
if err != nil {
return err
}
return nil return nil
} }

View File

@@ -1,7 +1,9 @@
package validators package validators
var ( var (
driverValues = []string{"KVM_X86", "KVM_PPC"} apiGroupValues = []string{"cloudapi", "cloudbroker", "system"}
driverValues = []string{"KVM_X86"}
accessTypeValues = []string{"R", "RCX", "ARCXDU"} accessTypeValues = []string{"R", "RCX", "ARCXDU"}
resTypesValues = []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"} resTypesValues = []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}
protoValues = []string{"tcp", "udp"} protoValues = []string{"tcp", "udp"}
@@ -10,38 +12,70 @@ var (
bserviceModeValues = []string{"ABSOLUTE", "RELATIVE"} bserviceModeValues = []string{"ABSOLUTE", "RELATIVE"}
computeTopologyValues = []string{"compute", "node"} computeTopologyValues = []string{"compute", "node"}
computePolicyValues = []string{"RECOMMENDED", "REQUIRED"} computePolicyValues = []string{"RECOMMENDED", "REQUIRED"}
computeModeValues = []string{"EQ", "EN", "ANY"} computeModeValues = []string{"EQ", "EN", "ANY"}
computeDiskTypeValues = []string{"D", "B"} computeDiskTypeValues = []string{"D", "B"}
computeNetTypeValues = []string{"EXTNET", "VINS"} computeNetTypeValues = []string{"EXTNET", "VINS"}
computeOrderValues = []string{"cdrom", "network", "hd"} computex86NetTypeValues = []string{"EXTNET", "VINS", "VFNIC", "DPDK"}
computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"} computeOrderValues = []string{"cdrom", "network", "hd"}
computeDriverValues = []string{"KVM_X86", "SVA_KVM_X86"} computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"}
computeDriverValues = []string{"KVM_X86", "SVA_KVM_X86"}
diskTypeValues = []string{"B", "T", "D"} diskTypeValues = []string{"B", "T", "D"}
flipgroupClientTypeValues = []string{"compute", "vins"} flipgroupClientTypeValues = []string{"compute", "vins"}
kvmNetTypeValues = []string{"EXTNET", "VINS", "NONE"} kvmNetTypeValues = []string{"EXTNET", "VINS", "NONE"}
kvmx86NetTypeValues = []string{"EXTNET", "VINS", "NONE", "VFNIC", "DPDK"}
lbAlgorithmValues = []string{"roundrobin", "static-rr", "leastconn"} lbAlgorithmValues = []string{"roundrobin", "static-rr", "leastconn"}
rgDefNetValues = []string{"PRIVATE", "PUBLIC", "NONE"} rgDefNetValues = []string{"PRIVATE", "PUBLIC", "NONE"}
rgNetTypeValues = []string{"PUBLIC", "PRIVATE"} rgNetTypeValues = []string{"PUBLIC", "PRIVATE"}
vinsTypeValues = []string{"DHCP", "VIP", "EXCLUDE"} vinsTypeValues = []string{"DHCP", "VIP", "EXCLUDED"}
imageBootTypeValues = []string{"uefi", "bios"} imageBootTypeValues = []string{"uefi", "bios"}
imageTypeValues = []string{"windows", "linux", "other"} imageTypeValues = []string{"windows", "linux", "unknown"}
imageDriversValues = []string{"KVM_X86"} imageDriversValues = []string{"KVM_X86"}
imageArchitectureValues = []string{"X86_64", "PPC64_LE"} imageArchitectureValues = []string{"X86_64"}
sepFieldTypeValues = []string{"int", "str", "bool", "list", "dict"} sepFieldTypeValues = []string{"int", "str", "bool", "list", "dict"}
networkPluginValues = []string{"flannel", "weawenet", "calico"} networkPluginValues = []string{"flannel", "weavenet", "calico"}
strictLooseValues = []string{"strict", "loose"} strictLooseValues = []string{"strict", "loose"}
interfaceStateValues = []string{"on", "off"} interfaceStateValues = []string{"on", "off"}
actionValues = []string{"power_on", "shutdown", "force_shutdown", "reboot"}
vmActionValues = []string{"stop", "move"}
computeFeaturesValues = []string{"hugepages", "numa", "cpupin", "vfnic", "dpdk", "changemac"}
networkInterfaceNamingValues = []string{"eth", "ens"}
numaAffinityValues = []string{"none", "strict", "loose"}
txModelValues = []string{"iothread", "timer", "selected by hypervisor"}
ioEventFDValues = []string{"on", "off", "selected by hypervisor"}
eventIDxValues = []string{"on", "off", "selected by hypervisor"}
chipsetValues = []string{"i440fx", "Q35"}
loaderTypeValues = []string{"linux", "windows", "unknown"}
sepTypeValues = []string{"hitachi", "dorado", "tatlin", "shared", "local", "des"}
languageValues = []string{"ru", "en"}
)
const (
mtuMin = 1
mtuMax = 9216
) )

View File

@@ -4,13 +4,10 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/tls" "crypto/tls"
"errors"
"fmt" "fmt"
"io" "io"
"mime/multipart"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -19,12 +16,10 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"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"
) )
// Legacy HTTP-client for platform // LegacyDecortClient is Legacy HTTP-client for platform
type LegacyDecortClient struct { type LegacyDecortClient struct {
decortURL string decortURL string
client *http.Client client *http.Client
@@ -55,7 +50,7 @@ func NewLegacy(cfg config.LegacyConfig) *LegacyDecortClient {
}, },
}, },
}, },
cfg: cfg, cfg: trimLegacyConfig(&cfg),
expiryTime: expiryTime, expiryTime: expiryTime,
mutex: &sync.Mutex{}, mutex: &sync.Mutex{},
} }
@@ -73,20 +68,18 @@ 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) {
// get token
if err := ldc.getToken(ctx); err != nil { if err := ldc.getToken(ctx); err != nil {
return nil, err return nil, err
} }
k8sCaCreateReq, okCa := params.(k8s_ca.CreateRequest)
k8sCbCreateReq, okCb := params.(k8s_cb.CreateRequest)
var body *bytes.Buffer var body *bytes.Buffer
var ctype string var ctype string
if okCa { byteSlice, ok := params.([]byte)
body, ctype = createK8sCloudApiLegacy(k8sCaCreateReq, ldc.cfg.Token) if ok {
} else if okCb { body = bytes.NewBuffer(byteSlice)
body, ctype = createK8sCloudBrokerLegacy(k8sCbCreateReq, ldc.cfg.Token) ctype = "application/octet-stream"
} else { } else {
values, err := query.Values(params) values, err := query.Values(params)
if err != nil { if err != nil {
@@ -95,320 +88,161 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st
body = bytes.NewBufferString(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token)) body = bytes.NewBufferString(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token))
} }
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+constants.Restmachine+url, body) req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+constants.RESTMACHINE+url, body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := ldc.do(req, ctype) // perform request
if err != nil { respBytes, err := ldc.do(req, ctype)
return nil, err
}
defer resp.Body.Close()
respBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if resp.StatusCode != 200 { return respBytes, err
return nil, errors.New(string(respBytes)) }
func (ldc *LegacyDecortClient) DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
body, ctype, err := multiPartReq(params)
if err != nil {
return nil, err
} }
return respBytes, nil req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+constants.RESTMACHINE+url, body)
if err != nil {
return nil, err
}
// get token
if err = ldc.getToken(ctx); err != nil {
return nil, err
}
// perform request
respBytes, err := ldc.do(req, ctype)
if err != nil {
return nil, err
}
return respBytes, err
} }
func (ldc *LegacyDecortClient) getToken(ctx context.Context) error { func (ldc *LegacyDecortClient) getToken(ctx context.Context) error {
ldc.mutex.Lock() ldc.mutex.Lock()
defer ldc.mutex.Unlock() defer ldc.mutex.Unlock()
if ldc.cfg.Token == "" || time.Now().After(ldc.expiryTime) { // new token is not needed
body := fmt.Sprintf("username=%s&password=%s", url.QueryEscape(ldc.cfg.Username), url.QueryEscape(ldc.cfg.Password)) if ldc.cfg.Token != "" && !time.Now().After(ldc.expiryTime) {
bodyReader := strings.NewReader(body) return nil
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)
} }
// set up request headers and body
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+constants.RESTMACHINE+"/cloudapi/user/authenticate", bodyReader)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
// request token
resp, err := ldc.client.Do(req)
if err != nil || resp == nil {
return fmt.Errorf("cannot get token: %w", err)
}
defer resp.Body.Close()
var tokenBytes []byte
tokenBytes, err = io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("cannot get token: %w", err)
}
if resp.StatusCode != 200 {
return fmt.Errorf("cannot get token: %s", tokenBytes)
}
// save token in config
token := string(tokenBytes)
ldc.cfg.Token = token
ldc.expiryTime = time.Now().AddDate(0, 0, 1)
return nil return nil
} }
func (ldc *LegacyDecortClient) do(req *http.Request, ctype string) (*http.Response, error) { // do method performs request and returns response as an array of bytes and nil error in case of response status code 200.
// In any other cases do returns nil response and error.
// Retries are implemented in case of connection reset errors.
func (ldc *LegacyDecortClient) do(req *http.Request, ctype string) ([]byte, error) {
// set up request headers and body
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
if ctype != "" { if ctype != "" {
req.Header.Add("Content-Type", ctype) req.Header.Set("Content-Type", ctype)
} else {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
} }
req.Header.Set("Accept", "application/json") req.Header.Set("Accept", "application/json")
// var resp *http.Response buf, err := io.ReadAll(req.Body)
// var err error
buf, _ := io.ReadAll(req.Body)
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
// req = req.Clone(req.Context())
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := ldc.client.Do(req)
if err != nil || resp == nil {
return resp, err
}
if resp.StatusCode == 200 {
return resp, err
}
respBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.Body.Close()
return resp, errors.New(string(respBytes)) req.Body.Close()
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := ldc.client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
// retries logic GOES HERE
// get http response
//var resp *http.Response
//for i := uint64(0); i < ldc.cfg.Retries; i++ {
// req := req.Clone(req.Context())
// req.Body = io.NopCloser(bytes.NewBuffer(buf))
//
// if i > 0 {
// time.Sleep(5 * time.Second) // no time sleep for the first request
// }
//
// resp, err = ldc.client.Do(req)
//
// // stop retries on success and close response body
// if resp != nil {
// defer resp.Body.Close()
// }
// if err == nil {
// break
// }
//
// // retries in case of connection errors with time sleep
// if isConnectionError(err) {
// continue
// }
//
// // return error in case of non-connection error
// return nil, err
//}
// handle http request errors
if err != nil {
return nil, err
}
if resp == nil {
return nil, fmt.Errorf("got empty response without error")
}
// handle successful request
respBytes, _ := io.ReadAll(resp.Body)
if resp.StatusCode == 200 {
return respBytes, nil
}
// handle errors with status code other than 200
err = fmt.Errorf("%s", respBytes)
return nil, fmt.Errorf("could not execute request: %w", err)
} }
func createK8sCloudApiLegacy(req k8s_ca.CreateRequest, token string) (*bytes.Buffer, string) { func trimLegacyConfig(cfg *config.LegacyConfig) config.LegacyConfig {
reqBody := &bytes.Buffer{} cfg.DecortURL = strings.TrimSuffix(cfg.DecortURL, "/")
writer := multipart.NewWriter(reqBody) return *cfg
if req.OidcCertificate != "" {
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
}
_ = writer.WriteField("name", req.Name)
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8SCIID, 10))
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
if req.MasterSEPID != 0 {
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
}
if req.MasterSEPPool != "" {
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
}
if req.WorkerSEPID != 0 {
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
}
if req.WorkerSEPPool != "" {
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
}
if req.Labels != nil {
for _, v := range req.Labels {
_ = writer.WriteField("labels", v)
}
}
if req.Taints != nil {
for _, v := range req.Taints {
_ = writer.WriteField("taints", v)
}
}
if req.Annotations != nil {
for _, v := range req.Annotations {
_ = writer.WriteField("annotations", v)
}
}
if req.MasterCPU != 0 {
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(req.MasterCPU), 10))
}
if req.MasterNum != 0 {
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(req.MasterNum), 10))
}
if req.MasterRAM != 0 {
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(req.MasterRAM), 10))
}
if req.MasterDisk != 0 {
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(req.MasterDisk), 10))
}
if req.WorkerCPU != 0 {
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(req.WorkerCPU), 10))
}
if req.WorkerNum != 0 {
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(req.WorkerNum), 10))
}
if req.WorkerRAM != 0 {
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(req.WorkerRAM), 10))
}
if req.WorkerDisk != 0 {
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(req.WorkerDisk), 10))
}
if req.ExtNetID != 0 {
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
}
if req.VinsId != 0 {
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
}
if !req.WithLB {
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
}
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
if req.AdditionalSANs != nil {
for _, v := range req.AdditionalSANs {
_ = writer.WriteField("additionalSANs", v)
}
}
if req.InitConfiguration != "" {
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
}
if req.ClusterConfiguration != "" {
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
}
if req.KubeletConfiguration != "" {
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
}
if req.KubeProxyConfiguration != "" {
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
}
if req.JoinConfiguration != "" {
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
}
if req.Description != "" {
_ = writer.WriteField("desc", req.Description)
}
if req.UserData != "" {
_ = writer.WriteField("userData", req.UserData)
}
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
_ = writer.WriteField("authkey", token)
ct := writer.FormDataContentType()
writer.Close()
return reqBody, ct
}
func createK8sCloudBrokerLegacy(req k8s_cb.CreateRequest, token string) (*bytes.Buffer, string) {
reqBody := &bytes.Buffer{}
writer := multipart.NewWriter(reqBody)
if req.OidcCertificate != "" {
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
}
_ = writer.WriteField("name", req.Name)
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8CIID, 10))
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
if req.MasterSEPID != 0 {
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
}
if req.MasterSEPPool != "" {
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
}
if req.WorkerSEPID != 0 {
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
}
if req.WorkerSEPPool != "" {
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
}
if req.Labels != nil {
for _, v := range req.Labels {
_ = writer.WriteField("labels", v)
}
}
if req.Taints != nil {
for _, v := range req.Taints {
_ = writer.WriteField("taints", v)
}
}
if req.Annotations != nil {
for _, v := range req.Annotations {
_ = writer.WriteField("annotations", v)
}
}
if req.MasterCPU != 0 {
_ = writer.WriteField("masterCpu", strconv.FormatUint(req.MasterCPU, 10))
}
if req.MasterNum != 0 {
_ = writer.WriteField("masterNum", strconv.FormatUint(req.MasterNum, 10))
}
if req.MasterRAM != 0 {
_ = writer.WriteField("masterRam", strconv.FormatUint(req.MasterRAM, 10))
}
if req.MasterDisk != 0 {
_ = writer.WriteField("masterDisk", strconv.FormatUint(req.MasterDisk, 10))
}
if req.WorkerCPU != 0 {
_ = writer.WriteField("workerCpu", strconv.FormatUint(req.WorkerCPU, 10))
}
if req.WorkerNum != 0 {
_ = writer.WriteField("workerNum", strconv.FormatUint(req.WorkerNum, 10))
}
if req.WorkerRAM != 0 {
_ = writer.WriteField("workerRam", strconv.FormatUint(req.WorkerRAM, 10))
}
if req.WorkerDisk != 0 {
_ = writer.WriteField("workerDisk", strconv.FormatUint(req.WorkerDisk, 10))
}
if req.ExtNetID != 0 {
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
}
if req.VinsId != 0 {
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
}
if !req.WithLB {
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
}
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
if req.AdditionalSANs != nil {
for _, v := range req.AdditionalSANs {
_ = writer.WriteField("additionalSANs", v)
}
}
if req.InitConfiguration != "" {
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
}
if req.ClusterConfiguration != "" {
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
}
if req.KubeletConfiguration != "" {
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
}
if req.KubeProxyConfiguration != "" {
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
}
if req.JoinConfiguration != "" {
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
}
if req.Description != "" {
_ = writer.WriteField("desc", req.Description)
}
if req.UserData != "" {
_ = writer.WriteField("userData", req.UserData)
}
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
_ = writer.WriteField("authkey", token)
ct := writer.FormDataContentType()
writer.Close()
return reqBody, ct
} }

View File

@@ -17,10 +17,6 @@ type DeleteUserRequest struct {
// ID or emailaddress of the user to remove // ID or emailaddress of the user to remove
// Required: true // Required: true
UserID string `url:"userId" json:"userId" validate:"required"` UserID string `url:"userId" json:"userId" validate:"required"`
// Recursively revoke access rights from owned cloudspaces and vmachines
// Required: false
RecursiveDelete bool `url:"recursivedelete" json:"recursivedelete"`
} }
// DeleteUser revokes user access from the account // DeleteUser revokes user access from the account

View File

@@ -13,6 +13,10 @@ type DisableEnableRequest struct {
// ID of account // ID of account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Reason of disabling
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
// Disable disables an account // Disable disables an account

View File

@@ -1,58 +0,0 @@
package account
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetConsumptionRequest struct to download the resources tracking files for an account
type GetConsumptionRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Epoch represents the start time
// Required: true
Start uint64 `url:"start" json:"start" validate:"required"`
// Epoch represents the end time
// Required: true
End uint64 `url:"end" json:"end" validate:"required"`
}
// GetConsumption downloads the resources tracking files for an account within a given period
func (a Account) GetConsumption(ctx context.Context, req GetConsumptionRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/account/getConsumption"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}
// GetConsumptionGet downloads the resources tracking files for an account within a given period
func (a Account) GetConsumptionGet(ctx context.Context, req GetConsumptionRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/account/getConsumption"
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListRequest struct to get list of accounts // ListRequest struct to get list of accounts
@@ -24,6 +26,10 @@ type ListRequest struct {
// Required: false // Required: false
Status string `url:"status,omitempty" json:"status,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -35,6 +41,7 @@ type ListRequest struct {
// List gets a list of all accounts the user has access to a ListAccounts struct // List gets a list of all accounts the user has access to a ListAccounts struct
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) { func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
res, err := a.ListRaw(ctx, req) res, err := a.ListRaw(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -52,6 +59,11 @@ func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, erro
// ListRaw gets a list of all accounts the user has access to as an array of bytes // ListRaw gets a list of all accounts the user has access to as an array of bytes
func (a Account) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) { func (a Account) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/account/list" url := "/cloudapi/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -46,6 +46,10 @@ type ListComputesRequest struct {
// Required: false // Required: false
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"` ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -57,6 +61,7 @@ type ListComputesRequest struct {
// 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err)) return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListDeletedRequest struct to get a list of deleted accounts // ListDeletedRequest struct to get a list of deleted accounts
@@ -27,10 +29,20 @@ type ListDeletedRequest struct {
// Find by access control list // Find by access control list
// Required: false // Required: false
ACL string `url:"acl,omitempty" json:"acl,omitempty"` ACL string `url:"acl,omitempty" json:"acl,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
} }
// ListDeleted gets list of all deleted accounts the user has access to // ListDeleted gets list of all deleted accounts the user has access to
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAccounts, error) { func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAccounts, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/account/listDeleted" url := "/cloudapi/account/listDeleted"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -30,6 +30,10 @@ type ListDisksRequest struct {
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -41,6 +45,7 @@ type ListDisksRequest struct {
// 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err)) return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -38,6 +38,10 @@ type ListFLIPGroupsRequest struct {
// Required: false // Required: false
FLIPGroupID uint64 `url:"flipGroupId,omitempty" json:"flipGroupId,omitempty"` FLIPGroupID uint64 `url:"flipGroupId,omitempty" json:"flipGroupId,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -49,6 +53,7 @@ type ListFLIPGroupsRequest struct {
// 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err)) return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -41,10 +41,15 @@ type ListRGRequest struct {
// Find by status // Find by status
// Required: false // Required: false
Status string `url:"status,omitempty" json:"status,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
} }
// ListRG gets list of all resource groups under specified account, accessible by the user // ListRG gets list of all resource groups under specified account, accessible by the user
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (*ListRG, error) { 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err)) return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -30,6 +30,10 @@ type ListTemplatesRequest struct {
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -41,6 +45,7 @@ type ListTemplatesRequest struct {
// ListTemplates gets list of templates which can be managed by this account // ListTemplates gets list of 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err)) return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -30,6 +30,10 @@ type ListVINSRequest struct {
// Required: false // Required: false
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"` ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -41,6 +45,7 @@ type ListVINSRequest struct {
// ListVINS gets list of all ViNSes under specified account, accessible by the user // ListVINS gets list of 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err)) return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -53,12 +53,18 @@ type ItemAccount struct {
// Access Control List // Access Control List
ACL []RecordACL `json:"acl"` ACL []RecordACL `json:"acl"`
// Compute Features
ComputeFeatures []string `json:"computeFeatures"`
// Created time // Created time
CreatedTime uint64 `json:"createdTime"` CreatedTime uint64 `json:"createdTime"`
// Deleted time // Deleted time
DeletedTime uint64 `json:"deletedTime"` DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// ID // ID
ID uint64 `json:"id"` ID uint64 `json:"id"`
@@ -176,6 +182,9 @@ type RecordAccount struct {
// Company URL // Company URL
CompanyURL string `json:"companyurl"` CompanyURL string `json:"companyurl"`
// Compute Features
ComputeFeatures []string `json:"computeFeatures"`
// Computes // Computes
Computes Computes `json:"computes"` Computes Computes `json:"computes"`
@@ -191,6 +200,9 @@ type RecordAccount struct {
// Created time // Created time
CreatedTime uint64 `json:"createdTime"` CreatedTime uint64 `json:"createdTime"`
// Description
Description string `json:"desc"`
// Deactivation time // Deactivation time
DeactivationTime float64 `json:"deactivationTime"` DeactivationTime float64 `json:"deactivationTime"`
@@ -374,6 +386,12 @@ type ItemVINS struct {
// External IP // External IP
ExternalIP string `json:"externalIP"` ExternalIP string `json:"externalIP"`
// Extnet ID
ExtnetId uint64 `json:"extnetId"`
// Free IPs
FreeIPs int64 `json:"freeIPs"`
// ID // ID
ID uint64 `json:"id"` ID uint64 `json:"id"`
@@ -500,6 +518,9 @@ type ItemRG struct {
// Deleted time // Deleted time
DeletedTime uint64 `json:"deletedTime"` DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Resource group ID // Resource group ID
RGID uint64 `json:"id"` RGID uint64 `json:"id"`

View File

@@ -14,6 +14,10 @@ type UpdateRequest struct {
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Description
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
// Name of the account // Name of the account
// Required: false // Required: false
Name string `url:"name,omitempty" json:"name,omitempty"` Name string `url:"name,omitempty" json:"name,omitempty"`
@@ -45,6 +49,11 @@ type UpdateRequest struct {
// Limit (positive) or disable (0) GPU resources // Limit (positive) or disable (0) GPU resources
// Required: false // Required: false
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"` GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
// List of strings with pools
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
} }
// Update updates an account name and resource types and limits // Update updates an account name and resource types and limits

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

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

View File

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

46
pkg/cloudapi/audit/get.go Normal file
View File

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

View File

@@ -0,0 +1,41 @@
package audit
// Main info about audit
type RecordAudit struct {
// Arguments
Arguments string `json:"args"`
// Call
Call string `json:"call"`
// GUID
GUID string `json:"guid"`
// Kwargs
Kwargs string `json:"kwargs"`
// RemoteAddr
RemoteAddr string `json:"remote_addr"`
// Response time
ResponseTime float64 `json:"responsetime"`
// Result
Result string `json:"result"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Tags
Tags string `json:"tags"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// TimestampEnd
TimestampEnd float64 `json:"timestampEnd"`
// User
User string `json:"user"`
}

View File

@@ -24,7 +24,7 @@ func (b BService) Disable(ctx context.Context, req DisableRequest) (bool, error)
return false, validators.ValidationErrors(validators.GetErrors(err)) return false, validators.ValidationErrors(validators.GetErrors(err))
} }
url := "/cloudapi/bservice/delete" url := "/cloudapi/bservice/disable"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil { if err != nil {

View File

@@ -41,7 +41,6 @@ type GroupAddRequest struct {
// Compute driver // Compute driver
// should be one of: // should be one of:
// - KVM_X86 // - KVM_X86
// - KVM_PPC
// Required: true // Required: true
Driver string `url:"driver" json:"driver" validate:"driver"` Driver string `url:"driver" json:"driver" validate:"driver"`
@@ -72,6 +71,20 @@ type GroupAddRequest struct {
// Meta data for working group computes, format YAML "user_data": 1111 // Meta data for working group computes, format YAML "user_data": 1111
// Required: false // Required: false
UserData string `url:"userData,omitempty" json:"userData,omitempty"` UserData string `url:"userData,omitempty" json:"userData,omitempty"`
//Chipset "i440fx" or "Q35
//Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"chipset"`
}
// GetRAM returns RAM field values
func (r GroupAddRequest) GetRAM() map[string]uint64 {
res := make(map[string]uint64, 1)
res["RAM"] = r.RAM
return res
} }
// GroupAdd creates new Compute Group within BasicService. // GroupAdd creates new Compute Group within BasicService.

View File

@@ -22,6 +22,12 @@ type GroupResizeRequest struct {
// Required: true // Required: true
Count int64 `url:"count" json:"count" validate:"required"` Count int64 `url:"count" json:"count" validate:"required"`
//Chipset for new computes, either i440fx or Q35 (i440fx by default)
//Available values : i440fx, Q35
//Default value : i440fx
//Required: true
Chipset string `url:"chipset" json:"chipset" validate:"required,chipset"`
// Either delta or absolute value of computes // Either delta or absolute value of computes
// Should be one of: // Should be one of:
// - ABSOLUTE // - ABSOLUTE

View File

@@ -43,6 +43,16 @@ type GroupUpdateRequest struct {
Force bool `url:"force,omitempty" json:"force,omitempty"` Force bool `url:"force,omitempty" json:"force,omitempty"`
} }
// GetRAM returns RAM field values
func (r GroupUpdateRequest) GetRAM() map[string]uint64 {
res := make(map[string]uint64, 1)
res["RAM"] = r.RAM
return res
}
// GroupUpdate updates existing Compute group within Basic Service and apply new settings to its computes as necessary // GroupUpdate updates existing Compute group within Basic Service and apply new settings to its computes as necessary
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) { func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListRequest struct to get list of BasicService instances // ListRequest struct to get list of BasicService instances
@@ -40,6 +42,10 @@ type ListRequest struct {
// Required: false // Required: false
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"` AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -51,6 +57,7 @@ type ListRequest struct {
// List gets list of BasicService instances associated with the specified Resource Group as a ListBasicServices struct // List gets list of BasicService instances associated with the specified Resource Group as a ListBasicServices struct
func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices, error) { func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices, error) {
res, err := b.ListRaw(ctx, req) res, err := b.ListRaw(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -68,6 +75,11 @@ func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices
// ListRaw gets list of BasicService instances associated with the specified Resource Group as an array of bytes // ListRaw gets list of BasicService instances associated with the specified Resource Group as an array of bytes
func (b BService) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) { func (b BService) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/bservice/list" url := "/cloudapi/bservice/list"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListDeletedRequest struct to get list of deleted BasicService instances // ListDeletedRequest struct to get list of deleted BasicService instances
@@ -16,6 +18,10 @@ type ListDeletedRequest struct {
// Required: false // Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -27,6 +33,11 @@ type ListDeletedRequest struct {
// ListDeleted gets list of deleted BasicService instances associated with the specified Resource Group // ListDeleted gets list of deleted BasicService instances associated with the specified Resource Group
func (b BService) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListBasicServices, error) { func (b BService) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListBasicServices, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/bservice/listDeleted" url := "/cloudapi/bservice/listDeleted"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -93,7 +93,7 @@ type RecordBasicService struct {
// Main information about Compute // Main information about Compute
type ItemCompute struct { type ItemCompute struct {
// Account ID // Account ID
AccountID uint64 AccountID uint64 `json:"accountId"`
// Architecture // Architecture
Architecture string `json:"arch"` Architecture string `json:"arch"`
@@ -295,6 +295,9 @@ type ItemGroupCompute struct {
// List of information about OS Users // List of information about OS Users
OSUsers ListOSUsers `json:"osUsers"` OSUsers ListOSUsers `json:"osUsers"`
//Chipset
Chipset string `json:"chipset"`
} }
// List of Group Computes // List of Group Computes

View File

@@ -38,8 +38,9 @@ type AffinityRuleAddRequest struct {
Key string `url:"key" json:"key" validate:"required"` Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule // Value that must match the key to be taken into account when analyzing this rule
// Required: true // Required: false
Value string `url:"value" json:"value" validate:"required"` // Not required on purpose: despite required tag on platform, empty string is allowed
Value string `url:"value" json:"value"`
} }
// AffinityRuleAdd add affinity rule // AffinityRuleAdd add affinity rule

View File

@@ -38,8 +38,9 @@ type AffinityRuleRemoveRequest struct {
Key string `url:"key" json:"key" validate:"required"` Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule // Value that must match the key to be taken into account when analyzing this rule
// Required: true // Required: false
Value string `url:"value" json:"value" validate:"required"` // Not required on purpose: despite required tag on platform, empty string is allowed
Value string `url:"value" json:"value"`
} }
// AffinityRuleRemove remove affinity rule // AffinityRuleRemove remove affinity rule

View File

@@ -38,8 +38,9 @@ type AntiAffinityRuleAddRequest struct {
Key string `url:"key" json:"key" validate:"required"` Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule // Value that must match the key to be taken into account when analyzing this rule
// Required: true // Required: false
Value string `url:"value" json:"value" validate:"required"` // Not required on purpose: despite required tag on platform, empty string is allowed
Value string `url:"value" json:"value"`
} }
// AntiAffinityRuleAdd add anti affinity rule // AntiAffinityRuleAdd add anti affinity rule

View File

@@ -38,8 +38,9 @@ type AntiAffinityRuleRemoveRequest struct {
Key string `url:"key" json:"key" validate:"required"` Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule // Value that must match the key to be taken into account when analyzing this rule
// Required: true // Required: false
Value string `url:"value" json:"value" validate:"required"` // Not required on purpose: despite required tag on platform, empty string is allowed
Value string `url:"value" json:"value"`
} }
// AntiAffinityRuleRemove remove anti affinity rule // AntiAffinityRuleRemove remove anti affinity rule

View File

@@ -8,25 +8,25 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// RepairBootFSRequest struct to repair filesystem // BootDiskSetRequest struct to set boot disk for compute
type RepairBootFSRequest struct { type BootDiskSetRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Reason for action // ID of the disk to set as boot
// Required: false // Required: true
Reason string `url:"reason,omitempty" json:"reason,omitempty"` DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
} }
// RepairBootFS repairs compute boot disk filesystem // BootDiskSet sets boot disk for compute
func (c Compute) RepairBootFS(ctx context.Context, req RepairBootFSRequest) (bool, error) { func (c Compute) BootDiskSet(ctx context.Context, req BootDiskSetRequest) (bool, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err)) return false, validators.ValidationErrors(validators.GetErrors(err))
} }
url := "/cloudbroker/compute/repairBootFs" url := "/cloudapi/compute/bootDiskSet"
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 {

View File

@@ -0,0 +1,54 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ChangeIPRequest struct to change IP for network
type ChangeIPRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
// Network type
// 'EXTNET' for connect to external network directly
// 'VINS' for connect to ViNS
// Required: true
NetType string `url:"net_type" json:"net_type" validate:"computeNetType"`
// Network ID for connect to
// For EXTNET - external network ID
// For VINS - VINS ID
// Required: true
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
// IP address to which we will change the existing one, it must be from the same subnet
// Required: true
IPAddr string `url:"ip_addr" json:"ip_addr" validate:"required"`
}
// ChangeIP change reserved IP for compute instance
func (c Compute) ChangeIP(ctx context.Context, req ChangeIPRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/changeIp"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,46 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ChangeMACRequest struct to change MAC for network
type ChangeMACRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
// Current mac address
// Required: true
СurrentMAC string `url:"current_mac_address" json:"current_mac_address" validate:"required"`
// the MAC address to which we will change the existing one
// Required: true
NewMAC string `url:"new_mac_address" json:"new_mac_address" validate:"required"`
}
// ChangeMAC change MAC for compute instance
func (c Compute) ChangeMAC(ctx context.Context, req ChangeMACRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/changeMac"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -25,6 +25,11 @@ type CloneRequest struct {
// Name of the parent's snapshot to create clone from // Name of the parent's snapshot to create clone from
// Required: false // Required: false
SnapshotName string `url:"snapshotName,omitempty" json:"snapshotName,omitempty"` SnapshotName string `url:"snapshotName,omitempty" json:"snapshotName,omitempty"`
// true ignore that the compute is running
// Default: false
// Required: false
Force bool `url:"force" json:"force"`
} }
// Clone clones compute instance // Clone clones compute instance

View File

@@ -23,7 +23,7 @@ type CreateTemplateRequest struct {
type wrapperCreateTemplateRequest struct { type wrapperCreateTemplateRequest struct {
CreateTemplateRequest CreateTemplateRequest
Async bool `url:"async"` AsyncMode bool `url:"asyncMode"`
} }
// CreateTemplate create template from compute instance // CreateTemplate create template from compute instance
@@ -35,7 +35,7 @@ func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest)
reqWrapped := wrapperCreateTemplateRequest{ reqWrapped := wrapperCreateTemplateRequest{
CreateTemplateRequest: req, CreateTemplateRequest: req,
Async: false, AsyncMode: false,
} }
url := "/cloudapi/compute/createTemplate" url := "/cloudapi/compute/createTemplate"
@@ -62,7 +62,7 @@ func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequ
reqWrapped := wrapperCreateTemplateRequest{ reqWrapped := wrapperCreateTemplateRequest{
CreateTemplateRequest: req, CreateTemplateRequest: req,
Async: true, AsyncMode: true,
} }
url := "/cloudapi/compute/createTemplate" url := "/cloudapi/compute/createTemplate"

View File

@@ -0,0 +1,112 @@
package compute
import (
"context"
"net/http"
"strconv"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CreateTemplateFromBlankRequest struct to create template from boot disk of current compute
type CreateTemplateFromBlankRequest struct {
// ID of the compute to create template from
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name of the rescue disk
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Boot type of image BIOS or UEFI
// Required: true
BootType string `url:"boottype" json:"boottype" validate:"imageBootType"`
// Image type linux, windows or other
// Required: true
ImageType string `url:"imagetype" json:"imagetype" validate:"imageType"`
// Username for the image
// Required: false
Username string `url:"username,omitempty" json:"username,omitempty"`
// Password for the image
// Required: false
Password string `url:"password,omitempty" json:"password,omitempty"`
// Account ID to make the image exclusive
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// SEP ID
// Required: false
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Pool for image create
// Required: false
PoolName string `url:"poolName,omitempty" json:"poolName,omitempty"`
// Does this machine supports hot resize
// Default: false
// Required: false
HotResize bool `url:"hotresize" json:"hotresize"`
}
type wrapperCreateTemplateFromBlankRequest struct {
CreateTemplateFromBlankRequest
AsyncMode bool `url:"asyncMode"`
}
// CreateTemplateFromBlank creates template from boot disk of current compute in sync mode.
// It returns id of created compute and error.
func (c Compute) CreateTemplateFromBlank(ctx context.Context, req CreateTemplateFromBlankRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperCreateTemplateFromBlankRequest{
CreateTemplateFromBlankRequest: req,
AsyncMode: false,
}
url := "/cloudapi/compute/createTemplateFromBlank"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}
// CreateTemplateFromBlankAsync creates template from boot disk of current compute in async mode.
// It returns guid of task and error.
func (c Compute) CreateTemplateFromBlankAsync(ctx context.Context, req CreateTemplateFromBlankRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperCreateTemplateFromBlankRequest{
CreateTemplateFromBlankRequest: req,
AsyncMode: true,
}
url := "/cloudapi/compute/createTemplateFromBlank"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,53 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DiskMigrateRequest struct to migrate compute's disk to target disk
type DiskMigrateRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID source disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// ID target disk
// Required: true
TargetDiskID uint64 `url:"targetDiskId" json:"targetDiskId" validate:"required"`
// Migration mode. 1 - Data migration and domain update were already completed by third-party software.
// Use this if target disk already connected to compute and you only need to save changes for next reboot.
// Required: false
Mode int64 `url:"mode,omitempty" json:"mode,omitempty"`
}
// DiskMigrate - migrate compute's disk to target disk. Source disk will be detached, target disk will be attached to the same PCI slot.
// (WARNING) Current realisation is limited. No actual data migration will be performed.
// Use this API if target disk already connected to compute and you only need to save changes for next reboot (mode: 1).
func (c Compute) DiskMigrate(ctx context.Context, req DiskMigrateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/diskMigrate"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,46 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DiskSwitchToReplicationRequest struct to switch disk to it's replication
type DiskSwitchToReplicationRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to switch
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Delete replication relationship
// Required: false
StopReplication bool `url:"stopReplication" json:"stopReplication"`
}
// DiskSwitchToReplication switches disk to it's replication
func (c Compute) DiskSwitchToReplication(ctx context.Context, req DiskSwitchToReplicationRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/diskSwitchToReplication"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -48,8 +48,7 @@ var computes = ListComputes{
Devices: nil, Devices: nil,
Disks: []InfoDisk{ Disks: []InfoDisk{
{ {
ID: 65191, ID: 65191,
PCISlot: 6,
}, },
}, },
Driver: "KVM_X86", Driver: "KVM_X86",
@@ -64,7 +63,7 @@ var computes = ListComputes{
MigrationJob: 0, MigrationJob: 0,
Milestones: 363500, Milestones: 363500,
Name: "test", Name: "test",
Pinned: false, PinnedToStack: true,
RAM: 4096, RAM: 4096,
ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e", ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e",
Registered: true, Registered: true,
@@ -111,8 +110,7 @@ var computes = ListComputes{
Devices: nil, Devices: nil,
Disks: []InfoDisk{ Disks: []InfoDisk{
{ {
ID: 65248, ID: 65248,
PCISlot: 6,
}, },
}, },
Driver: "KVM_X86", Driver: "KVM_X86",
@@ -127,10 +125,10 @@ var computes = ListComputes{
MigrationJob: 0, MigrationJob: 0,
Milestones: 363853, Milestones: 363853,
Name: "compute_2", Name: "compute_2",
Pinned: false,
RAM: 4096, RAM: 4096,
ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff", ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff",
Registered: true, Registered: true,
PinnedToStack: true,
ResName: "compute-48556", ResName: "compute-48556",
RGID: 79727, RGID: 79727,
RGName: "sdk_negative_fields_test", RGName: "sdk_negative_fields_test",

View File

@@ -42,7 +42,7 @@ func (c Compute) GetLogGet(ctx context.Context, req GetLogRequest) (string, erro
return "", validators.ValidationErrors(validators.GetErrors(err)) return "", validators.ValidationErrors(validators.GetErrors(err))
} }
url := "/cloudapi//compute/getLog" url := "/cloudapi/compute/getLog"
res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req) res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil { if err != nil {

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListRequest struct to get list of available computes // ListRequest struct to get list of available computes
@@ -52,6 +54,10 @@ type ListRequest struct {
// Required: false // Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"` IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -64,6 +70,7 @@ type ListRequest struct {
// List gets list of the available computes. // List gets list of the available computes.
// Filtering based on status is possible // Filtering based on status is possible
func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, error) { func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, error) {
res, err := c.ListRaw(ctx, req) res, err := c.ListRaw(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -81,6 +88,11 @@ func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, erro
// ListRaw gets list of the available computes. // ListRaw gets list of the available computes.
func (c Compute) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) { func (c Compute) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/list" url := "/cloudapi/compute/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListDeletedRequest struct to get deleted computes list // ListDeletedRequest struct to get deleted computes list
@@ -44,6 +46,10 @@ type ListDeletedRequest struct {
// Required: false // Required: false
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"` ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -55,6 +61,11 @@ type ListDeletedRequest struct {
// ListDeleted gets list all deleted computes // ListDeleted gets list all deleted computes
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListComputes, error) { func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListComputes, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/listDeleted" url := "/cloudapi/compute/listDeleted"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -30,6 +30,10 @@ type ListPCIDeviceRequest struct {
// Required: false // Required: false
Status string `url:"status,omitempty" json:"status,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -41,6 +45,7 @@ type ListPCIDeviceRequest struct {
// ListPCIDevice gets list PCI device // ListPCIDevice gets list PCI device
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) (*ListPCIDevices, 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err)) return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -26,6 +26,10 @@ type ListVGPURequest struct {
// Required: false // Required: false
Status string `url:"status,omitempty" json:"status,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -41,6 +45,7 @@ type ListVGPURequest struct {
// ListVGPU gets list vGPU // ListVGPU gets list vGPU
func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) (*ListVGPUs, 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err)) return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -214,6 +214,9 @@ type RecordNetAttach struct {
// List VNF IDs // List VNF IDs
VNFs []uint64 `json:"vnfs"` VNFs []uint64 `json:"vnfs"`
// Maximum transmission unit
MTU uint64 `json:"mtu"`
} }
// Detailed information about audit // Detailed information about audit
@@ -296,15 +299,27 @@ type RecordCompute struct {
// List anti affinity rules // List anti affinity rules
AntiAffinityRules ListRules `json:"antiAffinityRules"` AntiAffinityRules ListRules `json:"antiAffinityRules"`
// Auto start when node restarted
AutoStart bool `json:"autoStart"`
// Architecture // Architecture
Architecture string `json:"arch"` Architecture string `json:"arch"`
// Boot order // Boot order
BootOrder []string `json:"bootOrder"` BootOrder []string `json:"bootOrder"`
// Boot type
BootType string `json:"bootType"`
// Boot disk size // Boot disk size
BootDiskSize uint64 `json:"bootdiskSize"` BootDiskSize uint64 `json:"bootdiskSize"`
// CD Image Id
CdImageId uint64 `json:"cdImageId"`
// Chipset
Chipset string `json:"chipset"`
// Clone reference // Clone reference
CloneReference uint64 `json:"cloneReference"` CloneReference uint64 `json:"cloneReference"`
@@ -314,6 +329,9 @@ type RecordCompute struct {
// Compute CI ID // Compute CI ID
ComputeCIID uint64 `json:"computeciId"` ComputeCIID uint64 `json:"computeciId"`
// CPU Pin
CPUPin bool `json:"cpupin"`
// Number of cores // Number of cores
CPU uint64 `json:"cpus"` CPU uint64 `json:"cpus"`
@@ -350,6 +368,12 @@ type RecordCompute struct {
// GUID // GUID
GUID uint64 `json:"guid"` GUID uint64 `json:"guid"`
// HPBacked
HPBacked bool `json:"hpBacked"`
// Hot resize
HotResize bool `json:"hotResize"`
// ID // ID
ID uint64 `json:"id"` ID uint64 `json:"id"`
@@ -362,6 +386,9 @@ type RecordCompute struct {
// List interfaces // List interfaces
Interfaces ListInterfaces `json:"interfaces"` Interfaces ListInterfaces `json:"interfaces"`
// Loader type
LoaderType string `json:"loaderType"`
// Lock status // Lock status
LockStatus string `json:"lockStatus"` LockStatus string `json:"lockStatus"`
@@ -380,6 +407,18 @@ type RecordCompute struct {
// Name // Name
Name string `json:"name"` Name string `json:"name"`
// NeedReboot
NeedReboot bool `json:"needReboot"`
// Network interface naming
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
// Numa Affinity
NumaAffinity string `json:"numaAffinity"`
//NumaNodeId
NumaNodeId int64 `json:"numaNodeId"`
// Natable VINS ID // Natable VINS ID
NatableVINSID uint64 `json:"natableVinsId"` NatableVINSID uint64 `json:"natableVinsId"`
@@ -398,8 +437,11 @@ type RecordCompute struct {
// List OS Users // List OS Users
OSUsers ListOSUser `json:"osUsers"` OSUsers ListOSUser `json:"osUsers"`
// Pinned or not // Pinned to stack
Pinned bool `json:"pinned"` PinnedToStack bool `json:"pinnedToStack"`
// PreferredCPU
PreferredCPU []int64 `json:"preferredCpu"`
// Number of RAM // Number of RAM
RAM uint64 `json:"ram"` RAM uint64 `json:"ram"`
@@ -413,6 +455,9 @@ type RecordCompute struct {
// Resource name // Resource name
ResName string `json:"resName"` ResName string `json:"resName"`
// Reserved Node Cpus
ReservedNodeCpus []uint64 `json:"reservedNodeCpus"`
// Resource group ID // Resource group ID
RGID uint64 `json:"rgId"` RGID uint64 `json:"rgId"`
@@ -457,6 +502,33 @@ type RecordCompute struct {
// Virtual image name // Virtual image name
VirtualImageName string `json:"virtualImageName"` VirtualImageName string `json:"virtualImageName"`
// VNC password
VNCPassword string `json:"vncPasswd"`
}
// Information about libvirt settings
type LibvirtSettings struct {
// TX mode
TXMode string `json:"txmode"`
// IO event
IOEventFD string `json:"ioeventfd"`
// Event ID
EventIDx string `json:"event_idx"`
// Number of queues
Queues uint64 `json:"queues"`
// RX queue size
RXQueueSize uint64 `json:"rx_queue_size"`
// TX queue size
TXQueueSize uint64 `json:"tx_queue_size"`
// GUID
GUID string `json:"guid"`
} }
// Main information about OS user // Main information about OS user
@@ -497,6 +569,9 @@ type ListSnapSets []ItemSnapSet
// Main information about VNF // Main information about VNF
type ItemVNFInterface struct { type ItemVNFInterface struct {
// Bus number
BusNumber uint64 `json:"bus_number"`
// Connection ID // Connection ID
ConnID uint64 `json:"connId"` ConnID uint64 `json:"connId"`
@@ -521,9 +596,15 @@ type ItemVNFInterface struct {
// Listen SSH or not // Listen SSH or not
ListenSSH bool `json:"listenSsh"` ListenSSH bool `json:"listenSsh"`
// Libvirt Settings
LibvirtSettings LibvirtSettings `json:"libvirtSettings"`
// MAC // MAC
MAC string `json:"mac"` MAC string `json:"mac"`
// Maximum transmission unit
MTU uint64 `json:"mtu"`
// Name // Name
Name string `json:"name"` Name string `json:"name"`
@@ -536,6 +617,9 @@ type ItemVNFInterface struct {
// Network type // Network type
NetType string `json:"netType"` NetType string `json:"netType"`
// NodeID
NodeID int64 `json:"nodeId"`
// PCI slot // PCI slot
PCISlot int64 `json:"pciSlot"` PCISlot int64 `json:"pciSlot"`
@@ -579,6 +663,9 @@ type ItemComputeDisk struct {
// Boot partition // Boot partition
BootPartition uint64 `json:"bootPartition"` BootPartition uint64 `json:"bootPartition"`
// Bus number
BusNumber uint64 `json:"bus_number"`
// Created time // Created time
CreatedTime uint64 `json:"createdTime"` CreatedTime uint64 `json:"createdTime"`
@@ -637,13 +724,13 @@ type ItemComputeDisk struct {
Passwd string `json:"passwd"` Passwd string `json:"passwd"`
// PCI slot // PCI slot
PCISlot int64 `json:"pciSlot"` PCISlot int64 `json:"pci_slot"`
// Pool // Pool
Pool string `json:"pool"` Pool string `json:"pool"`
// Present to // Present to
PresentTo []uint64 `json:"presentTo"` PresentTo map[string]uint64 `json:"presentTo"`
// Purge time // Purge time
PurgeTime uint64 `json:"purgeTime"` PurgeTime uint64 `json:"purgeTime"`
@@ -651,6 +738,9 @@ type ItemComputeDisk struct {
// Reality device number // Reality device number
RealityDeviceNumber uint64 `json:"realityDeviceNumber"` RealityDeviceNumber uint64 `json:"realityDeviceNumber"`
// Replication
Replication ItemReplication `json:"replication"`
// Resource ID // Resource ID
ResID string `json:"resId"` ResID string `json:"resId"`
@@ -663,6 +753,9 @@ type ItemComputeDisk struct {
// Shareable // Shareable
Shareable bool `json:"shareable"` Shareable bool `json:"shareable"`
// Size available
SizeAvailable uint64 `json:"sizeAvailable"`
// Size max // Size max
SizeMax uint64 `json:"sizeMax"` SizeMax uint64 `json:"sizeMax"`
@@ -681,10 +774,33 @@ type ItemComputeDisk struct {
// Type // Type
Type string `json:"type"` Type string `json:"type"`
// Updated by
UpdatedBy uint64 `json:"updatedBy"`
// Virtual machine ID // Virtual machine ID
VMID uint64 `json:"vmid"` VMID uint64 `json:"vmid"`
} }
type ItemReplication struct {
// DiskID
DiskID uint64 `json:"diskId"`
// PoolID
PoolID string `json:"poolId"`
// Role
Role string `json:"role"`
// SelfVolumeID
SelfVolumeID string `json:"selfVolumeId"`
// StorageID
StorageID string `json:"storageId"`
// VolumeID
VolumeID string `json:"volumeId"`
}
// Main information about snapshot extend // Main information about snapshot extend
type SnapshotExtend struct { type SnapshotExtend struct {
// GUID // GUID
@@ -758,6 +874,7 @@ type IOTune struct {
type ItemCompute struct { type ItemCompute struct {
// Access Control List // Access Control List
ACL ListACL `json:"acl"` ACL ListACL `json:"acl"`
// Account ID // Account ID
AccountID uint64 `json:"accountId"` AccountID uint64 `json:"accountId"`
@@ -776,15 +893,27 @@ type ItemCompute struct {
// List anti affinity rules // List anti affinity rules
AntiAffinityRules ListRules `json:"antiAffinityRules"` AntiAffinityRules ListRules `json:"antiAffinityRules"`
// Auto start when node restarted
AutoStart bool `json:"autoStart"`
// Architecture // Architecture
Architecture string `json:"arch"` Architecture string `json:"arch"`
// Boot order // Boot order
BootOrder []string `json:"bootOrder"` BootOrder []string `json:"bootOrder"`
// Boot type
BootType string `json:"bootType"`
// Boot disk size // Boot disk size
BootDiskSize uint64 `json:"bootdiskSize"` BootDiskSize uint64 `json:"bootdiskSize"`
// CD Image Id
CdImageId uint64 `json:"cdImageId"`
// Chipset
Chipset string `json:"chipset"`
// Clone reference // Clone reference
CloneReference uint64 `json:"cloneReference"` CloneReference uint64 `json:"cloneReference"`
@@ -794,6 +923,9 @@ type ItemCompute struct {
// Compute CI ID // Compute CI ID
ComputeCIID uint64 `json:"computeciId"` ComputeCIID uint64 `json:"computeciId"`
// CPU Pin
CPUPin bool `json:"cpupin"`
// Number of cores // Number of cores
CPU uint64 `json:"cpus"` CPU uint64 `json:"cpus"`
@@ -830,6 +962,12 @@ type ItemCompute struct {
// GUID // GUID
GUID uint64 `json:"guid"` GUID uint64 `json:"guid"`
// Hot resize
HotResize bool `json:"hotResize"`
// HPBacked
HPBacked bool `json:"hpBacked"`
// ID // ID
ID uint64 `json:"id"` ID uint64 `json:"id"`
@@ -839,6 +977,9 @@ type ItemCompute struct {
// List interfaces // List interfaces
Interfaces ListInterfaces `json:"interfaces"` Interfaces ListInterfaces `json:"interfaces"`
// Loader type
LoaderType string `json:"loaderType"`
// Lock status // Lock status
LockStatus string `json:"lockStatus"` LockStatus string `json:"lockStatus"`
@@ -857,8 +998,23 @@ type ItemCompute struct {
// Name // Name
Name string `json:"name"` Name string `json:"name"`
// Pinned or not // NeedReboot
Pinned bool `json:"pinned"` NeedReboot bool `json:"needReboot"`
// network interface naming
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
// Numa Affinity
NumaAffinity string `json:"numaAffinity"`
//NumaNodeId
NumaNodeId int64 `json:"numaNodeId"`
// Pinned to stack
PinnedToStack bool `json:"pinnedToStack"`
// PreferredCPU
PreferredCPU []int64 `json:"preferredCpu"`
// Number of RAM // Number of RAM
RAM uint64 `json:"ram"` RAM uint64 `json:"ram"`
@@ -872,6 +1028,9 @@ type ItemCompute struct {
// Resource name // Resource name
ResName string `json:"resName"` ResName string `json:"resName"`
// Reserved Node Cpus
ReservedNodeCpus []uint64 `json:"reservedNodeCpus"`
// Resource group ID // Resource group ID
RGID uint64 `json:"rgId"` RGID uint64 `json:"rgId"`
@@ -925,9 +1084,6 @@ type ListInfoDisks []InfoDisk
type InfoDisk struct { type InfoDisk struct {
// ID // ID
ID uint64 `json:"id"` ID uint64 `json:"id"`
// PCISlot
PCISlot int64 `json:"pciSlot"`
} }
// List information about computes // List information about computes
@@ -942,16 +1098,106 @@ type ListComputes struct {
// List VGPUs // List VGPUs
type ListVGPUs struct { type ListVGPUs struct {
// Data // Data
Data []interface{} `json:"data"` Data []ItemVGPU `json:"data"`
// Entry count // Entry count
EntryCount uint64 `json:"entryCount"` EntryCount uint64 `json:"entryCount"`
} }
// Main information about vgpu device
type ItemVGPU struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Created Time
CreatedTime uint64 `json:"createdTime"`
// Deleted Time
DeletedTime uint64 `json:"deletedTime"`
// GID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Last Claimed By
LastClaimedBy uint64 `json:"lastClaimedBy"`
// Last Update Time
LastUpdateTime uint64 `json:"lastUpdateTime"`
// Mode
Mode string `json:"mode"`
// PCI Slot
PCISlot uint64 `json:"pciSlot"`
// PGPUID
PGPUID uint64 `json:"pgpuid"`
// Profile ID
ProfileID uint64 `json:"profileId"`
// RAM
RAM uint64 `json:"ram"`
// Reference ID
ReferenceID string `json:"referenceId"`
// RG ID
RGID uint64 `json:"rgId"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// VM ID
VMID uint64 `json:"vmid"`
}
// Main information about PCI device
type ItemPCIDevice struct {
// Compute ID
ComputeID uint64 `json:"computeId"`
// Description
Description string `json:"description"`
// GUID
GUID uint64 `json:"guid"`
// HwPath
HwPath string `json:"hwPath"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Stack ID
StackID uint64 `json:"stackId"`
// Status
Status string `json:"status"`
// System name
SystemName string `json:"systemName"`
}
// List PCI devices // List PCI devices
type ListPCIDevices struct { type ListPCIDevices struct {
// Data // Data
Data []interface{} `json:"data"` Data []ItemPCIDevice `json:"data"`
// Entry count // Entry count
EntryCount uint64 `json:"entryCount"` EntryCount uint64 `json:"entryCount"`

View File

@@ -16,9 +16,11 @@ type NetAttachRequest struct {
// Network type // Network type
// 'EXTNET' for connect to external network directly // 'EXTNET' for connect to external network directly
// and 'VINS' for connect to ViNS // 'VINS' for connect to ViNS
// 'VFNIC' for connect to vfpool
// 'DPDK' for connect to DPDK
// Required: true // Required: true
NetType string `url:"netType" json:"netType" validate:"computeNetType"` NetType string `url:"netType" json:"netType" validate:"computex86NetType"`
// Network ID for connect to // Network ID for connect to
// For EXTNET - external network ID // For EXTNET - external network ID
@@ -29,6 +31,14 @@ type NetAttachRequest struct {
// Directly required IP address for new network interface // Directly required IP address for new network interface
// Required: false // Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"` IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// MAC address
// Required: false
MACAddr string `url:"mac_addr,omitempty" json:"mac_addr,omitempty"`
// Used only for DPDK type, must be 1-9216
// Required: false
MTU uint64 `url:"mtu,omitempty" json:"mtu,omitempty" validate:"omitempty,mtu"`
} }
// NetAttach attaches network to compute and gets info about network // NetAttach attaches network to compute and gets info about network

View File

@@ -24,8 +24,8 @@ type PFWAddRequest struct {
PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"` PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
// Internal base port number // Internal base port number
// Required: true // Required: false
LocalBasePort uint64 `url:"localBasePort" json:"localBasePort" validate:"required"` LocalBasePort uint64 `url:"localBasePort,omitempty" json:"localBasePort,omitempty"`
// Network protocol // Network protocol
// either "tcp" or "udp" // either "tcp" or "udp"

View File

@@ -13,25 +13,30 @@ type PinToStackRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Auto start when node restarted
// Required: false
// Default: false
AutoStart bool `url:"autoStart" json:"autoStart"`
} }
// PinToStack pin compute to current stack // PinToStack pin compute to current stack
func (c Compute) PinToStack(ctx context.Context, req PinToStackRequest) (uint64, error) { func (c Compute) PinToStack(ctx context.Context, req PinToStackRequest) (bool, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err)) return false, validators.ValidationErrors(validators.GetErrors(err))
} }
url := "/cloudapi/compute/pinToStack" url := "/cloudapi/compute/pinToStack"
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 0, err return false, err
} }
result, err := strconv.ParseUint(string(res), 10, 64) result, err := strconv.ParseBool(string(res))
if err != nil { if err != nil {
return 0, err return false, err
} }
return result, nil return result, nil

View File

@@ -27,6 +27,20 @@ type ResizeRequest struct {
// Force compute resize // Force compute resize
// Required: false // Required: false
Force bool `url:"force,omitempty" json:"force,omitempty"` Force bool `url:"force,omitempty" json:"force,omitempty"`
// Recommended isolated CPUs. Field is ignored if compute.cpupin=False or compute.pinned=False
// Required: false
PreferredCPU []int64 `url:"preferredCpu,omitempty" json:"preferredCpu,omitempty" validate:"omitempty,preferredCPU"`
}
// GetRAM returns RAM field values
func (r ResizeRequest) GetRAM() map[string]uint64 {
res := make(map[string]uint64, 1)
res["RAM"] = r.RAM
return res
} }
// Resize resizes compute instance // Resize resizes compute instance

View File

@@ -3,7 +3,6 @@ package compute
import ( import (
"context" "context"
"net/http" "net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
@@ -19,24 +18,52 @@ type SnapshotDeleteRequest struct {
Label string `url:"label" json:"label" validate:"required"` Label string `url:"label" json:"label" validate:"required"`
} }
type wrapperSnapshotDeleteRequeststruct struct {
SnapshotDeleteRequest
AsyncMode bool `url:"asyncMode"`
}
// SnapshotDelete deletes specified compute snapshot // SnapshotDelete deletes specified compute snapshot
func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) { func (c Compute) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (string, error) {
err := validators.ValidateRequest(req) err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err)) return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperSnapshotDeleteRequeststruct{
SnapshotDeleteRequest: req,
AsyncMode: false,
} }
url := "/cloudapi/compute/snapshotDelete" url := "/cloudapi/compute/snapshotDelete"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil { if err != nil {
return false, err return "", err
} }
result, err := strconv.ParseBool(string(res)) return string(res), nil
if err != nil { }
return false, err
} // SnapshotDeleteAsync deletes specified compute snapshot
func (c Compute) SnapshotDeleteAsync(ctx context.Context, req SnapshotDeleteRequest) (string, error) {
return result, nil err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
reqWrapped := wrapperSnapshotDeleteRequeststruct{
SnapshotDeleteRequest: req,
AsyncMode: true,
}
url := "/cloudapi/compute/snapshotDelete"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
return string(res), nil
} }

View File

@@ -21,6 +21,53 @@ type UpdateRequest struct {
// New description // New description
// Required: false // Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"` Description string `url:"desc,omitempty" json:"desc,omitempty"`
// Rule for VM placement with NUMA affinity.
// Possible values - none (placement without NUMA affinity),
// strict (strictly with NUMA affinity, if not possible - do not start VM),
// loose (use NUMA affinity if possible)
// Required: false
// Default: none
NumaAffinity string `url:"numaAffinity,omitempty" json:"numaAffinity,omitempty" validate:"omitempty,numaAffinity"`
// Run VM on dedicated CPUs. To use this feature, the system must be pre-configured by allocating CPUs on the physical node
// Required: false
// Default: false
CPUPin bool `url:"cpupin" json:"cpupin"`
// Type of the emulated system, Q35 or i440fx
// Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"omitempty,chipset"`
// Use Huge Pages to allocate RAM of the virtual machine. The system must be pre-configured by allocating Huge Pages on the physical node
// Required: false
// Default: false
HPBacked bool `url:"hpBacked" json:"hpBacked"`
// Auto start when node restarted
// Required: false
// Default: false
AutoStart bool `url:"autoStart" json:"autoStart"`
// Recommended isolated CPUs. Field is ignored if compute.cpupin=False or compute.pinned=False
// Required: false
PreferredCPU []int64 `url:"preferredCpu,omitempty" json:"preferredCpu,omitempty" validate:"omitempty,preferredCPU"`
// VM type linux, windows or unknown
// Required: false
LoaderType string `url:"loaderType,omitempty" json:"loaderType,omitempty" validate:"omitempty,loaderType"`
// Boot type of image bios or uefi
// Required: false
BootType string `url:"bootType,omitempty" json:"bootType,omitempty" validate:"omitempty,imageBootType"`
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming.
// Required: false
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
// Does this machine supports hot resize
// Required: false
HotResize bool `url:"hotResize,omitempty" json:"hotResize,omitempty"`
} }
// Update updates some properties of the compute // Update updates some properties of the compute

View File

@@ -3,8 +3,9 @@ package disks
import ( import (
"context" "context"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// CreateRequest struct to create disk // CreateRequest struct to create disk
@@ -13,10 +14,6 @@ type CreateRequest struct {
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// ID of the grid (platform)
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// Name of disk // Name of disk
// Required: true // Required: true
Name string `url:"name" json:"name" validate:"required"` Name string `url:"name" json:"name" validate:"required"`
@@ -29,17 +26,6 @@ type CreateRequest struct {
// Required: false // Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"` Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Type of disk
// - B=Boot
// - D=Data
// - T=Temp
// Required: true
Type string `url:"type" json:"type" validate:"diskType"`
// Size in GB default is 0
// Required: false
SSDSize uint64 `url:"ssdSize,omitempty" json:"ssdSize,omitempty"`
// Max IOPS disk can perform defaults to 2000 // Max IOPS disk can perform defaults to 2000
// Required: false // Required: false
IOPS uint64 `url:"iops,omitempty" json:"iops,omitempty"` IOPS uint64 `url:"iops,omitempty" json:"iops,omitempty"`

View File

@@ -21,10 +21,6 @@ type DeleteRequest struct {
// Whether to completely delete the disk, works only with non attached disks // Whether to completely delete the disk, works only with non attached disks
// Required: false // Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"` Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
// Reason to delete
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
// Delete deletes disk by ID // Delete deletes disk by ID

View File

@@ -14,10 +14,6 @@ type DisksDeleteRequest struct {
// Required: true // Required: true
DisksIDs []uint64 `url:"diskIds" json:"diskIds" validate:"required"` DisksIDs []uint64 `url:"diskIds" json:"diskIds" validate:"required"`
// Reason for deleting the disks
// Required: true
Reason string `url:"reason" json:"reason" validate:"required"`
// Whether to completely delete the disks, works only with non attached disks // Whether to completely delete the disks, works only with non attached disks
// Required: false // Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"` Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`

View File

@@ -35,9 +35,9 @@ var disks = ListDisks{
ParentID: 0, ParentID: 0,
PCISlot: 6, PCISlot: 6,
Pool: "vmstor", Pool: "vmstor",
PresentTo: []uint64{ //PresentTo: []uint64{
27, // 27,
}, //},
PurgeTime: 0, PurgeTime: 0,
ResID: "sample", ResID: "sample",
ResName: "sample", ResName: "sample",
@@ -78,10 +78,10 @@ var disks = ListDisks{
ParentID: 0, ParentID: 0,
PCISlot: 6, PCISlot: 6,
Pool: "vmstor", Pool: "vmstor",
PresentTo: []uint64{ //PresentTo: []uint64{
27, // 27,
27, // 27,
}, //},
PurgeTime: 0, PurgeTime: 0,
ResID: "sample", ResID: "sample",
ResName: "sample", ResName: "sample",
@@ -211,9 +211,9 @@ var searchDisks = ListSearchDisks{
ParentID: 0, ParentID: 0,
PCISlot: 6, PCISlot: 6,
Pool: "vmstor", Pool: "vmstor",
PresentTo: []uint64{ //PresentTo: []uint64{
27, // 27,
}, //},
PurgeTime: 0, PurgeTime: 0,
ResID: "sample", ResID: "sample",
ResName: "sample", ResName: "sample",
@@ -254,10 +254,10 @@ var searchDisks = ListSearchDisks{
ParentID: 0, ParentID: 0,
PCISlot: 6, PCISlot: 6,
Pool: "vmstor", Pool: "vmstor",
PresentTo: []uint64{ //PresentTo: []uint64{
27, // 27,
27, // 27,
}, //},
PurgeTime: 0, PurgeTime: 0,
ResID: "sample", ResID: "sample",
ResName: "sample", ResName: "sample",
@@ -393,7 +393,7 @@ var unattachedDisks = ListDisksUnattached{
Password: "", Password: "",
PCISlot: -1, PCISlot: -1,
Pool: "data05", Pool: "data05",
PresentTo: []uint64{}, PresentTo: map[string]uint64{},
PurgeAttempts: 0, PurgeAttempts: 0,
PurgeTime: 0, PurgeTime: 0,
RealityDeviceNumber: 0, RealityDeviceNumber: 0,
@@ -445,10 +445,10 @@ var unattachedDisks = ListDisksUnattached{
Password: "", Password: "",
PCISlot: -1, PCISlot: -1,
Pool: "data05", Pool: "data05",
PresentTo: []uint64{ //PresentTo: []uint64{
27, // 27,
27, // 27,
}, //},
PurgeAttempts: 0, PurgeAttempts: 0,
PurgeTime: 0, PurgeTime: 0,
RealityDeviceNumber: 0, RealityDeviceNumber: 0,

View File

@@ -0,0 +1,126 @@
package disks
import (
"context"
"net/http"
"strconv"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// FromPlatformDiskRequest struct to create template from platform disk
type FromPlatformDiskRequest struct {
// ID of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Name of the rescue disk
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Boot type of image BIOS or UEFI
// Required: true
BootType string `url:"boottype" json:"boottype" validate:"imageBootType"`
// Image type linux, windows or other
// Required: true
ImageType string `url:"imagetype" json:"imagetype" validate:"imageType"`
// Binary architecture of this image
// Should be:
// - X86_64
// Required: true
Architecture string `url:"architecture" json:"architecture" validate:"imageArchitecture"`
// Username for the image
// Required: false
Username string `url:"username,omitempty" json:"username,omitempty"`
// Password for the image
// Required: false
Password string `url:"password,omitempty" json:"password,omitempty"`
// Account ID to make the image exclusive
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// SEP ID
// Required: false
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Pool for image create
// Required: false
PoolName string `url:"poolName,omitempty" json:"poolName,omitempty"`
// List of types of compute suitable for image
// Example: [ "KVM_X86" ]
// Required: true
Drivers []string `url:"drivers" json:"drivers" validate:"required"`
// Does this machine supports hot resize
// Required: false
HotResize bool `url:"hotresize" json:"hotresize"`
// Bootable image
// Required: true
Bootable bool `url:"bootable" json:"bootable"`
}
type wrapperFromPlatformDiskRequest struct {
FromPlatformDiskRequest
AsyncMode bool `url:"asyncMode"`
}
// FromPlatformDisk creates template from platform disk in sync mode.
// It returns id of created disk and error.
func (d Disks) FromPlatformDisk(ctx context.Context, req FromPlatformDiskRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/fromPlatformDisk"
reqWrapped := wrapperFromPlatformDiskRequest{
FromPlatformDiskRequest: req,
AsyncMode: false,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}
// FromPlatformDiskAsync creates template from platform disk in async mode.
// It returns guid of task and error.
func (d Disks) FromPlatformDiskAsync(ctx context.Context, req FromPlatformDiskRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/fromPlatformDisk"
reqWrapped := wrapperFromPlatformDiskRequest{
FromPlatformDiskRequest: req,
AsyncMode: true,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListRequest struct to get list of disks // ListRequest struct to get list of disks
@@ -30,7 +32,7 @@ type ListRequest struct {
// Find by shared, true or false // Find by shared, true or false
// Required: false // Required: false
Shared bool `url:"shared,omitempty" json:"shared,omitempty"` Shared interface{} `url:"shared,omitempty" json:"shared,omitempty" validate:"omitempty,isBool"`
// ID of the account the disks belong to // ID of the account the disks belong to
// Required: false // Required: false
@@ -48,6 +50,10 @@ type ListRequest struct {
// Required: false // Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"` Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -59,6 +65,7 @@ type ListRequest struct {
// List gets list of the created disks belonging to an account as a ListDisks struct // List gets list of the created disks belonging to an account as a ListDisks struct
func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) { func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) {
res, err := d.ListRaw(ctx, req) res, err := d.ListRaw(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -76,6 +83,11 @@ func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) {
// ListRaw gets list of the created disks belonging to an account as an array of bytes // ListRaw gets list of the created disks belonging to an account as an array of bytes
func (d Disks) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) { func (d Disks) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/list" url := "/cloudapi/disks/list"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListDeletedRequest struct to get list of deleted disks // ListDeletedRequest struct to get list of deleted disks
@@ -26,7 +28,7 @@ type ListDeletedRequest struct {
// Find by shared, true or false // Find by shared, true or false
// Required: false // Required: false
Shared bool `url:"shared,omitempty" json:"shared,omitempty"` Shared interface{} `url:"shared,omitempty" json:"shared,omitempty" validate:"omitempty,isBool"`
// ID of the account the disks belong to // ID of the account the disks belong to
// Required: false // Required: false
@@ -36,6 +38,10 @@ type ListDeletedRequest struct {
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -47,6 +53,11 @@ type ListDeletedRequest struct {
// ListDeleted gets list the deleted disks belonging to an account // ListDeleted gets list the deleted disks belonging to an account
func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListDisks, error) { func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListDisks, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/listDeleted" url := "/cloudapi/disks/listDeleted"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -4,13 +4,19 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListTypesRequest struct to get list types of disks // ListTypesRequest struct to get list types of disks
type ListTypesRequest struct { 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"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
@@ -23,6 +29,11 @@ type ListTypesRequest struct {
// ListTypes gets list defined disk types // ListTypes gets list defined disk types
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) (*ListTypes, error) { func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) (*ListTypes, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
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)

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListUnattachedRequest struct to get list of unattached disk // ListUnattachedRequest struct to get list of unattached disk
@@ -40,6 +42,10 @@ type ListUnattachedRequest struct {
// Required: false // Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"` Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -51,6 +57,11 @@ type ListUnattachedRequest struct {
// ListUnattached gets list of unattached disks // ListUnattached gets list of unattached disks
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (*ListDisksUnattached, error) { func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (*ListDisksUnattached, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/listUnattached" url := "/cloudapi/disks/listUnattached"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -14,9 +14,15 @@ type ItemDisk struct {
// Computes // Computes
Computes map[string]string `json:"computes"` Computes map[string]string `json:"computes"`
//Created by
CreatedBy string `json:"createdBy"`
// Created time // Created time
CreatedTime uint64 `json:"createdTime"` CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time // Deleted time
DeletedTime uint64 `json:"deletedTime"` DeletedTime uint64 `json:"deletedTime"`
@@ -50,6 +56,9 @@ type ItemDisk struct {
// Machine name // Machine name
MachineName string `json:"machineName"` MachineName string `json:"machineName"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name // Name
Name string `json:"name"` Name string `json:"name"`
@@ -69,11 +78,14 @@ type ItemDisk struct {
Pool string `json:"pool"` Pool string `json:"pool"`
// Present to // Present to
PresentTo []uint64 `json:"presentTo"` PresentTo map[string]uint64 `json:"presentTo"`
// Purge time // Purge time
PurgeTime uint64 `json:"purgeTime"` PurgeTime uint64 `json:"purgeTime"`
// Replication
Replication ItemReplication `json:"replication"`
// Resource ID // Resource ID
ResID string `json:"resId"` ResID string `json:"resId"`
@@ -92,6 +104,9 @@ type ItemDisk struct {
// SepID // SepID
SepID uint64 `json:"sepId"` SepID uint64 `json:"sepId"`
// Size available
SizeAvailable uint64 `json:"sizeAvailable"`
// Size max // Size max
SizeMax uint64 `json:"sizeMax"` SizeMax uint64 `json:"sizeMax"`
@@ -112,6 +127,12 @@ type ItemDisk struct {
// Virtual machine ID // Virtual machine ID
VMID uint64 `json:"vmid"` VMID uint64 `json:"vmid"`
// Update time
UpdatedTime uint64 `json:"updatedTime"`
// Updated by
UpdatedBy string `json:"updatedBy"`
} }
type ItemDiskUnattached struct { type ItemDiskUnattached struct {
@@ -197,7 +218,7 @@ type ItemDiskUnattached struct {
Pool string `json:"pool"` Pool string `json:"pool"`
// Present to // Present to
PresentTo []uint64 `json:"presentTo"` PresentTo map[string]uint64 `json:"presentTo"`
// Purge attempts // Purge attempts
PurgeAttempts uint64 `json:"purgeAttempts"` PurgeAttempts uint64 `json:"purgeAttempts"`
@@ -262,8 +283,10 @@ type ListDisks struct {
// List of unattached disks // List of unattached disks
type ListDisksUnattached struct { type ListDisksUnattached struct {
// Data
Data []ItemDiskUnattached `json:"data"` Data []ItemDiskUnattached `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"` EntryCount uint64 `json:"entryCount"`
} }
@@ -349,9 +372,15 @@ type RecordDisk struct {
// Computes // Computes
Computes map[string]string `json:"computes"` Computes map[string]string `json:"computes"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time // Created time
CreatedTime uint64 `json:"createdTime"` CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time // Deleted time
DeletedTime uint64 `json:"deletedTime"` DeletedTime uint64 `json:"deletedTime"`
@@ -379,6 +408,15 @@ type RecordDisk struct {
// IOTune // IOTune
IOTune IOTune `json:"iotune"` IOTune IOTune `json:"iotune"`
// Machine ID
MachineID uint64 `json:"machineId"`
// Machine name
MachineName string `json:"machineName"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name // Name
Name string `json:"name"` Name string `json:"name"`
@@ -398,11 +436,14 @@ type RecordDisk struct {
Pool string `json:"pool"` Pool string `json:"pool"`
// Present to // Present to
PresentTo []uint64 `json:"presentTo"` PresentTo map[string]uint64 `json:"presentTo"`
// Purge time // Purge time
PurgeTime uint64 `json:"purgeTime"` PurgeTime uint64 `json:"purgeTime"`
// Replication
Replication ItemReplication `json:"replication"`
// Resource ID // Resource ID
ResID string `json:"resId"` ResID string `json:"resId"`
@@ -421,6 +462,9 @@ type RecordDisk struct {
// Shareable // Shareable
Shareable bool `json:"shareable"` Shareable bool `json:"shareable"`
// Size available
SizeAvailable uint64 `json:"sizeAvailable"`
// Size max // Size max
SizeMax uint64 `json:"sizeMax"` SizeMax uint64 `json:"sizeMax"`
@@ -441,6 +485,32 @@ type RecordDisk struct {
// Virtual machine ID // Virtual machine ID
VMID uint64 `json:"vmid"` VMID uint64 `json:"vmid"`
// Update time
UpdatedTime uint64 `json:"updatedTime"`
// Updated by
UpdatedBy string `json:"updatedBy"`
}
type ItemReplication struct {
// DiskID
DiskID uint64 `json:"diskId"`
// PoolID
PoolID string `json:"poolId"`
// Role
Role string `json:"role"`
// SelfVolumeID
SelfVolumeID string `json:"selfVolumeId"`
// StorageID
StorageID string `json:"storageId"`
// VolumeID
VolumeID string `json:"volumeId"`
} }
type ListTypes struct { type ListTypes struct {

View File

@@ -0,0 +1,52 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ReplicateRequest struct to create an empty disk in chosen SEP and pool combination.
type ReplicateRequest struct {
// Id of the disk to replicate. This disk will become master in replication
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Name of replica disk to create
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// ID of SEP to create slave disk
// Required: true
SepID uint64 `url:"sepId" json:"sepId" validate:"required"`
// Pool name to create slave disk in
// Required: true
PoolName string `url:"poolName" json:"poolName" validate:"required"`
}
// Create an empty disk in chosen SEP and pool combination.
// Starts replication between chosen disk and newly created disk
// Note: only TATLIN type SEP are supported for replications between
func (d Disks) Replicate(ctx context.Context, req ReplicateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicate"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ReplicationResume struct to resume suspended replication
type ReplicationResumeRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationResume resume suspended replication
func (d Disks) ReplicationResume(ctx context.Context, req ReplicationResumeRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationResume"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ReplicationReverseRequest struct to change role between disks replications
type ReplicationReverseRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationReverse change role between disks replications
func (d Disks) ReplicationReverse(ctx context.Context, req ReplicationReverseRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationReverse"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,43 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ReplicationStartRequest struct to starts replication between two chosen disks
type ReplicationStartRequest struct {
// Id of the disk to replicate. Primary disk in replication
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// ID of target disk. Secondary disk in replication
// Required: true
TargetDiskID uint64 `url:"targetDiskId" json:"targetDiskId" validate:"required"`
}
// ReplicationStart starts replication between two chosen disks. It's required for both disks to have same size to avoid replication conflicts
// Note: Source disk's SEP and target SEP supported only of TATLIN type.
func (d Disks) ReplicationStart(ctx context.Context, req ReplicationStartRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationStart"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,32 @@
package disks
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ReplicationStatusRequest struct to get replication status
type ReplicationStatusRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationStatus get replication status
func (d Disks) ReplicationStatus(ctx context.Context, req ReplicationStatusRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationStatus"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ReplicationStopRequest struct to remove replication between disks completely
type ReplicationStopRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationStop remove replication between disks completely
func (d Disks) ReplicationStop(ctx context.Context, req ReplicationStopRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationStop"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ReplicationSuspendRequest struct to pause replication with possibility to resume from pause moment
type ReplicationSuspendRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationSuspend pause replication with possibility to resume from pause moment
func (d Disks) ReplicationSuspend(ctx context.Context, req ReplicationSuspendRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationSuspend"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -19,31 +19,6 @@ type ResizeRequest struct {
Size uint64 `url:"size" json:"size" validate:"required"` Size uint64 `url:"size" json:"size" validate:"required"`
} }
// Resize resizes disk
// Returns 200 if disk is resized online, else will return 202,
// in that case please stop and start your machine after changing the disk size, for your changes to be reflected.
// This method will not be used for disks, assigned to computes. Only unassigned disks and disks, assigned with "old" virtual machines.
func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/resize"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
// Resize2 resize disk // Resize2 resize disk
// Returns 200 if disk is resized online, else will return 202, // Returns 200 if disk is resized online, else will return 202,
// in that case please stop and start your machine after changing the disk size, for your changes to be reflected. // in that case please stop and start your machine after changing the disk size, for your changes to be reflected.

View File

@@ -13,10 +13,6 @@ type RestoreRequest struct {
// ID of the disk to restore // ID of the disk to restore
// Required: true // Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"` DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Reason for restoring the disk
// Required: true
Reason string `url:"reason" json:"reason" validate:"required"`
} }
// Restore restores a deleted unattached disk from recycle bin // Restore restores a deleted unattached disk from recycle bin

View File

@@ -18,6 +18,14 @@ type SearchRequest struct {
// If false, then disks having one of the statuses are not listed // If false, then disks having one of the statuses are not listed
// Required: false // Required: false
ShowAll bool `url:"show_all,omitempty" json:"show_all,omitempty"` ShowAll bool `url:"show_all,omitempty" json:"show_all,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"`
} }
// Search searches disks // Search searches disks

8
pkg/cloudapi/dpdknet.go Normal file
View File

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

View File

@@ -0,0 +1,15 @@
package dpdknet
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to DPDK network
type DPDKNet struct {
client interfaces.Caller
}
// Builder for dpdk endpoints
func New(client interfaces.Caller) *DPDKNet {
return &DPDKNet{
client,
}
}

View File

@@ -0,0 +1,46 @@
package dpdknet
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get information about DPDK network
type GetRequest struct {
// ID of the DPDK network
// Required: true
DPDKID uint64 `url:"dpdkId" json:"dpdkId" validate:"required"`
}
// Get DPDK network details as a RecordDPDKNet struct
func (d DPDKNet) Get(ctx context.Context, req GetRequest) (*RecordDPDKNet, error) {
res, err := d.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordDPDKNet{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets DPDK network details as an array of bytes
func (d DPDKNet) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/dpdknet/get"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,79 @@
package dpdknet
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListRequest struct to get list of DPDK networks
type ListRequest struct {
// Find by id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by gid
// Required: false
GID uint64 `url:"gid,omitempty" json:"gid,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by description
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by computeIDs
// Required: false
ComputeIDs []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of the created DPDK networks belonging to an account as a ListDPDKNet struct
func (d DPDKNet) List(ctx context.Context, req ListRequest) (*ListDPDKNet, error) {
res, err := d.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListDPDKNet{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of the created DPDK networks belonging to an account as an array of bytes
func (d DPDKNet) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/dpdknet/list"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,92 @@
package dpdknet
// Detailed information about DPDK network
type RecordDPDKNet struct {
// List of accounts with access
AccountAccess []uint64 `json:"accountAccess"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Description
Description string `json:"description"`
// Grid ID
GID uint64 `json:"gid"`
// Guid ID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// List of resource groups with access
RGAccess []uint64 `json:"rgAccess"`
// Status
Status string `json:"status"`
// OVS bridge
OVSBridge string `json:"ovsBridge"`
// Vlan ID
VlanID uint64 `json:"vlanId"`
// Compute IDs
ComputeIDs []uint64 `json:"computeIds"`
}
type ListDPDKNet struct {
// Data
Data []ItemDPDKNet `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
type ItemDPDKNet struct {
// List of accounts with access
AccountAccess []uint64 `json:"accountAccess"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Description
Description string `json:"description"`
// Grid ID
GID uint64 `json:"gid"`
// Guid ID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// List of resource groups with access
RGAccess []uint64 `json:"rgAccess"`
// Status
Status string `json:"status"`
// OVS bridge
OVSBridge string `json:"ovsBridge"`
// Vlan ID
VlanID uint64 `json:"vlanId"`
// Compute IDs
ComputeIDs []uint64 `json:"computeIds"`
}

View File

@@ -0,0 +1,50 @@
package extnet
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get information about reserved address or address poll
type GetReservedIP struct {
// AccountID of the account whose reservation information we want to receive
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Field for specifying the ID of extnet whose reservation information we want to receive
// Required: false
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
}
// GetReservedIP gets information about reserved address or address poll as a slice of RecordReservedIP struct
func (e ExtNet) GetReservedIP(ctx context.Context, req GetReservedIP) ([]RecordReservedIP, error) {
res, err := e.GetReservedIPRaw(ctx, req)
if err != nil {
return nil, err
}
reservedIP := make([]RecordReservedIP, 0)
err = json.Unmarshal(res, &reservedIP)
if err != nil {
return nil, err
}
return reservedIP, nil
}
// GetRaw gets detailed information about external network as an array of bytes
func (e ExtNet) GetReservedIPRaw(ctx context.Context, req GetReservedIP) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/extnet/getReservedIp"
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListRequest struct to get list of external network // ListRequest struct to get list of external network
@@ -36,6 +38,10 @@ type ListRequest struct {
// Required: false // Required: false
Status string `url:"status,omitempty" json:"status,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -43,10 +49,15 @@ type ListRequest 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"`
//openVswitch bridge name
//Required: false
OVSBridge string `url:"ovsBridge,omitempty" json:"ovsBridge,omitempty"`
} }
// List gets list of all available external networks as a ListExtNets struct // List gets list of all available external networks as a ListExtNets struct
func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNets, error) { func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNets, error) {
res, err := e.ListRaw(ctx, req) res, err := e.ListRaw(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -64,6 +75,11 @@ func (e ExtNet) List(ctx context.Context, req ListRequest) (*ListExtNets, error)
// ListRaw gets list of all available external networks as an array of bytes // ListRaw gets list of all available external networks as an array of bytes
func (e ExtNet) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) { func (e ExtNet) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/extnet/list" url := "/cloudapi/extnet/list"
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -22,6 +22,10 @@ type ListComputesRequest struct {
// Required: false // Required: false
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"` ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -33,6 +37,7 @@ type ListComputesRequest struct {
// 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err)) return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -87,6 +87,9 @@ type QOS struct {
// Main information about reservations // Main information about reservations
type ItemReservation struct { type ItemReservation struct {
// Account ID
AccountID uint64 `json:"account_id"`
// ClientType // ClientType
ClientType string `json:"clientType"` ClientType string `json:"clientType"`
@@ -170,7 +173,7 @@ type RecordExtNet struct {
Excluded []Excluded `json:"excluded"` Excluded []Excluded `json:"excluded"`
// Free IPs // Free IPs
FreeIPs uint64 `json:"free_ips"` FreeIPs int64 `json:"free_ips"`
// Gateway // Gateway
Gateway string `json:"gateway"` Gateway string `json:"gateway"`
@@ -199,6 +202,9 @@ type RecordExtNet struct {
// Network ID // Network ID
NetworkID uint64 `json:"networkId"` NetworkID uint64 `json:"networkId"`
// NTP
NTP []string `json:"ntp"`
// OVS Bridge // OVS Bridge
OVSBridge string `json:"ovsBridge"` OVSBridge string `json:"ovsBridge"`
@@ -226,3 +232,20 @@ type RecordExtNet struct {
// VNFs // VNFs
VNFs VNFs `json:"vnfs"` VNFs VNFs `json:"vnfs"`
} }
// Detailed information about reserved address or address pool
type RecordReservedIP struct {
ExtnetID int `json:"extnet_id"`
Reservations []Reservations `json:"reservations"`
}
type Reservations struct {
AccountID int `json:"account_id"`
ClientType string `json:"clientType"`
DomainName string `json:"domainname"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
Mac string `json:"mac"`
Type string `json:"type"`
VMID int `json:"vmId"`
}

View File

@@ -4,6 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// ListRequest struct to get list of FLIPGroup available to the current user // ListRequest struct to get list of FLIPGroup available to the current user
@@ -28,6 +30,10 @@ type ListRequest struct {
// Required: false // Required: false
ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"` ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"`
// Find by accountId
// Required: false
AccountId uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by resource group ID // Find by resource group ID
// Required: false // Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"` RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
@@ -36,6 +42,10 @@ type ListRequest struct {
// Required: false // Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"` ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by list of clientIds
// Required: false
ClientIDs []uint64 `url:"clientIds,omitempty" json:"clientIds,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"`
@@ -43,10 +53,23 @@ type ListRequest 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"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Find by connId
// Required: false
ConnId uint64 `url:"connId,omitempty" json:"connId,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
} }
// List gets list of FLIPGroup managed cluster instances available to the current user as a ListFLIPGroups struct // List gets list of FLIPGroup managed cluster instances available to the current user as a ListFLIPGroups struct
func (f FLIPGroup) List(ctx context.Context, req ListRequest) (*ListFLIPGroups, error) { func (f FLIPGroup) List(ctx context.Context, req ListRequest) (*ListFLIPGroups, error) {
res, err := f.ListRaw(ctx, req) res, err := f.ListRaw(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -64,6 +87,11 @@ func (f FLIPGroup) List(ctx context.Context, req ListRequest) (*ListFLIPGroups,
// ListRaw gets list of FLIPGroup managed cluster instances available to the current user as an array of bytes // ListRaw gets list of FLIPGroup managed cluster instances available to the current user as an array of bytes
func (f FLIPGroup) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) { func (f FLIPGroup) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/flipgroup/list" url := "/cloudapi/flipgroup/list"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -18,10 +18,6 @@ type CreateRequest struct {
// Required: true // Required: true
URL string `url:"url" json:"url" validate:"required,url"` URL string `url:"url" json:"url" validate:"required,url"`
// Grid (platform) ID where this template should be create in
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// Boot type of image bios or UEFI // Boot type of image bios or UEFI
// Required: true // Required: true
BootType string `url:"boottype" json:"boottype" validate:"required,imageBootType"` BootType string `url:"boottype" json:"boottype" validate:"required,imageBootType"`
@@ -34,6 +30,17 @@ type CreateRequest struct {
// Required: true // Required: true
ImageType string `url:"imagetype" json:"imagetype" validate:"required,imageType"` ImageType string `url:"imagetype" json:"imagetype" validate:"required,imageType"`
// Account ID to make the image exclusive
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming
// Should be:
// - eth
// - ens (default value)
// Required: false
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
// Does this machine supports hot resize // Does this machine supports hot resize
// Required: false // Required: false
HotResize bool `url:"hotresize,omitempty" json:"hotresize,omitempty"` HotResize bool `url:"hotresize,omitempty" json:"hotresize,omitempty"`
@@ -46,10 +53,6 @@ type CreateRequest struct {
// Required: false // Required: false
Password string `url:"password,omitempty" json:"password,omitempty"` Password string `url:"password,omitempty" json:"password,omitempty"`
// Account ID to make the image exclusive
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Username for upload binary media // Username for upload binary media
// Required: false // Required: false
UsernameDL string `url:"usernameDL,omitempty" json:"usernameDL,omitempty"` UsernameDL string `url:"usernameDL,omitempty" json:"usernameDL,omitempty"`
@@ -69,7 +72,6 @@ type CreateRequest struct {
// Binary architecture of this image // Binary architecture of this image
// Should be: // Should be:
// - X86_64 // - X86_64
// - PPC64_LE
// Required: false // Required: false
Architecture string `url:"architecture,omitempty" json:"architecture,omitempty" validate:"omitempty,imageArchitecture"` Architecture string `url:"architecture,omitempty" json:"architecture,omitempty" validate:"omitempty,imageArchitecture"`

View File

@@ -13,10 +13,6 @@ type DeleteRequest struct {
// ID of the image to delete // ID of the image to delete
// Required: true // Required: true
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"` ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
// Whether to completely delete the image
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
} }
// Delete deletes image by ID // Delete deletes image by ID

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